1 13 package com.tonbeller.wcf.format; 14 15 import java.util.List ; 16 17 20 public class StringHandler extends FormatHandlerSupport { 21 22 public String format(Object o, String userPattern) { 23 if (o == null) 25 return ""; 26 return String.valueOf(o); 27 } 28 29 30 public Object parse(String s, String userPattern) { 31 if (s.indexOf(13) >= 0) { 33 StringBuffer sb = new StringBuffer (); 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 value) { 45 return value instanceof String ; 46 } 47 48 public Object toNativeArray(List list) { 49 String [] array = new String [list.size()]; 50 for (int i = 0; i < array.length; i++) 51 array[i] = (String ) list.get(i); 52 return array; 53 } 54 55 public Object [] toObjectArray(Object value) { 56 if (value instanceof String ) 57 return new String [] {(String ) value }; 58 return (String []) value; 59 } 60 61 } | Popular Tags |