FileDocCategorySizeDatePackage
VCardParser_V30.javaAPI DocAndroid 1.5 API10107Wed May 06 22:41:56 BST 2009android.syncml.pim.vcard

VCardParser_V30

public class VCardParser_V30 extends VCardParser_V21
This class is used to parse vcard3.0.
Please refer to vCard Specification 3.0 (http://tools.ietf.org/html/rfc2426)

Fields Summary
private static final HashSet
acceptablePropsWithParam
private static final HashSet
sAcceptableEncodingV30
private static final HashSet
acceptablePropsWithoutParam
private String
mPreviousLine
Constructors Summary
Methods Summary
protected java.lang.StringgetBase64(java.lang.String firstString)
vCard 3.0 does not require two CRLF at the last of BASE64 data. It only requires that data should be MIME-encoded.

        StringBuilder builder = new StringBuilder();
        builder.append(firstString);
        
        while (true) {
            String line = getLine();
            if (line == null) {
                throw new VCardException(
                        "File ended during parsing BASE64 binary");
            }
            if (line.length() == 0) {
                break;
            } else if (!line.startsWith(" ") && !line.startsWith("\t")) {
                mPreviousLine = line;
                break;
            }
            builder.append(line);
        }
        
        return builder.toString();
    
protected java.lang.StringgetLine()

        if (mPreviousLine != null) {
            String ret = mPreviousLine;
            mPreviousLine = null;
            return ret;
        } else {
            return mReader.readLine();
        }
    
protected java.lang.StringgetNonEmptyLine()
vCard 3.0 requires that the line with space at the beginning of the line must be combined with previous line.

        String line;
        StringBuilder builder = null;
        while (true) {
            line = mReader.readLine();
            if (line == null) {
                if (builder != null) {
                    return builder.toString();
                } else if (mPreviousLine != null) {
                    String ret = mPreviousLine;
                    mPreviousLine = null;
                    return ret;
                }
                throw new VCardException("Reached end of buffer.");
            } else if (line.length() == 0) {
                if (builder != null) {
                    return builder.toString();
                } else if (mPreviousLine != null) {
                    String ret = mPreviousLine;
                    mPreviousLine = null;
                    return ret;
                }
            } else if (line.charAt(0) == ' " || line.charAt(0) == '\t") {
                if (builder != null) {
                    // TODO: Check whether MIME requires only one whitespace.
                    builder.append(line.substring(1));
                } else if (mPreviousLine != null) {
                    builder = new StringBuilder();
                    builder.append(mPreviousLine);
                    mPreviousLine = null;
                    builder.append(line.substring(1));
                } else {
                    throw new VCardException("Space exists at the beginning of the line");
                }
            } else {
                if (mPreviousLine == null) {
                    mPreviousLine = line;
                } else {
                    String ret = mPreviousLine;
                    mPreviousLine = line;
                    return ret;                    
                }
            }
        }
    
protected java.lang.StringgetVersion()

    
    
       
        return "3.0";
    
protected voidhandleAgent(java.lang.String propertyValue)

        // The way how vCard 3.0 supports "AGENT" is completely different from vCard 2.0.
        //
        // e.g.
        // AGENT:BEGIN:VCARD\nFN:Joe Friday\nTEL:+1-919-555-7878\n
        //  TITLE:Area Administrator\, Assistant\n EMAIL\;TYPE=INTERN\n
        //  ET:jfriday@host.com\nEND:VCARD\n
        //
        // TODO: fix this.
        //
        // issue:
        //  vCard 3.0 also allows this as an example.
        //
        // AGENT;VALUE=uri:
        //  CID:JQPUBLIC.part3.960129T083020.xyzMail@host3.com
        //
        // This is not VCARD. Should we support this?
        throw new VCardException("AGENT in vCard 3.0 is not supported yet.");
    
protected voidhandleAnyParam(java.lang.String paramName, java.lang.String paramValue)

        // vCard 3.0 accept comma-separated multiple values, but
        // current PropertyNode does not accept it.
        // For now, we do not split the values.
        //
        // TODO: fix this.
        super.handleAnyParam(paramName, paramValue);
    
protected voidhandleParams(java.lang.String params)
vCard 3.0 allows iana-token as paramType, while vCard 2.1 does not.

        try {
            super.handleParams(params);
        } catch (VCardException e) {
            // maybe IANA type
            String[] strArray = params.split("=", 2);
            if (strArray.length == 2) {
                handleAnyParam(strArray[0], strArray[1]);
            } else {
                // Must not come here in the current implementation.
                throw new VCardException(
                        "Unknown params value: " + params);
            }
        }
    
protected voidhandlePropertyValue(java.lang.String propertyName, java.lang.String propertyValue)

        if (mEncoding != null && mEncoding.equalsIgnoreCase("B")) {
            String result = getBase64(propertyValue);
            if (mBuilder != null) {
                ArrayList<String> v = new ArrayList<String>();
                v.add(result);
                mBuilder.propertyValues(v);
            }
        }
        
        super.handlePropertyValue(propertyName, propertyValue);
    
protected voidhandleType(java.lang.String ptypevalues)
vCard 3.0 defines param = param-name "=" param-value *("," param-value) param-name = iana-token / x-name param-value = ptext / quoted-string quoted-string = DQUOTE QSAFE-CHAR DQUOTE

        String[] ptypeArray = ptypevalues.split(",");
        mBuilder.propertyParamType("TYPE");
        for (String value : ptypeArray) {
            int length = value.length();
            if (length >= 2 && value.startsWith("\"") && value.endsWith("\"")) {
                mBuilder.propertyParamValue(value.substring(1, value.length() - 1));
            } else {
                mBuilder.propertyParamValue(value);
            }
        }
    
protected booleanisValidEncoding(java.lang.String encoding)

        return sAcceptableEncodingV30.contains(encoding.toUpperCase());
    
protected booleanisValidPropertyName(java.lang.String propertyName)

        return acceptablePropsWithParam.contains(propertyName) ||
            acceptablePropsWithoutParam.contains(propertyName);
    
protected java.lang.StringmaybeUnescapeText(java.lang.String text)
Return unescapeText(text). In vCard 3.0, 8bit text is always encoded.

        return unescapeText(text);
    
protected booleanreadBeginVCard()
vcard = [group "."] "BEGIN" ":" "VCARD" 1*CRLF 1*(contentline) ;A vCard object MUST include the VERSION, FN and N types. [group "."] "END" ":" "VCARD" 1*CRLF

        // TODO: vCard 3.0 supports group.
        return super.readBeginVCard();
    
protected voidreadEndVCard()

        // TODO: vCard 3.0 supports group.
        super.readEndVCard();
    
protected java.lang.StringunescapeText(java.lang.String text)
ESCAPED-CHAR = "\\" / "\;" / "\," / "\n" / "\N") ; \\ encodes \, \n or \N encodes newline ; \; encodes ;, \, encodes ,

        // In String#replaceAll(), "\\\\" means single slash. 
        return text.replaceAll("\\\\;", ";")
            .replaceAll("\\\\:", ":")
            .replaceAll("\\\\,", ",")
            .replaceAll("\\\\n", "\r\n")
            .replaceAll("\\\\N", "\r\n")
            .replaceAll("\\\\\\\\", "\\\\");