KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > columba > addressbook > parser > ParserUtil


1 // The contents of this file are subject to the Mozilla Public License Version
2
// 1.1
3
//(the "License"); you may not use this file except in compliance with the
4
//License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
5
//
6
//Software distributed under the License is distributed on an "AS IS" basis,
7
//WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
8
//for the specific language governing rights and
9
//limitations under the License.
10
//
11
//The Original Code is "The Columba Project"
12
//
13
//The Initial Developers of the Original Code are Frederik Dietz and Timo
14
// Stich.
15
//Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
16
//
17
//All Rights Reserved.
18
package org.columba.addressbook.parser;
19
20 import java.util.ArrayList JavaDoc;
21 import java.util.StringTokenizer JavaDoc;
22
23 import javax.swing.ImageIcon JavaDoc;
24
25 public class ParserUtil {
26
27     /**
28      * this method tries to break the display name into something meaningful to
29      * put under Given Name, Family Name and Middle Name. It'll miss prefix and
30      * suffix!
31      */

32     public static String JavaDoc[] tryBreakName(String JavaDoc displayName) {
33         String JavaDoc[] names = new String JavaDoc[] { "", "", "" };
34         int firstName = -1;
35         if ((firstName = displayName.indexOf(' ')) > 0)
36             names[0] = displayName.substring(0, firstName);
37         else
38             return names; // exit immediately, nothing more to do
39

40         int lastName = -1;
41         if ((lastName = displayName.lastIndexOf(' ')) >= firstName)
42             names[2] = displayName.substring(lastName + 1);
43         else
44             return names; // exit immediately, nothing more to do
45

46         if (lastName > firstName)
47             names[1] = displayName.substring(firstName, lastName).trim();
48
49         return names;
50     }
51
52     /**
53      * Create array from comma-separated string.
54      *
55      * @param s
56      * comma-separated string
57      * @param separator
58      *
59      * @return string array
60      */

61     public static String JavaDoc[] getArrayOfString(String JavaDoc s, String JavaDoc separator) {
62         ArrayList JavaDoc list = new ArrayList JavaDoc();
63
64         StringTokenizer JavaDoc tok = new StringTokenizer JavaDoc(s, separator);
65         while (tok.hasMoreTokens()) {
66             String JavaDoc t = tok.nextToken();
67             list.add(t);
68         }
69
70         return (String JavaDoc[]) list.toArray(new String JavaDoc[] { "" });
71
72     }
73
74     /**
75      * Create comma-separated string from string array.
76      *
77      * @param s
78      * string array
79      * @param separator
80      *
81      * @return comma separated string
82      */

83     public static String JavaDoc getStringOfArray(String JavaDoc[] s, String JavaDoc separator) {
84         StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
85         for (int i = 0; i < s.length; i++) {
86             if (s[i] != null && s[i].length() > 0) {
87                 buf.append(s[i]);
88                 if (i < s.length - 1)
89                     buf.append(separator);
90             }
91         }
92
93         return buf.toString();
94     }
95
96     public static ImageIcon JavaDoc createImageFromBase64String(String JavaDoc s) {
97
98         // TODO implement me!
99

100         return null;
101     }
102
103     public static String JavaDoc createBase64StringFromImage(ImageIcon JavaDoc image) {
104
105         // TODO implement me!
106

107         return null;
108     }
109
110 }
111
Popular Tags