KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > xml > fastinfoset > EncodingConstants


1 /*
2  * Fast Infoset ver. 0.1 software ("Software")
3  *
4  * Copyright, 2004-2005 Sun Microsystems, Inc. All Rights Reserved.
5  *
6  * Software is licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License. You may
8  * obtain a copy of the License at:
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
15  * License for the specific language governing permissions and limitations.
16  *
17  * Sun supports and benefits from the global community of open source
18  * developers, and thanks the community for its important contributions and
19  * open standards-based technology, which Sun has adopted into many of its
20  * products.
21  *
22  * Please note that portions of Software may be provided with notices and
23  * open source licenses from such communities and third parties that govern the
24  * use of those portions, and any licenses granted hereunder do not alter any
25  * rights and obligations you may have under such open source licenses,
26  * however, the disclaimer of warranty and limitation of liability provisions
27  * in this License will apply to all Software in this distribution.
28  *
29  * You acknowledge that the Software is not designed, licensed or intended
30  * for use in the design, construction, operation or maintenance of any nuclear
31  * facility.
32  *
33  * Apache License
34  * Version 2.0, January 2004
35  * http://www.apache.org/licenses/
36  *
37  */

38
39
40 package com.sun.xml.fastinfoset;
41
42 import java.io.UnsupportedEncodingException JavaDoc;
43 import org.jvnet.fastinfoset.RestrictedAlphabet;
44
45 public final class EncodingConstants {
46     static {
47         initiateCharacterTables();
48         initiateXMLDeclarationValues();
49     }
50     
51     public static final String JavaDoc XML_NAMESPACE_PREFIX = "xml";
52     public static final int XML_NAMESPACE_PREFIX_LENGTH = XML_NAMESPACE_PREFIX.length();
53     public static final String JavaDoc XML_NAMESPACE_NAME = "http://www.w3.org/XML/1998/namespace";
54     public static final int XML_NAMESPACE_NAME_LENGTH = XML_NAMESPACE_NAME.length();
55     public static final char[] XML_NAMESPACE_NAME_CHARS = XML_NAMESPACE_NAME.toCharArray();
56             
57     public static final String JavaDoc XMLNS_NAMESPACE_PREFIX = "xmlns";
58     public static final int XMLNS_NAMESPACE_PREFIX_LENGTH = XMLNS_NAMESPACE_PREFIX.length();
59     public static final char[] XMLNS_NAMESPACE_PREFIX_CHARS = XMLNS_NAMESPACE_PREFIX.toCharArray();
60     public static final String JavaDoc XMLNS_NAMESPACE_NAME = "http://www.w3.org/2000/xmlns/";
61     public static final int XMLNS_NAMESPACE_NAME_LENGTH = XMLNS_NAMESPACE_NAME.length();
62     public static final char[] XMLNS_NAMESPACE_NAME_CHARS = XMLNS_NAMESPACE_NAME.toCharArray();
63     
64     public static final int DOCUMENT_ADDITIONAL_DATA_FLAG = 0x40; // 01000000
65
public static final int DOCUMENT_INITIAL_VOCABULARY_FLAG = 0x20; // 00100000
66
public static final int DOCUMENT_NOTATIONS_FLAG = 0x10; // 00010000
67
public static final int DOCUMENT_UNPARSED_ENTITIES_FLAG = 0x08; // 00001000
68
public static final int DOCUMENT_CHARACTER_ENCODING_SCHEME = 0x04; // 00000100
69
public static final int DOCUMENT_STANDALONE_FLAG = 0x02; // 00000010
70
public static final int DOCUMENT_VERSION_FLAG = 0x01; // 00000001
71

72     public static final int INITIAL_VOCABULARY_EXTERNAL_VOCABULARY_FLAG = 0x10; // 00010000
73
public static final int INITIAL_VOCABULARY_RESTRICTED_ALPHABETS_FLAG = 0x08; // 00001000
74
public static final int INITIAL_VOCABULARY_ENCODING_ALGORITHMS_FLAG = 0x04; // 00000100
75
public static final int INITIAL_VOCABULARY_PREFIXES_FLAG = 0x02; // 00000010
76
public static final int INITIAL_VOCABULARY_NAMESPACE_NAMES_FLAG = 0x01; // 00000001
77
public static final int INITIAL_VOCABULARY_LOCAL_NAMES_FLAG = 0x80; // 1000000
78
public static final int INITIAL_VOCABULARY_OTHER_NCNAMES_FLAG = 0x40; // 01000000
79
public static final int INITIAL_VOCABULARY_OTHER_URIS_FLAG = 0x20; // 00100000
80
public static final int INITIAL_VOCABULARY_ATTRIBUTE_VALUES_FLAG = 0x10; // 00010000
81
public static final int INITIAL_VOCABULARY_CONTENT_CHARACTER_CHUNKS_FLAG = 0x08; // 00001000
82
public static final int INITIAL_VOCABULARY_OTHER_STRINGS_FLAG = 0x04; // 00000100
83
public static final int INITIAL_VOCABULARY_ELEMENT_NAME_SURROGATES_FLAG = 0x02; // 0000010
84
public static final int INITIAL_VOCABULARY_ATTRIBUTE_NAME_SURROGATES_FLAG = 0x01; // 00000001
85

86     public static final int NAME_SURROGATE_PREFIX_FLAG = 0x02;
87     public static final int NAME_SURROGATE_NAME_FLAG = 0x01;
88     
89     public static final int NOTATIONS = 0xC0; // 110000
90
public static final int NOTATIONS_MASK = 0xFC; // 6 bits
91
public static final int NOTATIONS_SYSTEM_IDENTIFIER_FLAG = 0x02;
92     public static final int NOTATIONS_PUBLIC_IDENTIFIER_FLAG = 0x01;
93     
94     public static final int UNPARSED_ENTITIES = 0xD0; // 1101000
95
public static final int UNPARSED_ENTITIES_MASK = 0xFE; // 7 bits
96
public static final int UNPARSED_ENTITIES_PUBLIC_IDENTIFIER_FLAG = 0x01;
97     
98     public static final int PROCESSING_INSTRUCTION = 0xE1; // 11100001
99
public static final int PROCESSING_INSTRUCTION_MASK = 0xFF; // 8 bits
100

101     public static final int COMMENT = 0xE2; // 11100010
102
public static final int COMMENT_MASK = 0xFF; // 8 bits
103

104     public static final int DOCUMENT_TYPE_DECLARATION = 0xC4; // 110001
105
public static final int DOCUMENT_TYPE_DECLARATION_MASK = 0xFC; // 6 bits
106
public static final int DOCUMENT_TYPE_SYSTEM_IDENTIFIER_FLAG = 0x02;
107     public static final int DOCUMENT_TYPE_PUBLIC_IDENTIFIER_FLAG = 0x01;
108     
109     public static final int ELEMENT = 0x00; // 0
110
public static final int ELEMENT_ATTRIBUTE_FLAG = 0x40; // 01000000
111
public static final int ELEMENT_NAMESPACES_FLAG = 0x38; // 00111000
112
public static final int ELEMENT_LITERAL_QNAME_FLAG = 0x3C; // 00111100
113

114     public static final int NAMESPACE_ATTRIBUTE = 0xCC; // 110011 00
115
public static final int NAMESPACE_ATTRIBUTE_MASK = 0xFC; // 6 bits
116
public static final int NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK = 0x03; // 2 bits
117
public static final int NAMESPACE_ATTRIBUTE_PREFIX_FLAG = 0x02;
118     public static final int NAMESPACE_ATTRIBUTE_NAME_FLAG = 0x01;
119     
120     public static final int ATTRIBUTE_LITERAL_QNAME_FLAG = 0x78; // 01111000
121

122     public static final int LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK = 0x03;
123     public static final int LITERAL_QNAME_PREFIX_FLAG = 0x02;
124     public static final int LITERAL_QNAME_NAMESPACE_NAME_FLAG = 0x01;
125
126     public static final int CHARACTER_CHUNK = 0x80; // 10
127
public static final int CHARACTER_CHUNK_ADD_TO_TABLE_FLAG = 0x10; // 00010000
128
public static final int CHARACTER_CHUNK_UTF_8_FLAG = 0x00; // 00000000
129
public static final int CHARACTER_CHUNK_UTF_16_FLAG = 0x04; // 00000100
130
public static final int CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG = 0x08; // 00001000
131
public static final int CHARACTER_CHUNK_ENCODING_ALGORITHM_FLAG = 0x0C; // 00001100
132

133     public static final int UNEXPANDED_ENTITY_REFERENCE = 0xC8; // 110010
134
public static final int UNEXPANDED_ENTITY_REFERENCE_MASK = 0xFC; // 6 bits
135
public static final int UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG = 0x02;
136     public static final int UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG = 0x01;
137     
138     public static final int NISTRING_ADD_TO_TABLE_FLAG = 0x40; // 01000000
139
public static final int NISTRING_UTF_8_FLAG = 0x00; // 00000000
140
public static final int NISTRING_UTF_16_FLAG = 0x10; // 00010000
141
public static final int NISTRING_RESTRICTED_ALPHABET_FLAG = 0x20; // 00100000
142
public static final int NISTRING_ENCODING_ALGORITHM_FLAG = 0x30; // 00110000
143

144     public static final int TERMINATOR = 0xF0;
145     public static final int DOUBLE_TERMINATOR = 0xFF;
146
147     
148     public static final int ENCODING_ALGORITHM_BUILTIN_END = 9;
149     public static final int ENCODING_ALGORITHM_APPLICATION_START = 32;
150     public static final int ENCODING_ALGORITHM_APPLICATION_MAX = 255;
151     
152     public static final int RESTRICTED_ALPHABET_BUILTIN_END = 1;
153     public static final int RESTRICTED_ALPHABET_APPLICATION_START = 32;
154     public static final int RESTRICTED_ALPHABET_APPLICATION_MAX = 255;
155     
156     // Octet string length contants
157

158     public static final int OCTET_STRING_LENGTH_SMALL_LIMIT = 0;
159     public static final int OCTET_STRING_LENGTH_MEDIUM_LIMIT = 1;
160     public static final int OCTET_STRING_LENGTH_MEDIUM_FLAG = 2;
161     public static final int OCTET_STRING_LENGTH_LARGE_FLAG = 3;
162     
163     public static final long OCTET_STRING_MAXIMUM_LENGTH = 4294967296L;
164     
165     /*
166      * C.22
167      */

168     public static final int OCTET_STRING_LENGTH_2ND_BIT_SMALL_LIMIT = 65;
169     public static final int OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_LIMIT = 321;
170     public static final int OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_FLAG = 0x40;
171     public static final int OCTET_STRING_LENGTH_2ND_BIT_LARGE_FLAG = 0x60;
172     public static final int OCTET_STRING_LENGTH_2ND_BIT_SMALL_MASK = 0x1F;
173
174     public static final int[] OCTET_STRING_LENGTH_2ND_BIT_VALUES = {
175         OCTET_STRING_LENGTH_2ND_BIT_SMALL_LIMIT,
176         OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_LIMIT,
177         OCTET_STRING_LENGTH_2ND_BIT_MEDIUM_FLAG,
178         OCTET_STRING_LENGTH_2ND_BIT_LARGE_FLAG
179     };
180     
181     /*
182      * C.23
183      */

184     public static final int OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT = 9;
185     public static final int OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT = 265;
186     public static final int OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_FLAG = 0x08;
187     public static final int OCTET_STRING_LENGTH_5TH_BIT_LARGE_FLAG = 0x0C;
188     public static final int OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK = 0x07;
189     
190     public static final int[] OCTET_STRING_LENGTH_5TH_BIT_VALUES = {
191         OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT,
192         OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT,
193         OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_FLAG,
194         OCTET_STRING_LENGTH_5TH_BIT_LARGE_FLAG
195     };
196
197     /*
198      * C.24
199      */

200     public static final int OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT = 3;
201     public static final int OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT = 259;
202     public static final int OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_FLAG = 0x02;
203     public static final int OCTET_STRING_LENGTH_7TH_BIT_LARGE_FLAG = 0x03;
204     public static final int OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK = 0x01;
205
206     public static final int[] OCTET_STRING_LENGTH_7TH_BIT_VALUES = {
207         OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT,
208         OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT,
209         OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_FLAG,
210         OCTET_STRING_LENGTH_7TH_BIT_LARGE_FLAG
211     };
212
213     
214     // Integer
215

216     public static final int INTEGER_SMALL_LIMIT = 0;
217     public static final int INTEGER_MEDIUM_LIMIT = 1;
218     public static final int INTEGER_LARGE_LIMIT = 2;
219     public static final int INTEGER_MEDIUM_FLAG = 3;
220     public static final int INTEGER_LARGE_FLAG = 4;
221     public static final int INTEGER_LARGE_LARGE_FLAG = 5;
222
223     public static final int INTEGER_MAXIMUM_SIZE = 1048576;
224
225     /*
226      * C.25
227      */

228     public static final int INTEGER_2ND_BIT_SMALL_LIMIT = 64;
229     public static final int INTEGER_2ND_BIT_MEDIUM_LIMIT = 8256;
230     public static final int INTEGER_2ND_BIT_LARGE_LIMIT = INTEGER_MAXIMUM_SIZE;
231     public static final int INTEGER_2ND_BIT_MEDIUM_FLAG = 0x40;
232     public static final int INTEGER_2ND_BIT_LARGE_FLAG = 0x60;
233     public static final int INTEGER_2ND_BIT_SMALL_MASK = 0x3F;
234     public static final int INTEGER_2ND_BIT_MEDIUM_MASK = 0x1F;
235     public static final int INTEGER_2ND_BIT_LARGE_MASK = 0x0F;
236     
237     public static final int[] INTEGER_2ND_BIT_VALUES = {
238         INTEGER_2ND_BIT_SMALL_LIMIT,
239         INTEGER_2ND_BIT_MEDIUM_LIMIT,
240         INTEGER_2ND_BIT_LARGE_LIMIT,
241         INTEGER_2ND_BIT_MEDIUM_FLAG,
242         INTEGER_2ND_BIT_LARGE_FLAG,
243         -1
244     };
245
246     /*
247      * C.27
248      */

249     public static final int INTEGER_3RD_BIT_SMALL_LIMIT = 32;
250     public static final int INTEGER_3RD_BIT_MEDIUM_LIMIT = 2080;
251     public static final int INTEGER_3RD_BIT_LARGE_LIMIT = 526368;
252     public static final int INTEGER_3RD_BIT_MEDIUM_FLAG = 0x20;
253     public static final int INTEGER_3RD_BIT_LARGE_FLAG = 0x28;
254     public static final int INTEGER_3RD_BIT_LARGE_LARGE_FLAG = 0x30;
255     public static final int INTEGER_3RD_BIT_SMALL_MASK = 0x1F;
256     public static final int INTEGER_3RD_BIT_MEDIUM_MASK = 0x07;
257     public static final int INTEGER_3RD_BIT_LARGE_MASK = 0x07;
258     public static final int INTEGER_3RD_BIT_LARGE_LARGE_MASK = 0x0F;
259
260     public static final int[] INTEGER_3RD_BIT_VALUES = {
261         INTEGER_3RD_BIT_SMALL_LIMIT,
262         INTEGER_3RD_BIT_MEDIUM_LIMIT,
263         INTEGER_3RD_BIT_LARGE_LIMIT,
264         INTEGER_3RD_BIT_MEDIUM_FLAG,
265         INTEGER_3RD_BIT_LARGE_FLAG,
266         INTEGER_3RD_BIT_LARGE_LARGE_FLAG
267     };
268     
269     /*
270      * C.28
271      */

272     public static final int INTEGER_4TH_BIT_SMALL_LIMIT = 16;
273     public static final int INTEGER_4TH_BIT_MEDIUM_LIMIT = 1040;
274     public static final int INTEGER_4TH_BIT_LARGE_LIMIT = 263184;
275     public static final int INTEGER_4TH_BIT_MEDIUM_FLAG = 0x10;
276     public static final int INTEGER_4TH_BIT_LARGE_FLAG = 0x14;
277     public static final int INTEGER_4TH_BIT_LARGE_LARGE_FLAG = 0x18;
278     public static final int INTEGER_4TH_BIT_SMALL_MASK = 0x0F;
279     public static final int INTEGER_4TH_BIT_MEDIUM_MASK = 0x03;
280     public static final int INTEGER_4TH_BIT_LARGE_MASK = 0x03;
281
282     public static final int[] INTEGER_4TH_BIT_VALUES = {
283         INTEGER_4TH_BIT_SMALL_LIMIT,
284         INTEGER_4TH_BIT_MEDIUM_LIMIT,
285         INTEGER_4TH_BIT_LARGE_LIMIT,
286         INTEGER_4TH_BIT_MEDIUM_FLAG,
287         INTEGER_4TH_BIT_LARGE_FLAG,
288         INTEGER_4TH_BIT_LARGE_LARGE_FLAG
289     };
290     
291     
292     public static int[] NUMERIC_CHARACTERS_TABLE;
293     
294     public static int[] DATE_TIME_CHARACTERS_TABLE;
295     
296     private static void initiateCharacterTables() {
297         NUMERIC_CHARACTERS_TABLE = new int[maxCharacter(RestrictedAlphabet.NUMERIC_CHARACTERS) + 1];
298         DATE_TIME_CHARACTERS_TABLE = new int[maxCharacter(RestrictedAlphabet.DATE_TIME_CHARACTERS) + 1];
299     
300         for (int i = 0; i < NUMERIC_CHARACTERS_TABLE.length ; i++) {
301             NUMERIC_CHARACTERS_TABLE[i] = -1;
302         }
303         for (int i = 0; i < DATE_TIME_CHARACTERS_TABLE.length ; i++) {
304             DATE_TIME_CHARACTERS_TABLE[i] = -1;
305         }
306         
307         for (int i = 0; i < RestrictedAlphabet.NUMERIC_CHARACTERS.length() ; i++) {
308             NUMERIC_CHARACTERS_TABLE[RestrictedAlphabet.NUMERIC_CHARACTERS.charAt(i)] = i;
309         }
310         for (int i = 0; i < RestrictedAlphabet.DATE_TIME_CHARACTERS.length() ; i++) {
311             DATE_TIME_CHARACTERS_TABLE[RestrictedAlphabet.DATE_TIME_CHARACTERS.charAt(i)] = i;
312         }
313     }
314     
315     private static int maxCharacter(String JavaDoc alphabet) {
316         int c = 0;
317         for (int i = 0; i < alphabet.length() ; i++) {
318             if (c < alphabet.charAt(i)) {
319                 c = alphabet.charAt(i);
320             }
321         }
322         
323         return c;
324     }
325     
326     public static final byte[] BINARY_HEADER = {(byte)0xE0, 0, 0, 1};
327     
328     public static byte[][] XML_DECLARATION_VALUES;
329     
330     private static void initiateXMLDeclarationValues() {
331         
332         XML_DECLARATION_VALUES = new byte[9][];
333         
334         try {
335             XML_DECLARATION_VALUES[0] = "<?xml encoding='finf'?>".getBytes("UTF-8");
336             XML_DECLARATION_VALUES[1] = "<?xml version='1.0' encoding='finf'?>".getBytes("UTF-8");
337             XML_DECLARATION_VALUES[2] = "<?xml version='1.1' encoding='finf'?>".getBytes("UTF-8");
338             XML_DECLARATION_VALUES[3] = "<?xml encoding='finf' standalone='no'?>".getBytes("UTF-8");
339             XML_DECLARATION_VALUES[4] = "<?xml encoding='finf' standalone='yes'?>".getBytes("UTF-8");
340             XML_DECLARATION_VALUES[5] = "<?xml version='1.0' encoding='finf' standalone='no'?>".getBytes("UTF-8");
341             XML_DECLARATION_VALUES[6] = "<?xml version='1.1' encoding='finf' standalone='no'?>".getBytes("UTF-8");
342             XML_DECLARATION_VALUES[7] = "<?xml version='1.0' encoding='finf' standalone='yes'?>".getBytes("UTF-8");
343             XML_DECLARATION_VALUES[8] = "<?xml version='1.1' encoding='finf' standalone='yes'?>".getBytes("UTF-8");
344         } catch (UnsupportedEncodingException JavaDoc e) {
345         }
346     }
347 }
348
Popular Tags