VCardParser_V40.java revision da2f6ef422b360827f2c5231552d8c9fad0ed8b1
1/*
2 * Copyright (C) 2010 The Android Open Source Project
3 *
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
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
16package com.android.vcard;
17
18import com.android.vcard.exception.VCardException;
19
20import java.io.IOException;
21import java.io.InputStream;
22import java.util.Arrays;
23import java.util.Collections;
24import java.util.HashSet;
25import java.util.Set;
26
27/**
28 * <p>
29 * vCard parser for vCard 4.0. DO NOT USE IN PRODUCTION.
30 * </p>
31 * <p>
32 * Currently this parser is based on vCard 4.0 specification rev 15 (partly).
33 * Note that some of current implementation lack basic capability required in vCard 4.0.
34 * (e.g. PHOTO has data parameter in rev 15 while this implementation requires "ENCODING=b")
35 * </p>
36 */
37public class VCardParser_V40 implements VCardParser {
38    /* package */ static final Set<String> sKnownPropertyNameSet =
39            Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
40                    "BEGIN", "END", "VERSION",
41                    "SOURCE", "KIND", "FN", "N", "NICKNAME",
42                    "PHOTO", "BDAY", "ANNIVERSARY", "GENDER", "ADR", "TEL",
43                    "EMAIL", "IMPP", "LANG", "TZ", "GEO", "TITLE", "ROLE",
44                    "LOGO", "ORG", "MEMBER", "RELATED", "CATEGORIES",
45                    "NOTE", "PRODID", "REV", "SOUND", "UID", "CLIENTPIDMAP",
46                    "URL", "KEY", "FBURL", "CALENDRURI", "CALURI", "XML")));
47
48    /**
49     * <p>
50     * A unmodifiable Set storing the values for the type "ENCODING", available in vCard 4.0.
51     * </p>
52     */
53    /* package */ static final Set<String> sAcceptableEncoding =
54            Collections.unmodifiableSet(new HashSet<String>(Arrays.asList(
55                    VCardConstants.PARAM_ENCODING_8BIT,
56                    VCardConstants.PARAM_ENCODING_B)));
57
58    private final VCardParserImpl_V30 mVCardParserImpl;
59
60    public VCardParser_V40() {
61        mVCardParserImpl = new VCardParserImpl_V40();
62    }
63
64    public VCardParser_V40(int vcardType) {
65        mVCardParserImpl = new VCardParserImpl_V40(vcardType);
66    }
67
68    @Override
69    public void parse(InputStream is, VCardInterpreter interepreter)
70            throws IOException, VCardException {
71        mVCardParserImpl.parse(is, interepreter);
72    }
73
74    @Override
75    public void cancel() {
76        mVCardParserImpl.cancel();
77    }
78}