KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > emf > ecore > xml > type > internal > DataValue


1 /**
2  * <copyright>
3  *
4  * Copyright (c) 2003-2005 IBM Corporation and others.
5  * All rights reserved. This program and the accompanying materials
6  * are made available under the terms of the Eclipse Public License v1.0
7  * which accompanies this distribution, and is available at
8  * http://www.eclipse.org/legal/epl-v10.html
9  *
10  * Contributors:
11  * IBM - Initial API and implementation
12  *
13  * </copyright>
14  *
15  * $Id: DataValue.java,v 1.8 2005/06/12 13:29:22 emerks Exp $
16  *
17  * ---------------------------------------------------------------------
18  *
19  * The Apache Software License, Version 1.1
20  *
21  *
22  * Copyright (c) 1999-2004 The Apache Software Foundation. All rights
23  * reserved.
24  *
25  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  *
29  * 1. Redistributions of source code must retain the above copyright
30  * notice, this list of conditions and the following disclaimer.
31  *
32  * 2. Redistributions in binary form must reproduce the above copyright
33  * notice, this list of conditions and the following disclaimer in
34  * the documentation and/or other materials provided with the
35  * distribution.
36  *
37  * 3. The end-user documentation included with the redistribution,
38  * if any, must include the following acknowledgment:
39  * "This product includes software developed by the
40  * Apache Software Foundation (http://www.apache.org/)."
41  * Alternately, this acknowledgment may appear in the software itself,
42  * if and wherever such third-party acknowledgments normally appear.
43  *
44  * 4. The names "Xerces" and "Apache Software Foundation" must
45  * not be used to endorse or promote products derived from this
46  * software without prior written permission. For written
47  * permission, please contact apache@apache.org.
48  *
49  * 5. Products derived from this software may not be called "Apache",
50  * nor may "Apache" appear in their name, without prior written
51  * permission of the Apache Software Foundation.
52  *
53  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
54  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
55  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
56  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
57  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
58  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
59  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
60  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
61  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
62  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
63  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
64  * SUCH DAMAGE.
65  * ====================================================================
66  *
67  * This software consists of voluntary contributions made by many
68  * individuals on behalf of the Apache Software Foundation and was
69  * originally based on software copyright (c) 1999, International
70  * Business Machines, Inc., http://www.apache.org. For more
71  * information on the Apache Software Foundation, please see
72  * <http://www.apache.org/>.
73  */

74 package org.eclipse.emf.ecore.xml.type.internal;
75
76
77 import java.io.IOException JavaDoc;
78 import java.io.Serializable JavaDoc;
79 import java.util.Arrays JavaDoc;
80 import java.util.Hashtable JavaDoc;
81
82 /**
83  * NOTE: this class is for internal use only.
84  */

