return null; String[] names = matchVCardPrefixedField("FN", rawText, true); if (names == null) { names = matchVCardPrefixedField("N", rawText, true); formatNames(names); String[] phoneNumbers = matchVCardPrefixedField("TEL", rawText, true); String[] emails = matchVCardPrefixedField("EMAIL", rawText, true); String note = matchSingleVCardPrefixedField("NOTE", rawText, false); String[] addresses = matchVCardPrefixedField("ADR", rawText, true); if (addresses != null) { for (int i = 0; i < addresses.length; i++) { addresses[i] = formatAddress(addresses[i]); String org = matchSingleVCardPrefixedField("ORG", rawText, true); String birthday = matchSingleVCardPrefixedField("BDAY", rawText, true); if (!isLikeVCardDate(birthday)) { birthday = null; String title = matchSingleVCardPrefixedField("TITLE", rawText, true); String url = matchSingleVCardPrefixedField("URL", rawText, true); return new AddressBookParsedResult(names, null, phoneNumbers, emails, note, addresses, org, birthday, title, url);
private static boolean isLikeVCardDate(String value) { if (value == null) { return true; } // Not really sure this is true but matches practice // Mach YYYYMMDD if (isStringOfDigits(value, 8)) { return true; } // or YYYY-MM-DD return value.length() == 10 && value.charAt(4) == '-' && value.charAt(7) == '-' && isSubstringOfDigits(value, 0, 4) && isSubstringOfDigits(value, 5, 2) && isSubstringOfDigits(value, 8, 2); }
element = decodeQuotedPrintable(element, quotedPrintableCharset); } else { element = stripContinuationCRLF(element); return null; return toStringArray(matches);
char nextNextChar = value.charAt(i+2); try { int encodedByte = 16 * toHexValue(nextChar) + toHexValue(nextNextChar); fragmentBuffer.write(encodedByte); } catch (IllegalArgumentException iae) { maybeAppendFragment(fragmentBuffer, charset, result); result.append(c); maybeAppendFragment(fragmentBuffer, charset, result); return result.toString();
static String matchSingleVCardPrefixedField(String prefix, String rawText, boolean trim) { String[] values = matchVCardPrefixedField(prefix, rawText, trim); return values == null ? null : values[0]; }
public static CalendarParsedResult parse(Result result) { String rawText = result.getText(); if (rawText == null) { return null; } int vEventStart = rawText.indexOf("BEGIN:VEVENT"); if (vEventStart < 0) { return null; } String summary = VCardResultParser.matchSingleVCardPrefixedField("SUMMARY", rawText, true); String start = VCardResultParser.matchSingleVCardPrefixedField("DTSTART", rawText, true); String end = VCardResultParser.matchSingleVCardPrefixedField("DTEND", rawText, true); String location = VCardResultParser.matchSingleVCardPrefixedField("LOCATION", rawText, true); String description = VCardResultParser.matchSingleVCardPrefixedField("DESCRIPTION", rawText, true); try { return new CalendarParsedResult(summary, start, end, location, null, description); } catch (IllegalArgumentException iae) { return null; } }
/** * Formats name fields of the form "Public;John;Q.;Reverend;III" into a form like * "Reverend John Q. Public III". * * @param names name values to format, in place */ private static void formatNames(String[] names) { if (names != null) { for (int i = 0; i < names.length; i++) { String name = names[i]; String[] components = new String[5]; int start = 0; int end; int componentIndex = 0; while ((end = name.indexOf(';', start)) > 0) { components[componentIndex] = name.substring(start, end); componentIndex++; start = end + 1; } components[componentIndex] = name.substring(start); StringBuffer newName = new StringBuffer(100); maybeAppendComponent(components, 3, newName); maybeAppendComponent(components, 1, newName); maybeAppendComponent(components, 2, newName); maybeAppendComponent(components, 0, newName); maybeAppendComponent(components, 4, newName); names[i] = newName.toString().trim(); } } }