1 16 17 18 package org.apache.xml.serialize; 19 20 21 import java.io.UnsupportedEncodingException ; 22 import java.util.Hashtable ; 23 import java.util.Locale ; 24 25 import org.apache.xerces.util.EncodingMap; 26 27 28 37 public class Encodings 38 { 39 40 41 44 static final int DEFAULT_LAST_PRINTABLE = 0x7F; 45 46 static final int LAST_PRINTABLE_UNICODE = 0xffff; 48 static final String [] UNICODE_ENCODINGS = { 50 "Unicode", "UnicodeBig", "UnicodeLittle", "GB2312", "UTF8", "UTF-16", 51 }; 52 static final String DEFAULT_ENCODING = "UTF8"; 54 55 static Hashtable _encodings = new Hashtable (); 59 60 63 static EncodingInfo getEncodingInfo(String encoding, boolean allowJavaNames) throws UnsupportedEncodingException { 64 EncodingInfo eInfo = null; 65 if (encoding == null) { 66 if((eInfo = (EncodingInfo)_encodings.get(DEFAULT_ENCODING)) != null) 67 return eInfo; 68 eInfo = new EncodingInfo(EncodingMap.getJava2IANAMapping(DEFAULT_ENCODING), DEFAULT_ENCODING, LAST_PRINTABLE_UNICODE); 69 _encodings.put(DEFAULT_ENCODING, eInfo); 70 return eInfo; 71 } 72 encoding = encoding.toUpperCase(Locale.ENGLISH); 74 String jName = EncodingMap.getIANA2JavaMapping(encoding); 75 if(jName == null) { 76 if(allowJavaNames ) { 78 EncodingInfo.testJavaEncodingName(encoding); 79 if((eInfo = (EncodingInfo)_encodings.get(encoding)) != null) 80 return eInfo; 81 int i=0; 83 for(; i<UNICODE_ENCODINGS.length; i++) { 84 if(UNICODE_ENCODINGS[i].equalsIgnoreCase(encoding)) { 85 eInfo = new EncodingInfo(EncodingMap.getJava2IANAMapping(encoding), encoding, LAST_PRINTABLE_UNICODE); 86 break; 87 } 88 } 89 if(i == UNICODE_ENCODINGS.length) { 90 eInfo = new EncodingInfo(EncodingMap.getJava2IANAMapping(encoding), encoding, DEFAULT_LAST_PRINTABLE); 91 } 92 _encodings.put(encoding, eInfo); 93 return eInfo; 94 } else { 95 throw new UnsupportedEncodingException (encoding); 96 } 97 } 98 if ((eInfo = (EncodingInfo)_encodings.get(jName)) != null) 99 return eInfo; 100 int i=0; 103 for(; i<UNICODE_ENCODINGS.length; i++) { 104 if(UNICODE_ENCODINGS[i].equalsIgnoreCase(jName)) { 105 eInfo = new EncodingInfo(encoding, jName, LAST_PRINTABLE_UNICODE); 106 break; 107 } 108 } 109 if(i == UNICODE_ENCODINGS.length) { 110 eInfo = new EncodingInfo(encoding, jName, DEFAULT_LAST_PRINTABLE); 111 } 112 _encodings.put(jName, eInfo); 113 return eInfo; 114 } 115 116 static final String JIS_DANGER_CHARS 117 = "\\\u007e\u007f\u00a2\u00a3\u00a5\u00ac" 118 +"\u2014\u2015\u2016\u2026\u203e\u203e\u2225\u222f\u301c" 119 +"\uff3c\uff5e\uffe0\uffe1\uffe2\uffe3"; 120 121 } 122 | Popular Tags |