2 * Copyright (C) 2009 The Android Open Source Project
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.android
.vcard
;
18 import com
.android
.vcard
.exception
.VCardException
;
20 import java
.io
.IOException
;
21 import java
.io
.InputStream
;
22 import java
.util
.Arrays
;
23 import java
.util
.Collections
;
24 import java
.util
.HashSet
;
29 * vCard parser for vCard 2.1. See the specification for more detail about the spec itself.
32 * The spec is written in 1996, and currently various types of "vCard 2.1" exist.
33 * To handle real the world vCard formats appropriately and effectively, this class does not
34 * obey with strict vCard 2.1.
35 * In stead, not only vCard spec but also real world vCard is considered.
37 * e.g. A lot of devices and softwares let vCard importer/exporter to use
38 * the PNG format to determine the type of image, while it is not allowed in
39 * the original specification. As of 2010, we can see even the FLV format
40 * (possible in Japanese mobile phones).
43 public final class VCardParser_V21
extends VCardParser
{
45 * A unmodifiable Set storing the property names available in the vCard 2.1 specification.
47 /* package */ static final Set
<String
> sKnownPropertyNameSet
=
48 Collections
.unmodifiableSet(new HashSet
<String
>(
49 Arrays
.asList("BEGIN", "END", "LOGO", "PHOTO", "LABEL", "FN", "TITLE", "SOUND",
50 "VERSION", "TEL", "EMAIL", "TZ", "GEO", "NOTE", "URL",
51 "BDAY", "ROLE", "REV", "UID", "KEY", "MAILER")));
54 * A unmodifiable Set storing the types known in vCard 2.1.
56 /* package */ static final Set
<String
> sKnownTypeSet
=
57 Collections
.unmodifiableSet(new HashSet
<String
>(
58 Arrays
.asList("DOM", "INTL", "POSTAL", "PARCEL", "HOME", "WORK",
59 "PREF", "VOICE", "FAX", "MSG", "CELL", "PAGER", "BBS",
60 "MODEM", "CAR", "ISDN", "VIDEO", "AOL", "APPLELINK",
61 "ATTMAIL", "CIS", "EWORLD", "INTERNET", "IBMMAIL",
62 "MCIMAIL", "POWERSHARE", "PRODIGY", "TLX", "X400", "GIF",
63 "CGM", "WMF", "BMP", "MET", "PMB", "DIB", "PICT", "TIFF",
64 "PDF", "PS", "JPEG", "QTIME", "MPEG", "MPEG2", "AVI",
65 "WAVE", "AIFF", "PCM", "X509", "PGP")));
68 * A unmodifiable Set storing the values for the type "VALUE", available in the vCard 2.1.
70 /* package */ static final Set
<String
> sKnownValueSet
=
71 Collections
.unmodifiableSet(new HashSet
<String
>(
72 Arrays
.asList("INLINE", "URL", "CONTENT-ID", "CID")));
76 * A unmodifiable Set storing the values for the type "ENCODING", available in the vCard 2.1.
79 * Though vCard 2.1 specification does not allow "B" encoding, some data may have it.
80 * We allow it for safety.
83 /* package */ static final Set
<String
> sAvailableEncoding
=
84 Collections
.unmodifiableSet(new HashSet
<String
>(
85 Arrays
.asList(VCardConstants
.PARAM_ENCODING_7BIT
,
86 VCardConstants
.PARAM_ENCODING_8BIT
,
87 VCardConstants
.PARAM_ENCODING_QP
,
88 VCardConstants
.PARAM_ENCODING_BASE64
,
89 VCardConstants
.PARAM_ENCODING_B
)));
91 private final VCardParserImpl_V21 mVCardParserImpl
;
93 public VCardParser_V21() {
94 mVCardParserImpl
= new VCardParserImpl_V21();
97 public VCardParser_V21(int vcardType
) {
98 mVCardParserImpl
= new VCardParserImpl_V21(vcardType
);
102 public void addInterpreter(VCardInterpreter interpreter
) {
103 mVCardParserImpl
.addInterpreter(interpreter
);
107 public void parse(InputStream is
) throws IOException
, VCardException
{
108 mVCardParserImpl
.parse(is
);
112 public void parseOne(InputStream is
) throws IOException
, VCardException
{
113 mVCardParserImpl
.parseOne(is
);
117 public void cancel() {
118 mVCardParserImpl
.cancel();