am a3dbee32: Merge change I919c20bb into eclair-mr2

Merge commit 'a3dbee32d1deab72e5bbf17ab34b961fb7ab4182' into eclair-mr2-plus-aosp

* commit 'a3dbee32d1deab72e5bbf17ab34b961fb7ab4182':
  Code clean up.
This commit is contained in:
Daisuke Miyakawa
2009-11-18 11:46:03 -08:00
committed by Android Git Automerger
8 changed files with 82 additions and 132 deletions

View File

@@ -95,7 +95,7 @@ public class VCardBuilder {
private final boolean mUsesUtf8; private final boolean mUsesUtf8;
private final boolean mUsesShiftJis; private final boolean mUsesShiftJis;
private final boolean mAppendTypeParamName; private final boolean mAppendTypeParamName;
private final boolean mRefrainsQPToPrimaryProperties; private final boolean mRefrainsQPToNameProperties;
private final boolean mNeedsToConvertPhoneticString; private final boolean mNeedsToConvertPhoneticString;
private final boolean mShouldAppendCharsetParam; private final boolean mShouldAppendCharsetParam;
@@ -118,7 +118,7 @@ public class VCardBuilder {
mUsesDefactProperty = VCardConfig.usesDefactProperty(vcardType); mUsesDefactProperty = VCardConfig.usesDefactProperty(vcardType);
mUsesUtf8 = VCardConfig.usesUtf8(vcardType); mUsesUtf8 = VCardConfig.usesUtf8(vcardType);
mUsesShiftJis = VCardConfig.usesShiftJis(vcardType); mUsesShiftJis = VCardConfig.usesShiftJis(vcardType);
mRefrainsQPToPrimaryProperties = VCardConfig.refrainsQPToPrimaryProperties(vcardType); mRefrainsQPToNameProperties = VCardConfig.shouldRefrainQPToNameProperties(vcardType);
mAppendTypeParamName = VCardConfig.appendTypeParamName(vcardType); mAppendTypeParamName = VCardConfig.appendTypeParamName(vcardType);
mNeedsToConvertPhoneticString = VCardConfig.needsToConvertPhoneticString(vcardType); mNeedsToConvertPhoneticString = VCardConfig.needsToConvertPhoneticString(vcardType);
@@ -255,7 +255,7 @@ public class VCardBuilder {
final boolean reallyAppendCharsetParameterToName = final boolean reallyAppendCharsetParameterToName =
shouldAppendCharsetParam(familyName, givenName, middleName, prefix, suffix); shouldAppendCharsetParam(familyName, givenName, middleName, prefix, suffix);
final boolean reallyUseQuotedPrintableToName = final boolean reallyUseQuotedPrintableToName =
(!mRefrainsQPToPrimaryProperties && (!mRefrainsQPToNameProperties &&
!(VCardUtils.containsOnlyNonCrLfPrintableAscii(familyName) && !(VCardUtils.containsOnlyNonCrLfPrintableAscii(familyName) &&
VCardUtils.containsOnlyNonCrLfPrintableAscii(givenName) && VCardUtils.containsOnlyNonCrLfPrintableAscii(givenName) &&
VCardUtils.containsOnlyNonCrLfPrintableAscii(middleName) && VCardUtils.containsOnlyNonCrLfPrintableAscii(middleName) &&
@@ -273,7 +273,7 @@ public class VCardBuilder {
final boolean reallyAppendCharsetParameterToFN = final boolean reallyAppendCharsetParameterToFN =
shouldAppendCharsetParam(formattedName); shouldAppendCharsetParam(formattedName);
final boolean reallyUseQuotedPrintableToFN = final boolean reallyUseQuotedPrintableToFN =
!mRefrainsQPToPrimaryProperties && !mRefrainsQPToNameProperties &&
!VCardUtils.containsOnlyNonCrLfPrintableAscii(formattedName); !VCardUtils.containsOnlyNonCrLfPrintableAscii(formattedName);
final String encodedFamily; final String encodedFamily;
@@ -353,7 +353,7 @@ public class VCardBuilder {
mBuilder.append(VCARD_END_OF_LINE); mBuilder.append(VCARD_END_OF_LINE);
} else if (!TextUtils.isEmpty(displayName)) { } else if (!TextUtils.isEmpty(displayName)) {
final boolean reallyUseQuotedPrintableToDisplayName = final boolean reallyUseQuotedPrintableToDisplayName =
(!mRefrainsQPToPrimaryProperties && (!mRefrainsQPToNameProperties &&
!VCardUtils.containsOnlyNonCrLfPrintableAscii(displayName)); !VCardUtils.containsOnlyNonCrLfPrintableAscii(displayName));
final String encodedDisplayName = final String encodedDisplayName =
reallyUseQuotedPrintableToDisplayName ? reallyUseQuotedPrintableToDisplayName ?
@@ -471,7 +471,7 @@ public class VCardBuilder {
mBuilder.append(VCardConstants.PARAM_TYPE_X_IRMC_N); mBuilder.append(VCardConstants.PARAM_TYPE_X_IRMC_N);
boolean reallyUseQuotedPrintable = boolean reallyUseQuotedPrintable =
(!mRefrainsQPToPrimaryProperties (!mRefrainsQPToNameProperties
&& !(VCardUtils.containsOnlyNonCrLfPrintableAscii( && !(VCardUtils.containsOnlyNonCrLfPrintableAscii(
phoneticFamilyName) phoneticFamilyName)
&& VCardUtils.containsOnlyNonCrLfPrintableAscii( && VCardUtils.containsOnlyNonCrLfPrintableAscii(
@@ -976,12 +976,8 @@ public class VCardBuilder {
// Note: vCard 3.0 does not allow any parameter addition toward "URL" // Note: vCard 3.0 does not allow any parameter addition toward "URL"
// property, while there's no document in vCard 2.1. // property, while there's no document in vCard 2.1.
//
// TODO: Should we allow adding it when appropriate?
// (Actually, we drop some data. Using "group.X-URL-TYPE" or something
// may help)
if (!TextUtils.isEmpty(website)) { if (!TextUtils.isEmpty(website)) {
appendLine(VCardConstants.PROPERTY_URL, website); appendLineWithCharsetAndQPDetection(VCardConstants.PROPERTY_URL, website);
} }
} }
} }
@@ -1041,23 +1037,9 @@ public class VCardBuilder {
if (data == null) { if (data == null) {
continue; continue;
} }
final String photoType; final String photoType = VCardUtils.guessImageType(data);
// Use some heuristics for guessing the format of the image. if (photoType == null) {
// TODO: there should be some general API for detecting the file format. Log.d(LOG_TAG, "Unknown photo type. Ignored.");
if (data.length >= 3 && data[0] == 'G' && data[1] == 'I'
&& data[2] == 'F') {
photoType = "GIF";
} else if (data.length >= 4 && data[0] == (byte) 0x89
&& data[1] == 'P' && data[2] == 'N' && data[3] == 'G') {
// Note: vCard 2.1 officially does not support PNG, but we may have it and
// using X- word like "X-PNG" may not let importers know it is PNG.
// So we use the String "PNG" as is...
photoType = "PNG";
} else if (data.length >= 2 && data[0] == (byte) 0xff
&& data[1] == (byte) 0xd8) {
photoType = "JPEG";
} else {
Log.d(LOG_TAG, "Unknown photo type. Ignore.");
continue; continue;
} }
final String photoString = new String(Base64.encodeBase64(data)); final String photoString = new String(Base64.encodeBase64(data));
@@ -1762,7 +1744,6 @@ public class VCardBuilder {
return builder.toString(); return builder.toString();
} }
/** /**
* Append '\' to the characters which should be escaped. The character set is different * Append '\' to the characters which should be escaped. The character set is different
* not only between vCard 2.1 and vCard 3.0 but also among each device. * not only between vCard 2.1 and vCard 3.0 but also among each device.

View File

@@ -144,11 +144,6 @@ public class VCardComposer {
private static final Uri sDataRequestUri; private static final Uri sDataRequestUri;
private static final Map<Integer, String> sImMap; private static final Map<Integer, String> sImMap;
/**
* See the comment in {@link VCardConfig#FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES}.
*/
private static final Set<String> sPrimaryPropertyNameSet;
static { static {
Uri.Builder builder = RawContacts.CONTENT_URI.buildUpon(); Uri.Builder builder = RawContacts.CONTENT_URI.buildUpon();
builder.appendQueryParameter(Data.FOR_EXPORT_ONLY, "1"); builder.appendQueryParameter(Data.FOR_EXPORT_ONLY, "1");
@@ -161,12 +156,6 @@ public class VCardComposer {
sImMap.put(Im.PROTOCOL_JABBER, VCardConstants.PROPERTY_X_JABBER); sImMap.put(Im.PROTOCOL_JABBER, VCardConstants.PROPERTY_X_JABBER);
sImMap.put(Im.PROTOCOL_SKYPE, VCardConstants.PROPERTY_X_SKYPE_USERNAME); sImMap.put(Im.PROTOCOL_SKYPE, VCardConstants.PROPERTY_X_SKYPE_USERNAME);
// Google talk is a special case. // Google talk is a special case.
// TODO: incomplete. Implement properly
sPrimaryPropertyNameSet = new HashSet<String>();
sPrimaryPropertyNameSet.add(VCardConstants.PROPERTY_N);
sPrimaryPropertyNameSet.add(VCardConstants.PROPERTY_FN);
sPrimaryPropertyNameSet.add(VCardConstants.PROPERTY_SOUND);
} }
public static interface OneEntryHandler { public static interface OneEntryHandler {

View File

@@ -37,6 +37,12 @@ public class VCardConfig {
/* package */ static final int LOG_LEVEL = LOG_LEVEL_NONE; /* package */ static final int LOG_LEVEL = LOG_LEVEL_NONE;
/* package */ static final int PARSE_TYPE_UNKNOWN = 0;
/* package */ static final int PARSE_TYPE_APPLE = 1;
/* package */ static final int PARSE_TYPE_MOBILE_PHONE_JP = 2; // For Japanese mobile phones.
/* package */ static final int PARSE_TYPE_FOMA = 3; // For Japanese FOMA mobile phones.
/* package */ static final int PARSE_TYPE_WINDOWS_MOBILE_JP = 4;
// Assumes that "iso-8859-1" is able to map "all" 8bit characters to some unicode and // Assumes that "iso-8859-1" is able to map "all" 8bit characters to some unicode and
// decode the unicode to the original charset. If not, this setting will cause some bug. // decode the unicode to the original charset. If not, this setting will cause some bug.
public static final String DEFAULT_CHARSET = "iso-8859-1"; public static final String DEFAULT_CHARSET = "iso-8859-1";
@@ -108,31 +114,26 @@ public class VCardConfig {
* </P> * </P>
* <P> * <P>
* We added this Android-specific notion since some (incomplete) vCard exporters for vCard 2.1 * We added this Android-specific notion since some (incomplete) vCard exporters for vCard 2.1
* do NOT use Quoted-Printable encoding toward some properties like "N", "FN", etc. even when * do NOT use Quoted-Printable encoding toward some properties related names like "N", "FN", etc.
* their values contain non-ascii or/and CR/LF, while they use the encoding in the other * even when their values contain non-ascii or/and CR/LF, while they use the encoding in the
* properties like "ADR", "ORG", etc. * other properties like "ADR", "ORG", etc.
* <P> * <P>
* We are afraid of the case where some vCard importer also forget handling QP presuming QP is * We are afraid of the case where some vCard importer also forget handling QP presuming QP is
* not used in such fields. * not used in such fields.
* </P> * </P>
* <P> * <P>
* This flag is useful when some target importer you are going to focus on does not accept * This flag is useful when some target importer you are going to focus on does not accept
* such "primary" property values with Quoted-Printable encoding. * such properties with Quoted-Printable encoding.
* </P> * </P>
* <P> * <P>
* Again, we should not use this flag at all for complying vCard 2.1 spec. * Again, we should not use this flag at all for complying vCard 2.1 spec.
* </P> * </P>
* <P> * <P>
* We will change the behavior around this flag in the future, after understanding the other
* real vCard cases around this problem. Please use this flag with extreme caution even when
* needed.
* </P>
* <P>
* In vCard 3.0, Quoted-Printable is explicitly "prohibitted", so we don't need to care this * In vCard 3.0, Quoted-Printable is explicitly "prohibitted", so we don't need to care this
* kind of problem (hopefully). * kind of problem (hopefully).
* </P> * </P>
*/ */
public static final int FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES = 0x10000000; public static final int FLAG_REFRAIN_QP_TO_NAME_PROPERTIES = 0x10000000;
/** /**
* <P> * <P>
@@ -311,7 +312,7 @@ public class VCardConfig {
public static final int VCARD_TYPE_V21_JAPANESE_MOBILE = public static final int VCARD_TYPE_V21_JAPANESE_MOBILE =
(FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_CHARSET_SHIFT_JIS | (FLAG_V21 | NAME_ORDER_JAPANESE | FLAG_CHARSET_SHIFT_JIS |
FLAG_CONVERT_PHONETIC_NAME_STRINGS | FLAG_CONVERT_PHONETIC_NAME_STRINGS |
FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES); FLAG_REFRAIN_QP_TO_NAME_PROPERTIES);
/* package */ static final String VCARD_TYPE_V21_JAPANESE_MOBILE_STR = "v21_japanese_mobile"; /* package */ static final String VCARD_TYPE_V21_JAPANESE_MOBILE_STR = "v21_japanese_mobile";
@@ -400,9 +401,9 @@ public class VCardConfig {
return (VCardConfig.LOG_LEVEL & VCardConfig.LOG_LEVEL_PERFORMANCE_MEASUREMENT) != 0; return (VCardConfig.LOG_LEVEL & VCardConfig.LOG_LEVEL_PERFORMANCE_MEASUREMENT) != 0;
} }
public static boolean refrainsQPToPrimaryProperties(final int vcardType) { public static boolean shouldRefrainQPToNameProperties(final int vcardType) {
return (!shouldUseQuotedPrintable(vcardType) || return (!shouldUseQuotedPrintable(vcardType) ||
((vcardType & FLAG_REFRAIN_QP_TO_PRIMARY_PROPERTIES) != 0)); ((vcardType & FLAG_REFRAIN_QP_TO_NAME_PROPERTIES) != 0));
} }
public static boolean appendTypeParamName(final int vcardType) { public static boolean appendTypeParamName(final int vcardType) {

View File

@@ -21,21 +21,15 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
public abstract class VCardParser { public abstract class VCardParser {
public static final int PARSER_MODE_DEFAULT = 0; protected final int mParseType;
/**
* The parser should ignore "AGENT" properties and nested vCard structure.
*/
public static final int PARSER_MODE_SCAN = 1;
protected final int mParserMode;
protected boolean mCanceled; protected boolean mCanceled;
public VCardParser() { public VCardParser() {
mParserMode = PARSER_MODE_DEFAULT; this(VCardConfig.PARSE_TYPE_UNKNOWN);
} }
public VCardParser(int parserMode) { public VCardParser(int parseType) {
mParserMode = parserMode; mParseType = parseType;
} }
/** /**

View File

@@ -95,12 +95,6 @@ public class VCardParser_V21 extends VCardParser {
protected Set<String> mUnknownTypeMap = new HashSet<String>(); protected Set<String> mUnknownTypeMap = new HashSet<String>();
protected Set<String> mUnknownValueMap = new HashSet<String>(); protected Set<String> mUnknownValueMap = new HashSet<String>();
// It seems Windows Mobile 6.5 uses "AGENT" property with completely wrong usage.
// We should just ignore just one line.
// e.g.
// "AGENT;CHARSET=SHIFT_JIS:some text"
private boolean mIgnoreInvalidAgentLine = false;
// For measuring performance. // For measuring performance.
private long mTimeTotal; private long mTimeTotal;
private long mTimeReadStartRecord; private long mTimeReadStartRecord;
@@ -116,33 +110,20 @@ public class VCardParser_V21 extends VCardParser {
private long mTimeHandleBase64; private long mTimeHandleBase64;
public VCardParser_V21() { public VCardParser_V21() {
this(null, PARSER_MODE_DEFAULT); this(VCardConfig.PARSE_TYPE_UNKNOWN);
}
public VCardParser_V21(int parserMode) {
this(null, parserMode);
} }
public VCardParser_V21(VCardSourceDetector detector) { public VCardParser_V21(VCardSourceDetector detector) {
this(detector, PARSER_MODE_DEFAULT); this(detector.getEstimatedType());
} }
/** /**
* TODO: Merge detector and parser mode. * TODO: Merge detector and parser mode.
*/ */
public VCardParser_V21(VCardSourceDetector detector, int parserMode) { public VCardParser_V21(int parseType) {
super(parserMode); super(parseType);
if (detector != null) { if (parseType == VCardConfig.PARSE_TYPE_FOMA) {
final int type = detector.getType(); mNestCount = 1;
if (type == VCardSourceDetector.TYPE_FOMA) {
mNestCount = 1;
} else if (type == VCardSourceDetector.TYPE_JAPANESE_MOBILE_PHONE) {
mIgnoreInvalidAgentLine = true;
}
}
if (parserMode == PARSER_MODE_SCAN) {
mIgnoreInvalidAgentLine = true;
} }
} }
@@ -827,24 +808,13 @@ public class VCardParser_V21 extends VCardParser {
* items *CRLF "END" [ws] ":" [ws] "VCARD" * items *CRLF "END" [ws] ":" [ws] "VCARD"
*/ */
protected void handleAgent(final String propertyValue) throws VCardException { protected void handleAgent(final String propertyValue) throws VCardException {
if (mIgnoreInvalidAgentLine && !propertyValue.toUpperCase().contains("BEGIN:VCARD")) { if (!propertyValue.toUpperCase().contains("BEGIN:VCARD")) {
// Apparently invalid line seen in Windows Mobile 6.5. Ignore them.
return; return;
} else { } else {
throw new VCardAgentNotSupportedException("AGENT Property is not supported now."); throw new VCardAgentNotSupportedException("AGENT Property is not supported now.");
} }
/* This is insufficient support. Also, AGENT Property is very rare and really hard to // TODO: Support AGENT property.
understand the content.
Ignore it for now.
String[] strArray = propertyValue.split(":", 2);
if (!(strArray.length == 2 ||
strArray[0].trim().equalsIgnoreCase("BEGIN") &&
strArray[1].trim().equalsIgnoreCase("VCARD"))) {
throw new VCardException("BEGIN:VCARD != \"" + propertyValue + "\"");
}
parseItems();
readEndVCard();
*/
} }
/** /**

View File

@@ -26,14 +26,6 @@ import java.util.Set;
* @hide * @hide
*/ */
public class VCardSourceDetector implements VCardInterpreter { public class VCardSourceDetector implements VCardInterpreter {
// Should only be used in package.
static final int TYPE_UNKNOWN = 0;
static final int TYPE_APPLE = 1;
static final int TYPE_JAPANESE_MOBILE_PHONE = 2; // Used in Japanese mobile phones.
static final int TYPE_FOMA = 3; // Used in some Japanese FOMA mobile phones.
static final int TYPE_WINDOWS_MOBILE_JP = 4;
// TODO: Excel, etc.
private static Set<String> APPLE_SIGNS = new HashSet<String>(Arrays.asList( private static Set<String> APPLE_SIGNS = new HashSet<String>(Arrays.asList(
"X-PHONETIC-FIRST-NAME", "X-PHONETIC-MIDDLE-NAME", "X-PHONETIC-LAST-NAME", "X-PHONETIC-FIRST-NAME", "X-PHONETIC-MIDDLE-NAME", "X-PHONETIC-LAST-NAME",
"X-ABADR", "X-ABUID")); "X-ABADR", "X-ABUID"));
@@ -51,7 +43,7 @@ public class VCardSourceDetector implements VCardInterpreter {
"X-SD-DESCRIPTION")); "X-SD-DESCRIPTION"));
private static String TYPE_FOMA_CHARSET_SIGN = "X-SD-CHAR_CODE"; private static String TYPE_FOMA_CHARSET_SIGN = "X-SD-CHAR_CODE";
private int mType = TYPE_UNKNOWN; private int mType = VCardConfig.PARSE_TYPE_UNKNOWN;
// Some mobile phones (like FOMA) tells us the charset of the data. // Some mobile phones (like FOMA) tells us the charset of the data.
private boolean mNeedParseSpecifiedCharset; private boolean mNeedParseSpecifiedCharset;
private String mSpecifiedCharset; private String mSpecifiedCharset;
@@ -80,21 +72,21 @@ public class VCardSourceDetector implements VCardInterpreter {
public void propertyName(String name) { public void propertyName(String name) {
if (name.equalsIgnoreCase(TYPE_FOMA_CHARSET_SIGN)) { if (name.equalsIgnoreCase(TYPE_FOMA_CHARSET_SIGN)) {
mType = TYPE_FOMA; mType = VCardConfig.PARSE_TYPE_FOMA;
mNeedParseSpecifiedCharset = true; mNeedParseSpecifiedCharset = true;
return; return;
} }
if (mType != TYPE_UNKNOWN) { if (mType != VCardConfig.PARSE_TYPE_UNKNOWN) {
return; return;
} }
if (WINDOWS_MOBILE_PHONE_SIGNS.contains(name)) { if (WINDOWS_MOBILE_PHONE_SIGNS.contains(name)) {
mType = TYPE_WINDOWS_MOBILE_JP; mType = VCardConfig.PARSE_TYPE_WINDOWS_MOBILE_JP;
} else if (FOMA_SIGNS.contains(name)) { } else if (FOMA_SIGNS.contains(name)) {
mType = TYPE_FOMA; mType = VCardConfig.PARSE_TYPE_FOMA;
} else if (JAPANESE_MOBILE_PHONE_SIGNS.contains(name)) { } else if (JAPANESE_MOBILE_PHONE_SIGNS.contains(name)) {
mType = TYPE_JAPANESE_MOBILE_PHONE; mType = VCardConfig.PARSE_TYPE_MOBILE_PHONE_JP;
} else if (APPLE_SIGNS.contains(name)) { } else if (APPLE_SIGNS.contains(name)) {
mType = TYPE_APPLE; mType = VCardConfig.PARSE_TYPE_APPLE;
} }
} }
@@ -110,7 +102,7 @@ public class VCardSourceDetector implements VCardInterpreter {
} }
} }
int getType() { /* package */ int getEstimatedType() {
return mType; return mType;
} }
@@ -124,14 +116,14 @@ public class VCardSourceDetector implements VCardInterpreter {
return mSpecifiedCharset; return mSpecifiedCharset;
} }
switch (mType) { switch (mType) {
case TYPE_WINDOWS_MOBILE_JP: case VCardConfig.PARSE_TYPE_WINDOWS_MOBILE_JP:
case TYPE_FOMA: case VCardConfig.PARSE_TYPE_FOMA:
case TYPE_JAPANESE_MOBILE_PHONE: case VCardConfig.PARSE_TYPE_MOBILE_PHONE_JP:
return "SHIFT_JIS"; return "SHIFT_JIS";
case TYPE_APPLE: case VCardConfig.PARSE_TYPE_APPLE:
return "UTF-8"; return "UTF-8";
default: default:
return null; return null;
} }
} }
} }

View File

@@ -23,6 +23,7 @@ import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.CommonDataKinds.StructuredPostal; import android.provider.ContactsContract.CommonDataKinds.StructuredPostal;
import android.telephony.PhoneNumberUtils; import android.telephony.PhoneNumberUtils;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.Log;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@@ -466,7 +467,7 @@ public class VCardUtils {
return true; return true;
} }
static public String toHalfWidthString(String orgString) { public static String toHalfWidthString(String orgString) {
if (TextUtils.isEmpty(orgString)) { if (TextUtils.isEmpty(orgString)) {
return null; return null;
} }
@@ -486,6 +487,30 @@ public class VCardUtils {
return builder.toString(); return builder.toString();
} }
/**
* Guesses the format of input image. Currently just the first few bytes are used.
* The type "GIF", "PNG", or "JPEG" is returned when possible. Returns null when
* the guess failed.
* @param input Image as byte array.
* @return The image type or null when the type cannot be determined.
*/
public static String guessImageType(final byte[] input) {
if (input.length >= 3 && input[0] == 'G' && input[1] == 'I' && input[2] == 'F') {
return "GIF";
} else if (input.length >= 4 && input[0] == (byte) 0x89
&& input[1] == 'P' && input[2] == 'N' && input[3] == 'G') {
// Note: vCard 2.1 officially does not support PNG, but we may have it and
// using X- word like "X-PNG" may not let importers know it is PNG.
// So we use the String "PNG" as is...
return "PNG";
} else if (input.length >= 2 && input[0] == (byte) 0xff
&& input[1] == (byte) 0xd8) {
return "JPEG";
} else {
return null;
}
}
private VCardUtils() { private VCardUtils() {
} }
} }

View File

@@ -1017,8 +1017,7 @@ public class VCardImporterTests extends VCardTestsBase {
.addNodeWithOrder("X-NO", ""); .addNodeWithOrder("X-NO", "");
// Only scan mode lets vCard parser accepts invalid AGENT lines like above. // Only scan mode lets vCard parser accepts invalid AGENT lines like above.
verifier.verify(R.raw.v21_winmo_65, V21, verifier.verify(R.raw.v21_winmo_65, V21, new VCardParser_V21());
new VCardParser_V21(VCardParser.PARSER_MODE_SCAN));
} }
public void testIgnoreAgentV21() throws IOException, VCardException { public void testIgnoreAgentV21() throws IOException, VCardException {
@@ -1027,8 +1026,7 @@ public class VCardImporterTests extends VCardTestsBase {
elem.addExpected(StructuredName.CONTENT_ITEM_TYPE) elem.addExpected(StructuredName.CONTENT_ITEM_TYPE)
.put(StructuredName.FAMILY_NAME, "Example") .put(StructuredName.FAMILY_NAME, "Example")
.put(StructuredName.DISPLAY_NAME, "Example"); .put(StructuredName.DISPLAY_NAME, "Example");
verifier.verify(R.raw.v21_winmo_65, V21, verifier.verify(R.raw.v21_winmo_65, V21, new VCardParser_V21());
new VCardParser_V21(VCardParser.PARSER_MODE_SCAN));
} }
public void testTolerateInvalidCommentLikeLineV21() throws IOException, VCardException { public void testTolerateInvalidCommentLikeLineV21() throws IOException, VCardException {