FileDocCategorySizeDatePackage
VCalParser.javaAPI DocAndroid 1.5 API3856Wed May 06 22:41:56 BST 2009android.syncml.pim.vcalendar

VCalParser

public class VCalParser extends Object

Fields Summary
private static final String
TAG
public static final String
VERSION_VCALENDAR10
public static final String
VERSION_VCALENDAR20
private android.syncml.pim.VParser
mParser
private String
mVersion
Constructors Summary
public VCalParser()


      
    
Methods Summary
private voidjudgeVersion(java.lang.String vcalStr)
If version not given. Search from vcal string of the VERSION property. Then instance mParser to appropriate parser.


        if (mVersion == null) {
            int versionIdx = vcalStr.indexOf("\nVERSION:");

            mVersion = VERSION_VCALENDAR10;

            if (versionIdx != -1){
                String versionStr = vcalStr.substring(
                        versionIdx, vcalStr.indexOf("\n", versionIdx + 1));
                if (versionStr.indexOf("2.0") > 0)
                    mVersion = VERSION_VCALENDAR20;
            }
        }
        if (mVersion.equals(VERSION_VCALENDAR10))
            mParser = new VCalParser_V10();
        if (mVersion.equals(VERSION_VCALENDAR20))
            mParser = new VCalParser_V20();
    
public booleanparse(java.lang.String vcalendarStr, android.syncml.pim.VDataBuilder builder)


        vcalendarStr = verifyVCal(vcalendarStr);
        try{
            boolean isSuccess = mParser.parse(
                    new ByteArrayInputStream(vcalendarStr.getBytes()),
                    "US-ASCII", builder);

            if (!isSuccess) {
                if (mVersion.equals(VERSION_VCALENDAR10)) {
                    if(Config.LOGD)
                        Log.d(TAG, "Parse failed for vCal 1.0 parser."
                            + " Try to use 2.0 parser.");
                    mVersion = VERSION_VCALENDAR20;
                    return parse(vcalendarStr, builder);
                }else
                    throw new VCalException("parse failed.(even use 2.0 parser)");
            }
        }catch (IOException e){
            throw new VCalException(e.getMessage());
        }
        return true;
    
private java.lang.StringverifyVCal(java.lang.String vcalStr)
Verify vCalendar string, and initialize mVersion according to it.


        //Version check
        judgeVersion(vcalStr);

        vcalStr = vcalStr.replaceAll("\r\n", "\n");
        String[] strlist = vcalStr.split("\n");

        StringBuilder replacedStr = new StringBuilder();

        for (int i = 0; i < strlist.length; i++) {
            if (strlist[i].indexOf(":") < 0) {
                if (strlist[i].length() == 0 && strlist[i + 1].indexOf(":") > 0)
                    replacedStr.append(strlist[i]).append("\r\n");
                else
                    replacedStr.append(" ").append(strlist[i]).append("\r\n");
            } else
                replacedStr.append(strlist[i]).append("\r\n");
        }
        if(Config.LOGD)Log.d(TAG, "After verify:\r\n" + replacedStr.toString());

        return replacedStr.toString();