1 74 package org.eclipse.emf.ecore.xml.type.internal; 75 76 77 import java.io.IOException ; 78 import java.io.Serializable ; 79 import java.util.Arrays ; 80 import java.util.Hashtable ; 81 82 85 public final class DataValue 86 { 87 88 static class ValidationContext 89 { 90 } 91 92 static class XSSimpleType 93 { 94 } 95 96 111 public static final class Base64 { 112 113 static private final int BASELENGTH = 255; 114 static private final int LOOKUPLENGTH = 64; 115 static private final int TWENTYFOURBITGROUP = 24; 116 static private final int EIGHTBIT = 8; 117 static private final int SIXTEENBIT = 16; 118 static private final int FOURBYTE = 4; 119 static private final int SIGN = -128; 120 static private final char PAD = '='; 121 static private final boolean fDebug = false; 122 static final private byte [] base64Alphabet = new byte[BASELENGTH]; 123 static final private char [] lookUpBase64Alphabet = new char[LOOKUPLENGTH]; 124 125 static { 126 127 for (int i = 0; i<BASELENGTH; i++) { 128 base64Alphabet[i] = -1; 129 } 130 for (int i = 'Z'; i >= 'A'; i--) { 131 base64Alphabet[i] = (byte) (i-'A'); 132 } 133 for (int i = 'z'; i>= 'a'; i--) { 134 base64Alphabet[i] = (byte) ( i-'a' + 26); 135 } 136 137 for (int i = '9'; i >= '0'; i--) { 138 base64Alphabet[i] = (byte) (i-'0' + 52); 139 } 140 141 base64Alphabet['+'] = 62; 142 base64Alphabet['/'] = 63; 143 144 for (int i = 0; i<=25; i++) 145 lookUpBase64Alphabet[i] = (char)('A'+i); 146 147 for (int i = 26, j = 0; i<=51; i++, j++) 148 lookUpBase64Alphabet[i] = (char)('a'+ j); 149 150 for (int i = 52, j = 0; i<=61; i++, j++) 151 lookUpBase64Alphabet[i] = (char)('0' + j); 152 lookUpBase64Alphabet[62] = '+'; 153 lookUpBase64Alphabet[63] = '/'; 154 155 } 156 157 protected static boolean isWhiteSpace(char octect) { 158 return (octect == 0x20 || octect == 0xd || octect == 0xa || octect == 0x9); 159 } 160 161 protected static boolean isPad(char octect) { 162 return (octect == PAD); 163 } 164 165 protected static boolean isData(char octect) { 166 return (base64Alphabet[octect] != -1); 167 } 168 169 protected static boolean isBase64(char octect) { 170 return (isWhiteSpace(octect) || isPad(octect) || isData(octect)); 171 } 172 173 179 public static String encode(byte[] binaryData) { 180 181 183 if (binaryData == null) 184 return null; 185 186 int lengthDataBits = binaryData.length*EIGHTBIT; 187 if (lengthDataBits == 0) { 188 return ""; 189 } 190 191 int fewerThan24bits = lengthDataBits%TWENTYFOURBITGROUP; 192 int numberTriplets = lengthDataBits/TWENTYFOURBITGROUP; 193 int numberQuartet = fewerThan24bits != 0 ? numberTriplets+1 : numberTriplets; 194 char encodedData[] = null; 195 196 encodedData = new char[numberQuartet*4]; 197 198 byte k=0, l=0, b1=0,b2=0,b3=0; 199 200 int encodedIndex = 0; 201 int dataIndex = 0; 202 if (fDebug) { 203 System.out.println("number of triplets = " + numberTriplets ); 204 } 205 206 for (int i=0; i<numberTriplets; i++) { 207 b1 = binaryData[dataIndex++]; 208 b2 = binaryData[dataIndex++]; 209 b3 = binaryData[dataIndex++]; 210 211 if (fDebug) { 212 System.out.println( "b1= " + b1 +", b2= " + b2 + ", b3= " + b3 ); 213 } 214 215 l = (byte)(b2 & 0x0f); 216 k = (byte)(b1 & 0x03); 217 218 byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0); 219 220 byte val2 = ((b2 & SIGN)==0)?(byte)(b2>>4):(byte)((b2)>>4^0xf0); 221 byte val3 = ((b3 & SIGN)==0)?(byte)(b3>>6):(byte)((b3)>>6^0xfc); 222 223 if (fDebug) { 224 System.out.println( "val2 = " + val2 ); 225 System.out.println( "k4 = " + (k<<4)); 226 System.out.println( "vak = " + (val2 | (k<<4))); 227 } 228 229 encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ]; 230 encodedData[encodedIndex++] = lookUpBase64Alphabet[ val2 | ( k<<4 )]; 231 encodedData[encodedIndex++] = lookUpBase64Alphabet[ (l <<2 ) | val3 ]; 232 encodedData[encodedIndex++] = lookUpBase64Alphabet[ b3 & 0x3f ]; 233 } 234 235 if (fewerThan24bits == EIGHTBIT) { 237 b1 = binaryData[dataIndex]; 238 k = (byte) ( b1 &0x03 ); 239 if (fDebug) { 240 System.out.println("b1=" + b1); 241 System.out.println("b1<<2 = " + (b1>>2) ); 242 } 243 byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0); 244 encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ]; 245 encodedData[encodedIndex++] = lookUpBase64Alphabet[ k<<4 ]; 246 encodedData[encodedIndex++] = PAD; 247 encodedData[encodedIndex++] = PAD; 248 } else if (fewerThan24bits == SIXTEENBIT) { 249 b1 = binaryData[dataIndex]; 250 b2 = binaryData[dataIndex +1 ]; 251 l = ( byte ) ( b2 &0x0f ); 252 k = ( byte ) ( b1 &0x03 ); 253 254 byte val1 = ((b1 & SIGN)==0)?(byte)(b1>>2):(byte)((b1)>>2^0xc0); 255 byte val2 = ((b2 & SIGN)==0)?(byte)(b2>>4):(byte)((b2)>>4^0xf0); 256 257 encodedData[encodedIndex++] = lookUpBase64Alphabet[ val1 ]; 258 encodedData[encodedIndex++] = lookUpBase64Alphabet[ val2 | ( k<<4 )]; 259 encodedData[encodedIndex++] = lookUpBase64Alphabet[ l<<2 ]; 260 encodedData[encodedIndex++] = PAD; 261 } 262 263 265 return new String (encodedData); 266 } 267 268 274 public static byte[] decode(String encoded) { 275 276 if (encoded == null) 277 return null; 278 279 char[] base64Data = encoded.toCharArray(); 280 int len = removeWhiteSpace(base64Data); 282 283 if (len%FOURBYTE != 0) { 284 return null; } 286 287 int numberQuadruple = (len/FOURBYTE ); 288 289 if (numberQuadruple == 0) 290 return new byte[0]; 291 292 byte decodedData[] = null; 293 byte b1=0,b2=0,b3=0, b4=0; 294 char d1=0,d2=0,d3=0,d4=0; 295 296 int i = 0; 297 int encodedIndex = 0; 298 int dataIndex = 0; 299 decodedData = new byte[ (numberQuadruple)*3]; 300 301 for (; i<numberQuadruple-1; i++) { 302 303 if (!isData( (d1 = base64Data[dataIndex++]) )|| 304 !isData( (d2 = base64Data[dataIndex++]) )|| 305 !isData( (d3 = base64Data[dataIndex++]) )|| 306 !isData( (d4 = base64Data[dataIndex++]) )) 307 return null; 309 b1 = base64Alphabet[d1]; 310 b2 = base64Alphabet[d2]; 311 b3 = base64Alphabet[d3]; 312 b4 = base64Alphabet[d4]; 313 314 decodedData[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ) ; 315 decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); 316 decodedData[encodedIndex++] = (byte)( b3<<6 | b4 ); 317 } 318 319 if (!isData( (d1 = base64Data[dataIndex++]) ) || 320 !isData( (d2 = base64Data[dataIndex++]) )) { 321 return null; } 323 324 b1 = base64Alphabet[d1]; 325 b2 = base64Alphabet[d2]; 326 327 d3 = base64Data[dataIndex++]; 328 d4 = base64Data[dataIndex++]; 329 if (!isData( (d3 ) ) || 330 !isData( (d4 ) )) { if (isPad( d3 ) && isPad( d4)) { if ((b2 & 0xf) != 0) return null; 334 byte[] tmp = new byte[ i*3 + 1 ]; 335 System.arraycopy( decodedData, 0, tmp, 0, i*3 ); 336 tmp[encodedIndex] = (byte)( b1 <<2 | b2>>4 ) ; 337 return tmp; 338 } else if (!isPad( d3) && isPad(d4)) { b3 = base64Alphabet[ d3 ]; 340 if ((b3 & 0x3 ) != 0) return null; 342 byte[] tmp = new byte[ i*3 + 2 ]; 343 System.arraycopy( decodedData, 0, tmp, 0, i*3 ); 344 tmp[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ); 345 tmp[encodedIndex] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); 346 return tmp; 347 } else { 348 return null; } 350 } else { b3 = base64Alphabet[ d3 ]; 352 b4 = base64Alphabet[ d4 ]; 353 decodedData[encodedIndex++] = (byte)( b1 <<2 | b2>>4 ) ; 354 decodedData[encodedIndex++] = (byte)(((b2 & 0xf)<<4 ) |( (b3>>2) & 0xf) ); 355 decodedData[encodedIndex++] = (byte)( b3<<6 | b4 ); 356 357 } 358 359 return decodedData; 360 } 361 362 368 protected static int removeWhiteSpace(char[] data) { 369 if (data == null) 370 return 0; 371 372 int newSize = 0; 374 int len = data.length; 375 for (int i = 0; i < len; i++) { 376 if (!isWhiteSpace(data[i])) 377 data[newSize++] = data[i]; 378 } 379 return newSize; 380 } 381 } 382 383 384 390 public static final class HexBin { 391 static private final int BASELENGTH = 255; 392 static private final int LOOKUPLENGTH = 16; 393 static final private byte [] hexNumberTable = new byte[BASELENGTH]; 394 static final private char [] lookUpHexAlphabet = new char[LOOKUPLENGTH]; 395 396 397 static { 398 for (int i = 0; i<BASELENGTH; i++ ) { 399 hexNumberTable[i] = -1; 400 } 401 for ( int i = '9'; i >= '0'; i--) { 402 hexNumberTable[i] = (byte) (i-'0'); 403 } 404 for ( int i = 'F'; i>= 'A'; i--) { 405 hexNumberTable[i] = (byte) ( i-'A' + 10 ); 406 } 407 for ( int i = 'f'; i>= 'a'; i--) { 408 hexNumberTable[i] = (byte) ( i-'a' + 10 ); 409 } 410 411 for(int i = 0; i<10; i++ ) 412 lookUpHexAlphabet[i] = (char)('0'+i); 413 for(int i = 10; i<=15; i++ ) 414 lookUpHexAlphabet[i] = (char)('A'+i -10); 415 } 416 417 423 static public String encode(byte[] binaryData) { 424 if (binaryData == null) 425 return null; 426 int lengthData = binaryData.length; 427 int lengthEncode = lengthData * 2; 428 char[] encodedData = new char[lengthEncode]; 429 int temp; 430 for (int i = 0; i < lengthData; i++) { 431 temp = binaryData[i]; 432 if (temp < 0) 433 temp += 256; 434 encodedData[i*2] = lookUpHexAlphabet[temp >> 4]; 435 encodedData[i*2+1] = lookUpHexAlphabet[temp & 0xf]; 436 } 437 return new String (encodedData); 438 } 439 440 446 static public byte[] decode(String encoded) { 447 if (encoded == null) 448 return null; 449 int lengthData = encoded.length(); 450 if (lengthData % 2 != 0) 451 return null; 452 453 char[] binaryData = encoded.toCharArray(); 454 int lengthDecode = lengthData / 2; 455 byte[] decodedData = new byte[lengthDecode]; 456 byte temp1, temp2; 457 for( int i = 0; i<lengthDecode; i++ ){ 458 temp1 = hexNumberTable[binaryData[i*2]]; 459 if (temp1 == -1) 460 return null; 461 temp2 = hexNumberTable[binaryData[i*2+1]]; 462 if (temp2 == -1) 463 return null; 464 decodedData[i] = (byte)((temp1 << 4) | temp2); 465 } 466 return decodedData; 467 } 468 } 469 470 917 public static class EncodingMap { 918 919 923 924 protected final static Hashtable fIANA2JavaMap = new Hashtable (); 925 926 927 protected final static Hashtable fJava2IANAMap = new Hashtable (); 928 929 933 static { 934 935 fIANA2JavaMap.put("BIG5", "Big5"); 937 fIANA2JavaMap.put("CSBIG5", "Big5"); 938 fIANA2JavaMap.put("CP037", "CP037"); 939 fIANA2JavaMap.put("IBM037", "CP037"); 940 fIANA2JavaMap.put("CSIBM037", "CP037"); 941 fIANA2JavaMap.put("EBCDIC-CP-US", "CP037"); 942 fIANA2JavaMap.put("EBCDIC-CP-CA", "CP037"); 943 fIANA2JavaMap.put("EBCDIC-CP-NL", "CP037"); 944 fIANA2JavaMap.put("EBCDIC-CP-WT", "CP037"); 945 fIANA2JavaMap.put("IBM273", "CP273"); 946 fIANA2JavaMap.put("CP273", "CP273"); 947 fIANA2JavaMap.put("CSIBM273", "CP273"); 948 fIANA2JavaMap.put("IBM277", "CP277"); 949 fIANA2JavaMap.put("CP277", "CP277"); 950 fIANA2JavaMap.put("CSIBM277", "CP277"); 951 fIANA2JavaMap.put("EBCDIC-CP-DK", "CP277"); 952 fIANA2JavaMap.put("EBCDIC-CP-NO", "CP277"); 953 fIANA2JavaMap.put("IBM278", "CP278"); 954 fIANA2JavaMap.put("CP278", "CP278"); 955 fIANA2JavaMap.put("CSIBM278", "CP278"); 956 fIANA2JavaMap.put("EBCDIC-CP-FI", "CP278"); 957 fIANA2JavaMap.put("EBCDIC-CP-SE", "CP278"); 958 fIANA2JavaMap.put("IBM280", "CP280"); 959 fIANA2JavaMap.put("CP280", "CP280"); 960 fIANA2JavaMap.put("CSIBM280", "CP280"); 961 fIANA2JavaMap.put("EBCDIC-CP-IT", "CP280"); 962 fIANA2JavaMap.put("IBM284", "CP284"); 963 fIANA2JavaMap.put("CP284", "CP284"); 964 fIANA2JavaMap.put("CSIBM284", "CP284"); 965 fIANA2JavaMap.put("EBCDIC-CP-ES", "CP284"); 966 fIANA2JavaMap.put("EBCDIC-CP-GB", "CP285"); 967 fIANA2JavaMap.put("IBM285", "CP285"); 968 fIANA2JavaMap.put("CP285", "CP285"); 969 fIANA2JavaMap.put("CSIBM285", "CP285"); 970 fIANA2JavaMap.put("EBCDIC-JP-KANA", "CP290"); 971 fIANA2JavaMap.put("IBM290", "CP290"); 972 fIANA2JavaMap.put("CP290", "CP290"); 973 fIANA2JavaMap.put("CSIBM290", "CP290"); 974 fIANA2JavaMap.put("EBCDIC-CP-FR", "CP297"); 975 fIANA2JavaMap.put("IBM297", "CP297"); 976 fIANA2JavaMap.put("CP297", "CP297"); 977 fIANA2JavaMap.put("CSIBM297", "CP297"); 978 fIANA2JavaMap.put("EBCDIC-CP-AR1", "CP420"); 979 fIANA2JavaMap.put("IBM420", "CP420"); 980 fIANA2JavaMap.put("CP420", "CP420"); 981 fIANA2JavaMap.put("CSIBM420", "CP420"); 982 fIANA2JavaMap.put("EBCDIC-CP-HE", "CP424"); 983 fIANA2JavaMap.put("IBM424", "CP424"); 984 fIANA2JavaMap.put("CP424", "CP424"); 985 fIANA2JavaMap.put("CSIBM424", "CP424"); 986 fIANA2JavaMap.put("IBM437", "CP437"); 987 fIANA2JavaMap.put("437", "CP437"); 988 fIANA2JavaMap.put("CP437", "CP437"); 989 fIANA2JavaMap.put("CSPC8CODEPAGE437", "CP437"); 990 fIANA2JavaMap.put("EBCDIC-CP-CH", "CP500"); 991 fIANA2JavaMap.put("IBM500", "CP500"); 992 fIANA2JavaMap.put("CP500", "CP500"); 993 fIANA2JavaMap.put("CSIBM500", "CP500"); 994 fIANA2JavaMap.put("EBCDIC-CP-CH", "CP500"); 995 fIANA2JavaMap.put("EBCDIC-CP-BE", "CP500"); 996 fIANA2JavaMap.put("IBM775", "CP775"); 997 fIANA2JavaMap.put("CP775", "CP775"); 998 fIANA2JavaMap.put("CSPC775BALTIC", "CP775"); 999 fIANA2JavaMap.put("IBM850", "CP850"); 1000 fIANA2JavaMap.put("850", "CP850"); 1001 fIANA2JavaMap.put("CP850", "CP850"); 1002 fIANA2JavaMap.put("CSPC850MULTILINGUAL", "CP850"); 1003 fIANA2JavaMap.put("IBM852", "CP852"); 1004 fIANA2JavaMap.put("852", "CP852"); 1005 fIANA2JavaMap.put("CP852", "CP852"); 1006 fIANA2JavaMap.put("CSPCP852", "CP852"); 1007 fIANA2JavaMap.put("IBM855", "CP855"); 1008 fIANA2JavaMap.put("855", "CP855"); 1009 fIANA2JavaMap.put("CP855", "CP855"); 1010 fIANA2JavaMap.put("CSIBM855", "CP855"); 1011 fIANA2JavaMap.put("IBM857", "CP857"); 1012 fIANA2JavaMap.put("857", "CP857"); 1013 fIANA2JavaMap.put("CP857", "CP857"); 1014 fIANA2JavaMap.put("CSIBM857", "CP857"); 1015 fIANA2JavaMap.put("IBM00858", "CP858"); 1016 fIANA2JavaMap.put("CP00858", "CP858"); 1017 fIANA2JavaMap.put("CCSID00858", "CP858"); 1018 fIANA2JavaMap.put("IBM860", "CP860"); 1019 fIANA2JavaMap.put("860", "CP860"); 1020 fIANA2JavaMap.put("CP860", "CP860"); 1021 fIANA2JavaMap.put("CSIBM860", "CP860"); 1022 fIANA2JavaMap.put("IBM861", "CP861"); 1023 fIANA2JavaMap.put("861", "CP861"); 1024 fIANA2JavaMap.put("CP861", "CP861"); 1025 fIANA2JavaMap.put("CP-IS", "CP861"); 1026 fIANA2JavaMap.put("CSIBM861", "CP861"); 1027 fIANA2JavaMap.put("IBM862", "CP862"); 1028 fIANA2JavaMap.put("862", "CP862"); 1029 fIANA2JavaMap.put("CP862", "CP862"); 1030 fIANA2JavaMap.put("CSPC862LATINHEBREW", "CP862"); 1031 fIANA2JavaMap.put("IBM863", "CP863"); 1032 fIANA2JavaMap.put("863", "CP863"); 1033 fIANA2JavaMap.put("CP863", "CP863"); 1034 fIANA2JavaMap.put("CSIBM863", "CP863"); 1035 fIANA2JavaMap.put("IBM864", "CP864"); 1036 fIANA2JavaMap.put("CP864", "CP864"); 1037 fIANA2JavaMap.put("CSIBM864", "CP864"); 1038 fIANA2JavaMap.put("IBM865", "CP865"); 1039 fIANA2JavaMap.put("865", "CP865"); 1040 fIANA2JavaMap.put("CP865", "CP865"); 1041 fIANA2JavaMap.put("CSIBM865", "CP865"); 1042 fIANA2JavaMap.put("IBM866", "CP866"); 1043 fIANA2JavaMap.put("866", "CP866"); 1044 fIANA2JavaMap.put("CP866", "CP866"); 1045 fIANA2JavaMap.put("CSIBM866", "CP866"); 1046 fIANA2JavaMap.put("IBM868", "CP868"); 1047 fIANA2JavaMap.put("CP868", "CP868"); 1048 fIANA2JavaMap.put("CSIBM868", "CP868"); 1049 fIANA2JavaMap.put("CP-AR", "CP868"); 1050 fIANA2JavaMap.put("IBM869", "CP869"); 1051 fIANA2JavaMap.put("CP869", "CP869"); 1052 fIANA2JavaMap.put("CSIBM869", "CP869"); 1053 fIANA2JavaMap.put("CP-GR", "CP869"); 1054 fIANA2JavaMap.put("IBM870", "CP870"); 1055 fIANA2JavaMap.put("CP870", "CP870"); 1056 fIANA2JavaMap.put("CSIBM870", "CP870"); 1057 fIANA2JavaMap.put("EBCDIC-CP-ROECE", "CP870"); 1058 fIANA2JavaMap.put("EBCDIC-CP-YU", "CP870"); 1059 fIANA2JavaMap.put("IBM871", "CP871"); 1060 fIANA2JavaMap.put("CP871", "CP871"); 1061 fIANA2JavaMap.put("CSIBM871", "CP871"); 1062 fIANA2JavaMap.put("EBCDIC-CP-IS", "CP871"); 1063 fIANA2JavaMap.put("IBM918", "CP918"); 1064 fIANA2JavaMap.put("CP918", "CP918"); 1065 fIANA2JavaMap.put("CSIBM918", "CP918"); 1066 fIANA2JavaMap.put("EBCDIC-CP-AR2", "CP918"); 1067 fIANA2JavaMap.put("IBM00924", "CP924"); 1068 fIANA2JavaMap.put("CP00924", "CP924"); 1069 fIANA2JavaMap.put("CCSID00924", "CP924"); 1070 fIANA2JavaMap.put("EBCDIC-LATIN9--EURO", "CP924"); 1072 fIANA2JavaMap.put("IBM1026", "CP1026"); 1073 fIANA2JavaMap.put("CP1026", "CP1026"); 1074 fIANA2JavaMap.put("CSIBM1026", "CP1026"); 1075 fIANA2JavaMap.put("IBM01140", "Cp1140"); 1076 fIANA2JavaMap.put("CP01140", "Cp1140"); 1077 fIANA2JavaMap.put("CCSID01140", "Cp1140"); 1078 fIANA2JavaMap.put("IBM01141", "Cp1141"); 1079 fIANA2JavaMap.put("CP01141", "Cp1141"); 1080 fIANA2JavaMap.put("CCSID01141", "Cp1141"); 1081 fIANA2JavaMap.put("IBM01142", "Cp1142"); 1082 fIANA2JavaMap.put("CP01142", "Cp1142"); 1083 fIANA2JavaMap.put("CCSID01142", "Cp1142"); 1084 fIANA2JavaMap.put("IBM01143", "Cp1143"); 1085 fIANA2JavaMap.put("CP01143", "Cp1143"); 1086 fIANA2JavaMap.put("CCSID01143", "Cp1143"); 1087 fIANA2JavaMap.put("IBM01144", "Cp1144"); 1088 fIANA2JavaMap.put("CP01144", "Cp1144"); 1089 fIANA2JavaMap.put("CCSID01144", "Cp1144"); 1090 fIANA2JavaMap.put("IBM01145", "Cp1145"); 1091 fIANA2JavaMap.put("CP01145", "Cp1145"); 1092 fIANA2JavaMap.put("CCSID01145", "Cp1145"); 1093 fIANA2JavaMap.put("IBM01146", "Cp1146"); 1094 fIANA2JavaMap.put("CP01146", "Cp1146"); 1095 fIANA2JavaMap.put("CCSID01146", "Cp1146"); 1096 fIANA2JavaMap.put("IBM01147", "Cp1147"); 1097 fIANA2JavaMap.put("CP01147", "Cp1147"); 1098 fIANA2JavaMap.put("CCSID01147", "Cp1147"); 1099 fIANA2JavaMap.put("IBM01148", "Cp1148"); 1100 fIANA2JavaMap.put("CP01148", "Cp1148"); 1101 fIANA2JavaMap.put("CCSID01148", "Cp1148"); 1102 fIANA2JavaMap.put("IBM01149", "Cp1149"); 1103 fIANA2JavaMap.put("CP01149", "Cp1149"); 1104 fIANA2JavaMap.put("CCSID01149", "Cp1149"); 1105 fIANA2JavaMap.put("EUC-JP", "EUCJIS"); 1106 fIANA2JavaMap.put("CSEUCPKDFMTJAPANESE", "EUCJIS"); 1107 fIANA2JavaMap.put("EXTENDED_UNIX_CODE_PACKED_FORMAT_FOR_JAPANESE", "EUCJIS"); 1108 fIANA2JavaMap.put("EUC-KR", "KSC5601"); 1109 fIANA2JavaMap.put("GB2312", "GB2312"); 1110 fIANA2JavaMap.put("CSGB2312", "GB2312"); 1111 fIANA2JavaMap.put("ISO-2022-JP", "JIS"); 1112 fIANA2JavaMap.put("CSISO2022JP", "JIS"); 1113 fIANA2JavaMap.put("ISO-2022-KR", "ISO2022KR"); 1114 fIANA2JavaMap.put("CSISO2022KR", "ISO2022KR"); 1115 fIANA2JavaMap.put("ISO-2022-CN", "ISO2022CN"); 1116 1117 fIANA2JavaMap.put("X0201", "JIS0201"); 1118 fIANA2JavaMap.put("CSISO13JISC6220JP", "JIS0201"); 1119 fIANA2JavaMap.put("X0208", "JIS0208"); 1120 fIANA2JavaMap.put("ISO-IR-87", "JIS0208"); 1121 fIANA2JavaMap.put("X0208dbiJIS_X0208-1983", "JIS0208"); 1122 fIANA2JavaMap.put("CSISO87JISX0208", "JIS0208"); 1123 fIANA2JavaMap.put("X0212", "JIS0212"); 1124 fIANA2JavaMap.put("ISO-IR-159", "JIS0212"); 1125 fIANA2JavaMap.put("CSISO159JISX02121990", "JIS0212"); 1126 fIANA2JavaMap.put("GB18030", "GB18030"); 1127 fIANA2JavaMap.put("SHIFT_JIS", "SJIS"); 1128 fIANA2JavaMap.put("CSSHIFTJIS", "SJIS"); 1129 fIANA2JavaMap.put("MS_KANJI", "SJIS"); 1130 fIANA2JavaMap.put("WINDOWS-31J", "MS932"); 1131 fIANA2JavaMap.put("CSWINDOWS31J", "MS932"); 1132 1133 fIANA2JavaMap.put("WINDOWS-1250", "Cp1250"); 1135 fIANA2JavaMap.put("WINDOWS-1251", "Cp1251"); 1136 fIANA2JavaMap.put("WINDOWS-1252", "Cp1252"); 1137 fIANA2JavaMap.put("WINDOWS-1253", "Cp1253"); 1138 fIANA2JavaMap.put("WINDOWS-1254", "Cp1254"); 1139 fIANA2JavaMap.put("WINDOWS-1255", "Cp1255"); 1140 fIANA2JavaMap.put("WINDOWS-1256", "Cp1256"); 1141 fIANA2JavaMap.put("WINDOWS-1257", "Cp1257"); 1142 fIANA2JavaMap.put("WINDOWS-1258", "Cp1258"); 1143 fIANA2JavaMap.put("TIS-620", "TIS620"); 1144 1145 fIANA2JavaMap.put("ISO-8859-1", "ISO8859_1"); 1146 fIANA2JavaMap.put("ISO-IR-100", "ISO8859_1"); 1147 fIANA2JavaMap.put("ISO_8859-1", "ISO8859_1"); 1148 fIANA2JavaMap.put("LATIN1", "ISO8859_1"); 1149 fIANA2JavaMap.put("CSISOLATIN1", "ISO8859_1"); 1150 fIANA2JavaMap.put("L1", "ISO8859_1"); 1151 fIANA2JavaMap.put("IBM819", "ISO8859_1"); 1152 fIANA2JavaMap.put("CP819", "ISO8859_1"); 1153 1154 fIANA2JavaMap.put("ISO-8859-2", "ISO8859_2"); 1155 fIANA2JavaMap.put("ISO-IR-101", "ISO8859_2"); 1156 fIANA2JavaMap.put("ISO_8859-2", "ISO8859_2"); 1157 fIANA2JavaMap.put("LATIN2", "ISO8859_2"); 1158 fIANA2JavaMap.put("CSISOLATIN2", "ISO8859_2"); 1159 fIANA2JavaMap.put("L2", "ISO8859_2"); 1160 1161 fIANA2JavaMap.put("ISO-8859-3", "ISO8859_3"); 1162 fIANA2JavaMap.put("ISO-IR-109", "ISO8859_3"); 1163 fIANA2JavaMap.put("ISO_8859-3", "ISO8859_3"); 1164 fIANA2JavaMap.put("LATIN3", "ISO8859_3"); 1165 fIANA2JavaMap.put("CSISOLATIN3", "ISO8859_3"); 1166 fIANA2JavaMap.put("L3", "ISO8859_3"); 1167 1168 fIANA2JavaMap.put("ISO-8859-4", "ISO8859_4"); 1169 fIANA2JavaMap.put("ISO-IR-110", "ISO8859_4"); 1170 fIANA2JavaMap.put("ISO_8859-4", "ISO8859_4"); 1171 fIANA2JavaMap.put("LATIN4", "ISO8859_4"); 1172 fIANA2JavaMap.put("CSISOLATIN4", "ISO8859_4"); 1173 fIANA2JavaMap.put("L4", "ISO8859_4"); 1174 1175 fIANA2JavaMap.put("ISO-8859-5", "ISO8859_5"); 1176 fIANA2JavaMap.put("ISO-IR-144", "ISO8859_5"); 1177 fIANA2JavaMap.put("ISO_8859-5", "ISO8859_5"); 1178 fIANA2JavaMap.put("CYRILLIC", "ISO8859_5"); 1179 fIANA2JavaMap.put("CSISOLATINCYRILLIC", "ISO8859_5"); 1180 1181 fIANA2JavaMap.put("ISO-8859-6", "ISO8859_6"); 1182 fIANA2JavaMap.put("ISO-IR-127", "ISO8859_6"); 1183 fIANA2JavaMap.put("ISO_8859-6", "ISO8859_6"); 1184 fIANA2JavaMap.put("ECMA-114", "ISO8859_6"); 1185 fIANA2JavaMap.put("ASMO-708", "ISO8859_6"); 1186 fIANA2JavaMap.put("ARABIC", "ISO8859_6"); 1187 fIANA2JavaMap.put("CSISOLATINARABIC", "ISO8859_6"); 1188 1189 fIANA2JavaMap.put("ISO-8859-7", "ISO8859_7"); 1190 fIANA2JavaMap.put("ISO-IR-126", "ISO8859_7"); 1191 fIANA2JavaMap.put("ISO_8859-7", "ISO8859_7"); 1192 fIANA2JavaMap.put("ELOT_928", "ISO8859_7"); 1193 fIANA2JavaMap.put("ECMA-118", "ISO8859_7"); 1194 fIANA2JavaMap.put("GREEK", "ISO8859_7"); 1195 fIANA2JavaMap.put("CSISOLATINGREEK", "ISO8859_7"); 1196 fIANA2JavaMap.put("GREEK8", "ISO8859_7"); 1197 1198 fIANA2JavaMap.put("ISO-8859-8", "ISO8859_8"); 1199 fIANA2JavaMap.put("ISO-8859-8-I", "ISO8859_8"); fIANA2JavaMap.put("ISO-IR-138", "ISO8859_8"); 1201 fIANA2JavaMap.put("ISO_8859-8", "ISO8859_8"); 1202 fIANA2JavaMap.put("HEBREW", "ISO8859_8"); 1203 fIANA2JavaMap.put("CSISOLATINHEBREW", "ISO8859_8"); 1204 1205 fIANA2JavaMap.put("ISO-8859-9", "ISO8859_9"); 1206 fIANA2JavaMap.put("ISO-IR-148", "ISO8859_9"); 1207 fIANA2JavaMap.put("ISO_8859-9", "ISO8859_9"); 1208 fIANA2JavaMap.put("LATIN5", "ISO8859_9"); 1209 fIANA2JavaMap.put("CSISOLATIN5", "ISO8859_9"); 1210 fIANA2JavaMap.put("L5", "ISO8859_9"); 1211 1212 fIANA2JavaMap.put("KOI8-R", "KOI8_R"); 1213 fIANA2JavaMap.put("CSKOI8R", "KOI8_R"); 1214 fIANA2JavaMap.put("US-ASCII", "ASCII"); 1215 fIANA2JavaMap.put("ISO-IR-6", "ASCII"); 1216 fIANA2JavaMap.put("ANSI_X3.4-1986", "ASCII"); 1217 fIANA2JavaMap.put("ISO_646.IRV:1991", "ASCII"); 1218 fIANA2JavaMap.put("ASCII", "ASCII"); 1219 fIANA2JavaMap.put("CSASCII", "ASCII"); 1220 fIANA2JavaMap.put("ISO646-US", "ASCII"); 1221 fIANA2JavaMap.put("US", "ASCII"); 1222 fIANA2JavaMap.put("IBM367", "ASCII"); 1223 fIANA2JavaMap.put("CP367", "ASCII"); 1224 fIANA2JavaMap.put("UTF-8", "UTF8"); 1225 fIANA2JavaMap.put("UTF-16", "Unicode"); 1226 fIANA2JavaMap.put("UTF-16BE", "UnicodeBig"); 1227 fIANA2JavaMap.put("UTF-16LE", "UnicodeLittle"); 1228 1229 fIANA2JavaMap.put("IBM-1047", "Cp1047"); 1233 fIANA2JavaMap.put("IBM1047", "Cp1047"); 1234 fIANA2JavaMap.put("CP1047", "Cp1047"); 1235 1236 fIANA2JavaMap.put("IBM-37", "CP037"); 1239 fIANA2JavaMap.put("IBM-273", "CP273"); 1240 fIANA2JavaMap.put("IBM-277", "CP277"); 1241 fIANA2JavaMap.put("IBM-278", "CP278"); 1242 fIANA2JavaMap.put("IBM-280", "CP280"); 1243 fIANA2JavaMap.put("IBM-284", "CP284"); 1244 fIANA2JavaMap.put("IBM-285", "CP285"); 1245 fIANA2JavaMap.put("IBM-290", "CP290"); 1246 fIANA2JavaMap.put("IBM-297", "CP297"); 1247 fIANA2JavaMap.put("IBM-420", "CP420"); 1248 fIANA2JavaMap.put("IBM-424", "CP424"); 1249 fIANA2JavaMap.put("IBM-437", "CP437"); 1250 fIANA2JavaMap.put("IBM-500", "CP500"); 1251 fIANA2JavaMap.put("IBM-775", "CP775"); 1252 fIANA2JavaMap.put("IBM-850", "CP850"); 1253 fIANA2JavaMap.put("IBM-852", "CP852"); 1254 fIANA2JavaMap.put("IBM-855", "CP855"); 1255 fIANA2JavaMap.put("IBM-857", "CP857"); 1256 fIANA2JavaMap.put("IBM-858", "CP858"); 1257 fIANA2JavaMap.put("IBM-860", "CP860"); 1258 fIANA2JavaMap.put("IBM-861", "CP861"); 1259 fIANA2JavaMap.put("IBM-862", "CP862"); 1260 fIANA2JavaMap.put("IBM-863", "CP863"); 1261 fIANA2JavaMap.put("IBM-864", "CP864"); 1262 fIANA2JavaMap.put("IBM-865", "CP865"); 1263 fIANA2JavaMap.put("IBM-866", "CP866"); 1264 fIANA2JavaMap.put("IBM-868", "CP868"); 1265 fIANA2JavaMap.put("IBM-869", "CP869"); 1266 fIANA2JavaMap.put("IBM-870", "CP870"); 1267 fIANA2JavaMap.put("IBM-871", "CP871"); 1268 fIANA2JavaMap.put("IBM-918", "CP918"); 1269 fIANA2JavaMap.put("IBM-924", "CP924"); 1270 fIANA2JavaMap.put("IBM-1026", "CP1026"); 1271 fIANA2JavaMap.put("IBM-1140", "Cp1140"); 1272 fIANA2JavaMap.put("IBM-1141", "Cp1141"); 1273 fIANA2JavaMap.put("IBM-1142", "Cp1142"); 1274 fIANA2JavaMap.put("IBM-1143", "Cp1143"); 1275 fIANA2JavaMap.put("IBM-1144", "Cp1144"); 1276 fIANA2JavaMap.put("IBM-1145", "Cp1145"); 1277 fIANA2JavaMap.put("IBM-1146", "Cp1146"); 1278 fIANA2JavaMap.put("IBM-1147", "Cp1147"); 1279 fIANA2JavaMap.put("IBM-1148", "Cp1148"); 1280 fIANA2JavaMap.put("IBM-1149", "Cp1149"); 1281 fIANA2JavaMap.put("IBM-819", "ISO8859_1"); 1282 fIANA2JavaMap.put("IBM-367", "ASCII"); 1283 1284 1288 fJava2IANAMap.put("ISO8859_1", "ISO-8859-1"); 1291 fJava2IANAMap.put("ISO8859_2", "ISO-8859-2"); 1292 fJava2IANAMap.put("ISO8859_3", "ISO-8859-3"); 1293 fJava2IANAMap.put("ISO8859_4", "ISO-8859-4"); 1294 fJava2IANAMap.put("ISO8859_5", "ISO-8859-5"); 1295 fJava2IANAMap.put("ISO8859_6", "ISO-8859-6"); 1296 fJava2IANAMap.put("ISO8859_7", "ISO-8859-7"); 1297 fJava2IANAMap.put("ISO8859_8", "ISO-8859-8"); 1298 fJava2IANAMap.put("ISO8859_9", "ISO-8859-9"); 1299 fJava2IANAMap.put("Big5", "BIG5"); 1300 fJava2IANAMap.put("CP037", "EBCDIC-CP-US"); 1301 fJava2IANAMap.put("CP273", "IBM273"); 1302 fJava2IANAMap.put("CP277", "EBCDIC-CP-DK"); 1303 fJava2IANAMap.put("CP278", "EBCDIC-CP-FI"); 1304 fJava2IANAMap.put("CP280", "EBCDIC-CP-IT"); 1305 fJava2IANAMap.put("CP284", "EBCDIC-CP-ES"); 1306 fJava2IANAMap.put("CP285", "EBCDIC-CP-GB"); 1307 fJava2IANAMap.put("CP290", "EBCDIC-JP-KANA"); 1308 fJava2IANAMap.put("CP297", "EBCDIC-CP-FR"); 1309 fJava2IANAMap.put("CP420", "EBCDIC-CP-AR1"); 1310 fJava2IANAMap.put("CP424", "EBCDIC-CP-HE"); 1311 fJava2IANAMap.put("CP437", "IBM437"); 1312 fJava2IANAMap.put("CP500", "EBCDIC-CP-CH"); 1313 fJava2IANAMap.put("CP775", "IBM775"); 1314 fJava2IANAMap.put("CP850", "IBM850"); 1315 fJava2IANAMap.put("CP852", "IBM852"); 1316 fJava2IANAMap.put("CP855", "IBM855"); 1317 fJava2IANAMap.put("CP857", "IBM857"); 1318 fJava2IANAMap.put("CP858", "IBM00858"); 1319 fJava2IANAMap.put("CP860", "IBM860"); 1320 fJava2IANAMap.put("CP861", "IBM861"); 1321 fJava2IANAMap.put("CP862", "IBM862"); 1322 fJava2IANAMap.put("CP863", "IBM863"); 1323 fJava2IANAMap.put("CP864", "IBM864"); 1324 fJava2IANAMap.put("CP865", "IBM865"); 1325 fJava2IANAMap.put("CP866", "IBM866"); 1326 fJava2IANAMap.put("CP868", "IBM868"); 1327 fJava2IANAMap.put("CP869", "IBM869"); 1328 fJava2IANAMap.put("CP870", "EBCDIC-CP-ROECE"); 1329 fJava2IANAMap.put("CP871", "EBCDIC-CP-IS"); 1330 fJava2IANAMap.put("CP918", "EBCDIC-CP-AR2"); 1331 fJava2IANAMap.put("CP924", "IBM00924"); 1332 fJava2IANAMap.put("CP1026", "IBM1026"); 1333 fJava2IANAMap.put("Cp01140", "IBM01140"); 1334 fJava2IANAMap.put("Cp01141", "IBM01141"); 1335 fJava2IANAMap.put("Cp01142", "IBM01142"); 1336 fJava2IANAMap.put("Cp01143", "IBM01143"); 1337 fJava2IANAMap.put("Cp01144", "IBM01144"); 1338 fJava2IANAMap.put("Cp01145", "IBM01145"); 1339 fJava2IANAMap.put("Cp01146", "IBM01146"); 1340 fJava2IANAMap.put("Cp01147", "IBM01147"); 1341 fJava2IANAMap.put("Cp01148", "IBM01148"); 1342 fJava2IANAMap.put("Cp01149", "IBM01149"); 1343 fJava2IANAMap.put("EUCJIS", "EUC-JP"); 1344 fJava2IANAMap.put("GB2312", "GB2312"); 1345 fJava2IANAMap.put("ISO2022KR", "ISO-2022-KR"); 1346 fJava2IANAMap.put("ISO2022CN", "ISO-2022-CN"); 1347 fJava2IANAMap.put("JIS", "ISO-2022-JP"); 1348 fJava2IANAMap.put("KOI8_R", "KOI8-R"); 1349 fJava2IANAMap.put("KSC5601", "EUC-KR"); 1350 fJava2IANAMap.put("GB18030", "GB18030"); 1351 fJava2IANAMap.put("SJIS", "SHIFT_JIS"); 1352 fJava2IANAMap.put("MS932", "WINDOWS-31J"); 1353 fJava2IANAMap.put("UTF8", "UTF-8"); 1354 fJava2IANAMap.put("Unicode", "UTF-16"); 1355 fJava2IANAMap.put("UnicodeBig", "UTF-16BE"); 1356 fJava2IANAMap.put("UnicodeLittle", "UTF-16LE"); 1357 fJava2IANAMap.put("JIS0201", "X0201"); 1358 fJava2IANAMap.put("JIS0208", "X0208"); 1359 fJava2IANAMap.put("JIS0212", "ISO-IR-159"); 1360 1361 fJava2IANAMap.put("CP1047", "IBM1047"); 1363 1364 } 1366 1370 1371 public EncodingMap() {} 1372 1373 1377 1383 public static void putIANA2JavaMapping(String ianaEncoding, 1384 String javaEncoding) { 1385 fIANA2JavaMap.put(ianaEncoding, javaEncoding); 1386 } 1388 1393 public static String getIANA2JavaMapping(String ianaEncoding) { 1394 return (String )fIANA2JavaMap.get(ianaEncoding); 1395 } 1397 1402 public static String removeIANA2JavaMapping(String ianaEncoding) { 1403 return (String )fIANA2JavaMap.remove(ianaEncoding); 1404 } 1406 1412 public static void putJava2IANAMapping(String javaEncoding, 1413 String ianaEncoding) { 1414 fJava2IANAMap.put(javaEncoding, ianaEncoding); 1415 } 1417 1422 public static String getJava2IANAMapping(String javaEncoding) { 1423 return (String )fJava2IANAMap.get(javaEncoding); 1424 } 1426 1431 public static String removeJava2IANAMapping(String javaEncoding) { 1432 return (String )fJava2IANAMap.remove(javaEncoding); 1433 } 1435} 1437 1438 1473 public static final class URI implements Serializable { 1474 1475 1476 1482 public static class MalformedURIException extends IOException { 1483 1484 1488 public MalformedURIException() { 1489 super(); 1490 } 1491 1492 1498 public MalformedURIException(String p_msg) { 1499 super(p_msg); 1500 } 1501 } 1502 1503 private static final byte [] fgLookupTable = new byte[128]; 1504 1505 1508 1509 1510 private static final int RESERVED_CHARACTERS = 0x01; 1512 1513 1515 private static final int MARK_CHARACTERS = 0x02; 1516 1517 1518 private static final int SCHEME_CHARACTERS = 0x04; 1519 1520 1522 private static final int USERINFO_CHARACTERS = 0x08; 1523 1524 1525 private static final int ASCII_ALPHA_CHARACTERS = 0x10; 1526 1527 1528 private static final int ASCII_DIGIT_CHARACTERS = 0x20; 1529 1530 1531 private static final int ASCII_HEX_CHARACTERS = 0x40; 1532 1533 1534 private static final int PATH_CHARACTERS = 0x80; 1535 1536 1537 private static final int MASK_ALPHA_NUMERIC = ASCII_ALPHA_CHARACTERS | ASCII_DIGIT_CHARACTERS; 1538 1539 1540 private static final int MASK_UNRESERVED_MASK = MASK_ALPHA_NUMERIC | MARK_CHARACTERS; 1541 1542 1543 private static final int MASK_URI_CHARACTER = MASK_UNRESERVED_MASK | RESERVED_CHARACTERS; 1544 1545 1546 private static final int MASK_SCHEME_CHARACTER = MASK_ALPHA_NUMERIC | SCHEME_CHARACTERS; 1547 1548 1549 private static final int MASK_USERINFO_CHARACTER = MASK_UNRESERVED_MASK | USERINFO_CHARACTERS; 1550 1551 1552 private static final int MASK_PATH_CHARACTER = MASK_UNRESERVED_MASK | PATH_CHARACTERS; 1553 1554 static { 1555 for (int i = '0'; i <= '9'; ++i) { 1557 fgLookupTable[i] |= ASCII_DIGIT_CHARACTERS | ASCII_HEX_CHARACTERS; 1558 } 1559 1560 for (int i = 'A'; i <= 'F'; ++i) { 1562 fgLookupTable[i] |= ASCII_ALPHA_CHARACTERS | ASCII_HEX_CHARACTERS; 1563 fgLookupTable[i+0x00000020] |= ASCII_ALPHA_CHARACTERS | ASCII_HEX_CHARACTERS; 1564 } 1565 1566 for (int i = 'G'; i <= 'Z'; ++i) { 1568 fgLookupTable[i] |= ASCII_ALPHA_CHARACTERS; 1569 fgLookupTable[i+0x00000020] |= ASCII_ALPHA_CHARACTERS; 1570 } 1571 1572 fgLookupTable[';'] |= RESERVED_CHARACTERS; 1574 fgLookupTable['/'] |= RESERVED_CHARACTERS; 1575 fgLookupTable['?'] |= RESERVED_CHARACTERS; 1576 fgLookupTable[':'] |= RESERVED_CHARACTERS; 1577 fgLookupTable['@'] |= RESERVED_CHARACTERS; 1578 fgLookupTable['&'] |= RESERVED_CHARACTERS; 1579 fgLookupTable['='] |= RESERVED_CHARACTERS; 1580 fgLookupTable['+'] |= RESERVED_CHARACTERS; 1581 fgLookupTable['$'] |= RESERVED_CHARACTERS; 1582 fgLookupTable[','] |= RESERVED_CHARACTERS; 1583 fgLookupTable['['] |= RESERVED_CHARACTERS; 1584 fgLookupTable[']'] |= RESERVED_CHARACTERS; 1585 1586 fgLookupTable['-'] |= MARK_CHARACTERS; 1588 fgLookupTable['_'] |= MARK_CHARACTERS; 1589 fgLookupTable['.'] |= MARK_CHARACTERS; 1590 fgLookupTable['!'] |= MARK_CHARACTERS; 1591 fgLookupTable['~'] |= MARK_CHARACTERS; 1592 fgLookupTable['*'] |= MARK_CHARACTERS; 1593 fgLookupTable['\''] |= MARK_CHARACTERS; 1594 fgLookupTable['('] |= MARK_CHARACTERS; 1595 fgLookupTable[')'] |= MARK_CHARACTERS; 1596 1597 fgLookupTable['+'] |= SCHEME_CHARACTERS; 1599 fgLookupTable['-'] |= SCHEME_CHARACTERS; 1600 fgLookupTable['.'] |= SCHEME_CHARACTERS; 1601 1602 fgLookupTable[';'] |= USERINFO_CHARACTERS; 1604 fgLookupTable[':'] |= USERINFO_CHARACTERS; 1605 fgLookupTable['&'] |= USERINFO_CHARACTERS; 1606 fgLookupTable['='] |= USERINFO_CHARACTERS; 1607 fgLookupTable['+'] |= USERINFO_CHARACTERS; 1608 fgLookupTable['$'] |= USERINFO_CHARACTERS; 1609 fgLookupTable[','] |= USERINFO_CHARACTERS; 1610 1611 fgLookupTable[';'] |= PATH_CHARACTERS; 1613 fgLookupTable['/'] |= PATH_CHARACTERS; 1614 fgLookupTable[':'] |= PATH_CHARACTERS; 1615 fgLookupTable['@'] |= PATH_CHARACTERS; 1616 fgLookupTable['&'] |= PATH_CHARACTERS; 1617 fgLookupTable['='] |= PATH_CHARACTERS; 1618 fgLookupTable['+'] |= PATH_CHARACTERS; 1619 fgLookupTable['$'] |= PATH_CHARACTERS; 1620 fgLookupTable[','] |= PATH_CHARACTERS; 1621 } 1622 public static final URI BASE_URI; 1623 static { 1624 URI uri = null; 1625 try { 1626 uri = new URI("abc://def.ghi.jkl"); 1627 } catch (URI.MalformedURIException ex) { 1628 } 1629 BASE_URI = uri; 1630 } 1631 1632 private String m_scheme = null; 1633 1634 1635 private String m_userinfo = null; 1636 1637 1638 private String m_host = null; 1639 1640 1641 private int m_port = -1; 1642 1643 1644 private String m_regAuthority = null; 1645 1646 1647 private String m_path = null; 1648 1649 1651 private String m_queryString = null; 1652 1653 1654 private String m_fragment = null; 1655 1656 1659 public URI() { 1660 } 1661 1662 1668 public URI(URI p_other) { 1669 initialize(p_other); 1670 } 1671 1672 1687 public URI(String p_uriSpec) throws MalformedURIException { 1688 this((URI)null, p_uriSpec); 1689 } 1690 1691 1703 public URI(URI p_base, String p_uriSpec) throws MalformedURIException { 1704 initialize(p_base, p_uriSpec); 1705 } 1706 1707 1719 public URI(String p_scheme, String p_schemeSpecificPart) 1720 throws MalformedURIException { 1721 if (p_scheme == null || p_scheme.trim().length() == 0) { 1722 throw new MalformedURIException( 1723 "Cannot construct URI with null/empty scheme!"); 1724 } 1725 if (p_schemeSpecificPart == null || 1726 p_schemeSpecificPart.trim().length() == 0) { 1727 throw new MalformedURIException( 1728 "Cannot construct URI with null/empty scheme-specific part!"); 1729 } 1730 setScheme(p_scheme); 1731 setPath(p_schemeSpecificPart); 1732 } 1733 1734 1755 public URI(String p_scheme, String p_host, String p_path, 1756 String p_queryString, String p_fragment) 1757 throws MalformedURIException { 1758 this(p_scheme, null, p_host, -1, p_path, p_queryString, p_fragment); 1759 } 1760 1761 1786 public URI(String p_scheme, String p_userinfo, 1787 String p_host, int p_port, String p_path, 1788 String p_queryString, String p_fragment) 1789 throws MalformedURIException { 1790 if (p_scheme == null || p_scheme.trim().length() == 0) { 1791 throw new MalformedURIException("Scheme is required!"); 1792 } 1793 1794 if (p_host == null) { 1795 if (p_userinfo != null) { 1796 throw new MalformedURIException( 1797 "Userinfo may not be specified if host is not specified!"); 1798 } 1799 if (p_port != -1) { 1800 throw new MalformedURIException( 1801 "Port may not be specified if host is not specified!"); 1802 } 1803 } 1804 1805 if (p_path != null) { 1806 if (p_path.indexOf('?') != -1 && p_queryString != null) { 1807 throw new MalformedURIException( 1808 "Query string cannot be specified in path and query string!"); 1809 } 1810 1811 if (p_path.indexOf('#') != -1 && p_fragment != null) { 1812 throw new MalformedURIException( 1813 "Fragment cannot be specified in both the path and fragment!"); 1814 } 1815 } 1816 1817 setScheme(p_scheme); 1818 setHost(p_host); 1819 setPort(p_port); 1820 setUserinfo(p_userinfo); 1821 setPath(p_path); 1822 setQueryString(p_queryString); 1823 setFragment(p_fragment); 1824 } 1825 1826 1831 private void initialize(URI p_other) { 1832 m_scheme = p_other.getScheme(); 1833 m_userinfo = p_other.getUserinfo(); 1834 m_host = p_other.getHost(); 1835 m_port = p_other.getPort(); 1836 m_regAuthority = p_other.getRegBasedAuthority(); 1837 m_path = p_other.getPath(); 1838 m_queryString = p_other.getQueryString(); 1839 m_fragment = p_other.getFragment(); 1840 } 1841 1842 1858 private void initialize(URI p_base, String p_uriSpec) 1859 throws MalformedURIException { 1860 1861 String uriSpec = p_uriSpec; 1862 int uriSpecLen = (uriSpec != null) ? uriSpec.length() : 0; 1863 1864 if (p_base == null && uriSpecLen == 0) { 1865 throw new MalformedURIException( 1866 "Cannot initialize URI with empty parameters."); 1867 } 1868 1869 if (uriSpecLen == 0) { 1871 initialize(p_base); 1872 return; 1873 } 1874 1875 int index = 0; 1876 1877 int colonIdx = uriSpec.indexOf(':'); 1881 if (colonIdx != -1) { 1882 final int searchFrom = colonIdx - 1; 1883 int slashIdx = uriSpec.lastIndexOf('/', searchFrom); 1885 int queryIdx = uriSpec.lastIndexOf('?', searchFrom); 1886 int fragmentIdx = uriSpec.lastIndexOf('#', searchFrom); 1887 1888 if (colonIdx < 2 || slashIdx != -1 || 1889 queryIdx != -1 || fragmentIdx != -1) { 1890 if (colonIdx == 0 || (p_base == null && fragmentIdx != 0)) { 1892 throw new MalformedURIException("No scheme found in URI."); 1893 } 1894 } 1895 else { 1896 initializeScheme(uriSpec); 1897 index = m_scheme.length()+1; 1898 1899 if (colonIdx == uriSpecLen - 1 || uriSpec.charAt(colonIdx+1) == '#') { 1901 throw new MalformedURIException("Scheme specific part cannot be empty."); 1902 } 1903 } 1904 } 1905 else if (p_base == null && uriSpec.indexOf('#') != 0) { 1906 throw new MalformedURIException("No scheme found in URI."); 1907 } 1908 1909 if (((index+1) < uriSpecLen) && 1919 (uriSpec.charAt(index) == '/' && uriSpec.charAt(index+1) == '/')) { 1920 index += 2; 1921 int startPos = index; 1922 1923 char testChar = '\0'; 1925 while (index < uriSpecLen) { 1926 testChar = uriSpec.charAt(index); 1927 if (testChar == '/' || testChar == '?' || testChar == '#') { 1928 break; 1929 } 1930 index++; 1931 } 1932 1933 if (index > startPos) { 1937 if (!initializeAuthority(uriSpec.substring(startPos, index))) { 1940 index = startPos - 2; 1941 } 1942 } 1943 else { 1944 m_host = ""; 1945 } 1946 } 1947 1948 initializePath(uriSpec, index); 1949 1950 if (p_base != null) { 1956 1957 if (m_path.length() == 0 && m_scheme == null && 1965 m_host == null && m_regAuthority == null) { 1966 m_scheme = p_base.getScheme(); 1967 m_userinfo = p_base.getUserinfo(); 1968 m_host = p_base.getHost(); 1969 m_port = p_base.getPort(); 1970 m_regAuthority = p_base.getRegBasedAuthority(); 1971 m_path = p_base.getPath(); 1972 1973 if (m_queryString == null) { 1974 m_queryString = p_base.getQueryString(); 1975 } 1976 return; 1977 } 1978 1979 if (m_scheme == null) { 1982 m_scheme = p_base.getScheme(); 1983 } 1984 else { 1985 return; 1986 } 1987 1988 if (m_host == null && m_regAuthority == null) { 1991 m_userinfo = p_base.getUserinfo(); 1992 m_host = p_base.getHost(); 1993 m_port = p_base.getPort(); 1994 m_regAuthority = p_base.getRegBasedAuthority(); 1995 } 1996 else { 1997 return; 1998 } 1999 2000 if (m_path.length() > 0 && 2002 m_path.startsWith("/")) { 2003 return; 2004 } 2005 2006 String path = ""; 2009 String basePath = p_base.getPath(); 2010 2011 if (basePath != null && basePath.length() > 0) { 2013 int lastSlash = basePath.lastIndexOf('/'); 2014 if (lastSlash != -1) { 2015 path = basePath.substring(0, lastSlash+1); 2016 } 2017 } 2018 else if (m_path.length() > 0) { 2019 path = "/"; 2020 } 2021 2022 path = path.concat(m_path); 2024 2025 index = -1; 2027 while ((index = path.indexOf("/./")) != -1) { 2028 path = path.substring(0, index+1).concat(path.substring(index+3)); 2029 } 2030 2031 if (path.endsWith("/.")) { 2033 path = path.substring(0, path.length()-1); 2034 } 2035 2036 index = 1; 2039 int segIndex = -1; 2040 String tempString = null; 2041 2042 while ((index = path.indexOf("/../", index)) > 0) { 2043 tempString = path.substring(0, path.indexOf("/../")); 2044 segIndex = tempString.lastIndexOf('/'); 2045 if (segIndex != -1) { 2046 if (!tempString.substring(segIndex).equals("..")) { 2047 path = path.substring(0, segIndex+1).concat(path.substring(index+4)); 2048 index = segIndex; 2049 } 2050 else 2051 index += 4; 2052 } 2053 else 2054 index += 4; 2055 } 2056 2057 if (path.endsWith("/..")) { 2060 tempString = path.substring(0, path.length()-3); 2061 segIndex = tempString.lastIndexOf('/'); 2062 if (segIndex != -1) { 2063 path = path.substring(0, segIndex+1); 2064 } 2065 } 2066 m_path = path; 2067 } 2068 } 2069 2070 2078 private void initializeScheme(String p_uriSpec) 2079 throws MalformedURIException { 2080 int uriSpecLen = p_uriSpec.length(); 2081 int index = 0; 2082 String scheme = null; 2083 char testChar = '\0'; 2084 2085 while (index < uriSpecLen) { 2086 testChar = p_uriSpec.charAt(index); 2087 if (testChar == ':' || testChar == '/' || 2088 testChar == '?' || testChar == '#') { 2089 break; 2090 } 2091 index++; 2092 } 2093 scheme = p_uriSpec.substring(0, index); 2094 2095 if (scheme.length() == 0) { 2096 throw new MalformedURIException("No scheme found in URI."); 2097 } 2098 else { 2099 setScheme(scheme); 2100 } 2101 } 2102 2103 2112 private boolean initializeAuthority(String p_uriSpec) { 2113 2114 int index = 0; 2115 int start = 0; 2116 int end = p_uriSpec.length(); 2117 2118 char testChar = '\0'; 2119 String userinfo = null; 2120 2121 if (p_uriSpec.indexOf('@', start) != -1) { 2123 while (index < end) { 2124 testChar = p_uriSpec.charAt(index); 2125 if (testChar == '@') { 2126 break; 2127 } 2128 index++; 2129 } 2130 userinfo = p_uriSpec.substring(start, index); 2131 index++; 2132 } 2133 2134 String host = null; 2137 start = index; 2138 boolean hasPort = false; 2139 if (index < end) { 2140 if (p_uriSpec.charAt(start) == '[') { 2141 int bracketIndex = p_uriSpec.indexOf(']', start); 2142 index = (bracketIndex != -1) ? bracketIndex : end; 2143 if (index+1 < end && p_uriSpec.charAt(index+1) == ':') { 2144 ++index; 2145 hasPort = true; 2146 } 2147 else { 2148 index = end; 2149 } 2150 } 2151 else { 2152 int colonIndex = p_uriSpec.lastIndexOf(':', end); 2153 index = (colonIndex > start) ? colonIndex : end; 2154 hasPort = (index != end); 2155 } 2156 } 2157 host = p_uriSpec.substring(start, index); 2158 int port = -1; 2159 if (host.length() > 0) { 2160 if (hasPort) { 2162 index++; 2163 start = index; 2164 while (index < end) { 2165 index++; 2166 } 2167 String portStr = p_uriSpec.substring(start, index); 2168 if (portStr.length() > 0) { 2169 2177 try { 2180 port = Integer.parseInt(portStr); 2181 if (port == -1) --port; 2182 } 2183 catch (NumberFormatException nfe) { 2184 port = -2; 2185 } 2186 } 2187 } 2188 } 2189 2190 if (isValidServerBasedAuthority(host, port, userinfo)) { 2191 m_host = host; 2192 m_port = port; 2193 m_userinfo = userinfo; 2194 return true; 2195 } 2196 else if (isValidRegistryBasedAuthority(p_uriSpec)) { 2201 m_regAuthority = p_uriSpec; 2202 return true; 2203 } 2204 return false; 2205 } 2206 2207 2218 private boolean isValidServerBasedAuthority(String host, int port, String userinfo) { 2219 2220 if (!isWellFormedAddress(host)) { 2222 return false; 2223 } 2224 2225 if (port < -1 || port > 65535) { 2230 return false; 2231 } 2232 2233 if (userinfo != null) { 2235 int index = 0; 2238 int end = userinfo.length(); 2239 char testChar = '\0'; 2240 while (index < end) { 2241 testChar = userinfo.charAt(index); 2242 if (testChar == '%') { 2243 if (index+2 >= end || 2244 !isHex(userinfo.charAt(index+1)) || 2245 !isHex(userinfo.charAt(index+2))) { 2246 return false; 2247 } 2248 index += 2; 2249 } 2250 else if (!isUserinfoCharacter(testChar)) { 2251 return false; 2252 } 2253 ++index; 2254 } 2255 } 2256 return true; 2257 } 2258 2259 2266 private boolean isValidRegistryBasedAuthority(String authority) { 2267 int index = 0; 2268 int end = authority.length(); 2269 char testChar; 2270 2271 while (index < end) { 2272 testChar = authority.charAt(index); 2273 2274 if (testChar == '%') { 2276 if (index+2 >= end || 2277 !isHex(authority.charAt(index+1)) || 2278 !isHex(authority.charAt(index+2))) { 2279 return false; 2280 } 2281 index += 2; 2282 } 2283 else if (!isPathCharacter(testChar)) { 2286 return false; 2287 } 2288 ++index; 2289 } 2290 return true; 2291 } 2292 2293 2301 private void initializePath(String p_uriSpec, int p_nStartIndex) 2302 throws MalformedURIException { 2303 if (p_uriSpec == null) { 2304 throw new MalformedURIException( 2305 "Cannot initialize path from null string!"); 2306 } 2307 2308 int index = p_nStartIndex; 2309 int start = p_nStartIndex; 2310 int end = p_uriSpec.length(); 2311 char testChar = '\0'; 2312 2313 if (start < end) { 2315 if (getScheme() == null || p_uriSpec.charAt(start) == '/') { 2317 2318 while (index < end) { 2322 testChar = p_uriSpec.charAt(index); 2323 2324 if (testChar == '%') { 2326 if (index+2 >= end || 2327 !isHex(p_uriSpec.charAt(index+1)) || 2328 !isHex(p_uriSpec.charAt(index+2))) { 2329 throw new MalformedURIException( 2330 "Path contains invalid escape sequence!"); 2331 } 2332 index += 2; 2333 } 2334 else if (!isPathCharacter(testChar)) { 2337 if (testChar == '?' || testChar == '#') { 2338 break; 2339 } 2340 throw new MalformedURIException( 2341 "Path contains invalid character: " + testChar); 2342 } 2343 ++index; 2344 } 2345 } 2346 else { 2347 2348 while (index < end) { 2351 testChar = p_uriSpec.charAt(index); 2352 2353 if (testChar == '?' || testChar == '#') { 2354 break; 2355 } 2356 2357 if (testChar == '%') { 2359 if (index+2 >= end || 2360 !isHex(p_uriSpec.charAt(index+1)) || 2361 !isHex(p_uriSpec.charAt(index+2))) { 2362 throw new MalformedURIException( 2363 "Opaque part contains invalid escape sequence!"); 2364 } 2365 index += 2; 2366 } 2367 else if (!isURICharacter(testChar)) { 2373 throw new MalformedURIException( 2374 "Opaque part contains invalid character: " + testChar); 2375 } 2376 ++index; 2377 } 2378 } 2379 } 2380 m_path = p_uriSpec.substring(start, index); 2381 2382 if (testChar == '?') { 2384 index++; 2385 start = index; 2386 while (index < end) { 2387 testChar = p_uriSpec.charAt(index); 2388 if (testChar == '#') { 2389 break; 2390 } 2391 if (testChar == '%') { 2392 if (index+2 >= end || 2393 !isHex(p_uriSpec.charAt(index+1)) || 2394 !isHex(p_uriSpec.charAt(index+2))) { 2395 throw new MalformedURIException( 2396 "Query string contains invalid escape sequence!"); 2397 } 2398 index += 2; 2399 } 2400 else if (!isURICharacter(testChar)) { 2401 throw new MalformedURIException( 2402 "Query string contains invalid character: " + testChar); 2403 } 2404 index++; 2405 } 2406 m_queryString = p_uriSpec.substring(start, index); 2407 } 2408 2409 if (testChar == '#') { 2411 index++; 2412 start = index; 2413 while (index < end) { 2414 testChar = p_uriSpec.charAt(index); 2415 2416 if (testChar == '%') { 2417 if (index+2 >= end || 2418 !isHex(p_uriSpec.charAt(index+1)) || 2419 !isHex(p_uriSpec.charAt(index+2))) { 2420 throw new MalformedURIException( 2421 "Fragment contains invalid escape sequence!"); 2422 } 2423 index += 2; 2424 } 2425 else if (!isURICharacter(testChar)) { 2426 throw new MalformedURIException( 2427 "Fragment contains invalid character: "+testChar); 2428 } 2429 index++; 2430 } 2431 m_fragment = p_uriSpec.substring(start, index); 2432 } 2433 } 2434 2435 2440 public String getScheme() { 2441 return m_scheme; 2442 } 2443 2444 2450 public String getSchemeSpecificPart() { 2451 StringBuffer schemespec = new StringBuffer (); 2452 2453 if (m_host != null || m_regAuthority != null) { 2454 schemespec.append("//"); 2455 2456 if (m_host != null) { 2458 2459 if (m_userinfo != null) { 2460 schemespec.append(m_userinfo); 2461 schemespec.append('@'); 2462 } 2463 2464 schemespec.append(m_host); 2465 2466 if (m_port != -1) { 2467 schemespec.append(':'); 2468 schemespec.append(m_port); 2469 } 2470 } 2471 else { 2473 schemespec.append(m_regAuthority); 2474 } 2475 } 2476 2477 if (m_path != null) { 2478 schemespec.append((m_path)); 2479 } 2480 2481 if (m_queryString != null) { 2482 schemespec.append('?'); 2483 schemespec.append(m_queryString); 2484 } 2485 2486 if (m_fragment != null) { 2487 schemespec.append('#'); 2488 schemespec.append(m_fragment); 2489 } 2490 2491 return schemespec.toString(); 2492 } 2493 2494 2499 public String getUserinfo() { 2500 return m_userinfo; 2501 } 2502 2503 2508 public String getHost() { 2509 return m_host; 2510 } 2511 2512 2517 public int getPort() { 2518 return m_port; 2519 } 2520 2521 2526 public String getRegBasedAuthority() { 2527 return m_regAuthority; 2528 } 2529 2530 2544 public String getPath(boolean p_includeQueryString, 2545 boolean p_includeFragment) { 2546 StringBuffer pathString = new StringBuffer (m_path); 2547 2548 if (p_includeQueryString && m_queryString != null) { 2549 pathString.append('?'); 2550 pathString.append(m_queryString); 2551 } 2552 2553 if (p_includeFragment && m_fragment != null) { 2554 pathString.append('#'); 2555 pathString.append(m_fragment); 2556 } 2557 return pathString.toString(); 2558 } 2559 2560 2566 public String getPath() { 2567 return m_path; 2568 } 2569 2570 2577 public String getQueryString() { 2578 return m_queryString; 2579 } 2580 2581 2588 public String getFragment() { 2589 return m_fragment; 2590 } 2591 2592 2601 public void setScheme(String p_scheme) throws MalformedURIException { 2602 if (p_scheme == null) { 2603 throw new MalformedURIException( 2604 "Cannot set scheme from null string!"); 2605 } 2606 if (!isConformantSchemeName(p_scheme)) { 2607 throw new MalformedURIException("The scheme is not conformant."); 2608 } 2609 2610 m_scheme = p_scheme.toLowerCase(); 2611 } 2612 2613 2622 public void setUserinfo(String p_userinfo) throws MalformedURIException { 2623 if (p_userinfo == null) { 2624 m_userinfo = null; 2625 return; 2626 } 2627 else { 2628 if (m_host == null) { 2629 throw new MalformedURIException( 2630 "Userinfo cannot be set when host is null!"); 2631 } 2632 2633 int index = 0; 2636 int end = p_userinfo.length(); 2637 char testChar = '\0'; 2638 while (index < end) { 2639 testChar = p_userinfo.charAt(index); 2640 if (testChar == '%') { 2641 if (index+2 >= end || 2642 !isHex(p_userinfo.charAt(index+1)) || 2643 !isHex(p_userinfo.charAt(index+2))) { 2644 throw new MalformedURIException( 2645 "Userinfo contains invalid escape sequence!"); 2646 } 2647 } 2648 else if (!isUserinfoCharacter(testChar)) { 2649 throw new MalformedURIException( 2650 "Userinfo contains invalid character:"+testChar); 2651 } 2652 index++; 2653 } 2654 } 2655 m_userinfo = p_userinfo; 2656 } 2657 2658 2670 public void setHost(String p_host) throws MalformedURIException { 2671 if (p_host == null || p_host.length() == 0) { 2672 if (p_host != null) { 2673 m_regAuthority = null; 2674 } 2675 m_host = p_host; 2676 m_userinfo = null; 2677 m_port = -1; 2678 return; 2679 } 2680 else if (!isWellFormedAddress(p_host)) { 2681 throw new MalformedURIException("Host is not a well formed address!"); 2682 } 2683 m_host = p_host; 2684 m_regAuthority = null; 2685 } 2686 2687 2698 public void setPort(int p_port) throws MalformedURIException { 2699 if (p_port >= 0 && p_port <= 65535) { 2700 if (m_host == null) { 2701 throw new MalformedURIException( 2702 "Port cannot be set when host is null!"); 2703 } 2704 } 2705 else if (p_port != -1) { 2706 throw new MalformedURIException("Invalid port number!"); 2707 } 2708 m_port = p_port; 2709 } 2710 2711 2722 public void setRegBasedAuthority(String authority) 2723 throws MalformedURIException { 2724 2725 if (authority == null) { 2726 m_regAuthority = null; 2727 return; 2728 } 2729 else if (authority.length() < 1 || 2732 !isValidRegistryBasedAuthority(authority) || 2733 authority.indexOf('/') != -1) { 2734 throw new MalformedURIException("Registry based authority is not well formed."); 2735 } 2736 m_regAuthority = authority; 2737 m_host = null; 2738 m_userinfo = null; 2739 m_port = -1; 2740 } 2741 2742 2756 public void setPath(String p_path) throws MalformedURIException { 2757 if (p_path == null) { 2758 m_path = null; 2759 m_queryString = null; 2760 m_fragment = null; 2761 } 2762 else { 2763 initializePath(p_path, 0); 2764 } 2765 } 2766 2767 2780 public void appendPath(String p_addToPath) 2781 throws MalformedURIException { 2782 if (p_addToPath == null || p_addToPath.trim().length() == 0) { 2783 return; 2784 } 2785 2786 if (!isURIString(p_addToPath)) { 2787 throw new MalformedURIException( 2788 "Path contains invalid character!"); 2789 } 2790 2791 if (m_path == null || m_path.trim().length() == 0) { 2792 if (p_addToPath.startsWith("/")) { 2793 m_path = p_addToPath; 2794 } 2795 else { 2796 m_path = "/" + p_addToPath; 2797 } 2798 } 2799 else if (m_path.endsWith("/")) { 2800 if (p_addToPath.startsWith("/")) { 2801 m_path = m_path.concat(p_addToPath.substring(1)); 2802 } 2803 else { 2804 m_path = m_path.concat(p_addToPath); 2805 } 2806 } 2807 else { 2808 if (p_addToPath.startsWith("/")) { 2809 m_path = m_path.concat(p_addToPath); 2810 } 2811 else { 2812 m_path = m_path.concat("/" + p_addToPath); 2813 } 2814 } 2815 } 2816 2817 2828 public void setQueryString(String p_queryString) throws MalformedURIException { 2829 if (p_queryString == null) { 2830 m_queryString = null; 2831 } 2832 else if (!isGenericURI()) { 2833 throw new MalformedURIException( 2834 "Query string can only be set for a generic URI!"); 2835 } 2836 else if (getPath() == null) { 2837 throw new MalformedURIException( 2838 "Query string cannot be set when path is null!"); 2839 } 2840 else if (!isURIString(p_queryString)) { 2841 throw new MalformedURIException( 2842 "Query string contains invalid character!"); 2843 } 2844 else { 2845 m_queryString = p_queryString; 2846 } 2847 } 2848 2849 2860 public void setFragment(String p_fragment) throws MalformedURIException { 2861 if (p_fragment == null) { 2862 m_fragment = null; 2863 } 2864 else if (!isGenericURI()) { 2865 throw new MalformedURIException( 2866 "Fragment can only be set for a generic URI!"); 2867 } 2868 else if (getPath() == null) { 2869 throw new MalformedURIException( 2870 "Fragment cannot be set when path is null!"); 2871 } 2872 else if (!isURIString(p_fragment)) { 2873 throw new MalformedURIException( 2874 "Fragment contains invalid character!"); 2875 } 2876 else { 2877 m_fragment = p_fragment; 2878 } 2879 } 2880 2881 2889 public boolean equals(Object p_test) { 2890 if (p_test instanceof URI) { 2891 URI testURI = (URI) p_test; 2892 if (((m_scheme == null && testURI.m_scheme == null) || 2893 (m_scheme != null && testURI.m_scheme != null && 2894 m_scheme.equals(testURI.m_scheme))) && 2895 ((m_userinfo == null && testURI.m_userinfo == null) || 2896 (m_userinfo != null && testURI.m_userinfo != null && 2897 m_userinfo.equals(testURI.m_userinfo))) && 2898 ((m_host == null && testURI.m_host == null) || 2899 (m_host != null && testURI.m_host != null && 2900 m_host.equals(testURI.m_host))) && 2901 m_port == testURI.m_port && 2902 ((m_path == null && testURI.m_path == null) || 2903 (m_path != null && testURI.m_path != null && 2904 m_path.equals(testURI.m_path))) && 2905 ((m_queryString == null && testURI.m_queryString == null) || 2906 (m_queryString != null && testURI.m_queryString != null && 2907 m_queryString.equals(testURI.m_queryString))) && 2908 ((m_fragment == null && testURI.m_fragment == null) || 2909 (m_fragment != null && testURI.m_fragment != null && 2910 m_fragment.equals(testURI.m_fragment)))) { 2911 return true; 2912 } 2913 } 2914 return false; 2915 } 2916 2917 2922 public String toString() { 2923 StringBuffer uriSpecString = new StringBuffer (); 2924 2925 if (m_scheme != null) { 2926 uriSpecString.append(m_scheme); 2927 uriSpecString.append(':'); 2928 } 2929 uriSpecString.append(getSchemeSpecificPart()); 2930 return uriSpecString.toString(); 2931 } 2932 2933 2940 public boolean isGenericURI() { 2941 return (m_host != null); 2944 } 2945 2946 2953 public static boolean isConformantSchemeName(String p_scheme) { 2954 if (p_scheme == null || p_scheme.trim().length() == 0) { 2955 return false; 2956 } 2957 2958 if (!isAlpha(p_scheme.charAt(0))) { 2959 return false; 2960 } 2961 2962 char testChar; 2963 int schemeLength = p_scheme.length(); 2964 for (int i = 1; i < schemeLength; ++i) { 2965 testChar = p_scheme.charAt(i); 2966 if (!isSchemeCharacter(testChar)) { 2967 return false; 2968 } 2969 } 2970 2971 return true; 2972 } 2973 2974 2986 public static boolean isWellFormedAddress(String address) { 2987 if (address == null) { 2988 return false; 2989 } 2990 2991 int addrLength = address.length(); 2992 if (addrLength == 0) { 2993 return false; 2994 } 2995 2996 if (address.startsWith("[")) { 2998 return isWellFormedIPv6Reference(address); 2999 } 3000 3001 if (address.startsWith(".") || 3003 address.startsWith("-") || 3004 address.endsWith("-")) { 3005 return false; 3006 } 3007 3008 int index = address.lastIndexOf('.'); 3012 if (address.endsWith(".")) { 3013 index = address.substring(0, index).lastIndexOf('.'); 3014 } 3015 3016 if (index+1 < addrLength && isDigit(address.charAt(index+1))) { 3017 return isWellFormedIPv4Address(address); 3018 } 3019 else { 3020 3024 if (addrLength > 255) { 3028 return false; 3029 } 3030 3031 char testChar; 3034 int labelCharCount = 0; 3035 3036 for (int i = 0; i < addrLength; i++) { 3037 testChar = address.charAt(i); 3038 if (testChar == '.') { 3039 if (!isAlphanum(address.charAt(i-1))) { 3040 return false; 3041 } 3042 if (i+1 < addrLength && !isAlphanum(address.charAt(i+1))) { 3043 return false; 3044 } 3045 labelCharCount = 0; 3046 } 3047 else if (!isAlphanum(testChar) && testChar != '-') { 3048 return false; 3049 } 3050 else if (++labelCharCount > 63) { 3052 return false; 3053 } 3054 } 3055 } 3056 return true; 3057 } 3058 3059 3070 public static boolean isWellFormedIPv4Address(String address) { 3071 3072 int addrLength = address.length(); 3073 char testChar; 3074 int numDots = 0; 3075 int numDigits = 0; 3076 3077 for (int i = 0; i < addrLength; i++) { 3088 testChar = address.charAt(i); 3089 if (testChar == '.') { 3090 if ((i > 0 && !isDigit(address.charAt(i-1))) || 3091 (i+1 < addrLength && !isDigit(address.charAt(i+1)))) { 3092 return false; 3093 } 3094 numDigits = 0; 3095 if (++numDots > 3) { 3096 return false; 3097 } 3098 } 3099 else if (!isDigit(testChar)) { 3100 return false; 3101 } 3102 else if (++numDigits > 3) { 3105 return false; 3106 } 3107 else if (numDigits == 3) { 3109 char first = address.charAt(i-2); 3110 char second = address.charAt(i-1); 3111 if (!(first < '2' || 3112 (first == '2' && 3113 (second < '5' || 3114 (second == '5' && testChar <= '5'))))) { 3115 return false; 3116 } 3117 } 3118 } 3119 return (numDots == 3); 3120 } 3121 3122 3137 public static boolean isWellFormedIPv6Reference(String address) { 3138 3139 int addrLength = address.length(); 3140 int index = 1; 3141 int end = addrLength-1; 3142 3143 if (!(addrLength > 2 && address.charAt(0) == '[' 3145 && address.charAt(end) == ']')) { 3146 return false; 3147 } 3148 3149 int [] counter = new int[1]; 3151 3152 index = scanHexSequence(address, index, end, counter); 3154 if (index == -1) { 3155 return false; 3156 } 3157 else if (index == end) { 3159 return (counter[0] == 8); 3160 } 3161 3162 if (index+1 < end && address.charAt(index) == ':') { 3163 if (address.charAt(index+1) == ':') { 3164 if (++counter[0] > 8) { 3166 return false; 3167 } 3168 index += 2; 3169 if (index == end) { 3171 return true; 3172 } 3173 } 3174 else { 3178 return (counter[0] == 6) && 3179 isWellFormedIPv4Address(address.substring(index+1, end)); 3180 } 3181 } 3182 else { 3183 return false; 3184 } 3185 3186 int prevCount = counter[0]; 3188 index = scanHexSequence(address, index, end, counter); 3189 3190 return (index == end) || 3194 (index != -1 && isWellFormedIPv4Address( 3195 address.substring((counter[0] > prevCount) ? index+1 : index, end))); 3196 } 3197 3198 3213 private static int scanHexSequence (String address, int index, int end, int [] counter) { 3214 3215 char testChar; 3216 int numDigits = 0; 3217 int start = index; 3218 3219 for (; index < end; ++index) { 3223 testChar = address.charAt(index); 3224 if (testChar == ':') { 3225 if (numDigits > 0 && ++counter[0] > 8) { 3227 return -1; 3228 } 3229 if (numDigits == 0 || ((index+1 < end) && address.charAt(index+1) == ':')) { 3231 return index; 3232 } 3233 numDigits = 0; 3234 } 3235 else if (!isHex(testChar)) { 3238 if (testChar == '.' && numDigits < 4 && numDigits > 0 && counter[0] <= 6) { 3239 int back = index - numDigits - 1; 3240 return (back >= start) ? back : (back+1); 3241 } 3242 return -1; 3243 } 3244 else if (++numDigits > 4) { 3246 return -1; 3247 } 3248 } 3249 return (numDigits > 0 && ++counter[0] <= 8) ? end : -1; 3250 } 3251 3252 3253 3258 private static boolean isDigit(char p_char) { 3259 return p_char >= '0' && p_char <= '9'; 3260 } 3261 3262 3268 private static boolean isHex(char p_char) { 3269 return (p_char <= 'f' && (fgLookupTable[p_char] & ASCII_HEX_CHARACTERS) != 0); 3270 } 3271 3272 3277 private static boolean isAlpha(char p_char) { 3278 return ((p_char >= 'a' && p_char <= 'z') || (p_char >= 'A' && p_char <= 'Z' )); 3279 } 3280 3281 3286 private static boolean isAlphanum(char p_char) { 3287 return (p_char <= 'z' && (fgLookupTable[p_char] & MASK_ALPHA_NUMERIC) != 0); 3288 } 3289 3290 3296 private static boolean isURICharacter (char p_char) { 3297 return (p_char <= '~' && (fgLookupTable[p_char] & MASK_URI_CHARACTER) != 0); 3298 } 3299 3300 3305 private static boolean isSchemeCharacter (char p_char) { 3306 return (p_char <= 'z' && (fgLookupTable[p_char] & MASK_SCHEME_CHARACTER) != 0); 3307 } 3308 3309 3314 private static boolean isUserinfoCharacter (char p_char) { 3315 return (p_char <= 'z' && (fgLookupTable[p_char] & MASK_USERINFO_CHARACTER) != 0); 3316 } 3317 3318 3323 private static boolean isPathCharacter (char p_char) { 3324 return (p_char <= '~' && (fgLookupTable[p_char] & MASK_PATH_CHARACTER) != 0); 3325 } 3326 3327 3328 3335 private static boolean isURIString(String p_uric) { 3336 if (p_uric == null) { 3337 return false; 3338 } 3339 int end = p_uric.length(); 3340 char testChar = '\0'; 3341 for (int i = 0; i < end; i++) { 3342 testChar = p_uric.charAt(i); 3343 if (testChar == '%') { 3344 if (i+2 >= end || 3345 !isHex(p_uric.charAt(i+1)) || 3346 !isHex(p_uric.charAt(i+2))) { 3347 return false; 3348 } 3349 else { 3350 i += 2; 3351 continue; 3352 } 3353 } 3354 if (isURICharacter(testChar)) { 3355 continue; 3356 } 3357 else { 3358 return false; 3359 } 3360 } 3361 return true; 3362 } 3363 3367 private static boolean gNeedEscaping[] = new boolean[128]; 3369 private static char gAfterEscaping1[] = new char[128]; 3371 private static char gAfterEscaping2[] = new char[128]; 3373 private static char[] gHexChs = {'0', '1', '2', '3', '4', '5', '6', '7', 3374 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'}; 3375 static { 3377 for (int i = 0; i <= 0x1f; i++) { 3378 gNeedEscaping[i] = true; 3379 gAfterEscaping1[i] = gHexChs[i >> 4]; 3380 gAfterEscaping2[i] = gHexChs[i & 0xf]; 3381 } 3382 gNeedEscaping[0x7f] = true; 3383 gAfterEscaping1[0x7f] = '7'; 3384 gAfterEscaping2[0x7f] = 'F'; 3385 char[] escChs = {' ', '<', '>', '"', '{', '}', 3386 '|', '\\', '^', '~', '`'}; 3387 int len = escChs.length; 3388 char ch; 3389 for (int i = 0; i < len; i++) { 3390 ch = escChs[i]; 3391 gNeedEscaping[ch] = true; 3392 gAfterEscaping1[ch] = gHexChs[ch >> 4]; 3393 gAfterEscaping2[ch] = gHexChs[ch & 0xf]; 3394 } 3395 } 3396 3397 public static String encode(String anyURI){ 3401 int len = anyURI.length(), ch; 3402 StringBuffer buffer = new StringBuffer (len*3); 3403 3404 int i = 0; 3406 for (; i < len; i++) { 3407 ch = anyURI.charAt(i); 3408 if (ch >= 128) 3410 break; 3411 if (gNeedEscaping[ch]) { 3412 buffer.append('%'); 3413 buffer.append(gAfterEscaping1[ch]); 3414 buffer.append(gAfterEscaping2[ch]); 3415 } 3416 else { 3417 buffer.append((char)ch); 3418 } 3419 } 3420 3421 if (i < len) { 3423 byte[] bytes = null; 3425 byte b; 3426 try { 3427 bytes = anyURI.substring(i).getBytes("UTF-8"); 3428 } catch (java.io.UnsupportedEncodingException e) { 3429 return anyURI; 3431 } 3432 len = bytes.length; 3433 3434 for (i = 0; i < len; i++) { 3436 b = bytes[i]; 3437 if (b < 0) { 3439 ch = b + 256; 3440 buffer.append('%'); 3441 buffer.append(gHexChs[ch >> 4]); 3442 buffer.append(gHexChs[ch & 0xf]); 3443 } 3444 else if (gNeedEscaping[b]) { 3445 buffer.append('%'); 3446 buffer.append(gAfterEscaping1[b]); 3447 buffer.append(gAfterEscaping2[b]); 3448 } 3449 else { 3450 buffer.append((char)b); 3451 } 3452 } 3453 } 3454 3455 if (buffer.length() != len) 3458 return buffer.toString(); 3459 else 3460 return anyURI; 3461 } 3462 3463} 3464 3465 3489 public static final class XMLChar { 3490 3491 3495 3496 private static final byte[] CHARS = new byte[1 << 16]; 3497 3498 3499 public static final int MASK_VALID = 0x01; 3500 3501 3502 public static final int MASK_SPACE = 0x02; 3503 3504 3505 public static final int MASK_NAME_START = 0x04; 3506 3507 3508 public static final int MASK_NAME = 0x08; 3509 3510 3511 public static final int MASK_PUBID = 0x10; 3512 3513 3521 public static final int MASK_CONTENT = 0x20; 3522 3523 3524 public static final int MASK_NCNAME_START = 0x40; 3525 3526 3527 public static final int MASK_NCNAME = 0x80; 3528 3529 3533 static { 3534 3535 3538 CHARS[9] = 35; 3539 CHARS[10] = 19; 3540 CHARS[13] = 19; 3541 CHARS[32] = 51; 3542 CHARS[33] = 49; 3543 CHARS[34] = 33; 3544 Arrays.fill(CHARS, 35, 38, (byte) 49 ); CHARS[38] = 1; 3546 Arrays.fill(CHARS, 39, 45, (byte) 49 ); Arrays.fill(CHARS, 45, 47, (byte) -71 ); CHARS[47] = 49; 3549 Arrays.fill(CHARS, 48, 58, (byte) -71 ); CHARS[58] = 61; 3551 CHARS[59] = 49; 3552 CHARS[60] = 1; 3553 CHARS[61] = 49; 3554 CHARS[62] = 33; 3555 Arrays.fill(CHARS, 63, 65, (byte) 49 ); Arrays.fill(CHARS, 65, 91, (byte) -3 ); Arrays.fill(CHARS, 91, 93, (byte) 33 ); CHARS[93] = 1; 3559 CHARS[94] = 33; 3560 CHARS[95] = -3; 3561 CHARS[96] = 33; 3562 Arrays.fill(CHARS, 97, 123, (byte) -3 ); Arrays.fill(CHARS, 123, 183, (byte) 33 ); CHARS[183] = -87; 3565 Arrays.fill(CHARS, 184, 192, (byte) 33 ); Arrays.fill(CHARS, 192, 215, (byte) -19 ); CHARS[215] = 33; 3568 Arrays.fill(CHARS, 216, 247, (byte) -19 ); CHARS[247] = 33; 3570 Arrays.fill(CHARS, 248, 306, (byte) -19 ); Arrays.fill(CHARS, 306, 308, (byte) 33 ); Arrays.fill(CHARS, 308, 319, (byte) -19 ); Arrays.fill(CHARS, 319, 321, (byte) 33 ); Arrays.fill(CHARS, 321, 329, (byte) -19 ); CHARS[329] = 33; 3576 Arrays.fill(CHARS, 330, 383, (byte) -19 ); CHARS[383] = 33; 3578 Arrays.fill(CHARS, 384, 452, (byte) -19 ); Arrays.fill(CHARS, 452, 461, (byte) 33 ); Arrays.fill(CHARS, 461, 497, (byte) -19 ); Arrays.fill(CHARS, 497, 500, (byte) 33 ); Arrays.fill(CHARS, 500, 502, (byte) -19 ); Arrays.fill(CHARS, 502, 506, (byte) 33 ); Arrays.fill(CHARS, 506, 536, (byte) -19 ); Arrays.fill(CHARS, 536, 592, (byte) 33 ); Arrays.fill(CHARS, 592, 681, (byte) -19 ); Arrays.fill(CHARS, 681, 699, (byte) 33 ); Arrays.fill(CHARS, 699, 706, (byte) -19 ); Arrays.fill(CHARS, 706, 720, (byte) 33 ); Arrays.fill(CHARS, 720, 722, (byte) -87 ); Arrays.fill(CHARS, 722, 768, (byte) 33 ); Arrays.fill(CHARS, 768, 838, (byte) -87 ); Arrays.fill(CHARS, 838, 864, (byte) 33 ); Arrays.fill(CHARS, 864, 866, (byte) -87 ); Arrays.fill(CHARS, 866, 902, (byte) 33 ); CHARS[902] = -19; 3597 CHARS[903] = -87; 3598 Arrays.fill(CHARS, 904, 907, (byte) -19 ); CHARS[907] = 33; 3600 CHARS[908] = -19; 3601 CHARS[909] = 33; 3602 Arrays.fill(CHARS, 910, 930, (byte) -19 ); CHARS[930] = 33; 3604 Arrays.fill(CHARS, 931, 975, (byte) -19 ); CHARS[975] = 33; 3606 Arrays.fill(CHARS, 976, 983, (byte) -19 ); Arrays.fill(CHARS, 983, 986, (byte) 33 ); CHARS[986] = -19; 3609 CHARS[987] = 33; 3610 CHARS[988] = -19; 3611 CHARS[989] = 33; 3612 CHARS[990] = -19; 3613 CHARS[991] = 33; 3614 CHARS[992] = -19; 3615 CHARS[993] = 33; 3616 Arrays.fill(CHARS, 994, 1012, (byte) -19 ); Arrays.fill(CHARS, 1012, 1025, (byte) 33 ); Arrays.fill(CHARS, 1025, 1037, (byte) -19 ); CHARS[1037] = 33; 3620 Arrays.fill(CHARS, 1038, 1104, (byte) -19 ); CHARS[1104] = 33; 3622 Arrays.fill(CHARS, 1105, 1117, (byte) -19 ); CHARS[1117] = 33; 3624 Arrays.fill(CHARS, 1118, 1154, (byte) -19 ); CHARS[1154] = 33; 3626 Arrays.fill(CHARS, 1155, 1159, (byte) -87 ); Arrays.fill(CHARS, 1159, 1168, (byte) 33 ); Arrays.fill(CHARS, 1168, 1221, (byte) -19 ); Arrays.fill(CHARS, 1221, 1223, (byte) 33 ); Arrays.fill(CHARS, 1223, 1225, (byte) -19 ); Arrays.fill(CHARS, 1225, 1227, (byte) 33 ); Arrays.fill(CHARS, 1227, 1229, (byte) -19 ); Arrays.fill(CHARS, 1229, 1232, (byte) 33 ); Arrays.fill(CHARS, 1232, 1260, (byte) -19 ); Arrays.fill(CHARS, 1260, 1262, (byte) 33 ); Arrays.fill(CHARS, 1262, 1270, (byte) -19 ); Arrays.fill(CHARS, 1270, 1272, (byte) 33 ); Arrays.fill(CHARS, 1272, 1274, (byte) -19 ); Arrays.fill(CHARS, 1274, 1329, (byte) 33 ); Arrays.fill(CHARS, 1329, 1367, (byte) -19 ); Arrays.fill(CHARS, 1367, 1369, (byte) 33 ); CHARS[1369] = -19; 3643 Arrays.fill(CHARS, 1370, 1377, (byte) 33 ); Arrays.fill(CHARS, 1377, 1415, (byte) -19 ); Arrays.fill(CHARS, 1415, 1425, (byte) 33 ); Arrays.fill(CHARS, 1425, 1442, (byte) -87 ); CHARS[1442] = 33; 3648 Arrays.fill(CHARS, 1443, 1466, (byte) -87 ); CHARS[1466] = 33; 3650 Arrays.fill(CHARS, 1467, 1470, (byte) -87 ); CHARS[1470] = 33; 3652 CHARS[1471] = -87; 3653 CHARS[1472] = 33; 3654 Arrays.fill(CHARS, 1473, 1475, (byte) -87 ); CHARS[1475] = 33; 3656 CHARS[1476] = -87; 3657 Arrays.fill(CHARS, 1477, 1488, (byte) 33 ); Arrays.fill(CHARS, 1488, 1515, (byte) -19 ); Arrays.fill(CHARS, 1515, 1520, (byte) 33 ); Arrays.fill(CHARS, 1520, 1523, (byte) -19 ); Arrays.fill(CHARS, 1523, 1569, (byte) 33 ); Arrays.fill(CHARS, 1569, 1595, (byte) -19 ); Arrays.fill(CHARS, 1595, 1600, (byte) 33 ); CHARS[1600] = -87; 3665 Arrays.fill(CHARS, 1601, 1611, (byte) -19 ); Arrays.fill(CHARS, 1611, 1619, (byte) -87 ); Arrays.fill(CHARS, 1619, 1632, (byte) 33 ); Arrays.fill(CHARS, 1632, 1642, (byte) -87 ); Arrays.fill(CHARS, 1642, 1648, (byte) 33 ); CHARS[1648] = -87; 3671 Arrays.fill(CHARS, 1649, 1720, (byte) -19 ); Arrays.fill(CHARS, 1720, 1722, (byte) 33 ); Arrays.fill(CHARS, 1722, 1727, (byte) -19 ); CHARS[1727] = 33; 3675 Arrays.fill(CHARS, 1728, 1743, (byte) -19 ); CHARS[1743] = 33; 3677 Arrays.fill(CHARS, 1744, 1748, (byte) -19 ); CHARS[1748] = 33; 3679 CHARS[1749] = -19; 3680 Arrays.fill(CHARS, 1750, 1765, (byte) -87 ); Arrays.fill(CHARS, 1765, 1767, (byte) -19 ); Arrays.fill(CHARS, 1767, 1769, (byte) -87 ); CHARS[1769] = 33; 3684 Arrays.fill(CHARS, 1770, 1774, (byte) -87 ); Arrays.fill(CHARS, 1774, 1776, (byte) 33 ); Arrays.fill(CHARS, 1776, 1786, (byte) -87 ); Arrays.fill(CHARS, 1786, 2305, (byte) 33 ); Arrays.fill(CHARS, 2305, 2308, (byte) -87 ); CHARS[2308] = 33; 3690 Arrays.fill(CHARS, 2309, 2362, (byte) -19 ); Arrays.fill(CHARS, 2362, 2364, (byte) 33 ); CHARS[2364] = -87; 3693 CHARS[2365] = -19; 3694 Arrays.fill(CHARS, 2366, 2382, (byte) -87 ); Arrays.fill(CHARS, 2382, 2385, (byte) 33 ); Arrays.fill(CHARS, 2385, 2389, (byte) -87 ); Arrays.fill(CHARS, 2389, 2392, (byte) 33 ); Arrays.fill(CHARS, 2392, 2402, (byte) -19 ); Arrays.fill(CHARS, 2402, 2404, (byte) -87 ); Arrays.fill(CHARS, 2404, 2406, (byte) 33 ); Arrays.fill(CHARS, 2406, 2416, (byte) -87 ); Arrays.fill(CHARS, 2416, 2433, (byte) 33 ); Arrays.fill(CHARS, 2433, 2436, (byte) -87 ); CHARS[2436] = 33; 3705 Arrays.fill(CHARS, 2437, 2445, (byte) -19 ); Arrays.fill(CHARS, 2445, 2447, (byte) 33 ); Arrays.fill(CHARS, 2447, 2449, (byte) -19 ); Arrays.fill(CHARS, 2449, 2451, (byte) 33 ); Arrays.fill(CHARS, 2451, 2473, (byte) -19 ); CHARS[2473] = 33; 3711 Arrays.fill(CHARS, 2474, 2481, (byte) -19 ); CHARS[2481] = 33; 3713 CHARS[2482] = -19; 3714 Arrays.fill(CHARS, 2483, 2486, (byte) 33 ); Arrays.fill(CHARS, 2486, 2490, (byte) -19 ); Arrays.fill(CHARS, 2490, 2492, (byte) 33 ); CHARS[2492] = -87; 3718 CHARS[2493] = 33; 3719 Arrays.fill(CHARS, 2494, 2501, (byte) -87 ); Arrays.fill(CHARS, 2501, 2503, (byte) 33 ); Arrays.fill(CHARS, 2503, 2505, (byte) -87 ); Arrays.fill(CHARS, 2505, 2507, (byte) 33 ); Arrays.fill(CHARS, 2507, 2510, (byte) -87 ); Arrays.fill(CHARS, 2510, 2519, (byte) 33 ); CHARS[2519] = -87; 3726 Arrays.fill(CHARS, 2520, 2524, (byte) 33 ); Arrays.fill(CHARS, 2524, 2526, (byte) -19 ); CHARS[2526] = 33; 3729 Arrays.fill(CHARS, 2527, 2530, (byte) -19 ); Arrays.fill(CHARS, 2530, 2532, (byte) -87 ); Arrays.fill(CHARS, 2532, 2534, (byte) 33 ); Arrays.fill(CHARS, 2534, 2544, (byte) -87 ); Arrays.fill(CHARS, 2544, 2546, (byte) -19 ); Arrays.fill(CHARS, 2546, 2562, (byte) 33 ); CHARS[2562] = -87; 3736 Arrays.fill(CHARS, 2563, 2565, (byte) 33 ); Arrays.fill(CHARS, 2565, 2571, (byte) -19 ); Arrays.fill(CHARS, 2571, 2575, (byte) 33 ); Arrays.fill(CHARS, 2575, 2577, (byte) -19 ); Arrays.fill(CHARS, 2577, 2579, (byte) 33 ); Arrays.fill(CHARS, 2579, 2601, (byte) -19 ); CHARS[2601] = 33; 3743 Arrays.fill(CHARS, 2602, 2609, (byte) -19 ); CHARS[2609] = 33; 3745 Arrays.fill(CHARS, 2610, 2612, (byte) -19 ); CHARS[2612] = 33; 3747 Arrays.fill(CHARS, 2613, 2615, (byte) -19 ); CHARS[2615] = 33; 3749 Arrays.fill(CHARS, 2616, 2618, (byte) -19 ); Arrays.fill(CHARS, 2618, 2620, (byte) 33 ); CHARS[2620] = -87; 3752 CHARS[2621] = 33; 3753 Arrays.fill(CHARS, 2622, 2627, (byte) -87 ); Arrays.fill(CHARS, 2627, 2631, (byte) 33 ); Arrays.fill(CHARS, 2631, 2633, (byte) -87 ); Arrays.fill(CHARS, 2633, 2635, (byte) 33 ); Arrays.fill(CHARS, 2635, 2638, (byte) -87 ); Arrays.fill(CHARS, 2638, 2649, (byte) 33 ); Arrays.fill(CHARS, 2649, 2653, (byte) -19 ); CHARS[2653] = 33; 3761 CHARS[2654] = -19; 3762 Arrays.fill(CHARS, 2655, 2662, (byte) 33 ); Arrays.fill(CHARS, 2662, 2674, (byte) -87 ); Arrays.fill(CHARS, 2674, 2677, (byte) -19 ); Arrays.fill(CHARS, 2677, 2689, (byte) 33 ); Arrays.fill(CHARS, 2689, 2692, (byte) -87 ); CHARS[2692] = 33; 3768 Arrays.fill(CHARS, 2693, 2700, (byte) -19 ); CHARS[2700] = 33; 3770 CHARS[2701] = -19; 3771 CHARS[2702] = 33; 3772 Arrays.fill(CHARS, 2703, 2706, (byte) -19 ); CHARS[2706] = 33; 3774 Arrays.fill(CHARS, 2707, 2729, (byte) -19 ); CHARS[2729] = 33; 3776 Arrays.fill(CHARS, 2730, 2737, (byte) -19 ); CHARS[2737] = 33; 3778 Arrays.fill(CHARS, 2738, 2740, (byte) -19 ); CHARS[2740] = 33; 3780 Arrays.fill(CHARS, 2741, 2746, (byte) -19 ); Arrays.fill(CHARS, 2746, 2748, (byte) 33 ); CHARS[2748] = -87; 3783 CHARS[2749] = -19; 3784 Arrays.fill(CHARS, 2750, 2758, (byte) -87 ); CHARS[2758] = 33; 3786 Arrays.fill(CHARS, 2759, 2762, (byte) -87 ); CHARS[2762] = 33; 3788 Arrays.fill(CHARS, 2763, 2766, (byte) -87 ); Arrays.fill(CHARS, 2766, 2784, (byte) 33 ); CHARS[2784] = -19; 3791 Arrays.fill(CHARS, 2785, 2790, (byte) 33 ); Arrays.fill(CHARS, 2790, 2800, (byte) -87 ); Arrays.fill(CHARS, 2800, 2817, (byte) 33 ); Arrays.fill(CHARS, 2817, 2820, (byte) -87 ); CHARS[2820] = 33; 3796 Arrays.fill(CHARS, 2821, 2829, (byte) -19 ); Arrays.fill(CHARS, 2829, 2831, (byte) 33 ); Arrays.fill(CHARS, 2831, 2833, (byte) -19 ); Arrays.fill(CHARS, 2833, 2835, (byte) 33 ); Arrays.fill(CHARS, 2835, 2857, (byte) -19 ); CHARS[2857] = 33; 3802 Arrays.fill(CHARS, 2858, 2865, (byte) -19 ); CHARS[2865] = 33; 3804 Arrays.fill(CHARS, 2866, 2868, (byte) -19 ); Arrays.fill(CHARS, 2868, 2870, (byte) 33 ); Arrays.fill(CHARS, 2870, 2874, (byte) -19 ); Arrays.fill(CHARS, 2874, 2876, (byte) 33 ); CHARS[2876] = -87; 3809 CHARS[2877] = -19; 3810 Arrays.fill(CHARS, 2878, 2884, (byte) -87 ); Arrays.fill(CHARS, 2884, 2887, (byte) 33 ); Arrays.fill(CHARS, 2887, 2889, (byte) -87 ); Arrays.fill(CHARS, 2889, 2891, (byte) 33 ); Arrays.fill(CHARS, 2891, 2894, (byte) -87 ); Arrays.fill(CHARS, 2894, 2902, (byte) 33 ); Arrays.fill(CHARS, 2902, 2904, (byte) -87 ); Arrays.fill(CHARS, 2904, 2908, (byte) 33 ); Arrays.fill(CHARS, 2908, 2910, (byte) -19 ); CHARS[2910] = 33; 3820 Arrays.fill(CHARS, 2911, 2914, (byte) -19 ); Arrays.fill(CHARS, 2914, 2918, (byte) 33 ); Arrays.fill(CHARS, 2918, 2928, (byte) -87 ); Arrays.fill(CHARS, 2928, 2946, (byte) 33 ); Arrays.fill(CHARS, 2946, 2948, (byte) -87 ); CHARS[2948] = 33; 3826 Arrays.fill(CHARS, 2949, 2955, (byte) -19 ); Arrays.fill(CHARS, 2955, 2958, (byte) 33 ); Arrays.fill(CHARS, 2958, 2961, (byte) -19 ); CHARS[2961] = 33; 3830 Arrays.fill(CHARS, 2962, 2966, (byte) -19 ); Arrays.fill(CHARS, 2966, 2969, (byte) 33 ); Arrays.fill(CHARS, 2969, 2971, (byte) -19 ); CHARS[2971] = 33; 3834 CHARS[2972] = -19; 3835 CHARS[2973] = 33; 3836 Arrays.fill(CHARS, 2974, 2976, (byte) -19 ); Arrays.fill(CHARS, 2976, 2979, (byte) 33 ); Arrays.fill(CHARS, 2979, 2981, (byte) -19 ); Arrays.fill(CHARS, 2981, 2984, (byte) 33 ); Arrays.fill(CHARS, 2984, 2987, (byte) -19 ); Arrays.fill(CHARS, 2987, 2990, (byte) 33 ); Arrays.fill(CHARS, 2990, 2998, (byte) -19 ); CHARS[2998] = 33; 3844 Arrays.fill(CHARS, 2999, 3002, (byte) -19 ); Arrays.fill(CHARS, 3002, 3006, (byte) 33 ); Arrays.fill(CHARS, 3006, 3011, (byte) -87 ); Arrays.fill(CHARS, 3011, 3014, (byte) 33 ); Arrays.fill(CHARS, 3014, 3017, (byte) -87 ); CHARS[3017] = 33; 3850 Arrays.fill(CHARS, 3018, 3022, (byte) -87 ); Arrays.fill(CHARS, 3022, 3031, (byte) 33 ); CHARS[3031] = -87; 3853 Arrays.fill(CHARS, 3032, 3047, (byte) 33 ); Arrays.fill(CHARS, 3047, 3056, (byte) -87 ); Arrays.fill(CHARS, 3056, 3073, (byte) 33 ); Arrays.fill(CHARS, 3073, 3076, (byte) -87 ); CHARS[3076] = 33; 3858 Arrays.fill(CHARS, 3077, 3085, (byte) -19 ); CHARS[3085] = 33; 3860 Arrays.fill(CHARS, 3086, 3089, (byte) -19 ); CHARS[3089] = 33; 3862 Arrays.fill(CHARS, 3090, 3113, (byte) -19 ); CHARS[3113] = 33; 3864 Arrays.fill(CHARS, 3114, 3124, (byte) -19 ); CHARS[3124] = 33; 3866 Arrays.fill(CHARS, 3125, 3130, (byte) -19 ); Arrays.fill(CHARS, 3130, 3134, (byte) 33 ); Arrays.fill(CHARS, 3134, 3141, (byte) -87 ); CHARS[3141] = 33; 3870 Arrays.fill(CHARS, 3142, 3145, (byte) -87 ); CHARS[3145] = 33; 3872 Arrays.fill(CHARS, 3146, 3150, (byte) -87 ); Arrays.fill(CHARS, 3150, 3157, (byte) 33 ); Arrays.fill(CHARS, 3157, 3159, (byte) -87 ); Arrays.fill(CHARS, 3159, 3168, (byte) 33 ); Arrays.fill(CHARS, 3168, 3170, (byte) -19 ); Arrays.fill(CHARS, 3170, 3174, (byte) 33 ); Arrays.fill(CHARS, 3174, 3184, (byte) -87 ); Arrays.fill(CHARS, 3184, 3202, (byte) 33 ); Arrays.fill(CHARS, 3202, 3204, (byte) -87 ); CHARS[3204] = 33; 3882 Arrays.fill(CHARS, 3205, 3213, (byte) -19 ); CHARS[3213] = 33; 3884 Arrays.fill(CHARS, 3214, 3217, (byte) -19 ); CHARS[3217] = 33; 3886 Arrays.fill(CHARS, 3218, 3241, (byte) -19 ); CHARS[3241] = 33; 3888 Arrays.fill(CHARS, 3242, 3252, (byte) -19 ); CHARS[3252] = 33; 3890 Arrays.fill(CHARS, 3253, 3258, (byte) -19 ); Arrays.fill(CHARS, 3258, 3262, (byte) 33 ); Arrays.fill(CHARS, 3262, 3269, (byte) -87 ); CHARS[3269] = 33; 3894 Arrays.fill(CHARS, 3270, 3273, (byte) -87 ); CHARS[3273] = 33; 3896 Arrays.fill(CHARS, 3274, 3278, (byte) -87 ); Arrays.fill(CHARS, 3278, 3285, (byte) 33 ); Arrays.fill(CHARS, 3285, 3287, (byte) -87 ); Arrays.fill(CHARS, 3287, 3294, (byte) 33 ); CHARS[3294] = -19; 3901 CHARS[3295] = 33; 3902 Arrays.fill(CHARS, 3296, 3298, (byte) -19 ); Arrays.fill(CHARS, 3298, 3302, (byte) 33 ); Arrays.fill(CHARS, 3302, 3312, (byte) -87 ); Arrays.fill(CHARS, 3312, 3330, (byte) 33 ); Arrays.fill(CHARS, 3330, 3332, (byte) -87 ); CHARS[3332] = 33; 3908 Arrays.fill(CHARS, 3333, 3341, (byte) -19 ); CHARS[3341] = 33; 3910 Arrays.fill(CHARS, 3342, 3345, (byte) -19 ); CHARS[3345] = 33; 3912 Arrays.fill(CHARS, 3346, 3369, (byte) -19 ); CHARS[3369] = 33; 3914 Arrays.fill(CHARS, 3370, 3386, (byte) -19 ); Arrays.fill(CHARS, 3386, 3390, (byte) 33 ); Arrays.fill(CHARS, 3390, 3396, (byte) -87 ); Arrays.fill(CHARS, 3396, 3398, (byte) 33 ); Arrays.fill(CHARS, 3398, 3401, (byte) -87 ); CHARS[3401] = 33; 3920 Arrays.fill(CHARS, 3402, 3406, (byte) -87 ); Arrays.fill(CHARS, 3406, 3415, (byte) 33 ); CHARS[3415] = -87; 3923 Arrays.fill(CHARS, 3416, 3424, (byte) 33 ); Arrays.fill(CHARS, 3424, 3426, (byte) -19 ); Arrays.fill(CHARS, 3426, 3430, (byte) 33 ); Arrays.fill(CHARS, 3430, 3440, (byte) -87 ); Arrays.fill(CHARS, 3440, 3585, (byte) 33 ); Arrays.fill(CHARS, 3585, 3631, (byte) -19 ); CHARS[3631] = 33; 3930 CHARS[3632] = -19; 3931 CHARS[3633] = -87; 3932 Arrays.fill(CHARS, 3634, 3636, (byte) -19 ); Arrays.fill(CHARS, 3636, 3643, (byte) -87 ); Arrays.fill(CHARS, 3643, 3648, (byte) 33 ); Arrays.fill(CHARS, 3648, 3654, (byte) -19 ); Arrays.fill(CHARS, 3654, 3663, (byte) -87 ); CHARS[3663] = 33; 3938 Arrays.fill(CHARS, 3664, 3674, (byte) -87 ); Arrays.fill(CHARS, 3674, 3713, (byte) 33 ); Arrays.fill(CHARS, 3713, 3715, (byte) -19 ); CHARS[3715] = 33; 3942 CHARS[3716] = -19; 3943 Arrays.fill(CHARS, 3717, 3719, (byte) 33 ); Arrays.fill(CHARS, 3719, 3721, (byte) -19 ); CHARS[3721] = 33; 3946 CHARS[3722] = -19; 3947 Arrays.fill(CHARS, 3723, 3725, (byte) 33 ); CHARS[3725] = -19; 3949 Arrays.fill(CHARS, 3726, 3732, (byte) 33 ); Arrays.fill(CHARS, 3732, 3736, (byte) -19 ); CHARS[3736] = 33; 3952 Arrays.fill(CHARS, 3737, 3744, (byte) -19 ); CHARS[3744] = 33; 3954 Arrays.fill(CHARS, 3745, 3748, (byte) -19 ); CHARS[3748] = 33; 3956 CHARS[3749] = -19; 3957 CHARS[3750] = 33; 3958 CHARS[3751] = -19; 3959 Arrays.fill(CHARS, 3752, 3754, (byte) 33 ); Arrays.fill(CHARS, 3754, 3756, (byte) -19 ); CHARS[3756] = 33; 3962 Arrays.fill(CHARS, 3757, 3759, (byte) -19 ); CHARS[3759] = 33; 3964 CHARS[3760] = -19; 3965 CHARS[3761] = -87; 3966 Arrays.fill(CHARS, 3762, 3764, (byte) -19 ); Arrays.fill(CHARS, 3764, 3770, (byte) -87 ); CHARS[3770] = 33; 3969 Arrays.fill(CHARS, 3771, 3773, (byte) -87 ); CHARS[3773] = -19; 3971 Arrays.fill(CHARS, 3774, 3776, (byte) 33 ); Arrays.fill(CHARS, 3776, 3781, (byte) -19 ); CHARS[3781] = 33; 3974 CHARS[3782] = -87; 3975 CHARS[3783] = 33; 3976 Arrays.fill(CHARS, 3784, 3790, (byte) -87 ); Arrays.fill(CHARS, 3790, 3792, (byte) 33 ); Arrays.fill(CHARS, 3792, 3802, (byte) -87 ); Arrays.fill(CHARS, 3802, 3864, (byte) 33 ); Arrays.fill(CHARS, 3864, 3866, (byte) -87 ); Arrays.fill(CHARS, 3866, 3872, (byte) 33 ); Arrays.fill(CHARS, 3872, 3882, (byte) -87 ); Arrays.fill(CHARS, 3882, 3893, (byte) 33 ); CHARS[3893] = -87; 3985 CHARS[3894] = 33; 3986 CHARS[3895] = -87; 3987 CHARS[3896] = 33; 3988 CHARS[3897] = -87; 3989 Arrays.fill(CHARS, 3898, 3902, (byte) 33 ); Arrays.fill(CHARS, 3902, 3904, (byte) -87 ); Arrays.fill(CHARS, 3904, 3912, (byte) -19 ); CHARS[3912] = 33; 3993 Arrays.fill(CHARS, 3913, 3946, (byte) -19 ); Arrays.fill(CHARS, 3946, 3953, (byte) 33 ); Arrays.fill(CHARS, 3953, 3973, (byte) -87 ); CHARS[3973] = 33; 3997 Arrays.fill(CHARS, 3974, 3980, (byte) -87 ); Arrays.fill(CHARS, 3980, 3984, (byte) 33 ); Arrays.fill(CHARS, 3984, 3990, (byte) -87 ); CHARS[3990] = 33; 4001 CHARS[3991] = -87; 4002 CHARS[3992] = 33; 4003 Arrays.fill(CHARS, 3993, 4014, (byte) -87 ); Arrays.fill(CHARS, 4014, 4017, (byte) 33 ); Arrays.fill(CHARS, 4017, 4024, (byte) -87 ); CHARS[4024] = 33; 4007 CHARS[4025] = -87; 4008 Arrays.fill(CHARS, 4026, 4256, (byte) 33 ); Arrays.fill(CHARS, 4256, 4294, (byte) -19 ); Arrays.fill(CHARS, 4294, 4304, (byte) 33 ); Arrays.fill(CHARS, 4304, 4343, (byte) -19 ); Arrays.fill(CHARS, 4343, 4352, (byte) 33 ); CHARS[4352] = -19; 4014 CHARS[4353] = 33; 4015 Arrays.fill(CHARS, 4354, 4356, (byte) -19 ); CHARS[4356] = 33; 4017 Arrays.fill(CHARS, 4357, 4360, (byte) -19 ); CHARS[4360] = 33; 4019 CHARS[4361] = -19; 4020 CHARS[4362] = 33; 4021 Arrays.fill(CHARS, 4363, 4365, (byte) -19 ); CHARS[4365] = 33; 4023 Arrays.fill(CHARS, 4366, 4371, (byte) -19 ); Arrays.fill(CHARS, 4371, 4412, (byte) 33 ); CHARS[4412] = -19; 4026 CHARS[4413] = 33; 4027 CHARS[4414] = -19; 4028 CHARS[4415] = 33; 4029 CHARS[4416] = -19; 4030 Arrays.fill(CHARS, 4417, 4428, (byte) 33 ); CHARS[4428] = -19; 4032 CHARS[4429] = 33; 4033 CHARS[4430] = -19; 4034 CHARS[4431] = 33; 4035 CHARS[4432] = -19; 4036 Arrays.fill(CHARS, 4433, 4436, (byte) 33 ); Arrays.fill(CHARS, 4436, 4438, (byte) -19 ); Arrays.fill(CHARS, 4438, 4441, (byte) 33 ); CHARS[4441] = -19; 4040 Arrays.fill(CHARS, 4442, 4447, (byte) 33 ); Arrays.fill(CHARS, 4447, 4450, (byte) -19 ); CHARS[4450] = 33; 4043 CHARS[4451] = -19; 4044 CHARS[4452] = 33; 4045 CHARS[4453] = -19; 4046 CHARS[4454] = 33; 4047 CHARS[4455] = -19; 4048 CHARS[4456] = 33; 4049 CHARS[4457] = -19; 4050 Arrays.fill(CHARS, 4458, 4461, (byte) 33 ); Arrays.fill(CHARS, 4461, 4463, (byte) -19 ); Arrays.fill(CHARS, 4463, 4466, (byte) 33 ); Arrays.fill(CHARS, 4466, 4468, (byte) -19 ); CHARS[4468] = 33; 4055 CHARS[4469] = -19; 4056 Arrays.fill(CHARS, 4470, 4510, (byte) 33 ); CHARS[4510] = -19; 4058 Arrays.fill(CHARS, 4511, 4520, (byte) 33 ); CHARS[4520] = -19; 4060 Arrays.fill(CHARS, 4521, 4523, (byte) 33 ); CHARS[4523] = -19; 4062 Arrays.fill(CHARS, 4524, 4526, (byte) 33 ); Arrays.fill(CHARS, 4526, 4528, (byte) -19 ); Arrays.fill(CHARS, 4528, 4535, (byte) 33 ); Arrays.fill(CHARS, 4535, 4537, (byte) -19 ); CHARS[4537] = 33; 4067 CHARS[4538] = -19; 4068 CHARS[4539] = 33; 4069 Arrays.fill(CHARS, 4540, 4547, (byte) -19 ); Arrays.fill(CHARS, 4547, 4587, (byte) 33 ); CHARS[4587] = -19; 4072 Arrays.fill(CHARS, 4588, 4592, (byte) 33 ); CHARS[4592] = -19; 4074 Arrays.fill(CHARS, 4593, 4601, (byte) 33 ); CHARS[4601] = -19; 4076 Arrays.fill(CHARS, 4602, 7680, (byte) 33 ); Arrays.fill(CHARS, 7680, 7836, (byte) -19 ); Arrays.fill(CHARS, 7836, 7840, (byte) 33 ); Arrays.fill(CHARS, 7840, 7930, (byte) -19 ); Arrays.fill(CHARS, 7930, 7936, (byte) 33 ); Arrays.fill(CHARS, 7936, 7958, (byte) -19 ); Arrays.fill(CHARS, 7958, 7960, (byte) 33 ); Arrays.fill(CHARS, 7960, 7966, (byte) -19 ); Arrays.fill(CHARS, 7966, 7968, (byte) 33 ); Arrays.fill(CHARS, 7968, 8006, (byte) -19 ); Arrays.fill(CHARS, 8006, 8008, (byte) 33 ); Arrays.fill(CHARS, 8008, 8014, (byte) -19 ); Arrays.fill(CHARS, 8014, 8016, (byte) 33 ); Arrays.fill(CHARS, 8016, 8024, (byte) -19 ); CHARS[8024] = 33; 4091 CHARS[8025] = -19; 4092 CHARS[8026] = 33; 4093 CHARS[8027] = -19; 4094 CHARS[8028] = 33; 4095 CHARS[8029] = -19; 4096 CHARS[8030] = 33; 4097 Arrays.fill(CHARS, 8031, 8062, (byte) -19 ); Arrays.fill(CHARS, 8062, 8064, (byte) 33 ); Arrays.fill(CHARS, 8064, 8117, (byte) -19 ); CHARS[8117] = 33; 4101 Arrays.fill(CHARS, 8118, 8125, (byte) -19 ); CHARS[8125] = 33; 4103 CHARS[8126] = -19; 4104 Arrays.fill(CHARS, 8127, 8130, (byte) 33 ); Arrays.fill(CHARS, 8130, 8133, (byte) -19 ); CHARS[8133] = 33; 4107 Arrays.fill(CHARS, 8134, 8141, (byte) -19 ); Arrays.fill(CHARS, 8141, 8144, (byte) 33 ); Arrays.fill(CHARS, 8144, 8148, (byte) -19 ); Arrays.fill(CHARS, 8148, 8150, (byte) 33 ); Arrays.fill(CHARS, 8150, 8156, (byte) -19 ); Arrays.fill(CHARS, 8156, 8160, (byte) 33 ); Arrays.fill(CHARS, 8160, 8173, (byte) -19 ); Arrays.fill(CHARS, 8173, 8178, (byte) 33 ); Arrays.fill(CHARS, 8178, 8181, (byte) -19 ); CHARS[8181] = 33; 4117 Arrays.fill(CHARS, 8182, 8189, (byte) -19 ); Arrays.fill(CHARS, 8189, 8400, (byte) 33 ); Arrays.fill(CHARS, 8400, 8413, (byte) -87 ); Arrays.fill(CHARS, 8413, 8417, (byte) 33 ); CHARS[8417] = -87; 4122 Arrays.fill(CHARS, 8418, 8486, (byte) 33 ); CHARS[8486] = -19; 4124 Arrays.fill(CHARS, 8487, 8490, (byte) 33 ); Arrays.fill(CHARS, 8490, 8492, (byte) -19 ); Arrays.fill(CHARS, 8492, 8494, (byte) 33 ); CHARS[8494] = -19; 4128 Arrays.fill(CHARS, 8495, 8576, (byte) 33 ); Arrays.fill(CHARS, 8576, 8579, (byte) -19 ); Arrays.fill(CHARS, 8579, 12293, (byte) 33 ); CHARS[12293] = -87; 4132 CHARS[12294] = 33; 4133 CHARS[12295] = -19; 4134 Arrays.fill(CHARS, 12296, 12321, (byte) 33 ); Arrays.fill(CHARS, 12321, 12330, (byte) -19 ); Arrays.fill(CHARS, 12330, 12336, (byte) -87 ); CHARS[12336] = 33; 4138 Arrays.fill(CHARS, 12337, 12342, (byte) -87 ); Arrays.fill(CHARS, 12342, 12353, (byte) 33 ); Arrays.fill(CHARS, 12353, 12437, (byte) -19 ); Arrays.fill(CHARS, 12437, 12441, (byte) 33 ); Arrays.fill(CHARS, 12441, 12443, (byte) -87 ); Arrays.fill(CHARS, 12443, 12445, (byte) 33 ); Arrays.fill(CHARS, 12445, 12447, (byte) -87 ); Arrays.fill(CHARS, 12447, 12449, (byte) 33 ); Arrays.fill(CHARS, 12449, 12539, (byte) -19 ); CHARS[12539] = 33; 4148 Arrays.fill(CHARS, 12540, 12543, (byte) -87 ); Arrays.fill(CHARS, 12543, 12549, (byte) 33 ); Arrays.fill(CHARS, 12549, 12589, (byte) -19 ); Arrays.fill(CHARS, 12589, 19968, (byte) 33 ); Arrays.fill(CHARS, 19968, 40870, (byte) -19 ); Arrays.fill(CHARS, 40870, 44032, (byte) 33 ); Arrays.fill(CHARS, 44032, 55204, (byte) -19 ); Arrays.fill(CHARS, 55204, 55296, (byte) 33 ); Arrays.fill(CHARS, 57344, 65534, (byte) 33 ); 4158 } 4160 4164 4169 public static boolean isSupplemental(int c) { 4170 return (c >= 0x10000 && c <= 0x10FFFF); 4171 } 4172 4173 4180 public static int supplemental(char h, char l) { 4181 return (h - 0xD800) * 0x400 + (l - 0xDC00) + 0x10000; 4182 } 4183 4184 4189 public static char highSurrogate(int c) { 4190 return (char) (((c - 0x00010000) >> 10) + 0xD800); 4191 } 4192 4193 4198 public static char lowSurrogate(int c) { 4199 return (char) (((c - 0x00010000) & 0x3FF) + 0xDC00); 4200 } 4201 4202 4207 public static boolean isHighSurrogate(int c) { 4208 return (0xD800 <= c && c <= 0xDBFF); 4209 } 4210 4211 4216 public static boolean isLowSurrogate(int c) { 4217 return (0xDC00 <= c && c <= 0xDFFF); 4218 } 4219 4220 4221 4231 public static boolean isValid(int c) { 4232 return (c < 0x10000 && (CHARS[c] & MASK_VALID) != 0) || 4233 (0x10000 <= c && c <= 0x10FFFF); 4234 } 4236 4241 public static boolean isInvalid(int c) { 4242 return !isValid(c); 4243 } 4245 4250 public static boolean isContent(int c) { 4251 return (c < 0x10000 && (CHARS[c] & MASK_CONTENT) != 0) || 4252 (0x10000 <= c && c <= 0x10FFFF); 4253 } 4255 4261 public static boolean isMarkup(int c) { 4262 return c == '<' || c == '&' || c == '%'; 4263 } 4265 4271 public static boolean isSpace(int c) { 4272 return c <= 0x20 && (CHARS[c] & MASK_SPACE) != 0; 4273 } 4275 4282 public static boolean isNameStart(int c) { 4283 return c < 0x10000 && (CHARS[c] & MASK_NAME_START) != 0; 4284 } 4286 4293 public static boolean isName(int c) { 4294 return c < 0x10000 && (CHARS[c] & MASK_NAME) != 0; 4295 } 4297 4304 public static boolean isNCNameStart(int c) { 4305 return c < 0x10000 && (CHARS[c] & MASK_NCNAME_START) != 0; 4306 } 4308 4315 public static boolean isNCName(int c) { 4316 return c < 0x10000 && (CHARS[c] & MASK_NCNAME) != 0; 4317 } 4319 4326 public static boolean isPubid(int c) { 4327 return c < 0x10000 && (CHARS[c] & MASK_PUBID) != 0; 4328 } 4330 4333 4340 public static boolean isValidName(String name) { 4341 if (name.length() == 0) 4342 return false; 4343 char ch = name.charAt(0); 4344 if( isNameStart(ch) == false) 4345 return false; 4346 for (int i = 1; i < name.length(); i++ ) { 4347 ch = name.charAt(i); 4348 if( isName( ch ) == false ){ 4349 return false; 4350 } 4351 } 4352 return true; 4353 } 4355 4356 4360 4367 public static boolean isValidNCName(String ncName) { 4368 if (ncName.length() == 0) 4369 return false; 4370 char ch = ncName.charAt(0); 4371 if( isNCNameStart(ch) == false) 4372 return false; 4373 for (int i = 1; i < ncName.length(); i++ ) { 4374 ch = ncName.charAt(i); 4375 if( isNCName( ch ) == false ){ 4376 return false; 4377 } 4378 } 4379 return true; 4380 } 4382 4385 4392 public static boolean isValidNmtoken(String nmtoken) { 4393 if (nmtoken.length() == 0) 4394 return false; 4395 for (int i = 0; i < nmtoken.length(); i++ ) { 4396 char ch = nmtoken.charAt(i); 4397 if( ! isName( ch ) ){ 4398 return false; 4399 } 4400 } 4401 return true; 4402 } 4404 4405 4406 4407 4408 4410 4418 public static boolean isValidIANAEncoding(String ianaEncoding) { 4419 if (ianaEncoding != null) { 4420 int length = ianaEncoding.length(); 4421 if (length > 0) { 4422 char c = ianaEncoding.charAt(0); 4423 if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { 4424 for (int i = 1; i < length; i++) { 4425 c = ianaEncoding.charAt(i); 4426 if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && 4427 (c < '0' || c > '9') && c != '.' && c != '_' && 4428 c != '-') { 4429 return false; 4430 } 4431 } 4432 return true; 4433 } 4434 } 4435 } 4436 return false; 4437 } 4439 4447 public static boolean isValidJavaEncoding(String javaEncoding) { 4448 if (javaEncoding != null) { 4449 int length = javaEncoding.length(); 4450 if (length > 0) { 4451 for (int i = 1; i < length; i++) { 4452 char c = javaEncoding.charAt(i); 4453 if ((c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && 4454 (c < '0' || c > '9') && c != '.' && c != '_' && 4455 c != '-') { 4456 return false; 4457 } 4458 } 4459 return true; 4460 } 4461 } 4462 return false; 4463 } 4465 4466 } 4468 public static class TypeValidator { 4469 4470 public static final short LESS_THAN = -1; 4472 public static final short EQUAL = 0; 4473 public static final short GREATER_THAN = 1; 4474 public static final short INDETERMINATE = 2; 4475 4476 4477 public static final boolean isDigit(char ch) { 4479 return ch >= '0' && ch <= '9'; 4480 } 4481 4482 public static final int getDigit(char ch) { 4485 return isDigit(ch) ? ch - '0' : -1; 4486 } 4487 4488} 4490} 4491 | Popular Tags |