001: /*
002: *
003: *
004: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006: *
007: * This program is free software; you can redistribute it and/or
008: * modify it under the terms of the GNU General Public License version
009: * 2 only, as published by the Free Software Foundation.
010: *
011: * This program is distributed in the hope that it will be useful, but
012: * WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * General Public License version 2 for more details (a copy is
015: * included at /legal/license.txt).
016: *
017: * You should have received a copy of the GNU General Public License
018: * version 2 along with this work; if not, write to the Free Software
019: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA
021: *
022: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023: * Clara, CA 95054 or visit www.sun.com if you need additional
024: * information or have any questions.
025: */
026:
027: package com.sun.kvem.midp.pim.formats;
028:
029: import java.io.IOException;
030: import java.io.Writer;
031:
032: /**
033: * Implementation of PIMEncoding for VCard/2.1.
034: *
035: */
036: public class VCard21Format extends VCardFormat {
037:
038: /**
039: * Property used to store categories
040: */
041: private static final String PROPERTY_CATEGORY = "X-J2MEWTK-CATEGORY";
042:
043: /**
044: * Property used to store access class.
045: */
046: private static final String PROPERTY_CLASS = "X-J2MEWTK-CLASS";
047:
048: /**
049: * Writes the attributes for a field.
050: * @param w the output writer stream
051: * @param attributes the attributes to be processed
052: * @throws IOException if an error occurs writing
053: */
054: protected void writeAttributes(Writer w, int attributes)
055: throws IOException {
056: for (int i = 0; i < 32; i++) {
057: long mask = 1l << i;
058: if ((attributes & mask) != 0) {
059: String attributeLabel = VCardSupport
060: .getAttributeLabel((int) mask);
061: if (attributeLabel != null) {
062: w.write(';');
063: w.write(attributeLabel);
064: }
065: }
066: }
067: }
068:
069: /**
070: * Gets the binary value describing all flags in a vCard line.
071: * @param attributes input selection attributes
072: * @return binary attribute codes
073: */
074: protected int parseAttributes(String[] attributes) {
075: int code = 0;
076: for (int i = 0; i < attributes.length; i++) {
077: code |= VCardSupport.getAttributeCode(attributes[i], 0);
078: }
079: return code;
080: }
081:
082: /**
083: * Returns name of encoding.
084: * @return encoding name
085: */
086: protected String getBinaryEncodingName() {
087: return "BASE64";
088: }
089:
090: /**
091: * Returns the property category.
092: * @return property category
093: */
094: protected String getCategoryProperty() {
095: return PROPERTY_CATEGORY;
096: }
097:
098: /**
099: * Returns class property.
100: * @return class property
101: */
102: protected String getClassProperty() {
103: return PROPERTY_CLASS;
104: }
105:
106: /**
107: * Returns VCard version.
108: * @return VCard version "2.1"
109: */
110: protected String getVersion() {
111: return "2.1";
112: }
113:
114: }
|