1 57 58 59 package com.sun.org.apache.xml.internal.serialize; 60 61 62 import java.io.UnsupportedEncodingException ; 63 import java.util.Hashtable ; 64 import java.util.Locale ; 65 66 import com.sun.org.apache.xerces.internal.util.EncodingMap; 67 68 69 78 public class Encodings 79 { 80 81 82 85 static final int DEFAULT_LAST_PRINTABLE = 0x7F; 86 87 static final int LAST_PRINTABLE_UNICODE = 0xffff; 89 static final String [] UNICODE_ENCODINGS = { 91 "Unicode", "UnicodeBig", "UnicodeLittle", "GB2312", "UTF8", 92 }; 93 static final String DEFAULT_ENCODING = "UTF8"; 95 96 static Hashtable _encodings = new Hashtable (); 100 101 104 static EncodingInfo getEncodingInfo(String encoding, boolean allowJavaNames) throws UnsupportedEncodingException { 105 EncodingInfo eInfo = null; 106 if (encoding == null) { 107 if((eInfo = (EncodingInfo)_encodings.get(DEFAULT_ENCODING)) != null) 108 return eInfo; 109 eInfo = new EncodingInfo(EncodingMap.getJava2IANAMapping(DEFAULT_ENCODING), DEFAULT_ENCODING, LAST_PRINTABLE_UNICODE); 110 _encodings.put(DEFAULT_ENCODING, eInfo); 111 return eInfo; 112 } 113 encoding = encoding.toUpperCase(Locale.ENGLISH); 115 String jName = EncodingMap.getIANA2JavaMapping(encoding); 116 if(jName == null) { 117 if(allowJavaNames ) { 119 EncodingInfo.testJavaEncodingName(encoding); 120 if((eInfo = (EncodingInfo)_encodings.get(encoding)) != null) 121 return eInfo; 122 int i=0; 124 for(; i<UNICODE_ENCODINGS.length; i++) { 125 if(UNICODE_ENCODINGS[i].equalsIgnoreCase(encoding)) { 126 eInfo = new EncodingInfo(EncodingMap.getJava2IANAMapping(encoding), encoding, LAST_PRINTABLE_UNICODE); 127 break; 128 } 129 } 130 if(i == UNICODE_ENCODINGS.length) { 131 eInfo = new EncodingInfo(EncodingMap.getJava2IANAMapping(encoding), encoding, DEFAULT_LAST_PRINTABLE); 132 } 133 _encodings.put(encoding, eInfo); 134 return eInfo; 135 } else { 136 throw new UnsupportedEncodingException (encoding); 137 } 138 } 139 if ((eInfo = (EncodingInfo)_encodings.get(jName)) != null) 140 return eInfo; 141 int i=0; 144 for(; i<UNICODE_ENCODINGS.length; i++) { 145 if(UNICODE_ENCODINGS[i].equalsIgnoreCase(jName)) { 146 eInfo = new EncodingInfo(encoding, jName, LAST_PRINTABLE_UNICODE); 147 break; 148 } 149 } 150 if(i == UNICODE_ENCODINGS.length) { 151 eInfo = new EncodingInfo(encoding, jName, DEFAULT_LAST_PRINTABLE); 152 } 153 _encodings.put(jName, eInfo); 154 return eInfo; 155 } 156 157 static final String JIS_DANGER_CHARS 158 = "\\\u007e\u007f\u00a2\u00a3\u00a5\u00ac" 159 +"\u2014\u2015\u2016\u2026\u203e\u203e\u2225\u222f\u301c" 160 +"\uff3c\uff5e\uffe0\uffe1\uffe2\uffe3"; 161 162 } 163 | Popular Tags |