KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tonbeller > wcf > format > StringHandler


1 /*
2  * ====================================================================
3  * This software is subject to the terms of the Common Public License
4  * Agreement, available at the following URL:
5  * http://www.opensource.org/licenses/cpl.html .
6  * Copyright (C) 2003-2004 TONBELLER AG.
7  * All Rights Reserved.
8  * You must accept the terms of that agreement to use this software.
9  * ====================================================================
10  *
11  *
12  */

13 package com.tonbeller.wcf.format;
14
15 import java.util.List JavaDoc;
16
17 /**
18  * @author av
19  */

20 public class StringHandler extends FormatHandlerSupport {
21
22   public String JavaDoc format(Object JavaDoc o, String JavaDoc userPattern) {
23     // dont show "null"
24
if (o == null)
25       return "";
26     return String.valueOf(o);
27   }
28
29
30   public Object JavaDoc parse(String JavaDoc s, String JavaDoc userPattern) {
31     // microsoft sends \r\n sometimes?!
32
if (s.indexOf(13) >= 0) {
33       StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
34       char[] ca = s.toCharArray();
35       for (int i = 0; i < ca.length; i++) {
36         if (ca[i] != 13)
37           sb.append(ca[i]);
38       }
39       s = sb.toString();
40     }
41     return s;
42   }
43
44   public boolean canHandle(Object JavaDoc value) {
45     return value instanceof String JavaDoc;
46   }
47
48   public Object JavaDoc toNativeArray(List JavaDoc list) {
49     String JavaDoc[] array = new String JavaDoc[list.size()];
50     for (int i = 0; i < array.length; i++)
51       array[i] = (String JavaDoc) list.get(i);
52     return array;
53   }
54   
55   public Object JavaDoc[] toObjectArray(Object JavaDoc value) {
56     if (value instanceof String JavaDoc)
57       return new String JavaDoc[] {(String JavaDoc) value };
58     return (String JavaDoc[]) value;
59   }
60
61 }
Popular Tags