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 javax.microedition.pim.Event;
030:
031: /**
032: * Helper methods for vEvent implementations.
033: *
034: */
035: public class VEventSupport {
036:
037: /**
038: * Converts JSR75 field code to vCalendar property name.
039: * @param field identifier for field name
040: * @return label for requested field
041: */
042: public static String getFieldLabel(int field) {
043: switch (field) {
044: case Event.ALARM:
045: return "DALARM";
046: case Event.CLASS:
047: return "CLASS";
048: case Event.END:
049: return "DTEND";
050: case Event.LOCATION:
051: return "LOCATION";
052: case Event.NOTE:
053: return "DESCRIPTION";
054: case Event.REVISION:
055: return "LAST-MODIFIED";
056: case Event.START:
057: return "DTSTART";
058: case Event.SUMMARY:
059: return "SUMMARY";
060: case Event.UID:
061: return "UID";
062: default:
063: return null;
064: }
065: }
066:
067: /**
068: * Converts vCalendar property name to JSR75 field code.
069: * @param fieldName label of requested field
070: * @return identifier for requested field
071: */
072: public static int getFieldCode(String fieldName) {
073: if (fieldName.equals("DTSTART"))
074: return Event.START;
075: else if (fieldName.equals("DTEND"))
076: return Event.END;
077: else if (fieldName.equals("DALARM"))
078: return Event.ALARM;
079: else if (fieldName.equals("LOCATION"))
080: return Event.LOCATION;
081: else if (fieldName.equals("DESCRIPTION"))
082: return Event.NOTE;
083: else if (fieldName.equals("LAST-MODIFIED"))
084: return Event.REVISION;
085: else if (fieldName.equals("SUMMARY"))
086: return Event.SUMMARY;
087: else if (fieldName.equals("UID"))
088: return Event.UID;
089: else if (fieldName.equals("CLASS"))
090: return Event.CLASS;
091: else
092: return -1;
093: }
094:
095: /**
096: * Gets the value of the vEvent CLASS field for the given
097: * value of the Event.CLASS field.
098: * This method encapsulates the following mapping:
099: * Event.CLASS_PUBLIC -> "PUBLIC"
100: * Event.CLASS_PRIVATE -> "PRIVATE"
101: * Event.CLASS_CONFIDENTIAL -> "CONFIDENTIAL"
102: *
103: * @param fieldValue the value of the Event.CLASS field
104: * @return a string describing the class for the field value, or null if
105: * fieldValue is out of range
106: */
107: public static String getClassType(int fieldValue) {
108: switch (fieldValue) {
109: case Event.CLASS_CONFIDENTIAL:
110: return "CONFIDENTIAL";
111: case Event.CLASS_PRIVATE:
112: return "PRIVATE";
113: case Event.CLASS_PUBLIC:
114: return "PUBLIC";
115: }
116: return null;
117: }
118:
119: /**
120: * Gets the value of the Event.CLASS field for the given
121: * value of the vEvent CLASS property.
122: * This method encapsulates the following mapping:
123: * Event.CLASS_PUBLIC <- "PUBLIC"
124: * Event.CLASS_PRIVATE <- "PRIVATE"
125: * Event.CLASS_CONFIDENTIAL <- "CONFIDENTIAL"
126: *
127: * @param s the value of the CLASS property
128: * @return the corresponding field of Event, or -1 if s is not recognized
129: */
130: public static int getClassCode(String s) {
131: switch (s.length()) {
132: case 6:
133: if (s.equals("PUBLIC")) {
134: return Event.CLASS_PUBLIC;
135: }
136: break;
137: case 7:
138: if (s.equals("PRIVATE")) {
139: return Event.CLASS_PRIVATE;
140: }
141: break;
142: case 12:
143: if (s.equals("CONFIDENTIAL")) {
144: return Event.CLASS_CONFIDENTIAL;
145: }
146: break;
147: }
148: return -1;
149: }
150:
151: }
|