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

📄 mailsyncfilter.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 java.util.Date;

import com.funambol.mailclient.MailFilter;
import com.funambol.syncml.protocol.SyncFilter;
import com.funambol.util.MailDateFormatter;
import com.funambol.util.DateUtil;

/**
 * This class implements the interface <i>SyncFilter</i> to apply a 
 * MailFilter to the SyncML stack.
 */
public class MailSyncFilter extends MailFilter implements SyncFilter {
    
    //-------------------------------------------------------------- Attributes

    /**
     * If this field is set, retrieve the specified message only.
     */
    private String luid;

    //------------------------------------------------------------ Constructors

    /**
     * Default constructor. 
     */
    public MailSyncFilter() {
        super();
        luid = null;
    }

    /** 
     * Copy constructor from a MailFilter object. Used to create a new
     * MailSyncFilter with a defined MailFilter.
     */
    public MailSyncFilter(MailFilter ref) {
        super(ref);
        luid = null;
    }

    /**
     * Single message filter. Initialize a filter to get a single message using
     * the id as key. By default, the entire message is retrieved, but it's
     * possible to limit it changing the other parameters.
     */
    public MailSyncFilter(String luid) {
        super();
        this.luid = luid;
    }

    //---------------------------------------------------------- Public Methods

    /**
     * Return the LUID of the single message to be retrieved
     */
    public String getLuid() {
        return luid;
    }

    /**
     * Set the message id of the single message to be retrieved
     */
    public void setLuid(String luid) {
        this.luid = luid;
    }

    /**
     * Override equals method to compare two filters
     */
    public boolean equals(MailSyncFilter f) {
        if(!super.equals(f)) {
            return false;
        }
        if(this.luid == null) {
            if(f.luid != null) return false;
        }
        else {
            if(!this.luid.equals(f.luid)) {
                return false;
            }
        }
        return true;
    }

    /**
     * Format the Filter in SyncML syntax, according to the parameter
     * contained in the SyncFilter implementation.
     * @return the SyncML filter to add to the Alert command.
     */
    public String toSyncML() {
        return toSyncML(0);
    }

    /**
     * Format the Filter in SyncML syntax. This is done according to the
     * parameter contained in the SyncFilter implementation, but with a size
     * limit forced by the sync engine. This limit is usually maxMsgSize
     * or MaxObjSize.
     *
     * @return the SyncML filter to add to the Alert command.
     */
    public String toSyncML(int maxSize) {

        Date date = getDate();
        int size = getSize();

        // A maximum size is sent by the SyncManager, use it as a limit.
        if(maxSize > 0) {
            if(size == 0 || size > maxSize) {
                size = maxSize;
            }
        }
        else if(luid == null) {
            // If no limit is sent by the engine, and the filter is the
            // full one, not inclusive, return an empty string
            if(this.equals(new MailSyncFilter())) {
                return "";
            }
        }

        StringBuffer ret = new StringBuffer("<Filter>");

        if(luid != null || date != null) {
            // Set Record Filter
            ret.append("<Record><Item><Meta>\n").
                append("<Type xmlns=\"syncml:metinf\">").
                append("syncml:filtertype-cgi</Type>\n").
                append("</Meta>\n<Data><![CDATA[");

            // If the message id is present, get that only, otherwise
            // use the date, if present
            if (luid != null) {
                ret.append("&LUID&iEQ;"+luid);
            }
            else if (date != null) {
                Date gmt = new DateUtil(date).toGMT().getTime();
                ret.append("modified&iGE;"+MailDateFormatter.dateToUTC(gmt));
            }

            ret.append("]]></Data>\n</Item></Record>\n");
        }

        // Set field-level filter.
        ret.append("<Field><Item><Meta>\n").
            append("<Type xmlns=\"syncml:metinf\">").
            append("application/vnd.syncml-devinf+xml</Type>\n").
            append("</Meta>\n<Data><Property>\n<PropName>emailitem</PropName>\n").
            append("<MaxSize>").append(size).append("</MaxSize>\n").
            append("<PropParam><ParamName>texttype</ParamName></PropParam>\n");

        if(downloadAttachments()) {
            ret.append("<PropParam><ParamName>attachtype</ParamName>").
                append("</PropParam>\n");
        }
        
        ret.append("</Property>\n</Data>\n</Item>\n</Field>\n");

        // Set INCLUSIVE if luid is set
        if (luid != null) {
            ret.append("<FilterType>INCLUSIVE</FilterType>\n");
        }

        ret.append("</Filter>");

        return ret.toString();
    }

/*

Esclusivo:


<Record><Item><Meta><Type xmlns="syncml:metinf">syncml:filtertype-cgi</Type>
</Meta>
<Data><![CDATA[modified&iGE;20061201T000000Z]]></Data>
</Item>
</Record>
<Field><Item><Meta><Type xmlns="syncml:metinf">application/vnd.syncml-devinf+xml</Type>
</Meta>
<Data><Property><PropName>emailitem</PropName>
<MaxSize>491520</MaxSize>
<PropParam><ParamName>texttype</ParamName>
</PropParam>
</Property>
</Data>
</Item>
</Field>

Inclusivo:

<Record><Item><Meta><Type xmlns="syncml:metinf">syncml:filtertype-cgi</Type>
</Meta>
<Data><![CDATA[&LUID&iEQ;I/AAAAAKMAADQCAAAAAAAAACEAAAA=]]></Data>
</Item>
</Record>
<Field><Item><Meta><Type xmlns="syncml:metinf">application/vnd.syncml-devinf+xml</Type>
</Meta>
<Data><Property><PropName>emailitem</PropName>
<MaxSize>491520</MaxSize>
<PropParam><ParamName>texttype</ParamName>
</PropParam>
<PropParam><ParamName>attachtype</ParamName>
</PropParam>
</Property>
</Data>
</Item>
</Field>
<FilterType>INCLUSIVE</FilterType>

     */

     

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -