1 5 6 package javax.xml.bind.annotation.adapters; 7 8 9 10 20 public final class NormalizedStringAdapter extends XmlAdapter<String ,String > { 21 25 public String unmarshal(String text) { 26 if(text==null) return null; 28 int i=text.length()-1; 29 30 while( i>=0 && !isWhiteSpaceExceptSpace(text.charAt(i)) ) 32 i--; 33 34 if( i<0 ) 35 return text; 37 38 char[] buf = text.toCharArray(); 41 42 buf[i--] = ' '; 43 for( ; i>=0; i-- ) 44 if( isWhiteSpaceExceptSpace(buf[i])) 45 buf[i] = ' '; 46 47 return new String (buf); 48 } 49 50 55 public String marshal(String s) { 56 return s; 57 } 58 59 60 64 protected static boolean isWhiteSpaceExceptSpace(char ch) { 65 if( ch>=0x20 ) return false; 68 69 return ch == 0x9 || ch == 0xA || ch == 0xD; 71 } 72 } 73 | Popular Tags |