85 public final class DataValue
86 {
87
88 static class ValidationContext
89 {
90 }
91
92 static class XSSimpleType
93 {
94 }
95
96 /*
97  * This class provides encode/decode for RFC 2045 Base64 as
98  * defined by RFC 2045, N. Freed and N. Borenstein.
99  * RFC 2045: Multipurpose Internet Mail Extensions (MIME)
100  * Part One: Format of Internet Message Bodies. Reference
101  * 1996 Available at: http://www.ietf.org/rfc/rfc2045.txt
102  * This class is used by XML Schema binary format validation
103  *
104  * This implementation does not encode/decode streaming
105  * data. You need the data that you will encode/decode
106  * already on a byte arrray.
107  *
108  * @author Jeffrey Rodriguez
109  * @author Sandy Gao
110  */

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   /**
174    * Encodes hex octects into Base64
175    *
176    * @param binaryData Array containing binaryData
177    * @return Encoded Base64 array
178    */

179   public static String JavaDoc encode(byte[] binaryData) {
180
181       // This implementation was changed to not introduce multi line content.
182

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       // form integral number of 6-bit groups
236
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       //encodedData[encodedIndex] = 0xa;
264

265       return new String JavaDoc(encodedData);
266   }
267
268   /**
269    * Decodes Base64 data into octects
270    *
271    * @param encoded
272    * @return Array containind decoded data.
273    */

274   public static byte[] decode(String JavaDoc encoded) {
275
276       if (encoded == null)
277           return null;
278
279       char[] base64Data = encoded.toCharArray();
280       // remove white spaces
281
int len = removeWhiteSpace(base64Data);
282       
283       if (len%FOURBYTE != 0) {
284           return null;//should be divisible by four
285
}
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;//if found "no data" just return null
308

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;//if found "no data" just return null
322
}
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 ) )) {//Check if they are PAD characters
331
if (isPad( d3 ) && isPad( d4)) { //Two PAD e.g. 3c[Pad][Pad]
332
if ((b2 & 0xf) != 0)//last 4 bits should be zero
333
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)) { //One PAD e.g. 3cQ[Pad]
339
b3 = base64Alphabet[ d3 ];
340               if ((b3 & 0x3 ) != 0)//last 2 bits should be zero
341
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;//an error like "3c[Pad]r", "3cdX", "3cXd", "3cXX" where X is non data
349
}
350       } else { //No PAD e.g 3cQl
351
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   /**
363    * remove WhiteSpace from MIME containing encoded Base64 data.
364    *
365    * @param data the byte array of base64 data (with WS)
366    * @return the new length
367    */

368   protected static int removeWhiteSpace(char[] data) {
369       if (data == null)
370           return 0;
371
372       // count characters that's not whitespace
373
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 /*
385  * format validation
386  *
387  * This class encodes/decodes hexadecimal data
388  * @author Jeffrey Rodriguez
389  */

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   /**
418    * Encode a byte array to hex string
419    *
420    * @param binaryData array of byte to encode
421    * @return return encoded string
422    */

423   static public String JavaDoc 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 JavaDoc(encodedData);
438   }
439
440   /**
441    * Decode hex string to a byte array
442    *
443    * @param encoded encoded string
444    * @return return array of byte to encode
445    */

446   static public byte[] decode(String JavaDoc 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 /*
471  * EncodingMap is a convenience class which handles conversions between
472  * IANA encoding names and Java encoding names, and vice versa. The
473  * encoding names used in XML instance documents <strong>must</strong>
474  * be the IANA encoding names specified or one of the aliases for those names
475  * which IANA defines.
476  * <p>
477  * <TABLE BORDER="0" WIDTH="100%">
478  * <TR>
479  * <TD WIDTH="33%">
480  * <P ALIGN="CENTER"><B>Common Name</B>
481  * </TD>
482  * <TD WIDTH="15%">
483  * <P ALIGN="CENTER"><B>Use this name in XML files</B>
484  * </TD>
485  * <TD WIDTH="12%">
486  * <P ALIGN="CENTER"><B>Name Type</B>
487  * </TD>
488  * <TD WIDTH="31%">
489  * <P ALIGN="CENTER"><B>Xerces converts to this Java Encoder Name</B>
490  * </TD>
491  * </TR>
492  * <TR>
493  * <TD WIDTH="33%">8 bit Unicode</TD>
494  * <TD WIDTH="15%">
495  * <P ALIGN="CENTER">UTF-8
496  * </TD>
497  * <TD WIDTH="12%">
498  * <P ALIGN="CENTER">IANA
499  * </TD>
500  * <TD WIDTH="31%">
501  * <P ALIGN="CENTER">UTF8
502  * </TD>
503  * </TR>
504  * <TR>
505  * <TD WIDTH="33%">ISO Latin 1</TD>
506  * <TD WIDTH="15%">
507  * <P ALIGN="CENTER">ISO-8859-1
508  * </TD>
509  * <TD WIDTH="12%">
510  * <P ALIGN="CENTER">MIME
511  * </TD>
512  * <TD WIDTH="31%">
513  * <P ALIGN="CENTER">ISO-8859-1
514  * </TD>
515  * </TR>
516  * <TR>
517  * <TD WIDTH="33%">ISO Latin 2</TD>
518  * <TD WIDTH="15%">
519  * <P ALIGN="CENTER">ISO-8859-2
520  * </TD>
521  * <TD WIDTH="12%">
522  * <P ALIGN="CENTER">MIME
523  * </TD>
524  * <TD WIDTH="31%">
525  * <P ALIGN="CENTER">ISO-8859-2
526  * </TD>
527  * </TR>
528  * <TR>
529  * <TD WIDTH="33%">ISO Latin 3</TD>
530  * <TD WIDTH="15%">
531  * <P ALIGN="CENTER">ISO-8859-3
532  * </TD>
533  * <TD WIDTH="12%">
534  * <P ALIGN="CENTER">MIME
535  * </TD>
536  * <TD WIDTH="31%">
537  * <P ALIGN="CENTER">ISO-8859-3
538  * </TD>
539  * </TR>
540  * <TR>
541  * <TD WIDTH="33%">ISO Latin 4</TD>
542  * <TD WIDTH="15%">
543  * <P ALIGN="CENTER">ISO-8859-4
544  * </TD>
545  * <TD WIDTH="12%">
546  * <P ALIGN="CENTER">MIME
547  * </TD>
548  * <TD WIDTH="31%">
549  * <P ALIGN="CENTER">ISO-8859-4
550  * </TD>
551  * </TR>
552  * <TR>
553  * <TD WIDTH="33%">ISO Latin Cyrillic</TD>
554  * <TD WIDTH="15%">
555  * <P ALIGN="CENTER">ISO-8859-5
556  * </TD>
557  * <TD WIDTH="12%">
558  * <P ALIGN="CENTER">MIME
559  * </TD>
560  * <TD WIDTH="31%">
561  * <P ALIGN="CENTER">ISO-8859-5
562  * </TD>
563  * </TR>
564  * <TR>
565  * <TD WIDTH="33%">ISO Latin Arabic</TD>
566  * <TD WIDTH="15%">
567  * <P ALIGN="CENTER">ISO-8859-6
568  * </TD>
569  * <TD WIDTH="12%">
570  * <P ALIGN="CENTER">MIME
571  * </TD>
572  * <TD WIDTH="31%">
573  * <P ALIGN="CENTER">ISO-8859-6
574  * </TD>
575  * </TR>
576  * <TR>
577  * <TD WIDTH="33%">ISO Latin Greek</TD>
578  * <TD WIDTH="15%">
579  * <P ALIGN="CENTER">ISO-8859-7
580  * </TD>
581  * <TD WIDTH="12%">
582  * <P ALIGN="CENTER">MIME
583  * </TD>
584  * <TD WIDTH="31%">
585  * <P ALIGN="CENTER">ISO-8859-7
586  * </TD>
587  * </TR>
588  * <TR>
589  * <TD WIDTH="33%">ISO Latin Hebrew</TD>
590  * <TD WIDTH="15%">
591  * <P ALIGN="CENTER">ISO-8859-8
592  * </TD>
593  * <TD WIDTH="12%">
594  * <P ALIGN="CENTER">MIME
595  * </TD>
596  * <TD WIDTH="31%">
597  * <P ALIGN="CENTER">ISO-8859-8
598  * </TD>
599  * </TR>
600  * <TR>
601  * <TD WIDTH="33%">ISO Latin 5</TD>
602  * <TD WIDTH="15%">
603  * <P ALIGN="CENTER">ISO-8859-9
604  * </TD>
605  * <TD WIDTH="12%">
606  * <P ALIGN="CENTER">MIME
607  * </TD>
608  * <TD WIDTH="31%">
609  * <P ALIGN="CENTER">ISO-8859-9
610  * </TD>
611  * </TR>
612  * <TR>
613  * <TD WIDTH="33%">EBCDIC: US</TD>
614  * <TD WIDTH="15%">
615  * <P ALIGN="CENTER">ebcdic-cp-us
616  * </TD>
617  * <TD WIDTH="12%">
618  * <P ALIGN="CENTER">IANA
619  * </TD>
620  * <TD WIDTH="31%">
621  * <P ALIGN="CENTER">cp037
622  * </TD>
623  * </TR>
624  * <TR>
625  * <TD WIDTH="33%">EBCDIC: Canada</TD>
626  * <TD WIDTH="15%">
627  * <P ALIGN="CENTER">ebcdic-cp-ca
628  * </TD>
629  * <TD WIDTH="12%">
630  * <P ALIGN="CENTER">IANA
631  * </TD>
632  * <TD WIDTH="31%">
633  * <P ALIGN="CENTER">cp037
634  * </TD>
635  * </TR>
636  * <TR>
637  * <TD WIDTH="33%">EBCDIC: Netherlands</TD>
638  * <TD WIDTH="15%">
639  * <P ALIGN="CENTER">ebcdic-cp-nl
640  * </TD>
641  * <TD WIDTH="12%">
642  * <P ALIGN="CENTER">IANA
643  * </TD>
644  * <TD WIDTH="31%">
645  * <P ALIGN="CENTER">cp037
646  * </TD>
647  * </TR>
648  * <TR>
649  * <TD WIDTH="33%">EBCDIC: Denmark</TD>
650  * <TD WIDTH="15%">
651  * <P ALIGN="CENTER">ebcdic-cp-dk
652  * </TD>
653  * <TD WIDTH="12%">
654  * <P ALIGN="CENTER">IANA
655  * </TD>
656  * <TD WIDTH="31%">
657  * <P ALIGN="CENTER">cp277
658  * </TD>
659  * </TR>
660  * <TR>
661  * <TD WIDTH="33%">EBCDIC: Norway</TD>
662  * <TD WIDTH="15%">
663  * <P ALIGN="CENTER">ebcdic-cp-no
664  * </TD>
665  * <TD WIDTH="12%">
666  * <P ALIGN="CENTER">IANA
667  * </TD>
668  * <TD WIDTH="31%">
669  * <P ALIGN="CENTER">cp277
670  * </TD>
671  * </TR>
672  * <TR>
673  * <TD WIDTH="33%">EBCDIC: Finland</TD>
674  * <TD WIDTH="15%">
675  * <P ALIGN="CENTER">ebcdic-cp-fi
676  * </TD>
677  * <TD WIDTH="12%">
678  * <P ALIGN="CENTER">IANA
679  * </TD>
680  * <TD WIDTH="31%">
681  * <P ALIGN="CENTER">cp278
682  * </TD>
683  * </TR>
684  * <TR>
685  * <TD WIDTH="33%">EBCDIC: Sweden</TD>
686  * <TD WIDTH="15%">
687  * <P ALIGN="CENTER">ebcdic-cp-se
688  * </TD>
689  * <TD WIDTH="12%">
690  * <P ALIGN="CENTER">IANA
691  * </TD>
692  * <TD WIDTH="31%">
693  * <P ALIGN="CENTER">cp278
694  * </TD>
695  * </TR>
696  * <TR>
697  * <TD WIDTH="33%">EBCDIC: Italy</TD>
698  * <TD WIDTH="15%">
699  * <P ALIGN="CENTER">ebcdic-cp-it
700  * </TD>
701  * <TD WIDTH="12%">
702  * <P ALIGN="CENTER">IANA
703  * </TD>
704  * <TD WIDTH="31%">
705  * <P ALIGN="CENTER">cp280
706  * </TD>
707  * </TR>
708  * <TR>
709  * <TD WIDTH="33%">EBCDIC: Spain, Latin America</TD>
710  * <TD WIDTH="15%">
711  * <P ALIGN="CENTER">ebcdic-cp-es
712  * </TD>
713  * <TD WIDTH="12%">
714  * <P ALIGN="CENTER">IANA
715  * </TD>
716  * <TD WIDTH="31%">
717  * <P ALIGN="CENTER">cp284
718  * </TD>
719  * </TR>
720  * <TR>
721  * <TD WIDTH="33%">EBCDIC: Great Britain</TD>
722  * <TD WIDTH="15%">
723  * <P ALIGN="CENTER">ebcdic-cp-gb
724  * </TD>
725  * <TD WIDTH="12%">
726  * <P ALIGN="CENTER">IANA
727  * </TD>
728  * <TD WIDTH="31%">
729  * <P ALIGN="CENTER">cp285
730  * </TD>
731  * </TR>
732  * <TR>
733  * <TD WIDTH="33%">EBCDIC: France</TD>
734  * <TD WIDTH="15%">
735  * <P ALIGN="CENTER">ebcdic-cp-fr
736  * </TD>
737  * <TD WIDTH="12%">
738  * <P ALIGN="CENTER">IANA
739  * </TD>
740  * <TD WIDTH="31%">
741  * <P ALIGN="CENTER">cp297
742  * </TD>
743  * </TR>
744  * <TR>
745  * <TD WIDTH="33%">EBCDIC: Arabic</TD>
746  * <TD WIDTH="15%">
747  * <P ALIGN="CENTER">ebcdic-cp-ar1
748  * </TD>
749  * <TD WIDTH="12%">
750  * <P ALIGN="CENTER">IANA
751  * </TD>
752  * <TD WIDTH="31%">
753  * <P ALIGN="CENTER">cp420
754  * </TD>
755  * </TR>
756  * <TR>
757  * <TD WIDTH="33%">EBCDIC: Hebrew</TD>
758  * <TD WIDTH="15%">
759  * <P ALIGN="CENTER">ebcdic-cp-he
760  * </TD>
761  * <TD WIDTH="12%">
762  * <P ALIGN="CENTER">IANA
763  * </TD>
764  * <TD WIDTH="31%">
765  * <P ALIGN="CENTER">cp424
766  * </TD>
767  * </TR>
768  * <TR>
769  * <TD WIDTH="33%">EBCDIC: Switzerland</TD>
770  * <TD WIDTH="15%">
771  * <P ALIGN="CENTER">ebcdic-cp-ch
772  * </TD>
773  * <TD WIDTH="12%">
774  * <P ALIGN="CENTER">IANA
775  * </TD>
776  * <TD WIDTH="31%">
777  * <P ALIGN="CENTER">cp500
778  * </TD>
779  * </TR>
780  * <TR>
781  * <TD WIDTH="33%">EBCDIC: Roece</TD>
782  * <TD WIDTH="15%">
783  * <P ALIGN="CENTER">ebcdic-cp-roece
784  * </TD>
785  * <TD WIDTH="12%">
786  * <P ALIGN="CENTER">IANA
787  * </TD>
788  * <TD WIDTH="31%">
789  * <P ALIGN="CENTER">cp870
790  * </TD>
791  * </TR>
792  * <TR>
793  * <TD WIDTH="33%">EBCDIC: Yugoslavia</TD>
794  * <TD WIDTH="15%">
795  * <P ALIGN="CENTER">ebcdic-cp-yu
796  * </TD>
797  * <TD WIDTH="12%">
798  * <P ALIGN="CENTER">IANA
799  * </TD>
800  * <TD WIDTH="31%">
801  * <P ALIGN="CENTER">cp870
802  * </TD>
803  * </TR>
804  * <TR>
805  * <TD WIDTH="33%">EBCDIC: Iceland</TD>
806  * <TD WIDTH="15%">
807  * <P ALIGN="CENTER">ebcdic-cp-is
808  * </TD>
809  * <TD WIDTH="12%">
810  * <P ALIGN="CENTER">IANA
811  * </TD>
812  * <TD WIDTH="31%">
813  * <P ALIGN="CENTER">cp871
814  * </TD>
815  * </TR>
816  * <TR>
817  * <TD WIDTH="33%">EBCDIC: Urdu</TD>
818  * <TD WIDTH="15%">
819  * <P ALIGN="CENTER">ebcdic-cp-ar2
820  * </TD>
821  * <TD WIDTH="12%">
822  * <P ALIGN="CENTER">IANA
823  * </TD>
824  * <TD WIDTH="31%">
825  * <P ALIGN="CENTER">cp918
826  * </TD>
827  * </TR>
828  * <TR>
829  * <TD WIDTH="33%">Chinese for PRC, mixed 1/2 byte</TD>
830  * <TD WIDTH="15%">
831  * <P ALIGN="CENTER">gb2312
832  * </TD>
833  * <TD WIDTH="12%">
834  * <P ALIGN="CENTER">MIME
835  * </TD>
836  * <TD WIDTH="31%">
837  * <P ALIGN="CENTER">GB2312
838  * </TD>
839  * </TR>
840  * <TR>
841  * <TD WIDTH="33%">Extended Unix Code, packed for Japanese</TD>
842  * <TD WIDTH="15%">
843  * <P ALIGN="CENTER">euc-jp
844  * </TD>
845  * <TD WIDTH="12%">
846  * <P ALIGN="CENTER">MIME
847  * </TD>
848  * <TD WIDTH="31%">
849  * <P ALIGN="CENTER">eucjis
850  * </TD>
851  * </TR>
852  * <TR>
853  * <TD WIDTH="33%">Japanese: iso-2022-jp</TD>
854  * <TD WIDTH="15%">
855  * <P ALIGN="CENTER">iso-2020-jp
856  * </TD>
857  * <TD WIDTH="12%">
858  * <P ALIGN="CENTER">MIME
859  * </TD>
860  * <TD WIDTH="31%">
861  * <P ALIGN="CENTER">JIS
862  * </TD>
863  * </TR>
864  * <TR>
865  * <TD WIDTH="33%">Japanese: Shift JIS</TD>
866  * <TD WIDTH="15%">
867  * <P ALIGN="CENTER">Shift_JIS
868  * </TD>
869  * <TD WIDTH="12%">
870  * <P ALIGN="CENTER">MIME
871  * </TD>
872  * <TD WIDTH="31%">
873  * <P ALIGN="CENTER">SJIS
874  * </TD>
875  * </TR>
876  * <TR>
877  * <TD WIDTH="33%">Chinese: Big5</TD>
878  * <TD WIDTH="15%">
879  * <P ALIGN="CENTER">Big5
880  * </TD>
881  * <TD WIDTH="12%">
882  * <P ALIGN="CENTER">MIME
883  * </TD>
884  * <TD WIDTH="31%">
885  * <P ALIGN="CENTER">Big5
886  * </TD>
887  * </TR>
888  * <TR>
889  * <TD WIDTH="33%">Extended Unix Code, packed for Korean</TD>
890  * <TD WIDTH="15%">
891  * <P ALIGN="CENTER">euc-kr
892  * </TD>
893  * <TD WIDTH="12%">
894  * <P ALIGN="CENTER">MIME
895  * </TD>
896  * <TD WIDTH="31%">
897  * <P ALIGN="CENTER">iso2022kr
898  * </TD>
899  * </TR>
900  * <TR>
901  * <TD WIDTH="33%">Cyrillic</TD>
902  * <TD WIDTH="15%">
903  * <P ALIGN="CENTER">koi8-r
904  * </TD>
905  * <TD WIDTH="12%">
906  * <P ALIGN="CENTER">MIME
907  * </TD>
908  * <TD WIDTH="31%">
909  * <P ALIGN="CENTER">koi8-r
910  * </TD>
911  * </TR>
912  * </TABLE>
913  *
914  * @author TAMURA Kent, IBM
915  * @author Andy Clark, IBM
916  */

917 public static class EncodingMap {
918
919     //
920
// Data
921
//
922

923     /** fIANA2JavaMap */
924     protected final static Hashtable JavaDoc fIANA2JavaMap = new Hashtable JavaDoc();
925
926     /** fJava2IANAMap */
927     protected final static Hashtable JavaDoc fJava2IANAMap = new Hashtable JavaDoc();
928
929     //
930
// Static initialization
931
//
932

933     static {
934
935         // add IANA to Java encoding mappings.
936
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        // is this an error???
1071
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        // Add support for Cp1252 and its friends
1134
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"); // added since this encoding only differs w.r.t. presentation
1200
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        // support for 1047, as proposed to be added to the
1230
// IANA registry in
1231
// http://lists.w3.org/Archives/Public/ietf-charset/2002JulSep/0049.html
1232
fIANA2JavaMap.put("IBM-1047", "Cp1047");
1233        fIANA2JavaMap.put("IBM1047", "Cp1047");
1234        fIANA2JavaMap.put("CP1047", "Cp1047");
1235
1236        // Adding new aliases as proposed in
1237
// http://lists.w3.org/Archives/Public/ietf-charset/2002JulSep/0058.html
1238
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        // REVISIT:
1285
// j:CNS11643 -> EUC-TW?
1286
// ISO-2022-CN? ISO-2022-CN-EXT?
1287

1288        // add Java to IANA encoding mappings
1289
//fJava2IANAMap.put("8859_1", "US-ASCII"); // ?
1290
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        // proposed addition (see above for details):
1362
fJava2IANAMap.put("CP1047", "IBM1047");
1363
1364    } // <clinit>()
1365

1366    //
1367
// Constructors
1368
//
1369

1370    /** Default constructor. */
1371    public EncodingMap() {}
1372
1373    //
1374
// Public static methods
1375
//
1376

1377    /**
1378     * Adds an IANA to Java encoding name mapping.
1379     *
1380     * @param ianaEncoding The IANA encoding name.
1381     * @param javaEncoding The Java encoding name.
1382     */

1383    public static void putIANA2JavaMapping(String JavaDoc ianaEncoding,
1384                                           String JavaDoc javaEncoding) {
1385        fIANA2JavaMap.put(ianaEncoding, javaEncoding);
1386    } // putIANA2JavaMapping(String,String)
1387

1388    /**
1389     * Returns the Java encoding name for the specified IANA encoding name.
1390     *
1391     * @param ianaEncoding The IANA encoding name.
1392     */

1393    public static String JavaDoc getIANA2JavaMapping(String JavaDoc ianaEncoding) {
1394        return (String JavaDoc)fIANA2JavaMap.get(ianaEncoding);
1395    } // getIANA2JavaMapping(String):String
1396

1397    /**
1398     * Removes an IANA to Java encoding name mapping.
1399     *
1400     * @param ianaEncoding The IANA encoding name.
1401     */

1402    public static String JavaDoc removeIANA2JavaMapping(String JavaDoc ianaEncoding) {
1403        return (String JavaDoc)fIANA2JavaMap.remove(ianaEncoding);
1404    } // removeIANA2JavaMapping(String):String
1405

1406    /**
1407     * Adds a Java to IANA encoding name mapping.
1408     *
1409     * @param javaEncoding The Java encoding name.
1410     * @param ianaEncoding The IANA encoding name.
1411     */

1412    public static void putJava2IANAMapping(String JavaDoc javaEncoding,
1413                                           String JavaDoc ianaEncoding) {
1414        fJava2IANAMap.put(javaEncoding, ianaEncoding);
1415    } // putJava2IANAMapping(String,String)
1416

1417    /**
1418     * Returns the IANA encoding name for the specified Java encoding name.
1419     *
1420     * @param javaEncoding The Java encoding name.
1421     */

1422    public static String JavaDoc getJava2IANAMapping(String JavaDoc javaEncoding) {
1423        return (String JavaDoc)fJava2IANAMap.get(javaEncoding);
1424    } // getJava2IANAMapping(String):String
1425

1426    /**
1427     * Removes a Java to IANA encoding name mapping.
1428     *
1429     * @param javaEncoding The Java encoding name.
1430     */

1431    public static String JavaDoc removeJava2IANAMapping(String JavaDoc javaEncoding) {
1432        return (String JavaDoc)fJava2IANAMap.remove(javaEncoding);
1433    } // removeJava2IANAMapping
1434

1435} // class EncodingMap
1436

1437
1438/**********************************************************************
1439* A class to represent a Uniform Resource Identifier (URI). This class
1440* is designed to handle the parsing of URIs and provide access to
1441* the various components (scheme, host, port, userinfo, path, query
1442* string and fragment) that may constitute a URI.
1443* <p>
1444* Parsing of a URI specification is done according to the URI
1445* syntax described in
1446* <a HREF="http://www.ietf.org/rfc/rfc2396.txt?number=2396">RFC 2396</a>,
1447* and amended by
1448* <a HREF="http://www.ietf.org/rfc/rfc2732.txt?number=2732">RFC 2732</a>.
1449* <p>
1450* Every absolute URI consists of a scheme, followed by a colon (':'),
1451* followed by a scheme-specific part. For URIs that follow the
1452* "generic URI" syntax, the scheme-specific part begins with two
1453* slashes ("//") and may be followed by an authority segment (comprised
1454* of user information, host, and port), path segment, query segment
1455* and fragment. Note that RFC 2396 no longer specifies the use of the
1456* parameters segment and excludes the "user:password" syntax as part of
1457* the authority segment. If "user:password" appears in a URI, the entire
1458* user/password string is stored as userinfo.
1459* <p>
1460* For URIs that do not follow the "generic URI" syntax (e.g. mailto),
1461* the entire scheme-specific part is treated as the "path" portion
1462* of the URI.
1463* <p>
1464* Note that, unlike the java.net.URL class, this class does not provide
1465* any built-in network access functionality nor does it provide any
1466* scheme-specific functionality (for example, it does not know a
1467* default port for a specific scheme). Rather, it only knows the
1468* grammar and basic set of operations that can be applied to a URI.
1469*
1470* @version $Id: DataValue.java,v 1.8 2005/06/12 13:29:22 emerks Exp $
1471*
1472**********************************************************************/

1473 public static final class URI implements Serializable JavaDoc {
1474   
1475
1476  /*******************************************************************
1477  * MalformedURIExceptions are thrown in the process of building a URI
1478  * or setting fields on a URI when an operation would result in an
1479  * invalid URI specification.
1480  *
1481  ********************************************************************/

1482  public static class MalformedURIException extends IOException JavaDoc {
1483
1484   /******************************************************************
1485    * Constructs a <code>MalformedURIException</code> with no specified
1486    * detail message.
1487    ******************************************************************/

1488    public MalformedURIException() {
1489      super();
1490    }
1491
1492    /*****************************************************************
1493    * Constructs a <code>MalformedURIException</code> with the
1494    * specified detail message.
1495    *
1496    * @param p_msg the detail message.
1497    ******************************************************************/

1498    public MalformedURIException(String JavaDoc p_msg) {
1499      super(p_msg);
1500    }
1501  }
1502
1503  private static final byte [] fgLookupTable = new byte[128];
1504  
1505  /**
1506   * Character Classes
1507   */

1508  
1509  /** reserved characters ;/?:@&=+$,[] */
1510  //RFC 2732 added '[' and ']' as reserved characters
1511
private static final int RESERVED_CHARACTERS = 0x01;
1512  
1513  /** URI punctuation mark characters: -_.!~*'() - these, combined with
1514      alphanumerics, constitute the "unreserved" characters */

1515  private static final int MARK_CHARACTERS = 0x02;
1516  
1517  /** scheme can be composed of alphanumerics and these characters: +-. */
1518  private static final int SCHEME_CHARACTERS = 0x04;
1519  
1520  /** userinfo can be composed of unreserved, escaped and these
1521      characters: ;:&=+$, */

1522  private static final int USERINFO_CHARACTERS = 0x08;
1523  
1524  /** ASCII letter characters */
1525  private static final int ASCII_ALPHA_CHARACTERS = 0x10;
1526  
1527  /** ASCII digit characters */
1528  private static final int ASCII_DIGIT_CHARACTERS = 0x20;
1529  
1530  /** ASCII hex characters */
1531  private static final int ASCII_HEX_CHARACTERS = 0x40;
1532  
1533  /** Path characters */
1534  private static final int PATH_CHARACTERS = 0x80;
1535
1536  /** Mask for alpha-numeric characters */
1537  private static final int MASK_ALPHA_NUMERIC = ASCII_ALPHA_CHARACTERS | ASCII_DIGIT_CHARACTERS;
1538  
1539  /** Mask for unreserved characters */
1540  private static final int MASK_UNRESERVED_MASK = MASK_ALPHA_NUMERIC | MARK_CHARACTERS;
1541  
1542  /** Mask for URI allowable characters except for % */
1543  private static final int MASK_URI_CHARACTER = MASK_UNRESERVED_MASK | RESERVED_CHARACTERS;
1544  
1545  /** Mask for scheme characters */
1546  private static final int MASK_SCHEME_CHARACTER = MASK_ALPHA_NUMERIC | SCHEME_CHARACTERS;
1547  
1548  /** Mask for userinfo characters */
1549  private static final int MASK_USERINFO_CHARACTER = MASK_UNRESERVED_MASK | USERINFO_CHARACTERS;
1550  
1551  /** Mask for path characters */
1552  private static final int MASK_PATH_CHARACTER = MASK_UNRESERVED_MASK | PATH_CHARACTERS;
1553
1554  static {
1555      // Add ASCII Digits and ASCII Hex Numbers
1556
for (int i = '0'; i <= '9'; ++i) {
1557          fgLookupTable[i] |= ASCII_DIGIT_CHARACTERS | ASCII_HEX_CHARACTERS;
1558      }
1559
1560      // Add ASCII Letters and ASCII Hex Numbers
1561
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      // Add ASCII Letters
1567
for (int i = 'G'; i <= 'Z'; ++i) {
1568          fgLookupTable[i] |= ASCII_ALPHA_CHARACTERS;
1569          fgLookupTable[i+0x00000020] |= ASCII_ALPHA_CHARACTERS;
1570      }
1571
1572      // Add Reserved Characters
1573
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      // Add Mark Characters
1587
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      // Add Scheme Characters
1598
fgLookupTable['+'] |= SCHEME_CHARACTERS;
1599      fgLookupTable['-'] |= SCHEME_CHARACTERS;
1600      fgLookupTable['.'] |= SCHEME_CHARACTERS;
1601
1602      // Add Userinfo Characters
1603
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      // Add Path Characters
1612
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  /** Stores the scheme (usually the protocol) for this URI. */
1632  private String JavaDoc m_scheme = null;
1633
1634  /** If specified, stores the userinfo for this URI; otherwise null */
1635  private String JavaDoc m_userinfo = null;
1636
1637  /** If specified, stores the host for this URI; otherwise null */
1638  private String JavaDoc m_host = null;
1639
1640  /** If specified, stores the port for this URI; otherwise -1 */
1641  private int m_port = -1;
1642  
1643  /** If specified, stores the registry based authority for this URI; otherwise -1 */
1644  private String JavaDoc m_regAuthority = null;
1645
1646  /** If specified, stores the path for this URI; otherwise null */
1647  private String JavaDoc m_path = null;
1648
1649  /** If specified, stores the query string for this URI; otherwise
1650      null. */

1651  private String JavaDoc m_queryString = null;
1652
1653  /** If specified, stores the fragment for this URI; otherwise null */
1654  private String JavaDoc m_fragment = null;
1655
1656  /**
1657  * Construct a new and uninitialized URI.
1658  */

1659  public URI() {
1660  }
1661
1662 /**
1663  * Construct a new URI from another URI. All fields for this URI are
1664  * set equal to the fields of the URI passed in.
1665  *
1666  * @param p_other the URI to copy (cannot be null)
1667  */

1668  public URI(URI p_other) {
1669    initialize(p_other);
1670  }
1671
1672 /**
1673  * Construct a new URI from a URI specification string. If the
1674  * specification follows the "generic URI" syntax, (two slashes
1675  * following the first colon), the specification will be parsed
1676  * accordingly - setting the scheme, userinfo, host,port, path, query
1677  * string and fragment fields as necessary. If the specification does
1678  * not follow the "generic URI" syntax, the specification is parsed
1679  * into a scheme and scheme-specific part (stored as the path) only.
1680  *
1681  * @param p_uriSpec the URI specification string (cannot be null or
1682  * empty)
1683  *
1684  * @exception MalformedURIException if p_uriSpec violates any syntax
1685  * rules
1686  */

1687  public URI(String JavaDoc p_uriSpec) throws MalformedURIException {
1688    this((URI)null, p_uriSpec);
1689  }
1690
1691 /**
1692  * Construct a new URI from a base URI and a URI specification string.
1693  * The URI specification string may be a relative URI.
1694  *
1695  * @param p_base the base URI (cannot be null if p_uriSpec is null or
1696  * empty)
1697  * @param p_uriSpec the URI specification string (cannot be null or
1698  * empty if p_base is null)
1699  *
1700  * @exception MalformedURIException if p_uriSpec violates any syntax
1701  * rules
1702  */

1703  public URI(URI p_base, String JavaDoc p_uriSpec) throws MalformedURIException {
1704    initialize(p_base, p_uriSpec);
1705  }
1706
1707 /**
1708  * Construct a new URI that does not follow the generic URI syntax.
1709  * Only the scheme and scheme-specific part (stored as the path) are
1710  * initialized.
1711  *
1712  * @param p_scheme the URI scheme (cannot be null or empty)
1713  * @param p_schemeSpecificPart the scheme-specific part (cannot be
1714  * null or empty)
1715  *
1716  * @exception MalformedURIException if p_scheme violates any
1717  * syntax rules
1718  */

1719  public URI(String JavaDoc p_scheme, String JavaDoc 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 /**
1735  * Construct a new URI that follows the generic URI syntax from its
1736  * component parts. Each component is validated for syntax and some
1737  * basic semantic checks are performed as well. See the individual
1738  * setter methods for specifics.
1739  *
1740  * @param p_scheme the URI scheme (cannot be null or empty)
1741  * @param p_host the hostname, IPv4 address or IPv6 reference for the URI
1742  * @param p_path the URI path - if the path contains '?' or '#',
1743  * then the query string and/or fragment will be
1744  * set from the path; however, if the query and
1745  * fragment are specified both in the path and as
1746  * separate parameters, an exception is thrown
1747  * @param p_queryString the URI query string (cannot be specified
1748  * if path is null)
1749  * @param p_fragment the URI fragment (cannot be specified if path
1750  * is null)
1751  *
1752  * @exception MalformedURIException if any of the parameters violates
1753  * syntax rules or semantic rules
1754  */

1755  public URI(String JavaDoc p_scheme, String JavaDoc p_host, String JavaDoc p_path,
1756             String JavaDoc p_queryString, String JavaDoc p_fragment)
1757         throws MalformedURIException {
1758    this(p_scheme, null, p_host, -1, p_path, p_queryString, p_fragment);
1759  }
1760
1761 /**
1762  * Construct a new URI that follows the generic URI syntax from its
1763  * component parts. Each component is validated for syntax and some
1764  * basic semantic checks are performed as well. See the individual
1765  * setter methods for specifics.
1766  *
1767  * @param p_scheme the URI scheme (cannot be null or empty)
1768  * @param p_userinfo the URI userinfo (cannot be specified if host
1769  * is null)
1770  * @param p_host the hostname, IPv4 address or IPv6 reference for the URI
1771  * @param p_port the URI port (may be -1 for "unspecified"; cannot
1772  * be specified if host is null)
1773  * @param p_path the URI path - if the path contains '?' or '#',
1774  * then the query string and/or fragment will be
1775  * set from the path; however, if the query and
1776  * fragment are specified both in the path and as
1777  * separate parameters, an exception is thrown
1778  * @param p_queryString the URI query string (cannot be specified
1779  * if path is null)
1780  * @param p_fragment the URI fragment (cannot be specified if path
1781  * is null)
1782  *
1783  * @exception MalformedURIException if any of the parameters violates
1784  * syntax rules or semantic rules
1785  */

1786  public URI(String JavaDoc p_scheme, String JavaDoc p_userinfo,
1787             String JavaDoc p_host, int p_port, String JavaDoc p_path,
1788             String JavaDoc p_queryString, String JavaDoc 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 /**
1827  * Initialize all fields of this URI from another URI.
1828  *
1829  * @param p_other the URI to copy (cannot be null)
1830  */

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 /**
1843  * Initializes this URI from a base URI and a URI specification string.
1844  * See RFC 2396 Section 4 and Appendix B for specifications on parsing
1845  * the URI and Section 5 for specifications on resolving relative URIs
1846  * and relative paths.
1847  *
1848  * @param p_base the base URI (may be null if p_uriSpec is an absolute
1849  * URI)
1850  * @param p_uriSpec the URI spec string which may be an absolute or
1851  * relative URI (can only be null/empty if p_base
1852  * is not null)
1853  *
1854  * @exception MalformedURIException if p_base is null and p_uriSpec
1855  * is not an absolute URI or if
1856  * p_uriSpec violates syntax rules
1857  */

1858  private void initialize(URI p_base, String JavaDoc p_uriSpec)
1859                         throws MalformedURIException {
1860    
1861    String JavaDoc 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    // just make a copy of the base if spec is empty
1870
if (uriSpecLen == 0) {
1871      initialize(p_base);
1872      return;
1873    }
1874
1875    int index = 0;
1876
1877    // Check for scheme, which must be before '/', '?' or '#'. Also handle
1878
// names with DOS drive letters ('D:'), so 1-character schemes are not
1879
// allowed.
1880
int colonIdx = uriSpec.indexOf(':');
1881    if (colonIdx != -1) {
1882        final int searchFrom = colonIdx - 1;
1883        // search backwards starting from character before ':'.
1884
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            // A standalone base is a valid URI according to spec
1891
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            // Neither 'scheme:' or 'scheme:#fragment' are valid URIs.
1900
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    // Two slashes means we may have authority, but definitely means we're either
1910
// matching net_path or abs_path. These two productions are ambiguous in that
1911
// every net_path (except those containing an IPv6Reference) is an abs_path.
1912
// RFC 2396 resolves this ambiguity by applying a greedy left most matching rule.
1913
// Try matching net_path first, and if that fails we don't have authority so
1914
// then attempt to match abs_path.
1915
//
1916
// net_path = "//" authority [ abs_path ]
1917
// abs_path = "/" path_segments
1918
if (((index+1) < uriSpecLen) &&
1919        (uriSpec.charAt(index) == '/' && uriSpec.charAt(index+1) == '/')) {
1920      index += 2;
1921      int startPos = index;
1922
1923      // Authority will be everything up to path, query or fragment
1924
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      // Attempt to parse authority. If the section is an empty string
1934
// this is a valid server based authority, so set the host to this
1935
// value.
1936
if (index > startPos) {
1937        // If we didn't find authority we need to back up. Attempt to
1938
// match against abs_path next.
1939
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    // Resolve relative URI to base URI - see RFC 2396 Section 5.2
1951
// In some cases, it might make more sense to throw an exception
1952
// (when scheme is specified is the string spec and the base URI
1953
// is also specified, for example), but we're just following the
1954
// RFC specifications
1955
if (p_base != null) {
1956
1957      // check to see if this is the current doc - RFC 2396 5.2 #2
1958
// note that this is slightly different from the RFC spec in that
1959
// we don't include the check for query string being null
1960
// - this handles cases where the urispec is just a query
1961
// string or a fragment (e.g. "?y" or "#s") -
1962
// see <http://www.ics.uci.edu/~fielding/url/test1.html> which
1963
// identified this as a bug in the RFC
1964
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      // check for scheme - RFC 2396 5.2 #3
1980
// if we found a scheme, it means absolute URI, so we're done
1981
if (m_scheme == null) {
1982        m_scheme = p_base.getScheme();
1983      }
1984      else {
1985        return;
1986      }
1987
1988      // check for authority - RFC 2396 5.2 #4
1989
// if we found a host, then we've got a network path, so we're done
1990
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      // check for absolute path - RFC 2396 5.2 #5
2001
if (m_path.length() > 0 &&
2002          m_path.startsWith("/")) {
2003        return;
2004      }
2005
2006      // if we get to this point, we need to resolve relative path
2007
// RFC 2396 5.2 #6
2008
String JavaDoc path = "";
2009      String JavaDoc basePath = p_base.getPath();
2010
2011      // 6a - get all but the last segment of the base URI path
2012
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      // 6b - append the relative URI path
2023
path = path.concat(m_path);
2024
2025      // 6c - remove all "./" where "." is a complete path segment
2026
index = -1;
2027      while ((index = path.indexOf("/./")) != -1) {
2028        path = path.substring(0, index+1).concat(path.substring(index+3));
2029      }
2030
2031      // 6d - remove "." if path ends with "." as a complete path segment
2032
if (path.endsWith("/.")) {
2033        path = path.substring(0, path.length()-1);
2034      }
2035
2036      // 6e - remove all "<segment>/../" where "<segment>" is a complete
2037
// path segment not equal to ".."
2038
index = 1;
2039      int segIndex = -1;
2040      String JavaDoc 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      // 6f - remove ending "<segment>/.." where "<segment>" is a
2058
// complete path segment
2059
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 /**
2071  * Initialize the scheme for this URI from a URI string spec.
2072  *
2073  * @param p_uriSpec the URI specification (cannot be null)
2074  *
2075  * @exception MalformedURIException if URI does not have a conformant
2076  * scheme
2077  */

2078  private void initializeScheme(String JavaDoc p_uriSpec)
2079                 throws MalformedURIException {
2080    int uriSpecLen = p_uriSpec.length();
2081    int index = 0;
2082    String JavaDoc 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 /**
2104  * Initialize the authority (either server or registry based)
2105  * for this URI from a URI string spec.
2106  *
2107  * @param p_uriSpec the URI specification (cannot be null)
2108  *
2109  * @return true if the given string matched server or registry
2110  * based authority
2111  */

2112  private boolean initializeAuthority(String JavaDoc p_uriSpec) {
2113    
2114    int index = 0;
2115    int start = 0;
2116    int end = p_uriSpec.length();
2117
2118    char testChar = '\0';
2119    String JavaDoc userinfo = null;
2120
2121    // userinfo is everything up to @
2122
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    // host is everything up to last ':', or up to
2135
// and including ']' if followed by ':'.
2136
String JavaDoc 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      // port
2161
if (hasPort) {
2162        index++;
2163        start = index;
2164        while (index < end) {
2165          index++;
2166        }
2167        String JavaDoc portStr = p_uriSpec.substring(start, index);
2168        if (portStr.length() > 0) {
2169          // REVISIT: Remove this code.
2170
/** for (int i = 0; i < portStr.length(); i++) {
2171            if (!isDigit(portStr.charAt(i))) {
2172              throw new MalformedURIException(
2173                   portStr +
2174                   " is invalid. Port should only contain digits!");
2175            }
2176          }**/

2177          // REVISIT: Remove this code.
2178
// Store port value as string instead of integer.
2179
try {
2180            port = Integer.parseInt(portStr);
2181            if (port == -1) --port;
2182          }
2183          catch (NumberFormatException JavaDoc 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    // Note: Registry based authority is being removed from a
2197
// new spec for URI which would obsolete RFC 2396. If the
2198
// spec is added to XML errata, processing of reg_name
2199
// needs to be removed. - mrglavas.
2200
else if (isValidRegistryBasedAuthority(p_uriSpec)) {
2201      m_regAuthority = p_uriSpec;
2202      return true;
2203    }
2204    return false;
2205  }
2206  
2207  /**
2208   * Determines whether the components host, port, and user info
2209   * are valid as a server authority.
2210   *
2211   * @param host the host component of authority
2212   * @param port the port number component of authority
2213   * @param userinfo the user info component of authority
2214   *
2215   * @return true if the given host, port, and userinfo compose
2216   * a valid server authority
2217   */

2218  private boolean isValidServerBasedAuthority(String JavaDoc host, int port, String JavaDoc userinfo) {
2219    
2220    // Check if the host is well formed.
2221
if (!isWellFormedAddress(host)) {
2222      return false;
2223    }
2224    
2225    // Check that port is well formed if it exists.
2226
// REVISIT: There's no restriction on port value ranges, but
2227
// perform the same check as in setPort to be consistent. Pass
2228
// in a string to this method instead of an integer.
2229
if (port < -1 || port > 65535) {
2230      return false;
2231    }
2232    
2233    // Check that userinfo is well formed if it exists.
2234
if (userinfo != null) {
2235      // Userinfo can contain alphanumerics, mark characters, escaped
2236
// and ';',':','&','=','+','$',','
2237
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  /**
2260   * Determines whether the given string is a registry based authority.
2261   *
2262   * @param authority the authority component of a URI
2263   *
2264   * @return true if the given string is a registry based authority
2265   */

2266  private boolean isValidRegistryBasedAuthority(String JavaDoc 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      // check for valid escape sequence
2275
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      // can check against path characters because the set
2284
// is the same except for '/' which we've already excluded.
2285
else if (!isPathCharacter(testChar)) {
2286        return false;
2287      }
2288      ++index;
2289    }
2290    return true;
2291  }
2292    
2293 /**
2294  * Initialize the path for this URI from a URI string spec.
2295  *
2296  * @param p_uriSpec the URI specification (cannot be null)
2297  * @param p_nStartIndex the index to begin scanning from
2298  *
2299  * @exception MalformedURIException if p_uriSpec violates syntax rules
2300  */

2301  private void initializePath(String JavaDoc 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    // path - everything up to query string or fragment
2314
if (start < end) {
2315      // RFC 2732 only allows '[' and ']' to appear in the opaque part.
2316
if (getScheme() == null || p_uriSpec.charAt(start) == '/') {
2317      
2318            // Scan path.
2319
// abs_path = "/" path_segments
2320
// rel_path = rel_segment [ abs_path ]
2321
while (index < end) {
2322                testChar = p_uriSpec.charAt(index);
2323            
2324                // check for valid escape sequence
2325
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                // Path segments cannot contain '[' or ']' since pchar
2335
// production was not changed by RFC 2732.
2336
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            // Scan opaque part.
2349
// opaque_part = uric_no_slash *uric
2350
while (index < end) {
2351                testChar = p_uriSpec.charAt(index);
2352            
2353                if (testChar == '?' || testChar == '#') {
2354                    break;
2355                }
2356                
2357                // check for valid escape sequence
2358
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                // If the scheme specific part is opaque, it can contain '['
2368
// and ']'. uric_no_slash wasn't modified by RFC 2732, which
2369
// I've interpreted as an error in the spec, since the
2370
// production should be equivalent to (uric - '/'), and uric
2371
// contains '[' and ']'. - mrglavas
2372
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    // query - starts with ? and up to fragment or end
2383
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    // fragment - starts with #
2410
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 /**
2436  * Get the scheme for this URI.
2437  *
2438  * @return the scheme for this URI
2439  */

2440  public String JavaDoc getScheme() {
2441    return m_scheme;
2442  }
2443
2444 /**
2445  * Get the scheme-specific part for this URI (everything following the
2446  * scheme and the first colon). See RFC 2396 Section 5.2 for spec.
2447  *
2448  * @return the scheme-specific part for this URI
2449  */

2450  public String JavaDoc getSchemeSpecificPart() {
2451    StringBuffer JavaDoc schemespec = new StringBuffer JavaDoc();
2452
2453    if (m_host != null || m_regAuthority != null) {
2454      schemespec.append("//");
2455    
2456      // Server based authority.
2457
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      // Registry based authority.
2472
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 /**
2495  * Get the userinfo for this URI.
2496  *
2497  * @return the userinfo for this URI (null if not specified).
2498  */

2499  public String JavaDoc getUserinfo() {
2500    return m_userinfo;
2501  }
2502
2503  /**
2504  * Get the host for this URI.
2505  *
2506  * @return the host for this URI (null if not specified).
2507  */

2508  public String JavaDoc getHost() {
2509    return m_host;
2510  }
2511
2512 /**
2513  * Get the port for this URI.
2514  *
2515  * @return the port for this URI (-1 if not specified).
2516  */

2517  public int getPort() {
2518    return m_port;
2519  }
2520  
2521  /**
2522   * Get the registry based authority for this URI.
2523   *
2524   * @return the registry based authority (null if not specified).
2525   */

2526  public String JavaDoc getRegBasedAuthority() {
2527    return m_regAuthority;
2528  }
2529
2530 /**
2531  * Get the path for this URI (optionally with the query string and
2532  * fragment).
2533  *
2534  * @param p_includeQueryString if true (and query string is not null),
2535  * then a "?" followed by the query string
2536  * will be appended
2537  * @param p_includeFragment if true (and fragment is not null),
2538  * then a "#" followed by the fragment
2539  * will be appended
2540  *
2541  * @return the path for this URI possibly including the query string
2542  * and fragment
2543  */

2544  public String JavaDoc getPath(boolean p_includeQueryString,
2545                        boolean p_includeFragment) {
2546    StringBuffer JavaDoc pathString = new StringBuffer JavaDoc(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 /**
2561  * Get the path for this URI. Note that the value returned is the path
2562  * only and does not include the query string or fragment.
2563  *
2564  * @return the path for this URI.
2565  */

2566  public String JavaDoc getPath() {
2567    return m_path;
2568  }
2569
2570 /**
2571  * Get the query string for this URI.
2572  *
2573  * @return the query string for this URI. Null is returned if there
2574  * was no "?" in the URI spec, empty string if there was a
2575  * "?" but no query string following it.
2576  */

2577  public String JavaDoc getQueryString() {
2578    return m_queryString;
2579  }
2580
2581 /**
2582  * Get the fragment for this URI.
2583  *
2584  * @return the fragment for this URI. Null is returned if there
2585  * was no "#" in the URI spec, empty string if there was a
2586  * "#" but no fragment following it.
2587  */

2588  public String JavaDoc getFragment() {
2589    return m_fragment;
2590  }
2591
2592 /**
2593  * Set the scheme for this URI. The scheme is converted to lowercase
2594  * before it is set.
2595  *
2596  * @param p_scheme the scheme for this URI (cannot be null)
2597  *
2598  * @exception MalformedURIException if p_scheme is not a conformant
2599  * scheme name
2600  */

2601  public void setScheme(String JavaDoc 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 /**
2614  * Set the userinfo for this URI. If a non-null value is passed in and
2615  * the host value is null, then an exception is thrown.
2616  *
2617  * @param p_userinfo the userinfo for this URI
2618  *
2619  * @exception MalformedURIException if p_userinfo contains invalid
2620  * characters
2621  */

2622  public void setUserinfo(String JavaDoc 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      // userinfo can contain alphanumerics, mark characters, escaped
2634
// and ';',':','&','=','+','$',','
2635
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 /**
2659  * <p>Set the host for this URI. If null is passed in, the userinfo
2660  * field is also set to null and the port is set to -1.</p>
2661  *
2662  * <p>Note: This method overwrites registry based authority if it
2663  * previously existed in this URI.</p>
2664  *
2665  * @param p_host the host for this URI
2666  *
2667  * @exception MalformedURIException if p_host is not a valid IP
2668  * address or DNS hostname.
2669  */

2670  public void setHost(String JavaDoc 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 /**
2688  * Set the port for this URI. -1 is used to indicate that the port is
2689  * not specified, otherwise valid port numbers are between 0 and 65535.
2690  * If a valid port number is passed in and the host field is null,
2691  * an exception is thrown.
2692  *
2693  * @param p_port the port number for this URI
2694  *
2695  * @exception MalformedURIException if p_port is not -1 and not a
2696  * valid port number
2697  */

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  /**
2712   * <p>Sets the registry based authority for this URI.</p>
2713   *
2714   * <p>Note: This method overwrites server based authority
2715   * if it previously existed in this URI.</p>
2716   *
2717   * @param authority the registry based authority for this URI
2718   *
2719   * @exception MalformedURIException it authority is not a
2720   * well formed registry based authority
2721   */

2722  public void setRegBasedAuthority(String JavaDoc authority)
2723    throws MalformedURIException {
2724
2725    if (authority == null) {
2726      m_regAuthority = null;
2727      return;
2728    }
2729  // reg_name = 1*( unreserved | escaped | "$" | "," |
2730
// ";" | ":" | "@" | "&" | "=" | "+" )
2731
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 /**
2743  * Set the path for this URI. If the supplied path is null, then the
2744  * query string and fragment are set to null as well. If the supplied
2745  * path includes a query string and/or fragment, these fields will be
2746  * parsed and set as well. Note that, for URIs following the "generic
2747  * URI" syntax, the path specified should start with a slash.
2748  * For URIs that do not follow the generic URI syntax, this method
2749  * sets the scheme-specific part.
2750  *
2751  * @param p_path the path for this URI (may be null)
2752  *
2753  * @exception MalformedURIException if p_path contains invalid
2754  * characters
2755  */

2756  public void setPath(String JavaDoc 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 /**
2768  * Append to the end of the path of this URI. If the current path does
2769  * not end in a slash and the path to be appended does not begin with
2770  * a slash, a slash will be appended to the current path before the
2771  * new segment is added. Also, if the current path ends in a slash
2772  * and the new segment begins with a slash, the extra slash will be
2773  * removed before the new segment is appended.
2774  *
2775  * @param p_addToPath the new segment to be added to the current path
2776  *
2777  * @exception MalformedURIException if p_addToPath contains syntax
2778  * errors
2779  */

2780  public void appendPath(String JavaDoc 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 /**
2818  * Set the query string for this URI. A non-null value is valid only
2819  * if this is an URI conforming to the generic URI syntax and
2820  * the path value is not null.
2821  *
2822  * @param p_queryString the query string for this URI
2823  *
2824  * @exception MalformedURIException if p_queryString is not null and this
2825  * URI does not conform to the generic
2826  * URI syntax or if the path is null
2827  */

2828  public void setQueryString(String JavaDoc 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 /**
2850  * Set the fragment for this URI. A non-null value is valid only
2851  * if this is a URI conforming to the generic URI syntax and
2852  * the path value is not null.
2853  *
2854  * @param p_fragment the fragment for this URI
2855  *
2856  * @exception MalformedURIException if p_fragment is not null and this
2857  * URI does not conform to the generic
2858  * URI syntax or if the path is null
2859  */

2860  public void setFragment(String JavaDoc 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 /**
2882  * Determines if the passed-in Object is equivalent to this URI.
2883  *
2884  * @param p_test the Object to test for equality.
2885  *
2886  * @return true if p_test is a URI with all values equal to this
2887  * URI, false otherwise
2888  */

2889  public boolean equals(Object JavaDoc 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 /**
2918  * Get the URI as a string specification. See RFC 2396 Section 5.2.
2919  *
2920  * @return the URI string specification
2921  */

2922  public String JavaDoc toString() {
2923    StringBuffer JavaDoc uriSpecString = new StringBuffer JavaDoc();
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 /**
2934  * Get the indicator as to whether this URI uses the "generic URI"
2935  * syntax.
2936  *
2937  * @return true if this URI uses the "generic URI" syntax, false
2938  * otherwise
2939  */

2940  public boolean isGenericURI() {
2941    // presence of the host (whether valid or empty) means
2942
// double-slashes which means generic uri
2943
return (m_host != null);
2944  }
2945
2946 /**
2947  * Determine whether a scheme conforms to the rules for a scheme name.
2948  * A scheme is conformant if it starts with an alphanumeric, and
2949  * contains only alphanumerics, '+','-' and '.'.
2950  *
2951  * @return true if the scheme is conformant, false otherwise
2952  */

2953  public static boolean isConformantSchemeName(String JavaDoc 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 /**
2975  * Determine whether a string is syntactically capable of representing
2976  * a valid IPv4 address, IPv6 reference or the domain name of a network host.
2977  * A valid IPv4 address consists of four decimal digit groups separated by a
2978  * '.'. Each group must consist of one to three digits. See RFC 2732 Section 3,
2979  * and RFC 2373 Section 2.2, for the definition of IPv6 references. A hostname
2980  * consists of domain labels (each of which must begin and end with an alphanumeric
2981  * but may contain '-') separated & by a '.'. See RFC 2396 Section 3.2.2.
2982  *
2983  * @return true if the string is a syntactically valid IPv4 address,
2984  * IPv6 reference or hostname
2985  */

2986  public static boolean isWellFormedAddress(String JavaDoc 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    // Check if the host is a valid IPv6reference.
2997
if (address.startsWith("[")) {
2998      return isWellFormedIPv6Reference(address);
2999    }
3000
3001    // Cannot start with a '.', '-', or end with a '-'.
3002
if (address.startsWith(".") ||
3003        address.startsWith("-") ||
3004        address.endsWith("-")) {
3005      return false;
3006    }
3007
3008    // rightmost domain label starting with digit indicates IP address
3009
// since top level domain label can only start with an alpha
3010
// see RFC 2396 Section 3.2.2
3011
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      // hostname = *( domainlabel "." ) toplabel [ "." ]
3021
// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
3022
// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
3023

3024      // RFC 2396 states that hostnames take the form described in
3025
// RFC 1034 (Section 3) and RFC 1123 (Section 2.1). According
3026
// to RFC 1034, hostnames are limited to 255 characters.
3027
if (addrLength > 255) {
3028        return false;
3029      }
3030      
3031      // domain labels can contain alphanumerics and '-"
3032
// but must start and end with an alphanumeric
3033
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        // RFC 1034: Labels must be 63 characters or less.
3051
else if (++labelCharCount > 63) {
3052          return false;
3053        }
3054      }
3055    }
3056    return true;
3057  }
3058  
3059  /**
3060   * <p>Determines whether a string is an IPv4 address as defined by
3061   * RFC 2373, and under the further constraint that it must be a 32-bit
3062   * address. Though not expressed in the grammar, in order to satisfy
3063   * the 32-bit address constraint, each segment of the address cannot
3064   * be greater than 255 (8 bits of information).</p>
3065   *
3066   * <p><code>IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT</code></p>
3067   *
3068   * @return true if the string is a syntactically valid IPv4 address
3069   */

3070  public static boolean isWellFormedIPv4Address(String JavaDoc address) {
3071      
3072      int addrLength = address.length();
3073      char testChar;
3074      int numDots = 0;
3075      int numDigits = 0;
3076
3077      // make sure that 1) we see only digits and dot separators, 2) that
3078
// any dot separator is preceded and followed by a digit and
3079
// 3) that we find 3 dots
3080
//
3081
// RFC 2732 amended RFC 2396 by replacing the definition
3082
// of IPv4address with the one defined by RFC 2373. - mrglavas
3083
//
3084
// IPv4address = 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT "." 1*3DIGIT
3085
//
3086
// One to three digits must be in each segment.
3087
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        // Check that that there are no more than three digits
3103
// in this segment.
3104
else if (++numDigits > 3) {
3105          return false;
3106        }
3107        // Check that this segment is not greater than 255.
3108
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  /**
3123   * <p>Determines whether a string is an IPv6 reference as defined
3124   * by RFC 2732, where IPv6address is defined in RFC 2373. The
3125   * IPv6 address is parsed according to Section 2.2 of RFC 2373,
3126   * with the additional constraint that the address be composed of
3127   * 128 bits of information.</p>
3128   *
3129   * <p><code>IPv6reference = "[" IPv6address "]"</code></p>
3130   *
3131   * <p>Note: The BNF expressed in RFC 2373 Appendix B does not
3132   * accurately describe section 2.2, and was in fact removed from
3133   * RFC 3513, the successor of RFC 2373.</p>
3134   *
3135   * @return true if the string is a syntactically valid IPv6 reference
3136   */

3137  public static boolean isWellFormedIPv6Reference(String JavaDoc address) {
3138
3139      int addrLength = address.length();
3140      int index = 1;
3141      int end = addrLength-1;
3142      
3143      // Check if string is a potential match for IPv6reference.
3144
if (!(addrLength > 2 && address.charAt(0) == '['
3145          && address.charAt(end) == ']')) {
3146          return false;
3147      }
3148      
3149      // Counter for the number of 16-bit sections read in the address.
3150
int [] counter = new int[1];
3151      
3152      // Scan hex sequence before possible '::' or IPv4 address.
3153
index = scanHexSequence(address, index, end, counter);
3154      if (index == -1) {
3155          return false;
3156      }
3157      // Address must contain 128-bits of information.
3158
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              // '::' represents at least one 16-bit group of zeros.
3165
if (++counter[0] > 8) {
3166                  return false;
3167              }
3168              index += 2;
3169              // Trailing zeros will fill out the rest of the address.
3170
if (index == end) {
3171                 return true;
3172              }
3173          }
3174          // If the second character wasn't ':', in order to be valid,
3175
// the remainder of the string must match IPv4Address,
3176
// and we must have read exactly 6 16-bit groups.
3177
else {
3178              return (counter[0] == 6) &&
3179                  isWellFormedIPv4Address(address.substring(index+1, end));
3180          }
3181      }
3182      else {
3183          return false;
3184      }
3185      
3186      // 3. Scan hex sequence after '::'.
3187
int prevCount = counter[0];
3188      index = scanHexSequence(address, index, end, counter);
3189
3190      // We've either reached the end of the string, the address ends in
3191
// an IPv4 address, or it is invalid. scanHexSequence has already
3192
// made sure that we have the right number of bits.
3193
return (index == end) ||
3194          (index != -1 && isWellFormedIPv4Address(
3195          address.substring((counter[0] > prevCount) ? index+1 : index, end)));
3196  }
3197  
3198  /**
3199   * Helper method for isWellFormedIPv6Reference which scans the
3200   * hex sequences of an IPv6 address. It returns the index of the
3201   * next character to scan in the address, or -1 if the string
3202   * cannot match a valid IPv6 address.
3203   *
3204   * @param address the string to be scanned
3205   * @param index the beginning index (inclusive)
3206   * @param end the ending index (exclusive)
3207   * @param counter a counter for the number of 16-bit sections read
3208   * in the address
3209   *
3210   * @return the index of the next character to scan, or -1 if the
3211   * string cannot match a valid IPv6 address
3212   */

3213  private static int scanHexSequence (String JavaDoc address, int index, int end, int [] counter) {
3214    
3215      char testChar;
3216      int numDigits = 0;
3217      int start = index;
3218      
3219      // Trying to match the following productions:
3220
// hexseq = hex4 *( ":" hex4)
3221
// hex4 = 1*4HEXDIG
3222
for (; index < end; ++index) {
3223        testChar = address.charAt(index);
3224        if (testChar == ':') {
3225            // IPv6 addresses are 128-bit, so there can be at most eight sections.
3226
if (numDigits > 0 && ++counter[0] > 8) {
3227                return -1;
3228            }
3229            // This could be '::'.
3230
if (numDigits == 0 || ((index+1 < end) && address.charAt(index+1) == ':')) {
3231                return index;
3232            }
3233            numDigits = 0;
3234        }
3235        // This might be invalid or an IPv4address. If it's potentially an IPv4address,
3236
// backup to just after the last valid character that matches hexseq.
3237
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        // There can be at most 4 hex digits per group.
3245
else if (++numDigits > 4) {
3246            return -1;
3247        }
3248      }
3249      return (numDigits > 0 && ++counter[0] <= 8) ? end : -1;
3250  }
3251
3252
3253 /**
3254  * Determine whether a char is a digit.
3255  *
3256  * @return true if the char is betweeen '0' and '9', false otherwise
3257  */

3258  private static boolean isDigit(char p_char) {
3259    return p_char >= '0' && p_char <= '9';
3260  }
3261
3262 /**
3263  * Determine whether a character is a hexadecimal character.
3264  *
3265  * @return true if the char is betweeen '0' and '9', 'a' and 'f'
3266  * or 'A' and 'F', false otherwise
3267  */

3268  private static boolean isHex(char p_char) {
3269    return (p_char <= 'f' && (fgLookupTable[p_char] & ASCII_HEX_CHARACTERS) != 0);
3270  }
3271
3272 /**
3273  * Determine whether a char is an alphabetic character: a-z or A-Z
3274  *
3275  * @return true if the char is alphabetic, false otherwise
3276  */

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 /**
3282  * Determine whether a char is an alphanumeric: 0-9, a-z or A-Z
3283  *
3284  * @return true if the char is alphanumeric, false otherwise
3285  */

3286  private static boolean isAlphanum(char p_char) {
3287     return (p_char <= 'z' && (fgLookupTable[p_char] & MASK_ALPHA_NUMERIC) != 0);
3288  }
3289
3290 /**
3291  * Determine whether a char is a URI character (reserved or
3292  * unreserved, not including '%' for escaped octets).
3293  *
3294  * @return true if the char is a URI character, false otherwise
3295  */

3296  private static boolean isURICharacter (char p_char) {
3297      return (p_char <= '~' && (fgLookupTable[p_char] & MASK_URI_CHARACTER) != 0);
3298  }
3299
3300 /**
3301  * Determine whether a char is a scheme character.
3302  *
3303  * @return true if the char is a scheme character, false otherwise
3304  */

3305  private static boolean isSchemeCharacter (char p_char) {
3306      return (p_char <= 'z' && (fgLookupTable[p_char] & MASK_SCHEME_CHARACTER) != 0);
3307  }
3308
3309 /**
3310  * Determine whether a char is a userinfo character.
3311  *
3312  * @return true if the char is a userinfo character, false otherwise
3313  */

3314  private static boolean isUserinfoCharacter (char p_char) {
3315      return (p_char <= 'z' && (fgLookupTable[p_char] & MASK_USERINFO_CHARACTER) != 0);
3316  }
3317  
3318 /**
3319  * Determine whether a char is a path character.
3320  *
3321  * @return true if the char is a path character, false otherwise
3322  */

3323  private static boolean isPathCharacter (char p_char) {
3324      return (p_char <= '~' && (fgLookupTable[p_char] & MASK_PATH_CHARACTER) != 0);
3325  }
3326
3327
3328 /**
3329  * Determine whether a given string contains only URI characters (also
3330  * called "uric" in RFC 2396). uric consist of all reserved
3331  * characters, unreserved characters and escaped characters.
3332  *
3333  * @return true if the string is comprised of uric, false otherwise
3334  */

3335  private static boolean isURIString(String JavaDoc 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  //
3364
// XML Schema anyURI specific information
3365
//
3366

3367  // which ASCII characters need to be escaped
3368
private static boolean gNeedEscaping[] = new boolean[128];
3369  // the first hex character if a character needs to be escaped
3370
private static char gAfterEscaping1[] = new char[128];
3371  // the second hex character if a character needs to be escaped
3372
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  // initialize the above 3 arrays
3376
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  // To encode special characters in anyURI, by using %HH to represent
3398
// special ASCII characters: 0x00~0x1F, 0x7F, ' ', '<', '>', etc.
3399
// and non-ASCII characters (whose value >= 128).
3400
public static String JavaDoc encode(String JavaDoc anyURI){
3401      int len = anyURI.length(), ch;
3402      StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(len*3);
3403
3404      // for each character in the anyURI
3405
int i = 0;
3406      for (; i < len; i++) {
3407          ch = anyURI.charAt(i);
3408          // if it's not an ASCII character, break here, and use UTF-8 encoding
3409
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      // we saw some non-ascii character
3422
if (i < len) {
3423          // get UTF-8 bytes for the remaining sub-string
3424
byte[] bytes = null;
3425          byte b;
3426          try {
3427              bytes = anyURI.substring(i).getBytes("UTF-8");
3428          } catch (java.io.UnsupportedEncodingException JavaDoc e) {
3429              // should never happen
3430
return anyURI;
3431          }
3432          len = bytes.length;
3433
3434          // for each byte
3435
for (i = 0; i < len; i++) {
3436              b = bytes[i];
3437              // for non-ascii character: make it positive, then escape
3438
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 encoding happened, create a new string;
3456
// otherwise, return the orginal one.
3457
if (buffer.length() != len)
3458          return buffer.toString();
3459      else
3460          return anyURI;
3461  }
3462
3463}
3464
3465 /**
3466  * This class defines the basic XML character properties. The data
3467  * in this class can be used to verify that a character is a valid
3468  * XML character or if the character is a space, name start, or name
3469  * character.
3470  * <p>
3471  * A series of convenience methods are supplied to ease the burden
3472  * of the developer. Because inlining the checks can improve per
3473  * character performance, the tables of character properties are
3474  * public. Using the character as an index into the <code>CHARS</code>
3475  * array and applying the appropriate mask flag (e.g.
3476  * <code>MASK_VALID</code>), yields the same results as calling the
3477  * convenience methods. There is one exception: check the comments
3478  * for the <code>isValid</code> method for details.
3479  *
3480  * @author Glenn Marcy, IBM
3481  * @author Andy Clark, IBM
3482  * @author Eric Ye, IBM
3483  * @author Arnaud Le Hors, IBM
3484  * @author Michael Glavassevich, IBM
3485  * @author Rahul Srivastava, Sun Microsystems Inc.
3486  *
3487  * @version $Id: DataValue.java,v 1.8 2005/06/12 13:29:22 emerks Exp $
3488  */

3489 public static final class XMLChar {
3490
3491     //
3492
// Constants
3493
//
3494

3495     /** Character flags. */
3496     private static final byte[] CHARS = new byte[1 << 16];
3497
3498     /** Valid character mask. */
3499     public static final int MASK_VALID = 0x01;
3500
3501     /** Space character mask. */
3502     public static final int MASK_SPACE = 0x02;
3503
3504     /** Name start character mask. */
3505     public static final int MASK_NAME_START = 0x04;
3506
3507     /** Name character mask. */
3508     public static final int MASK_NAME = 0x08;
3509
3510     /** Pubid character mask. */
3511     public static final int MASK_PUBID = 0x10;
3512     
3513     /**
3514      * Content character mask. Special characters are those that can
3515      * be considered the start of markup, such as '&lt;' and '&amp;'.
3516      * The various newline characters are considered special as well.
3517      * All other valid XML characters can be considered content.
3518      * <p>
3519      * This is an optimization for the inner loop of character scanning.
3520      */

3521     public static final int MASK_CONTENT = 0x20;
3522
3523     /** NCName start character mask. */
3524     public static final int MASK_NCNAME_START = 0x40;
3525
3526     /** NCName character mask. */
3527     public static final int MASK_NCNAME = 0x80;
3528
3529     //
3530
// Static initialization
3531
//
3532

3533     static {
3534         
3535         // Initializing the Character Flag Array
3536
// Code generated by: XMLCharGenerator.
3537

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 ); // Fill 3 of value (byte) 49
3545
CHARS[38] = 1;
3546         Arrays.fill(CHARS, 39, 45, (byte) 49 ); // Fill 6 of value (byte) 49
3547
Arrays.fill(CHARS, 45, 47, (byte) -71 ); // Fill 2 of value (byte) -71
3548
CHARS[47] = 49;
3549         Arrays.fill(CHARS, 48, 58, (byte) -71 ); // Fill 10 of value (byte) -71
3550
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 ); // Fill 2 of value (byte) 49
3556
Arrays.fill(CHARS, 65, 91, (byte) -3 ); // Fill 26 of value (byte) -3
3557
Arrays.fill(CHARS, 91, 93, (byte) 33 ); // Fill 2 of value (byte) 33
3558
CHARS[93] = 1;
3559         CHARS[94] = 33;
3560         CHARS[95] = -3;
3561         CHARS[96] = 33;
3562         Arrays.fill(CHARS, 97, 123, (byte) -3 ); // Fill 26 of value (byte) -3
3563
Arrays.fill(CHARS, 123, 183, (byte) 33 ); // Fill 60 of value (byte) 33
3564
CHARS[183] = -87;
3565         Arrays.fill(CHARS, 184, 192, (byte) 33 ); // Fill 8 of value (byte) 33
3566
Arrays.fill(CHARS, 192, 215, (byte) -19 ); // Fill 23 of value (byte) -19
3567
CHARS[215] = 33;
3568         Arrays.fill(CHARS, 216, 247, (byte) -19 ); // Fill 31 of value (byte) -19
3569
CHARS[247] = 33;
3570         Arrays.fill(CHARS, 248, 306, (byte) -19 ); // Fill 58 of value (byte) -19
3571
Arrays.fill(CHARS, 306, 308, (byte) 33 ); // Fill 2 of value (byte) 33
3572
Arrays.fill(CHARS, 308, 319, (byte) -19 ); // Fill 11 of value (byte) -19
3573
Arrays.fill(CHARS, 319, 321, (byte) 33 ); // Fill 2 of value (byte) 33
3574
Arrays.fill(CHARS, 321, 329, (byte) -19 ); // Fill 8 of value (byte) -19
3575
CHARS[329] = 33;
3576         Arrays.fill(CHARS, 330, 383, (byte) -19 ); // Fill 53 of value (byte) -19
3577
CHARS[383] = 33;
3578         Arrays.fill(CHARS, 384, 452, (byte) -19 ); // Fill 68 of value (byte) -19
3579
Arrays.fill(CHARS, 452, 461, (byte) 33 ); // Fill 9 of value (byte) 33
3580
Arrays.fill(CHARS, 461, 497, (byte) -19 ); // Fill 36 of value (byte) -19
3581
Arrays.fill(CHARS, 497, 500, (byte) 33 ); // Fill 3 of value (byte) 33
3582
Arrays.fill(CHARS, 500, 502, (byte) -19 ); // Fill 2 of value (byte) -19
3583
Arrays.fill(CHARS, 502, 506, (byte) 33 ); // Fill 4 of value (byte) 33
3584
Arrays.fill(CHARS, 506, 536, (byte) -19 ); // Fill 30 of value (byte) -19
3585
Arrays.fill(CHARS, 536, 592, (byte) 33 ); // Fill 56 of value (byte) 33
3586
Arrays.fill(CHARS, 592, 681, (byte) -19 ); // Fill 89 of value (byte) -19
3587
Arrays.fill(CHARS, 681, 699, (byte) 33 ); // Fill 18 of value (byte) 33
3588
Arrays.fill(CHARS, 699, 706, (byte) -19 ); // Fill 7 of value (byte) -19
3589
Arrays.fill(CHARS, 706, 720, (byte) 33 ); // Fill 14 of value (byte) 33
3590
Arrays.fill(CHARS, 720, 722, (byte) -87 ); // Fill 2 of value (byte) -87
3591
Arrays.fill(CHARS, 722, 768, (byte) 33 ); // Fill 46 of value (byte) 33
3592
Arrays.fill(CHARS, 768, 838, (byte) -87 ); // Fill 70 of value (byte) -87
3593
Arrays.fill(CHARS, 838, 864, (byte) 33 ); // Fill 26 of value (byte) 33
3594
Arrays.fill(CHARS, 864, 866, (byte) -87 ); // Fill 2 of value (byte) -87
3595
Arrays.fill(CHARS, 866, 902, (byte) 33 ); // Fill 36 of value (byte) 33
3596
CHARS[902] = -19;
3597         CHARS[903] = -87;
3598         Arrays.fill(CHARS, 904, 907, (byte) -19 ); // Fill 3 of value (byte) -19
3599
CHARS[907] = 33;
3600         CHARS[908] = -19;
3601         CHARS[909] = 33;
3602         Arrays.fill(CHARS, 910, 930, (byte) -19 ); // Fill 20 of value (byte) -19
3603
CHARS[930] = 33;
3604         Arrays.fill(CHARS, 931, 975, (byte) -19 ); // Fill 44 of value (byte) -19
3605
CHARS[975] = 33;
3606         Arrays.fill(CHARS, 976, 983, (byte) -19 ); // Fill 7 of value (byte) -19
3607
Arrays.fill(CHARS, 983, 986, (byte) 33 ); // Fill 3 of value (byte) 33
3608
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 ); // Fill 18 of value (byte) -19
3617
Arrays.fill(CHARS, 1012, 1025, (byte) 33 ); // Fill 13 of value (byte) 33
3618
Arrays.fill(CHARS, 1025, 1037, (byte) -19 ); // Fill 12 of value (byte) -19
3619
CHARS[1037] = 33;
3620         Arrays.fill(CHARS, 1038, 1104, (byte) -19 ); // Fill 66 of value (byte) -19
3621
CHARS[1104] = 33;
3622         Arrays.fill(CHARS, 1105, 1117, (byte) -19 ); // Fill 12 of value (byte) -19
3623
CHARS[1117] = 33;
3624         Arrays.fill(CHARS, 1118, 1154, (byte) -19 ); // Fill 36 of value (byte) -19
3625
CHARS[1154] = 33;
3626         Arrays.fill(CHARS, 1155, 1159, (byte) -87 ); // Fill 4 of value (byte) -87
3627
Arrays.fill(CHARS, 1159, 1168, (byte) 33 ); // Fill 9 of value (byte) 33
3628
Arrays.fill(CHARS, 1168, 1221, (byte) -19 ); // Fill 53 of value (byte) -19
3629
Arrays.fill(CHARS, 1221, 1223, (byte) 33 ); // Fill 2 of value (byte) 33
3630
Arrays.fill(CHARS, 1223, 1225, (byte) -19 ); // Fill 2 of value (byte) -19
3631
Arrays.fill(CHARS, 1225, 1227, (byte) 33 ); // Fill 2 of value (byte) 33
3632
Arrays.fill(CHARS, 1227, 1229, (byte) -19 ); // Fill 2 of value (byte) -19
3633
Arrays.fill(CHARS, 1229, 1232, (byte) 33 ); // Fill 3 of value (byte) 33
3634
Arrays.fill(CHARS, 1232, 1260, (byte) -19 ); // Fill 28 of value (byte) -19
3635
Arrays.fill(CHARS, 1260, 1262, (byte) 33 ); // Fill 2 of value (byte) 33
3636
Arrays.fill(CHARS, 1262, 1270, (byte) -19 ); // Fill 8 of value (byte) -19
3637
Arrays.fill(CHARS, 1270, 1272, (byte) 33 ); // Fill 2 of value (byte) 33
3638
Arrays.fill(CHARS, 1272, 1274, (byte) -19 ); // Fill 2 of value (byte) -19
3639
Arrays.fill(CHARS, 1274, 1329, (byte) 33 ); // Fill 55 of value (byte) 33
3640
Arrays.fill(CHARS, 1329, 1367, (byte) -19 ); // Fill 38 of value (byte) -19
3641
Arrays.fill(CHARS, 1367, 1369, (byte) 33 ); // Fill 2 of value (byte) 33
3642
CHARS[1369] = -19;
3643         Arrays.fill(CHARS, 1370, 1377, (byte) 33 ); // Fill 7 of value (byte) 33
3644
Arrays.fill(CHARS, 1377, 1415, (byte) -19 ); // Fill 38 of value (byte) -19
3645
Arrays.fill(CHARS, 1415, 1425, (byte) 33 ); // Fill 10 of value (byte) 33
3646
Arrays.fill(CHARS, 1425, 1442, (byte) -87 ); // Fill 17 of value (byte) -87
3647
CHARS[1442] = 33;
3648         Arrays.fill(CHARS, 1443, 1466, (byte) -87 ); // Fill 23 of value (byte) -87
3649
CHARS[1466] = 33;
3650         Arrays.fill(CHARS, 1467, 1470, (byte) -87 ); // Fill 3 of value (byte) -87
3651
CHARS[1470] = 33;
3652         CHARS[1471] = -87;
3653         CHARS[1472] = 33;
3654         Arrays.fill(CHARS, 1473, 1475, (byte) -87 ); // Fill 2 of value (byte) -87
3655
CHARS[1475] = 33;
3656         CHARS[1476] = -87;
3657         Arrays.fill(CHARS, 1477, 1488, (byte) 33 ); // Fill 11 of value (byte) 33
3658
Arrays.fill(CHARS, 1488, 1515, (byte) -19 ); // Fill 27 of value (byte) -19
3659
Arrays.fill(CHARS, 1515, 1520, (byte) 33 ); // Fill 5 of value (byte) 33
3660
Arrays.fill(CHARS, 1520, 1523, (byte) -19 ); // Fill 3 of value (byte) -19
3661
Arrays.fill(CHARS, 1523, 1569, (byte) 33 ); // Fill 46 of value (byte) 33
3662
Arrays.fill(CHARS, 1569, 1595, (byte) -19 ); // Fill 26 of value (byte) -19
3663
Arrays.fill(CHARS, 1595, 1600, (byte) 33 ); // Fill 5 of value (byte) 33
3664
CHARS[1600] = -87;
3665         Arrays.fill(CHARS, 1601, 1611, (byte) -19 ); // Fill 10 of value (byte) -19
3666
Arrays.fill(CHARS, 1611, 1619, (byte) -87 ); // Fill 8 of value (byte) -87
3667
Arrays.fill(CHARS, 1619, 1632, (byte) 33 ); // Fill 13 of value (byte) 33
3668
Arrays.fill(CHARS, 1632, 1642, (byte) -87 ); // Fill 10 of value (byte) -87
3669
Arrays.fill(CHARS, 1642, 1648, (byte) 33 ); // Fill 6 of value (byte) 33
3670
CHARS[1648] = -87;
3671         Arrays.fill(CHARS, 1649, 1720, (byte) -19 ); // Fill 71 of value (byte) -19
3672
Arrays.fill(CHARS, 1720, 1722, (byte) 33 ); // Fill 2 of value (byte) 33
3673
Arrays.fill(CHARS, 1722, 1727, (byte) -19 ); // Fill 5 of value (byte) -19
3674
CHARS[1727] = 33;
3675         Arrays.fill(CHARS, 1728, 1743, (byte) -19 ); // Fill 15 of value (byte) -19
3676
CHARS[1743] = 33;
3677         Arrays.fill(CHARS, 1744, 1748, (byte) -19 ); // Fill 4 of value (byte) -19
3678
CHARS[1748] = 33;
3679         CHARS[1749] = -19;
3680         Arrays.fill(CHARS, 1750, 1765, (byte) -87 ); // Fill 15 of value (byte) -87
3681
Arrays.fill(CHARS, 1765, 1767, (byte) -19 ); // Fill 2 of value (byte) -19
3682
Arrays.fill(CHARS, 1767, 1769, (byte) -87 ); // Fill 2 of value (byte) -87
3683
CHARS[1769] = 33;
3684         Arrays.fill(CHARS, 1770, 1774, (byte) -87 ); // Fill 4 of value (byte) -87
3685
Arrays.fill(CHARS, 1774, 1776, (byte) 33 ); // Fill 2 of value (byte) 33
3686
Arrays.fill(CHARS, 1776, 1786, (byte) -87 ); // Fill 10 of value (byte) -87
3687
Arrays.fill(CHARS, 1786, 2305, (byte) 33 ); // Fill 519 of value (byte) 33
3688
Arrays.fill(CHARS, 2305, 2308, (byte) -87 ); // Fill 3 of value (byte) -87
3689
CHARS[2308] = 33;
3690         Arrays.fill(CHARS, 2309, 2362, (byte) -19 ); // Fill 53 of value (byte) -19
3691
Arrays.fill(CHARS, 2362, 2364, (byte) 33 ); // Fill 2 of value (byte) 33
3692
CHARS[2364] = -87;
3693         CHARS[2365] = -19;
3694         Arrays.fill(CHARS, 2366, 2382, (byte) -87 ); // Fill 16 of value (byte) -87
3695
Arrays.fill(CHARS, 2382, 2385, (byte) 33 ); // Fill 3 of value (byte) 33
3696
Arrays.fill(CHARS, 2385, 2389, (byte) -87 ); // Fill 4 of value (byte) -87
3697
Arrays.fill(CHARS, 2389, 2392, (byte) 33 ); // Fill 3 of value (byte) 33
3698
Arrays.fill(CHARS, 2392, 2402, (byte) -19 ); // Fill 10 of value (byte) -19
3699
Arrays.fill(CHARS, 2402, 2404, (byte) -87 ); // Fill 2 of value (byte) -87
3700
Arrays.fill(CHARS, 2404, 2406, (byte) 33 ); // Fill 2 of value (byte) 33
3701
Arrays.fill(CHARS, 2406, 2416, (byte) -87 ); // Fill 10 of value (byte) -87
3702
Arrays.fill(CHARS, 2416, 2433, (byte) 33 ); // Fill 17 of value (byte) 33
3703
Arrays.fill(CHARS, 2433, 2436, (byte) -87 ); // Fill 3 of value (byte) -87
3704
CHARS[2436] = 33;
3705         Arrays.fill(CHARS, 2437, 2445, (byte) -19 ); // Fill 8 of value (byte) -19
3706
Arrays.fill(CHARS, 2445, 2447, (byte) 33 ); // Fill 2 of value (byte) 33
3707
Arrays.fill(CHARS, 2447, 2449, (byte) -19 ); // Fill 2 of value (byte) -19
3708
Arrays.fill(CHARS, 2449, 2451, (byte) 33 ); // Fill 2 of value (byte) 33
3709
Arrays.fill(CHARS, 2451, 2473, (byte) -19 ); // Fill 22 of value (byte) -19
3710
CHARS[2473] = 33;
3711         Arrays.fill(CHARS, 2474, 2481, (byte) -19 ); // Fill 7 of value (byte) -19
3712
CHARS[2481] = 33;
3713         CHARS[2482] = -19;
3714         Arrays.fill(CHARS, 2483, 2486, (byte) 33 ); // Fill 3 of value (byte) 33
3715
Arrays.fill(CHARS, 2486, 2490, (byte) -19 ); // Fill 4 of value (byte) -19
3716
Arrays.fill(CHARS, 2490, 2492, (byte) 33 ); // Fill 2 of value (byte) 33
3717
CHARS[2492] = -87;
3718         CHARS[2493] = 33;
3719         Arrays.fill(CHARS, 2494, 2501, (byte) -87 ); // Fill 7 of value (byte) -87
3720
Arrays.fill(CHARS, 2501, 2503, (byte) 33 ); // Fill 2 of value (byte) 33
3721
Arrays.fill(CHARS, 2503, 2505, (byte) -87 ); // Fill 2 of value (byte) -87
3722
Arrays.fill(CHARS, 2505, 2507, (byte) 33 ); // Fill 2 of value (byte) 33
3723
Arrays.fill(CHARS, 2507, 2510, (byte) -87 ); // Fill 3 of value (byte) -87
3724
Arrays.fill(CHARS, 2510, 2519, (byte) 33 ); // Fill 9 of value (byte) 33
3725
CHARS[2519] = -87;
3726         Arrays.fill(CHARS, 2520, 2524, (byte) 33 ); // Fill 4 of value (byte) 33
3727
Arrays.fill(CHARS, 2524, 2526, (byte) -19 ); // Fill 2 of value (byte) -19
3728
CHARS[2526] = 33;
3729         Arrays.fill(CHARS, 2527, 2530, (byte) -19 ); // Fill 3 of value (byte) -19
3730
Arrays.fill(CHARS, 2530, 2532, (byte) -87 ); // Fill 2 of value (byte) -87
3731
Arrays.fill(CHARS, 2532, 2534, (byte) 33 ); // Fill 2 of value (byte) 33
3732
Arrays.fill(CHARS, 2534, 2544, (byte) -87 ); // Fill 10 of value (byte) -87
3733
Arrays.fill(CHARS, 2544, 2546, (byte) -19 ); // Fill 2 of value (byte) -19
3734
Arrays.fill(CHARS, 2546, 2562, (byte) 33 ); // Fill 16 of value (byte) 33
3735
CHARS[2562] = -87;
3736         Arrays.fill(CHARS, 2563, 2565, (byte) 33 ); // Fill 2 of value (byte) 33
3737
Arrays.fill(CHARS, 2565, 2571, (byte) -19 ); // Fill 6 of value (byte) -19
3738
Arrays.fill(CHARS, 2571, 2575, (byte) 33 ); // Fill 4 of value (byte) 33
3739
Arrays.fill(CHARS, 2575, 2577, (byte) -19 ); // Fill 2 of value (byte) -19
3740
Arrays.fill(CHARS, 2577, 2579, (byte) 33 ); // Fill 2 of value (byte) 33
3741
Arrays.fill(CHARS, 2579, 2601, (byte) -19 ); // Fill 22 of value (byte) -19
3742
CHARS[2601] = 33;
3743         Arrays.fill(CHARS, 2602, 2609, (byte) -19 ); // Fill 7 of value (byte) -19
3744
CHARS[2609] = 33;
3745         Arrays.fill(CHARS, 2610, 2612, (byte) -19 ); // Fill 2 of value (byte) -19
3746
CHARS[2612] = 33;
3747         Arrays.fill(CHARS, 2613, 2615, (byte) -19 ); // Fill 2 of value (byte) -19
3748
CHARS[2615] = 33;
3749         Arrays.fill(CHARS, 2616, 2618, (byte) -19 ); // Fill 2 of value (byte) -19
3750
Arrays.fill(CHARS, 2618, 2620, (byte) 33 ); // Fill 2 of value (byte) 33
3751
CHARS[2620] = -87;
3752         CHARS[2621] = 33;
3753         Arrays.fill(CHARS, 2622, 2627, (byte) -87 ); // Fill 5 of value (byte) -87
3754
Arrays.fill(CHARS, 2627, 2631, (byte) 33 ); // Fill 4 of value (byte) 33
3755
Arrays.fill(CHARS, 2631, 2633, (byte) -87 ); // Fill 2 of value (byte) -87
3756
Arrays.fill(CHARS, 2633, 2635, (byte) 33 ); // Fill 2 of value (byte) 33
3757
Arrays.fill(CHARS, 2635, 2638, (byte) -87 ); // Fill 3 of value (byte) -87
3758
Arrays.fill(CHARS, 2638, 2649, (byte) 33 ); // Fill 11 of value (byte) 33
3759
Arrays.fill(CHARS, 2649, 2653, (byte) -19 ); // Fill 4 of value (byte) -19
3760
CHARS[2653] = 33;
3761         CHARS[2654] = -19;
3762         Arrays.fill(CHARS, 2655, 2662, (byte) 33 ); // Fill 7 of value (byte) 33
3763
Arrays.fill(CHARS, 2662, 2674, (byte) -87 ); // Fill 12 of value (byte) -87
3764
Arrays.fill(CHARS, 2674, 2677, (byte) -19 ); // Fill 3 of value (byte) -19
3765
Arrays.fill(CHARS, 2677, 2689, (byte) 33 ); // Fill 12 of value (byte) 33
3766
Arrays.fill(CHARS, 2689, 2692, (byte) -87 ); // Fill 3 of value (byte) -87
3767
CHARS[2692] = 33;
3768         Arrays.fill(CHARS, 2693, 2700, (byte) -19 ); // Fill 7 of value (byte) -19
3769
CHARS[2700] = 33;
3770         CHARS[2701] = -19;
3771         CHARS[2702] = 33;
3772         Arrays.fill(CHARS, 2703, 2706, (byte) -19 ); // Fill 3 of value (byte) -19
3773
CHARS[2706] = 33;
3774         Arrays.fill(CHARS, 2707, 2729, (byte) -19 ); // Fill 22 of value (byte) -19
3775
CHARS[2729] = 33;
3776         Arrays.fill(CHARS, 2730, 2737, (byte) -19 ); // Fill 7 of value (byte) -19
3777
CHARS[2737] = 33;
3778         Arrays.fill(CHARS, 2738, 2740, (byte) -19 ); // Fill 2 of value (byte) -19
3779
CHARS[2740] = 33;
3780         Arrays.fill(CHARS, 2741, 2746, (byte) -19 ); // Fill 5 of value (byte) -19
3781
Arrays.fill(CHARS, 2746, 2748, (byte) 33 ); // Fill 2 of value (byte) 33
3782
CHARS[2748] = -87;
3783         CHARS[2749] = -19;
3784         Arrays.fill(CHARS, 2750, 2758, (byte) -87 ); // Fill 8 of value (byte) -87
3785
CHARS[2758] = 33;
3786         Arrays.fill(CHARS, 2759, 2762, (byte) -87 ); // Fill 3 of value (byte) -87
3787
CHARS[2762] = 33;
3788         Arrays.fill(CHARS, 2763, 2766, (byte) -87 ); // Fill 3 of value (byte) -87
3789
Arrays.fill(CHARS, 2766, 2784, (byte) 33 ); // Fill 18 of value (byte) 33
3790
CHARS[2784] = -19;
3791         Arrays.fill(CHARS, 2785, 2790, (byte) 33 ); // Fill 5 of value (byte) 33
3792
Arrays.fill(CHARS, 2790, 2800, (byte) -87 ); // Fill 10 of value (byte) -87
3793
Arrays.fill(CHARS, 2800, 2817, (byte) 33 ); // Fill 17 of value (byte) 33
3794
Arrays.fill(CHARS, 2817, 2820, (byte) -87 ); // Fill 3 of value (byte) -87
3795
CHARS[2820] = 33;
3796         Arrays.fill(CHARS, 2821, 2829, (byte) -19 ); // Fill 8 of value (byte) -19
3797
Arrays.fill(CHARS, 2829, 2831, (byte) 33 ); // Fill 2 of value (byte) 33
3798
Arrays.fill(CHARS, 2831, 2833, (byte) -19 ); // Fill 2 of value (byte) -19
3799
Arrays.fill(CHARS, 2833, 2835, (byte) 33 ); // Fill 2 of value (byte) 33
3800
Arrays.fill(CHARS, 2835, 2857, (byte) -19 ); // Fill 22 of value (byte) -19
3801
CHARS[2857] = 33;
3802         Arrays.fill(CHARS, 2858, 2865, (byte) -19 ); // Fill 7 of value (byte) -19
3803
CHARS[2865] = 33;
3804         Arrays.fill(CHARS, 2866, 2868, (byte) -19 ); // Fill 2 of value (byte) -19
3805
Arrays.fill(CHARS, 2868, 2870, (byte) 33 ); // Fill 2 of value (byte) 33
3806
Arrays.fill(CHARS, 2870, 2874, (byte) -19 ); // Fill 4 of value (byte) -19
3807
Arrays.fill(CHARS, 2874, 2876, (byte) 33 ); // Fill 2 of value (byte) 33
3808
CHARS[2876] = -87;
3809         CHARS[2877] = -19;
3810         Arrays.fill(CHARS, 2878, 2884, (byte) -87 ); // Fill 6 of value (byte) -87
3811
Arrays.fill(CHARS, 2884, 2887, (byte) 33 ); // Fill 3 of value (byte) 33
3812
Arrays.fill(CHARS, 2887, 2889, (byte) -87 ); // Fill 2 of value (byte) -87
3813
Arrays.fill(CHARS, 2889, 2891, (byte) 33 ); // Fill 2 of value (byte) 33
3814
Arrays.fill(CHARS, 2891, 2894, (byte) -87 ); // Fill 3 of value (byte) -87
3815
Arrays.fill(CHARS, 2894, 2902, (byte) 33 ); // Fill 8 of value (byte) 33
3816
Arrays.fill(CHARS, 2902, 2904, (byte) -87 ); // Fill 2 of value (byte) -87
3817
Arrays.fill(CHARS, 2904, 2908, (byte) 33 ); // Fill 4 of value (byte) 33
3818
Arrays.fill(CHARS, 2908, 2910, (byte) -19 ); // Fill 2 of value (byte) -19
3819
CHARS[2910] = 33;
3820         Arrays.fill(CHARS, 2911, 2914, (byte) -19 ); // Fill 3 of value (byte) -19
3821
Arrays.fill(CHARS, 2914, 2918, (byte) 33 ); // Fill 4 of value (byte) 33
3822
Arrays.fill(CHARS, 2918, 2928, (byte) -87 ); // Fill 10 of value (byte) -87
3823
Arrays.fill(CHARS, 2928, 2946, (byte) 33 ); // Fill 18 of value (byte) 33
3824
Arrays.fill(CHARS, 2946, 2948, (byte) -87 ); // Fill 2 of value (byte) -87
3825
CHARS[2948] = 33;
3826         Arrays.fill(CHARS, 2949, 2955, (byte) -19 ); // Fill 6 of value (byte) -19
3827
Arrays.fill(CHARS, 2955, 2958, (byte) 33 ); // Fill 3 of value (byte) 33
3828
Arrays.fill(CHARS, 2958, 2961, (byte) -19 ); // Fill 3 of value (byte) -19
3829
CHARS[2961] = 33;
3830         Arrays.fill(CHARS, 2962, 2966, (byte) -19 ); // Fill 4 of value (byte) -19
3831
Arrays.fill(CHARS, 2966, 2969, (byte) 33 ); // Fill 3 of value (byte) 33
3832
Arrays.fill(CHARS, 2969, 2971, (byte) -19 ); // Fill 2 of value (byte) -19
3833
CHARS[2971] = 33;
3834         CHARS[2972] = -19;
3835         CHARS[2973] = 33;
3836         Arrays.fill(CHARS, 2974, 2976, (byte) -19 ); // Fill 2 of value (byte) -19
3837
Arrays.fill(CHARS, 2976, 2979, (byte) 33 ); // Fill 3 of value (byte) 33
3838
Arrays.fill(CHARS, 2979, 2981, (byte) -19 ); // Fill 2 of value (byte) -19
3839
Arrays.fill(CHARS, 2981, 2984, (byte) 33 ); // Fill 3 of value (byte) 33
3840
Arrays.fill(CHARS, 2984, 2987, (byte) -19 ); // Fill 3 of value (byte) -19
3841
Arrays.fill(CHARS, 2987, 2990, (byte) 33 ); // Fill 3 of value (byte) 33
3842
Arrays.fill(CHARS, 2990, 2998, (byte) -19 ); // Fill 8 of value (byte) -19
3843
CHARS[2998] = 33;
3844         Arrays.fill(CHARS, 2999, 3002, (byte) -19 ); // Fill 3 of value (byte) -19
3845
Arrays.fill(CHARS, 3002, 3006, (byte) 33 ); // Fill 4 of value (byte) 33
3846
Arrays.fill(CHARS, 3006, 3011, (byte) -87 ); // Fill 5 of value (byte) -87
3847
Arrays.fill(CHARS, 3011, 3014, (byte) 33 ); // Fill 3 of value (byte) 33
3848
Arrays.fill(CHARS, 3014, 3017, (byte) -87 ); // Fill 3 of value (byte) -87
3849
CHARS[3017] = 33;
3850         Arrays.fill(CHARS, 3018, 3022, (byte) -87 ); // Fill 4 of value (byte) -87
3851
Arrays.fill(CHARS, 3022, 3031, (byte) 33 ); // Fill 9 of value (byte) 33
3852
CHARS[3031] = -87;
3853         Arrays.fill(CHARS, 3032, 3047, (byte) 33 ); // Fill 15 of value (byte) 33
3854
Arrays.fill(CHARS, 3047, 3056, (byte) -87 ); // Fill 9 of value (byte) -87
3855
Arrays.fill(CHARS, 3056, 3073, (byte) 33 ); // Fill 17 of value (byte) 33
3856
Arrays.fill(CHARS, 3073, 3076, (byte) -87 ); // Fill 3 of value (byte) -87
3857
CHARS[3076] = 33;
3858         Arrays.fill(CHARS, 3077, 3085, (byte) -19 ); // Fill 8 of value (byte) -19
3859
CHARS[3085] = 33;
3860         Arrays.fill(CHARS, 3086, 3089, (byte) -19 ); // Fill 3 of value (byte) -19
3861
CHARS[3089] = 33;
3862         Arrays.fill(CHARS, 3090, 3113, (byte) -19 ); // Fill 23 of value (byte) -19
3863
CHARS[3113] = 33;
3864         Arrays.fill(CHARS, 3114, 3124, (byte) -19 ); // Fill 10 of value (byte) -19
3865
CHARS[3124] = 33;
3866         Arrays.fill(CHARS, 3125, 3130, (byte) -19 ); // Fill 5 of value (byte) -19
3867
Arrays.fill(CHARS, 3130, 3134, (byte) 33 ); // Fill 4 of value (byte) 33
3868
Arrays.fill(CHARS, 3134, 3141, (byte) -87 ); // Fill 7 of value (byte) -87
3869
CHARS[3141] = 33;
3870         Arrays.fill(CHARS, 3142, 3145, (byte) -87 ); // Fill 3 of value (byte) -87
3871
CHARS[3145] = 33;
3872         Arrays.fill(CHARS, 3146, 3150, (byte) -87 ); // Fill 4 of value (byte) -87
3873
Arrays.fill(CHARS, 3150, 3157, (byte) 33 ); // Fill 7 of value (byte) 33
3874
Arrays.fill(CHARS, 3157, 3159, (byte) -87 ); // Fill 2 of value (byte) -87
3875
Arrays.fill(CHARS, 3159, 3168, (byte) 33 ); // Fill 9 of value (byte) 33
3876
Arrays.fill(CHARS, 3168, 3170, (byte) -19 ); // Fill 2 of value (byte) -19
3877
Arrays.fill(CHARS, 3170, 3174, (byte) 33 ); // Fill 4 of value (byte) 33
3878
Arrays.fill(CHARS, 3174, 3184, (byte) -87 ); // Fill 10 of value (byte) -87
3879
Arrays.fill(CHARS, 3184, 3202, (byte) 33 ); // Fill 18 of value (byte) 33
3880
Arrays.fill(CHARS, 3202, 3204, (byte) -87 ); // Fill 2 of value (byte) -87
3881
CHARS[3204] = 33;
3882         Arrays.fill(CHARS, 3205, 3213, (byte) -19 ); // Fill 8 of value (byte) -19
3883
CHARS[3213] = 33;
3884         Arrays.fill(CHARS, 3214, 3217, (byte) -19 ); // Fill 3 of value (byte) -19
3885
CHARS[3217] = 33;
3886         Arrays.fill(CHARS, 3218, 3241, (byte) -19 ); // Fill 23 of value (byte) -19
3887
CHARS[3241] = 33;
3888         Arrays.fill(CHARS, 3242, 3252, (byte) -19 ); // Fill 10 of value (byte) -19
3889
CHARS[3252] = 33;
3890         Arrays.fill(CHARS, 3253, 3258, (byte) -19 ); // Fill 5 of value (byte) -19
3891
Arrays.fill(CHARS, 3258, 3262, (byte) 33 ); // Fill 4 of value (byte) 33
3892
Arrays.fill(CHARS, 3262, 3269, (byte) -87 ); // Fill 7 of value (byte) -87
3893
CHARS[3269] = 33;
3894         Arrays.fill(CHARS, 3270, 3273, (byte) -87 ); // Fill 3 of value (byte) -87
3895
CHARS[3273] = 33;
3896         Arrays.fill(CHARS, 3274, 3278, (byte) -87 ); // Fill 4 of value (byte) -87
3897
Arrays.fill(CHARS, 3278, 3285, (byte) 33 ); // Fill 7 of value (byte) 33
3898
Arrays.fill(CHARS, 3285, 3287, (byte) -87 ); // Fill 2 of value (byte) -87
3899
Arrays.fill(CHARS, 3287, 3294, (byte) 33 ); // Fill 7 of value (byte) 33
3900
CHARS[3294] = -19;
3901         CHARS[3295] = 33;
3902         Arrays.fill(CHARS, 3296, 3298, (byte) -19 ); // Fill 2 of value (byte) -19
3903
Arrays.fill(CHARS, 3298, 3302, (byte) 33 ); // Fill 4 of value (byte) 33
3904
Arrays.fill(CHARS, 3302, 3312, (byte) -87 ); // Fill 10 of value (byte) -87
3905
Arrays.fill(CHARS, 3312, 3330, (byte) 33 ); // Fill 18 of value (byte) 33
3906
Arrays.fill(CHARS, 3330, 3332, (byte) -87 ); // Fill 2 of value (byte) -87
3907
CHARS[3332] = 33;
3908         Arrays.fill(CHARS, 3333, 3341, (byte) -19 ); // Fill 8 of value (byte) -19
3909
CHARS[3341] = 33;
3910         Arrays.fill(CHARS, 3342, 3345, (byte) -19 ); // Fill 3 of value (byte) -19
3911
CHARS[3345] = 33;
3912         Arrays.fill(CHARS, 3346, 3369, (byte) -19 ); // Fill 23 of value (byte) -19
3913
CHARS[3369] = 33;
3914         Arrays.fill(CHARS, 3370, 3386, (byte) -19 ); // Fill 16 of value (byte) -19
3915
Arrays.fill(CHARS, 3386, 3390, (byte) 33 ); // Fill 4 of value (byte) 33
3916
Arrays.fill(CHARS, 3390, 3396, (byte) -87 ); // Fill 6 of value (byte) -87
3917
Arrays.fill(CHARS, 3396, 3398, (byte) 33 ); // Fill 2 of value (byte) 33
3918
Arrays.fill(CHARS, 3398, 3401, (byte) -87 ); // Fill 3 of value (byte) -87
3919
CHARS[3401] = 33;
3920         Arrays.fill(CHARS, 3402, 3406, (byte) -87 ); // Fill 4 of value (byte) -87
3921
Arrays.fill(CHARS, 3406, 3415, (byte) 33 ); // Fill 9 of value (byte) 33
3922
CHARS[3415] = -87;
3923         Arrays.fill(CHARS, 3416, 3424, (byte) 33 ); // Fill 8 of value (byte) 33
3924
Arrays.fill(CHARS, 3424, 3426, (byte) -19 ); // Fill 2 of value (byte) -19
3925
Arrays.fill(CHARS, 3426, 3430, (byte) 33 ); // Fill 4 of value (byte) 33
3926
Arrays.fill(CHARS, 3430, 3440, (byte) -87 ); // Fill 10 of value (byte) -87
3927
Arrays.fill(CHARS, 3440, 3585, (byte) 33 ); // Fill 145 of value (byte) 33
3928
Arrays.fill(CHARS, 3585, 3631, (byte) -19 ); // Fill 46 of value (byte) -19
3929
CHARS[3631] = 33;
3930         CHARS[3632] = -19;
3931         CHARS[3633] = -87;
3932         Arrays.fill(CHARS, 3634, 3636, (byte) -19 ); // Fill 2 of value (byte) -19
3933
Arrays.fill(CHARS, 3636, 3643, (byte) -87 ); // Fill 7 of value (byte) -87
3934
Arrays.fill(CHARS, 3643, 3648, (byte) 33 ); // Fill 5 of value (byte) 33
3935
Arrays.fill(CHARS, 3648, 3654, (byte) -19 ); // Fill 6 of value (byte) -19
3936
Arrays.fill(CHARS, 3654, 3663, (byte) -87 ); // Fill 9 of value (byte) -87
3937
CHARS[3663] = 33;
3938         Arrays.fill(CHARS, 3664, 3674, (byte) -87 ); // Fill 10 of value (byte) -87
3939
Arrays.fill(CHARS, 3674, 3713, (byte) 33 ); // Fill 39 of value (byte) 33
3940
Arrays.fill(CHARS, 3713, 3715, (byte) -19 ); // Fill 2 of value (byte) -19
3941
CHARS[3715] = 33;
3942         CHARS[3716] = -19;
3943         Arrays.fill(CHARS, 3717, 3719, (byte) 33 ); // Fill 2 of value (byte) 33
3944
Arrays.fill(CHARS, 3719, 3721, (byte) -19 ); // Fill 2 of value (byte) -19
3945
CHARS[3721] = 33;
3946         CHARS[3722] = -19;
3947         Arrays.fill(CHARS, 3723, 3725, (byte) 33 ); // Fill 2 of value (byte) 33
3948
CHARS[3725] = -19;
3949         Arrays.fill(CHARS, 3726, 3732, (byte) 33 ); // Fill 6 of value (byte) 33
3950
Arrays.fill(CHARS, 3732, 3736, (byte) -19 ); // Fill 4 of value (byte) -19
3951
CHARS[3736] = 33;
3952         Arrays.fill(CHARS, 3737, 3744, (byte) -19 ); // Fill 7 of value (byte) -19
3953
CHARS[3744] = 33;
3954         Arrays.fill(CHARS, 3745, 3748, (byte) -19 ); // Fill 3 of value (byte) -19
3955
CHARS[3748] = 33;
3956         CHARS[3749] = -19;
3957         CHARS[3750] = 33;
3958         CHARS[3751] = -19;
3959         Arrays.fill(CHARS, 3752, 3754, (byte) 33 ); // Fill 2 of value (byte) 33
3960
Arrays.fill(CHARS, 3754, 3756, (byte) -19 ); // Fill 2 of value (byte) -19
3961
CHARS[3756] = 33;
3962         Arrays.fill(CHARS, 3757, 3759, (byte) -19 ); // Fill 2 of value (byte) -19
3963
CHARS[3759] = 33;
3964         CHARS[3760] = -19;
3965         CHARS[3761] = -87;
3966         Arrays.fill(CHARS, 3762, 3764, (byte) -19 ); // Fill 2 of value (byte) -19
3967
Arrays.fill(CHARS, 3764, 3770, (byte) -87 ); // Fill 6 of value (byte) -87
3968
CHARS[3770] = 33;
3969         Arrays.fill(CHARS, 3771, 3773, (byte) -87 ); // Fill 2 of value (byte) -87
3970
CHARS[3773] = -19;
3971         Arrays.fill(CHARS, 3774, 3776, (byte) 33 ); // Fill 2 of value (byte) 33
3972
Arrays.fill(CHARS, 3776, 3781, (byte) -19 ); // Fill 5 of value (byte) -19
3973
CHARS[3781] = 33;
3974         CHARS[3782] = -87;
3975         CHARS[3783] = 33;
3976         Arrays.fill(CHARS, 3784, 3790, (byte) -87 ); // Fill 6 of value (byte) -87
3977
Arrays.fill(CHARS, 3790, 3792, (byte) 33 ); // Fill 2 of value (byte) 33
3978
Arrays.fill(CHARS, 3792, 3802, (byte) -87 ); // Fill 10 of value (byte) -87
3979
Arrays.fill(CHARS, 3802, 3864, (byte) 33 ); // Fill 62 of value (byte) 33
3980
Arrays.fill(CHARS, 3864, 3866, (byte) -87 ); // Fill 2 of value (byte) -87
3981
Arrays.fill(CHARS, 3866, 3872, (byte) 33 ); // Fill 6 of value (byte) 33
3982
Arrays.fill(CHARS, 3872, 3882, (byte) -87 ); // Fill 10 of value (byte) -87
3983
Arrays.fill(CHARS, 3882, 3893, (byte) 33 ); // Fill 11 of value (byte) 33
3984
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 ); // Fill 4 of value (byte) 33
3990
Arrays.fill(CHARS, 3902, 3904, (byte) -87 ); // Fill 2 of value (byte) -87
3991
Arrays.fill(CHARS, 3904, 3912, (byte) -19 ); // Fill 8 of value (byte) -19
3992
CHARS[3912] = 33;
3993         Arrays.fill(CHARS, 3913, 3946, (byte) -19 ); // Fill 33 of value (byte) -19
3994
Arrays.fill(CHARS, 3946, 3953, (byte) 33 ); // Fill 7 of value (byte) 33
3995
Arrays.fill(CHARS, 3953, 3973, (byte) -87 ); // Fill 20 of value (byte) -87
3996
CHARS[3973] = 33;
3997         Arrays.fill(CHARS, 3974, 3980, (byte) -87 ); // Fill 6 of value (byte) -87
3998
Arrays.fill(CHARS, 3980, 3984, (byte) 33 ); // Fill 4 of value (byte) 33
3999
Arrays.fill(CHARS, 3984, 3990, (byte) -87 ); // Fill 6 of value (byte) -87
4000
CHARS[3990] = 33;
4001         CHARS[3991] = -87;
4002         CHARS[3992] = 33;
4003         Arrays.fill(CHARS, 3993, 4014, (byte) -87 ); // Fill 21 of value (byte) -87
4004
Arrays.fill(CHARS, 4014, 4017, (byte) 33 ); // Fill 3 of value (byte) 33
4005
Arrays.fill(CHARS, 4017, 4024, (byte) -87 ); // Fill 7 of value (byte) -87
4006
CHARS[4024] = 33;
4007         CHARS[4025] = -87;
4008         Arrays.fill(CHARS, 4026, 4256, (byte) 33 ); // Fill 230 of value (byte) 33
4009
Arrays.fill(CHARS, 4256, 4294, (byte) -19 ); // Fill 38 of value (byte) -19
4010
Arrays.fill(CHARS, 4294, 4304, (byte) 33 ); // Fill 10 of value (byte) 33
4011
Arrays.fill(CHARS, 4304, 4343, (byte) -19 ); // Fill 39 of value (byte) -19
4012
Arrays.fill(CHARS, 4343, 4352, (byte) 33 ); // Fill 9 of value (byte) 33
4013
CHARS[4352] = -19;
4014         CHARS[4353] = 33;
4015         Arrays.fill(CHARS, 4354, 4356, (byte) -19 ); // Fill 2 of value (byte) -19
4016
CHARS[4356] = 33;
4017         Arrays.fill(CHARS, 4357, 4360, (byte) -19 ); // Fill 3 of value (byte) -19
4018
CHARS[4360] = 33;
4019         CHARS[4361] = -19;
4020         CHARS[4362] = 33;
4021         Arrays.fill(CHARS, 4363, 4365, (byte) -19 ); // Fill 2 of value (byte) -19
4022
CHARS[4365] = 33;
4023         Arrays.fill(CHARS, 4366, 4371, (byte) -19 ); // Fill 5 of value (byte) -19
4024
Arrays.fill(CHARS, 4371, 4412, (byte) 33 ); // Fill 41 of value (byte) 33
4025
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 ); // Fill 11 of value (byte) 33
4031
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 ); // Fill 3 of value (byte) 33
4037
Arrays.fill(CHARS, 4436, 4438, (byte) -19 ); // Fill 2 of value (byte) -19
4038
Arrays.fill(CHARS, 4438, 4441, (byte) 33 ); // Fill 3 of value (byte) 33
4039
CHARS[4441] = -19;
4040         Arrays.fill(CHARS, 4442, 4447, (byte) 33 ); // Fill 5 of value (byte) 33
4041
Arrays.fill(CHARS, 4447, 4450, (byte) -19 ); // Fill 3 of value (byte) -19
4042
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 ); // Fill 3 of value (byte) 33
4051
Arrays.fill(CHARS, 4461, 4463, (byte) -19 ); // Fill 2 of value (byte) -19
4052
Arrays.fill(CHARS, 4463, 4466, (byte) 33 ); // Fill 3 of value (byte) 33
4053
Arrays.fill(CHARS, 4466, 4468, (byte) -19 ); // Fill 2 of value (byte) -19
4054
CHARS[4468] = 33;
4055         CHARS[4469] = -19;
4056         Arrays.fill(CHARS, 4470, 4510, (byte) 33 ); // Fill 40 of value (byte) 33
4057
CHARS[4510] = -19;
4058         Arrays.fill(CHARS, 4511, 4520, (byte) 33 ); // Fill 9 of value (byte) 33
4059
CHARS[4520] = -19;
4060         Arrays.fill(CHARS, 4521, 4523, (byte) 33 ); // Fill 2 of value (byte) 33
4061
CHARS[4523] = -19;
4062         Arrays.fill(CHARS, 4524, 4526, (byte) 33 ); // Fill 2 of value (byte) 33
4063
Arrays.fill(CHARS, 4526, 4528, (byte) -19 ); // Fill 2 of value (byte) -19
4064
Arrays.fill(CHARS, 4528, 4535, (byte) 33 ); // Fill 7 of value (byte) 33
4065
Arrays.fill(CHARS, 4535, 4537, (byte) -19 ); // Fill 2 of value (byte) -19
4066
CHARS[4537] = 33;
4067         CHARS[4538] = -19;
4068         CHARS[4539] = 33;
4069         Arrays.fill(CHARS, 4540, 4547, (byte) -19 ); // Fill 7 of value (byte) -19
4070
Arrays.fill(CHARS, 4547, 4587, (byte) 33 ); // Fill 40 of value (byte) 33
4071
CHARS[4587] = -19;
4072         Arrays.fill(CHARS, 4588, 4592, (byte) 33 ); // Fill 4 of value (byte) 33
4073
CHARS[4592] = -19;
4074         Arrays.fill(CHARS, 4593, 4601, (byte) 33 ); // Fill 8 of value (byte) 33
4075
CHARS[4601] = -19;
4076         Arrays.fill(CHARS, 4602, 7680, (byte) 33 ); // Fill 3078 of value (byte) 33
4077
Arrays.fill(CHARS, 7680, 7836, (byte) -19 ); // Fill 156 of value (byte) -19
4078
Arrays.fill(CHARS, 7836, 7840, (byte) 33 ); // Fill 4 of value (byte) 33
4079
Arrays.fill(CHARS, 7840, 7930, (byte) -19 ); // Fill 90 of value (byte) -19
4080
Arrays.fill(CHARS, 7930, 7936, (byte) 33 ); // Fill 6 of value (byte) 33
4081
Arrays.fill(CHARS, 7936, 7958, (byte) -19 ); // Fill 22 of value (byte) -19
4082
Arrays.fill(CHARS, 7958, 7960, (byte) 33 ); // Fill 2 of value (byte) 33
4083
Arrays.fill(CHARS, 7960, 7966, (byte) -19 ); // Fill 6 of value (byte) -19
4084
Arrays.fill(CHARS, 7966, 7968, (byte) 33 ); // Fill 2 of value (byte) 33
4085
Arrays.fill(CHARS, 7968, 8006, (byte) -19 ); // Fill 38 of value (byte) -19
4086
Arrays.fill(CHARS, 8006, 8008, (byte) 33 ); // Fill 2 of value (byte) 33
4087
Arrays.fill(CHARS, 8008, 8014, (byte) -19 ); // Fill 6 of value (byte) -19
4088
Arrays.fill(CHARS, 8014, 8016, (byte) 33 ); // Fill 2 of value (byte) 33
4089
Arrays.fill(CHARS, 8016, 8024, (byte) -19 ); // Fill 8 of value (byte) -19
4090
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 ); // Fill 31 of value (byte) -19
4098
Arrays.fill(CHARS, 8062, 8064, (byte) 33 ); // Fill 2 of value (byte) 33
4099
Arrays.fill(CHARS, 8064, 8117, (byte) -19 ); // Fill 53 of value (byte) -19
4100
CHARS[8117] = 33;
4101         Arrays.fill(CHARS, 8118, 8125, (byte) -19 ); // Fill 7 of value (byte) -19
4102
CHARS[8125] = 33;
4103         CHARS[8126] = -19;
4104         Arrays.fill(CHARS, 8127, 8130, (byte) 33 ); // Fill 3 of value (byte) 33
4105
Arrays.fill(CHARS, 8130, 8133, (byte) -19 ); // Fill 3 of value (byte) -19
4106
CHARS[8133] = 33;
4107         Arrays.fill(CHARS, 8134, 8141, (byte) -19 ); // Fill 7 of value (byte) -19
4108
Arrays.fill(CHARS, 8141, 8144, (byte) 33 ); // Fill 3 of value (byte) 33
4109
Arrays.fill(CHARS, 8144, 8148, (byte) -19 ); // Fill 4 of value (byte) -19
4110
Arrays.fill(CHARS, 8148, 8150, (byte) 33 ); // Fill 2 of value (byte) 33
4111
Arrays.fill(CHARS, 8150, 8156, (byte) -19 ); // Fill 6 of value (byte) -19
4112
Arrays.fill(CHARS, 8156, 8160, (byte) 33 ); // Fill 4 of value (byte) 33
4113
Arrays.fill(CHARS, 8160, 8173, (byte) -19 ); // Fill 13 of value (byte) -19
4114
Arrays.fill(CHARS, 8173, 8178, (byte) 33 ); // Fill 5 of value (byte) 33
4115
Arrays.fill(CHARS, 8178, 8181, (byte) -19 ); // Fill 3 of value (byte) -19
4116
CHARS[8181] = 33;
4117         Arrays.fill(CHARS, 8182, 8189, (byte) -19 ); // Fill 7 of value (byte) -19
4118
Arrays.fill(CHARS, 8189, 8400, (byte) 33 ); // Fill 211 of value (byte) 33
4119
Arrays.fill(CHARS, 8400, 8413, (byte) -87 ); // Fill 13 of value (byte) -87
4120
Arrays.fill(CHARS, 8413, 8417, (byte) 33 ); // Fill 4 of value (byte) 33
4121
CHARS[8417] = -87;
4122         Arrays.fill(CHARS, 8418, 8486, (byte) 33 ); // Fill 68 of value (byte) 33
4123
CHARS[8486] = -19;
4124         Arrays.fill(CHARS, 8487, 8490, (byte) 33 ); // Fill 3 of value (byte) 33
4125
Arrays.fill(CHARS, 8490, 8492, (byte) -19 ); // Fill 2 of value (byte) -19
4126
Arrays.fill(CHARS, 8492, 8494, (byte) 33 ); // Fill 2 of value (byte) 33
4127
CHARS[8494] = -19;
4128         Arrays.fill(CHARS, 8495, 8576, (byte) 33 ); // Fill 81 of value (byte) 33
4129
Arrays.fill(CHARS, 8576, 8579, (byte) -19 ); // Fill 3 of value (byte) -19
4130
Arrays.fill(CHARS, 8579, 12293, (byte) 33 ); // Fill 3714 of value (byte) 33
4131
CHARS[12293] = -87;
4132         CHARS[12294] = 33;
4133         CHARS[12295] = -19;
4134         Arrays.fill(CHARS, 12296, 12321, (byte) 33 ); // Fill 25 of value (byte) 33
4135
Arrays.fill(CHARS, 12321, 12330, (byte) -19 ); // Fill 9 of value (byte) -19
4136
Arrays.fill(CHARS, 12330, 12336, (byte) -87 ); // Fill 6 of value (byte) -87
4137
CHARS[12336] = 33;
4138         Arrays.fill(CHARS, 12337, 12342, (byte) -87 ); // Fill 5 of value (byte) -87
4139
Arrays.fill(CHARS, 12342, 12353, (byte) 33 ); // Fill 11 of value (byte) 33
4140
Arrays.fill(CHARS, 12353, 12437, (byte) -19 ); // Fill 84 of value (byte) -19
4141
Arrays.fill(CHARS, 12437, 12441, (byte) 33 ); // Fill 4 of value (byte) 33
4142
Arrays.fill(CHARS, 12441, 12443, (byte) -87 ); // Fill 2 of value (byte) -87
4143
Arrays.fill(CHARS, 12443, 12445, (byte) 33 ); // Fill 2 of value (byte) 33
4144
Arrays.fill(CHARS, 12445, 12447, (byte) -87 ); // Fill 2 of value (byte) -87
4145
Arrays.fill(CHARS, 12447, 12449, (byte) 33 ); // Fill 2 of value (byte) 33
4146
Arrays.fill(CHARS, 12449, 12539, (byte) -19 ); // Fill 90 of value (byte) -19
4147
CHARS[12539] = 33;
4148         Arrays.fill(CHARS, 12540, 12543, (byte) -87 ); // Fill 3 of value (byte) -87
4149
Arrays.fill(CHARS, 12543, 12549, (byte) 33 ); // Fill 6 of value (byte) 33
4150
Arrays.fill(CHARS, 12549, 12589, (byte) -19 ); // Fill 40 of value (byte) -19
4151
Arrays.fill(CHARS, 12589, 19968, (byte) 33 ); // Fill 7379 of value (byte) 33
4152
Arrays.fill(CHARS, 19968, 40870, (byte) -19 ); // Fill 20902 of value (byte) -19
4153
Arrays.fill(CHARS, 40870, 44032, (byte) 33 ); // Fill 3162 of value (byte) 33
4154
Arrays.fill(CHARS, 44032, 55204, (byte) -19 ); // Fill 11172 of value (byte) -19
4155
Arrays.fill(CHARS, 55204, 55296, (byte) 33 ); // Fill 92 of value (byte) 33
4156
Arrays.fill(CHARS, 57344, 65534, (byte) 33 ); // Fill 8190 of value (byte) 33
4157

4158     } // <clinit>()
4159

4160     //
4161
// Public static methods
4162
//
4163

4164     /**
4165      * Returns true if the specified character is a supplemental character.
4166      *
4167      * @param c The character to check.
4168      */

4169     public static boolean isSupplemental(int c) {
4170         return (c >= 0x10000 && c <= 0x10FFFF);
4171     }
4172
4173     /**
4174      * Returns true the supplemental character corresponding to the given
4175      * surrogates.
4176      *
4177      * @param h The high surrogate.
4178      * @param l The low surrogate.
4179      */

4180     public static int supplemental(char h, char l) {
4181         return (h - 0xD800) * 0x400 + (l - 0xDC00) + 0x10000;
4182     }
4183
4184     /**
4185      * Returns the high surrogate of a supplemental character
4186      *
4187      * @param c The supplemental character to "split".
4188      */

4189     public static char highSurrogate(int c) {
4190         return (char) (((c - 0x00010000) >> 10) + 0xD800);
4191     }
4192
4193     /**
4194      * Returns the low surrogate of a supplemental character
4195      *
4196      * @param c The supplemental character to "split".
4197      */

4198     public static char lowSurrogate(int c) {
4199         return (char) (((c - 0x00010000) & 0x3FF) + 0xDC00);
4200     }
4201
4202     /**
4203      * Returns whether the given character is a high surrogate
4204      *
4205      * @param c The character to check.
4206      */

4207     public static boolean isHighSurrogate(int c) {
4208         return (0xD800 <= c && c <= 0xDBFF);
4209     }
4210
4211     /**
4212      * Returns whether the given character is a low surrogate
4213      *
4214      * @param c The character to check.
4215      */

4216     public static boolean isLowSurrogate(int c) {
4217         return (0xDC00 <= c && c <= 0xDFFF);
4218     }
4219
4220
4221     /**
4222      * Returns true if the specified character is valid. This method
4223      * also checks the surrogate character range from 0x10000 to 0x10FFFF.
4224      * <p>
4225      * If the program chooses to apply the mask directly to the
4226      * <code>CHARS</code> array, then they are responsible for checking
4227      * the surrogate character range.
4228      *
4229      * @param c The character to check.
4230      */

4231     public static boolean isValid(int c) {
4232         return (c < 0x10000 && (CHARS[c] & MASK_VALID) != 0) ||
4233                (0x10000 <= c && c <= 0x10FFFF);
4234     } // isValid(int):boolean
4235

4236     /**
4237      * Returns true if the specified character is invalid.
4238      *
4239      * @param c The character to check.
4240      */

4241     public static boolean isInvalid(int c) {
4242         return !isValid(c);
4243     } // isInvalid(int):boolean
4244

4245     /**
4246      * Returns true if the specified character can be considered content.
4247      *
4248      * @param c The character to check.
4249      */

4250     public static boolean isContent(int c) {
4251         return (c < 0x10000 && (CHARS[c] & MASK_CONTENT) != 0) ||
4252                (0x10000 <= c && c <= 0x10FFFF);
4253     } // isContent(int):boolean
4254

4255     /**
4256      * Returns true if the specified character can be considered markup.
4257      * Markup characters include '&lt;', '&amp;', and '%'.
4258      *
4259      * @param c The character to check.
4260      */

4261     public static boolean isMarkup(int c) {
4262         return c == '<' || c == '&' || c == '%';
4263     } // isMarkup(int):boolean
4264

4265     /**
4266      * Returns true if the specified character is a space character
4267      * as defined by production [3] in the XML 1.0 specification.
4268      *
4269      * @param c The character to check.
4270      */

4271     public static boolean isSpace(int c) {
4272         return c <= 0x20 && (CHARS[c] & MASK_SPACE) != 0;
4273     } // isSpace(int):boolean
4274

4275     /**
4276      * Returns true if the specified character is a valid name start
4277      * character as defined by production [5] in the XML 1.0
4278      * specification.
4279      *
4280      * @param c The character to check.
4281      */

4282     public static boolean isNameStart(int c) {
4283         return c < 0x10000 && (CHARS[c] & MASK_NAME_START) != 0;
4284     } // isNameStart(int):boolean
4285

4286     /**
4287      * Returns true if the specified character is a valid name
4288      * character as defined by production [4] in the XML 1.0
4289      * specification.
4290      *
4291      * @param c The character to check.
4292      */

4293     public static boolean isName(int c) {
4294         return c < 0x10000 && (CHARS[c] & MASK_NAME) != 0;
4295     } // isName(int):boolean
4296

4297     /**
4298      * Returns true if the specified character is a valid NCName start
4299      * character as defined by production [4] in Namespaces in XML
4300      * recommendation.
4301      *
4302      * @param c The character to check.
4303      */

4304     public static boolean isNCNameStart(int c) {
4305         return c < 0x10000 && (CHARS[c] & MASK_NCNAME_START) != 0;
4306     } // isNCNameStart(int):boolean
4307

4308     /**
4309      * Returns true if the specified character is a valid NCName
4310      * character as defined by production [5] in Namespaces in XML
4311      * recommendation.
4312      *
4313      * @param c The character to check.
4314      */

4315     public static boolean isNCName(int c) {
4316         return c < 0x10000 && (CHARS[c] & MASK_NCNAME) != 0;
4317     } // isNCName(int):boolean
4318

4319     /**
4320      * Returns true if the specified character is a valid Pubid
4321      * character as defined by production [13] in the XML 1.0
4322      * specification.
4323      *
4324      * @param c The character to check.
4325      */

4326     public static boolean isPubid(int c) {
4327         return c < 0x10000 && (CHARS[c] & MASK_PUBID) != 0;
4328     } // isPubid(int):boolean
4329

4330     /*
4331      * [5] Name ::= (Letter | '_' | ':') (NameChar)*
4332      */

4333     /**
4334      * Check to see if a string is a valid Name according to [5]
4335      * in the XML 1.0 Recommendation
4336      *
4337      * @param name string to check
4338      * @return true if name is a valid Name
4339      */

4340     public static boolean isValidName(String JavaDoc 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     } // isValidName(String):boolean
4354

4355
4356     /*
4357      * from the namespace rec
4358      * [4] NCName ::= (Letter | '_') (NCNameChar)*
4359      */

4360     /**
4361      * Check to see if a string is a valid NCName according to [4]
4362      * from the XML Namespaces 1.0 Recommendation
4363      *
4364      * @param ncName string to check
4365      * @return true if name is a valid NCName
4366      */

4367     public static boolean isValidNCName(String JavaDoc 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     } // isValidNCName(String):boolean
4381

4382     /*
4383      * [7] Nmtoken ::= (NameChar)+
4384      */

4385     /**
4386      * Check to see if a string is a valid Nmtoken according to [7]
4387      * in the XML 1.0 Recommendation
4388      *
4389      * @param nmtoken string to check
4390      * @return true if nmtoken is a valid Nmtoken
4391      */

4392     public static boolean isValidNmtoken(String JavaDoc 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     } // isValidName(String):boolean
4403

4404
4405
4406
4407
4408     // encodings
4409

4410     /**
4411      * Returns true if the encoding name is a valid IANA encoding.
4412      * This method does not verify that there is a decoder available
4413      * for this encoding, only that the characters are valid for an
4414      * IANA encoding name.
4415      *
4416      * @param ianaEncoding The IANA encoding name.
4417      */

4418     public static boolean isValidIANAEncoding(String JavaDoc 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     } // isValidIANAEncoding(String):boolean
4438

4439     /**
4440      * Returns true if the encoding name is a valid Java encoding.
4441      * This method does not verify that there is a decoder available
4442      * for this encoding, only that the characters are valid for an
4443      * Java encoding name.
4444      *
4445      * @param javaEncoding The Java encoding name.
4446      */

4447     public static boolean isValidJavaEncoding(String JavaDoc 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     } // isValidIANAEncoding(String):boolean
4464

4465
4466 } // class XMLChar
4467

4468 public static class TypeValidator {
4469
4470   //order constants
4471
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   // check whether the character is in the range 0x30 ~ 0x39
4478
public static final boolean isDigit(char ch) {
4479       return ch >= '0' && ch <= '9';
4480   }
4481   
4482   // if the character is in the range 0x30 ~ 0x39, return its int value (0~9),
4483
// otherwise, return -1
4484
public static final int getDigit(char ch) {
4485       return isDigit(ch) ? ch - '0' : -1;
4486   }
4487   
4488} // interface TypeValidator
4489

4490}
4491
Popular Tags