📄 folderdata.java
字号:
/*
* Copyright (C) 2006-2007 Funambol
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package com.funambol.mailclient.syncml;
import com.funambol.util.ChunkedString;
import java.util.Date;
import com.funambol.mail.Store;
import com.funambol.util.Log;
import com.funambol.util.XmlUtil;
import com.funambol.util.MailDateFormatter;
import com.funambol.util.XmlException;
/**
* This class is able to parse and format the OMA-DS 1.2 Folder object.
*/
class FolderData {
// ------------------------------------------------------- Private data
private static final String FOLDER_TAG = "Folder";
private static final String NAME_TAG = "name";
private static final String CREATED_TAG = "created";
private static final String ROLE_TAG = "role";
private String name;
private Date created;
private String role;
// ------------------------------------------------------- Constructors
/**
* Inizialize an empty instance
*/
public FolderData() {
this(null, null, null);
}
/**
* Inizialize an empty instance
*/
public FolderData(String name, Date created, String role) {
this.name = name;
this.created = created;
this.role = role;
}
// ---------------------------------------------------------- Accessors
/** Returns folder name */
public String getName() { return name; }
/** Returns the created time */
public Date getCreated() { return created; }
/** Returns the folder role */
public String getRole() { return role; }
/** Sets folder name */
public void setName(String name) { this.name = name; }
/** Sets the created time */
public void setCreated(Date created) { this.created = created; }
/** Sets the folder role */
public void setRole(String role) { this.role= role; }
// ----------------------------------------------------- Public Methods
/**
* Parse the item content.
*/
public void parse(byte[] syncmlData) throws XmlException {
ChunkedString xml = new ChunkedString(new String(syncmlData));
role = XmlUtil.getTagValue(xml, ROLE_TAG).toString();
//TODO: be careful while doing turkish localization: there are
//two different lowercase 'i' in turkey!
if (role.toLowerCase().equals(Store.INBOX.toLowerCase())) {
Log.debug("Folder Inbox from server");
name = Store.INBOX;
}
else if (role.toLowerCase().equals(Store.OUTBOX.toLowerCase())) {
Log.debug("Folder Outbox from server");
name = Store.OUTBOX;
}
else if (role.toLowerCase().equals(Store.DRAFTS.toLowerCase())) {
Log.debug("Folder Drafts from server");
name = Store.DRAFTS;
}
else if (role.toLowerCase().equals(Store.SENT.toLowerCase())) {
Log.debug("Folder Sent from server");
name = Store.SENT;
}
else {
throw new XmlException("Invalid folder from server:"+role);
}
created = MailDateFormatter.parseUTCDate(XmlUtil.getTagValue(xml, CREATED_TAG).toString());
}
/**
* Format the item content.
*/
public byte[] format() {
StringBuffer out = new StringBuffer("<Folder>\n");
XmlUtil.addElement(out, NAME_TAG, name);
String utcdate = MailDateFormatter.dateToUTC(created);
XmlUtil.addElement(out, CREATED_TAG, utcdate);
XmlUtil.addElement(out, ROLE_TAG, role);
out.append("</Folder>\n");
return out.toString().getBytes();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -