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