001: // The contents of this file are subject to the Mozilla Public License Version
002: // 1.1
003: //(the "License"); you may not use this file except in compliance with the
004: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
005: //
006: //Software distributed under the License is distributed on an "AS IS" basis,
007: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
008: //for the specific language governing rights and
009: //limitations under the License.
010: //
011: //The Original Code is "The Columba Project"
012: //
013: //The Initial Developers of the Original Code are Frederik Dietz and Timo
014: // Stich.
015: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
016: //
017: //All Rights Reserved.
018: package org.columba.addressbook.parser;
019:
020: import java.util.ArrayList;
021: import java.util.StringTokenizer;
022:
023: import javax.swing.ImageIcon;
024:
025: public class ParserUtil {
026:
027: /**
028: * this method tries to break the display name into something meaningful to
029: * put under Given Name, Family Name and Middle Name. It'll miss prefix and
030: * suffix!
031: */
032: public static String[] tryBreakName(String displayName) {
033: String[] names = new String[] { "", "", "" };
034: int firstName = -1;
035: if ((firstName = displayName.indexOf(' ')) > 0)
036: names[0] = displayName.substring(0, firstName);
037: else
038: return names; // exit immediately, nothing more to do
039:
040: int lastName = -1;
041: if ((lastName = displayName.lastIndexOf(' ')) >= firstName)
042: names[2] = displayName.substring(lastName + 1);
043: else
044: return names; // exit immediately, nothing more to do
045:
046: if (lastName > firstName)
047: names[1] = displayName.substring(firstName, lastName)
048: .trim();
049:
050: return names;
051: }
052:
053: /**
054: * Create array from comma-separated string.
055: *
056: * @param s
057: * comma-separated string
058: * @param separator
059: *
060: * @return string array
061: */
062: public static String[] getArrayOfString(String s, String separator) {
063: ArrayList list = new ArrayList();
064:
065: StringTokenizer tok = new StringTokenizer(s, separator);
066: while (tok.hasMoreTokens()) {
067: String t = tok.nextToken();
068: list.add(t);
069: }
070:
071: return (String[]) list.toArray(new String[] { "" });
072:
073: }
074:
075: /**
076: * Create comma-separated string from string array.
077: *
078: * @param s
079: * string array
080: * @param separator
081: *
082: * @return comma separated string
083: */
084: public static String getStringOfArray(String[] s, String separator) {
085: StringBuffer buf = new StringBuffer();
086: for (int i = 0; i < s.length; i++) {
087: if (s[i] != null && s[i].length() > 0) {
088: buf.append(s[i]);
089: if (i < s.length - 1)
090: buf.append(separator);
091: }
092: }
093:
094: return buf.toString();
095: }
096:
097: public static ImageIcon createImageFromBase64String(String s) {
098:
099: // TODO implement me!
100:
101: return null;
102: }
103:
104: public static String createBase64StringFromImage(ImageIcon image) {
105:
106: // TODO implement me!
107:
108: return null;
109: }
110:
111: }
|