Loading core/java/android/pim/vcard/VCardParser_V21.java +19 −8 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.pim.vcard; package android.pim.vcard; import android.pim.vcard.exception.VCardException; import android.pim.vcard.exception.VCardException; import android.pim.vcard.exception.VCardInvalidCommentLineException; import android.pim.vcard.exception.VCardInvalidLineException; import android.pim.vcard.exception.VCardNestedException; import android.pim.vcard.exception.VCardNestedException; import android.pim.vcard.exception.VCardNotSupportedException; import android.pim.vcard.exception.VCardNotSupportedException; import android.pim.vcard.exception.VCardVersionException; import android.pim.vcard.exception.VCardVersionException; Loading Loading @@ -52,7 +54,7 @@ public class VCardParser_V21 extends VCardParser { Arrays.asList("INLINE", "URL", "CONTENT-ID", "CID")); Arrays.asList("INLINE", "URL", "CONTENT-ID", "CID")); /** Store the property names available in vCard 2.1 */ /** Store the property names available in vCard 2.1 */ private static final HashSet<String> sAvailablePropertyNameV21 = private static final HashSet<String> sAvailablePropertyNameSetV21 = new HashSet<String>(Arrays.asList( new HashSet<String>(Arrays.asList( "BEGIN", "LOGO", "PHOTO", "LABEL", "FN", "TITLE", "SOUND", "BEGIN", "LOGO", "PHOTO", "LABEL", "FN", "TITLE", "SOUND", "VERSION", "TEL", "EMAIL", "TZ", "GEO", "NOTE", "URL", "VERSION", "TEL", "EMAIL", "TZ", "GEO", "NOTE", "URL", Loading Loading @@ -156,7 +158,7 @@ public class VCardParser_V21 extends VCardParser { * @return true when the propertyName is a valid property name. * @return true when the propertyName is a valid property name. */ */ protected boolean isValidPropertyName(String propertyName) { protected boolean isValidPropertyName(String propertyName) { if (!(sAvailablePropertyNameV21.contains(propertyName.toUpperCase()) || if (!(sAvailablePropertyNameSetV21.contains(propertyName.toUpperCase()) || propertyName.startsWith("X-")) && propertyName.startsWith("X-")) && !mWarningValueMap.contains(propertyName)) { !mWarningValueMap.contains(propertyName)) { mWarningValueMap.add(propertyName); mWarningValueMap.add(propertyName); Loading Loading @@ -346,7 +348,12 @@ public class VCardParser_V21 extends VCardParser { mBuilder.startProperty(); mBuilder.startProperty(); mTimeStartProperty += System.currentTimeMillis() - start; mTimeStartProperty += System.currentTimeMillis() - start; } } try { ended = parseItem(); ended = parseItem(); } catch (VCardInvalidCommentLineException e) { Log.e(LOG_TAG, "Invalid line which looks like some comment was found. Ignored."); ended = false; } if (mBuilder != null && !ended) { if (mBuilder != null && !ended) { long start = System.currentTimeMillis(); long start = System.currentTimeMillis(); mBuilder.endProperty(); mBuilder.endProperty(); Loading @@ -373,7 +380,7 @@ public class VCardParser_V21 extends VCardParser { return true; return true; } } if (propertyNameAndValue.length != 2) { if (propertyNameAndValue.length != 2) { throw new VCardException("Invalid line \"" + line + "\""); throw new VCardInvalidLineException("Invalid line \"" + line + "\""); } } String propertyName = propertyNameAndValue[0].toUpperCase(); String propertyName = propertyNameAndValue[0].toUpperCase(); String propertyValue = propertyNameAndValue[1]; String propertyValue = propertyNameAndValue[1]; Loading Loading @@ -424,6 +431,10 @@ public class VCardParser_V21 extends VCardParser { String[] propertyNameAndValue = new String[2]; String[] propertyNameAndValue = new String[2]; if (length > 0 && line.charAt(0) == '#') { throw new VCardInvalidCommentLineException(); } for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) { char ch = line.charAt(i); char ch = line.charAt(i); switch (state) { switch (state) { Loading Loading @@ -488,7 +499,7 @@ public class VCardParser_V21 extends VCardParser { } } } } throw new VCardException("Invalid line: \"" + line + "\""); throw new VCardInvalidLineException("Invalid line: \"" + line + "\""); } } Loading Loading @@ -540,7 +551,7 @@ public class VCardParser_V21 extends VCardParser { /** /** * ptypeval = knowntype / "X-" word * ptypeval = knowntype / "X-" word */ */ protected void handleType(String ptypeval) { protected void handleType(final String ptypeval) { String upperTypeValue = ptypeval; String upperTypeValue = ptypeval; if (!(sKnownTypeSet.contains(upperTypeValue) || upperTypeValue.startsWith("X-")) && if (!(sKnownTypeSet.contains(upperTypeValue) || upperTypeValue.startsWith("X-")) && !mWarningValueMap.contains(ptypeval)) { !mWarningValueMap.contains(ptypeval)) { Loading @@ -556,7 +567,7 @@ public class VCardParser_V21 extends VCardParser { /** /** * pvalueval = "INLINE" / "URL" / "CONTENT-ID" / "CID" / "X-" word * pvalueval = "INLINE" / "URL" / "CONTENT-ID" / "CID" / "X-" word */ */ protected void handleValue(String pvalueval) throws VCardException { protected void handleValue(final String pvalueval) throws VCardException { if (sKnownValueSet.contains(pvalueval.toUpperCase()) || if (sKnownValueSet.contains(pvalueval.toUpperCase()) || pvalueval.startsWith("X-")) { pvalueval.startsWith("X-")) { if (mBuilder != null) { if (mBuilder != null) { Loading core/java/android/pim/vcard/exception/VCardInvalidCommentLineException.java 0 → 100644 +32 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.pim.vcard.exception; /** * Thrown when the vCard has some line starting with '#'. In the specification, * both vCard 2.1 and vCard 3.0 does not allow such line, but some actual exporter emit * such lines. */ public class VCardInvalidCommentLineException extends VCardInvalidLineException { public VCardInvalidCommentLineException() { super(); } public VCardInvalidCommentLineException(final String message) { super(message); } } core/java/android/pim/vcard/exception/VCardInvalidLineException.java 0 → 100644 +32 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.pim.vcard.exception; /** * Thrown when the vCard has some line starting with '#'. In the specification, * both vCard 2.1 and vCard 3.0 does not allow such line, but some actual exporter emit * such lines. */ public class VCardInvalidLineException extends VCardException { public VCardInvalidLineException() { super(); } public VCardInvalidLineException(final String message) { super(message); } } Loading
core/java/android/pim/vcard/VCardParser_V21.java +19 −8 Original line number Original line Diff line number Diff line Loading @@ -16,6 +16,8 @@ package android.pim.vcard; package android.pim.vcard; import android.pim.vcard.exception.VCardException; import android.pim.vcard.exception.VCardException; import android.pim.vcard.exception.VCardInvalidCommentLineException; import android.pim.vcard.exception.VCardInvalidLineException; import android.pim.vcard.exception.VCardNestedException; import android.pim.vcard.exception.VCardNestedException; import android.pim.vcard.exception.VCardNotSupportedException; import android.pim.vcard.exception.VCardNotSupportedException; import android.pim.vcard.exception.VCardVersionException; import android.pim.vcard.exception.VCardVersionException; Loading Loading @@ -52,7 +54,7 @@ public class VCardParser_V21 extends VCardParser { Arrays.asList("INLINE", "URL", "CONTENT-ID", "CID")); Arrays.asList("INLINE", "URL", "CONTENT-ID", "CID")); /** Store the property names available in vCard 2.1 */ /** Store the property names available in vCard 2.1 */ private static final HashSet<String> sAvailablePropertyNameV21 = private static final HashSet<String> sAvailablePropertyNameSetV21 = new HashSet<String>(Arrays.asList( new HashSet<String>(Arrays.asList( "BEGIN", "LOGO", "PHOTO", "LABEL", "FN", "TITLE", "SOUND", "BEGIN", "LOGO", "PHOTO", "LABEL", "FN", "TITLE", "SOUND", "VERSION", "TEL", "EMAIL", "TZ", "GEO", "NOTE", "URL", "VERSION", "TEL", "EMAIL", "TZ", "GEO", "NOTE", "URL", Loading Loading @@ -156,7 +158,7 @@ public class VCardParser_V21 extends VCardParser { * @return true when the propertyName is a valid property name. * @return true when the propertyName is a valid property name. */ */ protected boolean isValidPropertyName(String propertyName) { protected boolean isValidPropertyName(String propertyName) { if (!(sAvailablePropertyNameV21.contains(propertyName.toUpperCase()) || if (!(sAvailablePropertyNameSetV21.contains(propertyName.toUpperCase()) || propertyName.startsWith("X-")) && propertyName.startsWith("X-")) && !mWarningValueMap.contains(propertyName)) { !mWarningValueMap.contains(propertyName)) { mWarningValueMap.add(propertyName); mWarningValueMap.add(propertyName); Loading Loading @@ -346,7 +348,12 @@ public class VCardParser_V21 extends VCardParser { mBuilder.startProperty(); mBuilder.startProperty(); mTimeStartProperty += System.currentTimeMillis() - start; mTimeStartProperty += System.currentTimeMillis() - start; } } try { ended = parseItem(); ended = parseItem(); } catch (VCardInvalidCommentLineException e) { Log.e(LOG_TAG, "Invalid line which looks like some comment was found. Ignored."); ended = false; } if (mBuilder != null && !ended) { if (mBuilder != null && !ended) { long start = System.currentTimeMillis(); long start = System.currentTimeMillis(); mBuilder.endProperty(); mBuilder.endProperty(); Loading @@ -373,7 +380,7 @@ public class VCardParser_V21 extends VCardParser { return true; return true; } } if (propertyNameAndValue.length != 2) { if (propertyNameAndValue.length != 2) { throw new VCardException("Invalid line \"" + line + "\""); throw new VCardInvalidLineException("Invalid line \"" + line + "\""); } } String propertyName = propertyNameAndValue[0].toUpperCase(); String propertyName = propertyNameAndValue[0].toUpperCase(); String propertyValue = propertyNameAndValue[1]; String propertyValue = propertyNameAndValue[1]; Loading Loading @@ -424,6 +431,10 @@ public class VCardParser_V21 extends VCardParser { String[] propertyNameAndValue = new String[2]; String[] propertyNameAndValue = new String[2]; if (length > 0 && line.charAt(0) == '#') { throw new VCardInvalidCommentLineException(); } for (int i = 0; i < length; i++) { for (int i = 0; i < length; i++) { char ch = line.charAt(i); char ch = line.charAt(i); switch (state) { switch (state) { Loading Loading @@ -488,7 +499,7 @@ public class VCardParser_V21 extends VCardParser { } } } } throw new VCardException("Invalid line: \"" + line + "\""); throw new VCardInvalidLineException("Invalid line: \"" + line + "\""); } } Loading Loading @@ -540,7 +551,7 @@ public class VCardParser_V21 extends VCardParser { /** /** * ptypeval = knowntype / "X-" word * ptypeval = knowntype / "X-" word */ */ protected void handleType(String ptypeval) { protected void handleType(final String ptypeval) { String upperTypeValue = ptypeval; String upperTypeValue = ptypeval; if (!(sKnownTypeSet.contains(upperTypeValue) || upperTypeValue.startsWith("X-")) && if (!(sKnownTypeSet.contains(upperTypeValue) || upperTypeValue.startsWith("X-")) && !mWarningValueMap.contains(ptypeval)) { !mWarningValueMap.contains(ptypeval)) { Loading @@ -556,7 +567,7 @@ public class VCardParser_V21 extends VCardParser { /** /** * pvalueval = "INLINE" / "URL" / "CONTENT-ID" / "CID" / "X-" word * pvalueval = "INLINE" / "URL" / "CONTENT-ID" / "CID" / "X-" word */ */ protected void handleValue(String pvalueval) throws VCardException { protected void handleValue(final String pvalueval) throws VCardException { if (sKnownValueSet.contains(pvalueval.toUpperCase()) || if (sKnownValueSet.contains(pvalueval.toUpperCase()) || pvalueval.startsWith("X-")) { pvalueval.startsWith("X-")) { if (mBuilder != null) { if (mBuilder != null) { Loading
core/java/android/pim/vcard/exception/VCardInvalidCommentLineException.java 0 → 100644 +32 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.pim.vcard.exception; /** * Thrown when the vCard has some line starting with '#'. In the specification, * both vCard 2.1 and vCard 3.0 does not allow such line, but some actual exporter emit * such lines. */ public class VCardInvalidCommentLineException extends VCardInvalidLineException { public VCardInvalidCommentLineException() { super(); } public VCardInvalidCommentLineException(final String message) { super(message); } }
core/java/android/pim/vcard/exception/VCardInvalidLineException.java 0 → 100644 +32 −0 Original line number Original line Diff line number Diff line /* * Copyright (C) 2009 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package android.pim.vcard.exception; /** * Thrown when the vCard has some line starting with '#'. In the specification, * both vCard 2.1 and vCard 3.0 does not allow such line, but some actual exporter emit * such lines. */ public class VCardInvalidLineException extends VCardException { public VCardInvalidLineException() { super(); } public VCardInvalidLineException(final String message) { super(message); } }