FileDocCategorySizeDatePackage
VCardSourceDetector.javaAPI DocAndroid 5.1 API7346Thu Mar 12 22:22:54 GMT 2015com.android.vcard

VCardSourceDetector

public class VCardSourceDetector extends Object implements VCardInterpreter

The class which tries to detects the source of a vCard file from its contents.

The specification of vCard (including both 2.1 and 3.0) is not so strict as to guess its format just by reading beginning few lines (usually we can, but in some most pessimistic case, we cannot until at almost the end of the file). Also we cannot store all vCard entries in memory, while there's no specification how big the vCard entry would become after the parse.

This class is usually used for the "first scan", in which we can understand which vCard version is used (and how many entries exist in a file).

Fields Summary
private static final String
LOG_TAG
private static Set
APPLE_SIGNS
private static Set
JAPANESE_MOBILE_PHONE_SIGNS
private static Set
WINDOWS_MOBILE_PHONE_SIGNS
private static Set
FOMA_SIGNS
private static String
TYPE_FOMA_CHARSET_SIGN
public static final int
PARSE_TYPE_UNKNOWN
Represents that no estimation is available. Users of this class is able to this constant when you don't want to let a vCard parser rely on estimation for parse type.
private static final int
PARSE_TYPE_APPLE
private static final int
PARSE_TYPE_MOBILE_PHONE_JP
private static final int
PARSE_TYPE_DOCOMO_FOMA
private static final int
PARSE_TYPE_WINDOWS_MOBILE_V65_JP
private int
mParseType
private int
mVersion
private String
mSpecifiedCharset
Constructors Summary
Methods Summary
public java.lang.StringgetEstimatedCharset()

Returns charset String guessed from the source's properties. This method must be called after parsing target file(s).

return
Charset String. Null is returned if guessing the source fails.

        if (TextUtils.isEmpty(mSpecifiedCharset)) {
            return mSpecifiedCharset;
        }
        switch (mParseType) {
            case PARSE_TYPE_WINDOWS_MOBILE_V65_JP:
            case PARSE_TYPE_DOCOMO_FOMA:
            case PARSE_TYPE_MOBILE_PHONE_JP:
                return "SHIFT_JIS";
            case PARSE_TYPE_APPLE:
                return "UTF-8";
            default:
                return null;
        }
    
public intgetEstimatedType()

return
The available type can be used with vCard parser. You probably need to use {{@link #getEstimatedCharset()} to understand the charset to be used.

        switch (mParseType) {
            case PARSE_TYPE_DOCOMO_FOMA:
                return VCardConfig.VCARD_TYPE_DOCOMO;
            case PARSE_TYPE_MOBILE_PHONE_JP:
                return VCardConfig.VCARD_TYPE_V21_JAPANESE_MOBILE;
            case PARSE_TYPE_APPLE:
            case PARSE_TYPE_WINDOWS_MOBILE_V65_JP:
            default: {
                if (mVersion == VCardConfig.VERSION_21) {
                    return VCardConfig.VCARD_TYPE_V21_GENERIC;
                } else if (mVersion == VCardConfig.VERSION_30) {
                    return VCardConfig.VCARD_TYPE_V30_GENERIC;
                } else if (mVersion == VCardConfig.VERSION_40) {
                    return VCardConfig.VCARD_TYPE_V40_GENERIC;
                } else {
                    return VCardConfig.VCARD_TYPE_UNKNOWN;
                }
            }
        }
    
public voidonEntryEnded()

    
public voidonEntryStarted()

    
public voidonPropertyCreated(VCardProperty property)

        final String propertyName = property.getName();
        final List<String> valueList = property.getValueList();

        if (propertyName.equalsIgnoreCase(VCardConstants.PROPERTY_VERSION)
                && valueList.size() > 0) {
            final String versionString = valueList.get(0);
            if (versionString.equals(VCardConstants.VERSION_V21)) {
                mVersion = VCardConfig.VERSION_21;
            } else if (versionString.equals(VCardConstants.VERSION_V30)) {
                mVersion = VCardConfig.VERSION_30;
            } else if (versionString.equals(VCardConstants.VERSION_V40)) {
                mVersion = VCardConfig.VERSION_40;
            } else {
                Log.w(LOG_TAG, "Invalid version string: " + versionString);
            }
        } else if (propertyName.equalsIgnoreCase(TYPE_FOMA_CHARSET_SIGN)) {
            mParseType = PARSE_TYPE_DOCOMO_FOMA;
            if (valueList.size() > 0) {
                mSpecifiedCharset = valueList.get(0);
            }
        }
        if (mParseType != PARSE_TYPE_UNKNOWN) {
            return;
        }
        if (WINDOWS_MOBILE_PHONE_SIGNS.contains(propertyName)) {
            mParseType = PARSE_TYPE_WINDOWS_MOBILE_V65_JP;
        } else if (FOMA_SIGNS.contains(propertyName)) {
            mParseType = PARSE_TYPE_DOCOMO_FOMA;
        } else if (JAPANESE_MOBILE_PHONE_SIGNS.contains(propertyName)) {
            mParseType = PARSE_TYPE_MOBILE_PHONE_JP;
        } else if (APPLE_SIGNS.contains(propertyName)) {
            mParseType = PARSE_TYPE_APPLE;
        }
    
public voidonVCardEnded()

    
public voidonVCardStarted()