1 38 39 40 package com.sun.xml.fastinfoset; 41 42 import java.io.UnsupportedEncodingException ; 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 XML_NAMESPACE_PREFIX = "xml"; 52 public static final int XML_NAMESPACE_PREFIX_LENGTH = XML_NAMESPACE_PREFIX.length(); 53 public static final String 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 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 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; public static final int DOCUMENT_INITIAL_VOCABULARY_FLAG = 0x20; public static final int DOCUMENT_NOTATIONS_FLAG = 0x10; public static final int DOCUMENT_UNPARSED_ENTITIES_FLAG = 0x08; public static final int DOCUMENT_CHARACTER_ENCODING_SCHEME = 0x04; public static final int DOCUMENT_STANDALONE_FLAG = 0x02; public static final int DOCUMENT_VERSION_FLAG = 0x01; 72 public static final int INITIAL_VOCABULARY_EXTERNAL_VOCABULARY_FLAG = 0x10; public static final int INITIAL_VOCABULARY_RESTRICTED_ALPHABETS_FLAG = 0x08; public static final int INITIAL_VOCABULARY_ENCODING_ALGORITHMS_FLAG = 0x04; public static final int INITIAL_VOCABULARY_PREFIXES_FLAG = 0x02; public static final int INITIAL_VOCABULARY_NAMESPACE_NAMES_FLAG = 0x01; public static final int INITIAL_VOCABULARY_LOCAL_NAMES_FLAG = 0x80; public static final int INITIAL_VOCABULARY_OTHER_NCNAMES_FLAG = 0x40; public static final int INITIAL_VOCABULARY_OTHER_URIS_FLAG = 0x20; public static final int INITIAL_VOCABULARY_ATTRIBUTE_VALUES_FLAG = 0x10; public static final int INITIAL_VOCABULARY_CONTENT_CHARACTER_CHUNKS_FLAG = 0x08; public static final int INITIAL_VOCABULARY_OTHER_STRINGS_FLAG = 0x04; public static final int INITIAL_VOCABULARY_ELEMENT_NAME_SURROGATES_FLAG = 0x02; public static final int INITIAL_VOCABULARY_ATTRIBUTE_NAME_SURROGATES_FLAG = 0x01; 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; public static final int NOTATIONS_MASK = 0xFC; 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; public static final int UNPARSED_ENTITIES_MASK = 0xFE; public static final int UNPARSED_ENTITIES_PUBLIC_IDENTIFIER_FLAG = 0x01; 97 98 public static final int PROCESSING_INSTRUCTION = 0xE1; public static final int PROCESSING_INSTRUCTION_MASK = 0xFF; 101 public static final int COMMENT = 0xE2; public static final int COMMENT_MASK = 0xFF; 104 public static final int DOCUMENT_TYPE_DECLARATION = 0xC4; public static final int DOCUMENT_TYPE_DECLARATION_MASK = 0xFC; 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; public static final int ELEMENT_ATTRIBUTE_FLAG = 0x40; public static final int ELEMENT_NAMESPACES_FLAG = 0x38; public static final int ELEMENT_LITERAL_QNAME_FLAG = 0x3C; 114 public static final int NAMESPACE_ATTRIBUTE = 0xCC; public static final int NAMESPACE_ATTRIBUTE_MASK = 0xFC; public static final int NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK = 0x03; 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; 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; public static final int CHARACTER_CHUNK_ADD_TO_TABLE_FLAG = 0x10; public static final int CHARACTER_CHUNK_UTF_8_FLAG = 0x00; public static final int CHARACTER_CHUNK_UTF_16_FLAG = 0x04; public static final int CHARACTER_CHUNK_RESTRICTED_ALPHABET_FLAG = 0x08; public static final int CHARACTER_CHUNK_ENCODING_ALGORITHM_FLAG = 0x0C; 133 public static final int UNEXPANDED_ENTITY_REFERENCE = 0xC8; public static final int UNEXPANDED_ENTITY_REFERENCE_MASK = 0xFC; 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; public static final int NISTRING_UTF_8_FLAG = 0x00; public static final int NISTRING_UTF_16_FLAG = 0x10; public static final int NISTRING_RESTRICTED_ALPHABET_FLAG = 0x20; public static final int NISTRING_ENCODING_ALGORITHM_FLAG = 0x30; 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 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 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 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 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 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 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 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 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 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 e) { 345 } 346 } 347 } 348 | Popular Tags |