⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 folderdata.java

📁 moblie syncml mail javame
💻 JAVA
字号:
/*
 * Funambol is a mobile platform developed by Funambol, Inc. 
 * Copyright (C) 2003 - 2007 Funambol, Inc.
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Affero General Public License version 3 as published by
 * the Free Software Foundation with the addition of the following permission 
 * added to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED
 * WORK IN WHICH THE COPYRIGHT IS OWNED BY FUNAMBOL, FUNAMBOL DISCLAIMS THE 
 * WARRANTY OF NON INFRINGEMENT  OF THIRD PARTY RIGHTS.
 * 
 * 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 Affero General Public License 
 * along with this program; if not, see http://www.gnu.org/licenses or write to
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301 USA.
 * 
 * You can contact Funambol, Inc. headquarters at 643 Bair Island Road, Suite 
 * 305, Redwood City, CA 94063, USA, or at email address info@funambol.com.
 * 
 * The interactive user interfaces in modified source and object code versions
 * of this program must display Appropriate Legal Notices, as required under
 * Section 5 of the GNU Affero General Public License version 3.
 * 
 * In accordance with Section 7(b) of the GNU Affero General Public License
 * version 3, these Appropriate Legal Notices must retain the display of the
 * "Powered by Funambol" logo. If the display of the logo is not reasonably 
 * feasible for technical reasons, the Appropriate Legal Notices must display
 * the words "Powered by Funambol".
 */

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 + -