src/share/jaxws_classes/com/sun/xml/internal/fastinfoset/dom/DOMDocumentParser.java

Thu, 31 Aug 2017 15:18:52 +0800

author
aoqi
date
Thu, 31 Aug 2017 15:18:52 +0800
changeset 637
9c07ef4934dd
parent 384
8f2986ff0235
parent 0
373ffda63c9a
permissions
-rw-r--r--

merge

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 2004, 2012, Oracle and/or its affiliates. All rights reserved.
aoqi@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
aoqi@0 4 *
aoqi@0 5 * This code is free software; you can redistribute it and/or modify it
aoqi@0 6 * under the terms of the GNU General Public License version 2 only, as
aoqi@0 7 * published by the Free Software Foundation. Oracle designates this
aoqi@0 8 * particular file as subject to the "Classpath" exception as provided
aoqi@0 9 * by Oracle in the LICENSE file that accompanied this code.
aoqi@0 10 *
aoqi@0 11 * This code is distributed in the hope that it will be useful, but WITHOUT
aoqi@0 12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
aoqi@0 13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
aoqi@0 14 * version 2 for more details (a copy is included in the LICENSE file that
aoqi@0 15 * accompanied this code).
aoqi@0 16 *
aoqi@0 17 * You should have received a copy of the GNU General Public License version
aoqi@0 18 * 2 along with this work; if not, write to the Free Software Foundation,
aoqi@0 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
aoqi@0 20 *
aoqi@0 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
aoqi@0 22 * or visit www.oracle.com if you need additional information or have any
aoqi@0 23 * questions.
aoqi@0 24 *
aoqi@0 25 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
aoqi@0 26 */
aoqi@0 27
aoqi@0 28 package com.sun.xml.internal.fastinfoset.dom;
aoqi@0 29
aoqi@0 30 import com.sun.xml.internal.fastinfoset.Decoder;
aoqi@0 31 import com.sun.xml.internal.fastinfoset.DecoderStateTables;
aoqi@0 32 import com.sun.xml.internal.fastinfoset.EncodingConstants;
aoqi@0 33 import com.sun.xml.internal.fastinfoset.QualifiedName;
aoqi@0 34 import com.sun.xml.internal.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory;
aoqi@0 35 import com.sun.xml.internal.fastinfoset.util.CharArray;
aoqi@0 36 import com.sun.xml.internal.fastinfoset.util.CharArrayString;
aoqi@0 37 import java.io.IOException;
aoqi@0 38 import java.io.InputStream;
aoqi@0 39 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithm;
aoqi@0 40 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmException;
aoqi@0 41 import com.sun.xml.internal.org.jvnet.fastinfoset.EncodingAlgorithmIndexes;
aoqi@0 42 import com.sun.xml.internal.org.jvnet.fastinfoset.FastInfosetException;
aoqi@0 43 import org.w3c.dom.Attr;
aoqi@0 44 import org.w3c.dom.Document;
aoqi@0 45 import org.w3c.dom.Element;
aoqi@0 46 import org.w3c.dom.Node;
aoqi@0 47 import com.sun.xml.internal.fastinfoset.CommonResourceBundle;
aoqi@0 48 import com.sun.xml.internal.fastinfoset.util.DuplicateAttributeVerifier;
aoqi@0 49 import org.w3c.dom.Text;
aoqi@0 50
aoqi@0 51 /**
aoqi@0 52 * The Fast Infoset DOM parser.
aoqi@0 53 * <p>
aoqi@0 54 * Instantiate this parser to parse a fast infoset document in accordance
aoqi@0 55 * with the DOM API.
aoqi@0 56 *
aoqi@0 57 */
aoqi@0 58 public class DOMDocumentParser extends Decoder {
aoqi@0 59 protected Document _document;
aoqi@0 60
aoqi@0 61 protected Node _currentNode;
aoqi@0 62
aoqi@0 63 protected Element _currentElement;
aoqi@0 64
aoqi@0 65 protected Attr[] _namespaceAttributes = new Attr[16];
aoqi@0 66
aoqi@0 67 protected int _namespaceAttributesIndex;
aoqi@0 68
aoqi@0 69 protected int[] _namespacePrefixes = new int[16];
aoqi@0 70
aoqi@0 71 protected int _namespacePrefixesIndex;
aoqi@0 72
aoqi@0 73 /**
aoqi@0 74 * Parse a fast infoset document into a {@link Document} instance.
aoqi@0 75 * <p>
aoqi@0 76 * {@link Node}s will be created and appended to the {@link Document}
aoqi@0 77 * instance.
aoqi@0 78 *
aoqi@0 79 * @param d the {@link Document} instance.
aoqi@0 80 * @param s the input stream containing the fast infoset document.
aoqi@0 81 */
aoqi@0 82 public void parse(Document d, InputStream s) throws FastInfosetException, IOException {
aoqi@0 83 _currentNode = _document = d;
aoqi@0 84 _namespaceAttributesIndex = 0;
aoqi@0 85
aoqi@0 86 parse(s);
aoqi@0 87 }
aoqi@0 88
aoqi@0 89 protected final void parse(InputStream s) throws FastInfosetException, IOException {
aoqi@0 90 setInputStream(s);
aoqi@0 91 parse();
aoqi@0 92 }
aoqi@0 93
aoqi@0 94 protected void resetOnError() {
aoqi@0 95 _namespacePrefixesIndex = 0;
aoqi@0 96
aoqi@0 97 if (_v == null) {
aoqi@0 98 _prefixTable.clearCompletely();
aoqi@0 99 }
aoqi@0 100 _duplicateAttributeVerifier.clear();
aoqi@0 101 }
aoqi@0 102
aoqi@0 103 protected final void parse() throws FastInfosetException, IOException {
aoqi@0 104 try {
aoqi@0 105 reset();
aoqi@0 106 decodeHeader();
aoqi@0 107 processDII();
aoqi@0 108 } catch (RuntimeException e) {
aoqi@0 109 resetOnError();
aoqi@0 110 // Wrap runtime exception
aoqi@0 111 throw new FastInfosetException(e);
aoqi@0 112 } catch (FastInfosetException e) {
aoqi@0 113 resetOnError();
aoqi@0 114 throw e;
aoqi@0 115 } catch (IOException e) {
aoqi@0 116 resetOnError();
aoqi@0 117 throw e;
aoqi@0 118 }
aoqi@0 119 }
aoqi@0 120
aoqi@0 121 protected final void processDII() throws FastInfosetException, IOException {
aoqi@0 122 _b = read();
aoqi@0 123 if (_b > 0) {
aoqi@0 124 processDIIOptionalProperties();
aoqi@0 125 }
aoqi@0 126
aoqi@0 127 // Decode one Document Type II, Comment IIs, PI IIs and one EII
aoqi@0 128 boolean firstElementHasOccured = false;
aoqi@0 129 boolean documentTypeDeclarationOccured = false;
aoqi@0 130 while(!_terminate || !firstElementHasOccured) {
aoqi@0 131 _b = read();
aoqi@0 132 switch(DecoderStateTables.DII(_b)) {
aoqi@0 133 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
aoqi@0 134 processEII(_elementNameTable._array[_b], false);
aoqi@0 135 firstElementHasOccured = true;
aoqi@0 136 break;
aoqi@0 137 case DecoderStateTables.EII_AIIS_INDEX_SMALL:
aoqi@0 138 processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true);
aoqi@0 139 firstElementHasOccured = true;
aoqi@0 140 break;
aoqi@0 141 case DecoderStateTables.EII_INDEX_MEDIUM:
aoqi@0 142 processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
aoqi@0 143 firstElementHasOccured = true;
aoqi@0 144 break;
aoqi@0 145 case DecoderStateTables.EII_INDEX_LARGE:
aoqi@0 146 processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
aoqi@0 147 firstElementHasOccured = true;
aoqi@0 148 break;
aoqi@0 149 case DecoderStateTables.EII_LITERAL:
aoqi@0 150 {
aoqi@0 151 final QualifiedName qn = processLiteralQualifiedName(
aoqi@0 152 _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
aoqi@0 153 _elementNameTable.getNext());
aoqi@0 154 _elementNameTable.add(qn);
aoqi@0 155 processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
aoqi@0 156 firstElementHasOccured = true;
aoqi@0 157 break;
aoqi@0 158 }
aoqi@0 159 case DecoderStateTables.EII_NAMESPACES:
aoqi@0 160 processEIIWithNamespaces();
aoqi@0 161 firstElementHasOccured = true;
aoqi@0 162 break;
aoqi@0 163 case DecoderStateTables.DOCUMENT_TYPE_DECLARATION_II:
aoqi@0 164 {
aoqi@0 165 if (documentTypeDeclarationOccured) {
aoqi@0 166 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.secondOccurenceOfDTDII"));
aoqi@0 167 }
aoqi@0 168 documentTypeDeclarationOccured = true;
aoqi@0 169
aoqi@0 170 String system_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_SYSTEM_IDENTIFIER_FLAG) > 0)
aoqi@0 171 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : null;
aoqi@0 172 String public_identifier = ((_b & EncodingConstants.DOCUMENT_TYPE_PUBLIC_IDENTIFIER_FLAG) > 0)
aoqi@0 173 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : null;
aoqi@0 174
aoqi@0 175 _b = read();
aoqi@0 176 while (_b == EncodingConstants.PROCESSING_INSTRUCTION) {
aoqi@0 177 switch(decodeNonIdentifyingStringOnFirstBit()) {
aoqi@0 178 case NISTRING_STRING:
aoqi@0 179 if (_addToTable) {
aoqi@0 180 _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true));
aoqi@0 181 }
aoqi@0 182 break;
aoqi@0 183 case NISTRING_ENCODING_ALGORITHM:
aoqi@0 184 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm"));
aoqi@0 185 case NISTRING_INDEX:
aoqi@0 186 break;
aoqi@0 187 case NISTRING_EMPTY_STRING:
aoqi@0 188 break;
aoqi@0 189 }
aoqi@0 190 _b = read();
aoqi@0 191 }
aoqi@0 192 if ((_b & EncodingConstants.TERMINATOR) != EncodingConstants.TERMINATOR) {
aoqi@0 193 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingInstructionIIsNotTerminatedCorrectly"));
aoqi@0 194 }
aoqi@0 195 if (_b == EncodingConstants.DOUBLE_TERMINATOR) {
aoqi@0 196 _terminate = true;
aoqi@0 197 }
aoqi@0 198
aoqi@0 199 _notations.clear();
aoqi@0 200 _unparsedEntities.clear();
aoqi@0 201 /*
aoqi@0 202 * TODO
aoqi@0 203 * Report All events associated with DTD, PIs, notations etc
aoqi@0 204 */
aoqi@0 205 break;
aoqi@0 206 }
aoqi@0 207 case DecoderStateTables.COMMENT_II:
aoqi@0 208 processCommentII();
aoqi@0 209 break;
aoqi@0 210 case DecoderStateTables.PROCESSING_INSTRUCTION_II:
aoqi@0 211 processProcessingII();
aoqi@0 212 break;
aoqi@0 213 case DecoderStateTables.TERMINATOR_DOUBLE:
aoqi@0 214 _doubleTerminate = true;
aoqi@0 215 case DecoderStateTables.TERMINATOR_SINGLE:
aoqi@0 216 _terminate = true;
aoqi@0 217 break;
aoqi@0 218 default:
aoqi@0 219 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingDII"));
aoqi@0 220 }
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 // Decode any remaining Comment IIs, PI IIs
aoqi@0 224 while(!_terminate) {
aoqi@0 225 _b = read();
aoqi@0 226 switch(DecoderStateTables.DII(_b)) {
aoqi@0 227 case DecoderStateTables.COMMENT_II:
aoqi@0 228 processCommentII();
aoqi@0 229 break;
aoqi@0 230 case DecoderStateTables.PROCESSING_INSTRUCTION_II:
aoqi@0 231 processProcessingII();
aoqi@0 232 break;
aoqi@0 233 case DecoderStateTables.TERMINATOR_DOUBLE:
aoqi@0 234 _doubleTerminate = true;
aoqi@0 235 case DecoderStateTables.TERMINATOR_SINGLE:
aoqi@0 236 _terminate = true;
aoqi@0 237 break;
aoqi@0 238 default:
aoqi@0 239 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingDII"));
aoqi@0 240 }
aoqi@0 241 }
aoqi@0 242
aoqi@0 243 }
aoqi@0 244
aoqi@0 245 protected final void processDIIOptionalProperties() throws FastInfosetException, IOException {
aoqi@0 246 // Optimize for the most common case
aoqi@0 247 if (_b == EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) {
aoqi@0 248 decodeInitialVocabulary();
aoqi@0 249 return;
aoqi@0 250 }
aoqi@0 251
aoqi@0 252 if ((_b & EncodingConstants.DOCUMENT_ADDITIONAL_DATA_FLAG) > 0) {
aoqi@0 253 decodeAdditionalData();
aoqi@0 254 /*
aoqi@0 255 * TODO
aoqi@0 256 * how to report the additional data?
aoqi@0 257 */
aoqi@0 258 }
aoqi@0 259
aoqi@0 260 if ((_b & EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) > 0) {
aoqi@0 261 decodeInitialVocabulary();
aoqi@0 262 }
aoqi@0 263
aoqi@0 264 if ((_b & EncodingConstants.DOCUMENT_NOTATIONS_FLAG) > 0) {
aoqi@0 265 decodeNotations();
aoqi@0 266 // TODO Report notations
aoqi@0 267 }
aoqi@0 268
aoqi@0 269 if ((_b & EncodingConstants.DOCUMENT_UNPARSED_ENTITIES_FLAG) > 0) {
aoqi@0 270 decodeUnparsedEntities();
aoqi@0 271 // TODO Report unparsed entities
aoqi@0 272 }
aoqi@0 273
aoqi@0 274 if ((_b & EncodingConstants.DOCUMENT_CHARACTER_ENCODING_SCHEME) > 0) {
aoqi@0 275 /*String version = */decodeCharacterEncodingScheme();
aoqi@0 276 /*
aoqi@0 277 * TODO
aoqi@0 278 * how to report the character encoding scheme?
aoqi@0 279 */
aoqi@0 280 }
aoqi@0 281
aoqi@0 282 if ((_b & EncodingConstants.DOCUMENT_STANDALONE_FLAG) > 0) {
aoqi@0 283 /*boolean standalone = (*/read()/* > 0) ? true : false*/ ;
aoqi@0 284 /*
aoqi@0 285 * TODO
aoqi@0 286 * how to report the standalone flag?
aoqi@0 287 */
aoqi@0 288 }
aoqi@0 289
aoqi@0 290 if ((_b & EncodingConstants.DOCUMENT_VERSION_FLAG) > 0) {
aoqi@0 291 decodeVersion();
aoqi@0 292 /*
aoqi@0 293 * TODO
aoqi@0 294 * how to report the document version?
aoqi@0 295 */
aoqi@0 296 }
aoqi@0 297 }
aoqi@0 298
aoqi@0 299 protected final void processEII(QualifiedName name, boolean hasAttributes) throws FastInfosetException, IOException {
aoqi@0 300 if (_prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) {
aoqi@0 301 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qnameOfEIINotInScope"));
aoqi@0 302 }
aoqi@0 303
aoqi@0 304 final Node parentCurrentNode = _currentNode;
aoqi@0 305
aoqi@0 306 _currentNode = _currentElement = createElement(name.namespaceName, name.qName, name.localName);
aoqi@0 307
aoqi@0 308 if (_namespaceAttributesIndex > 0) {
aoqi@0 309 for (int i = 0; i < _namespaceAttributesIndex; i++) {
aoqi@0 310 _currentElement.setAttributeNode(_namespaceAttributes[i]);
aoqi@0 311 _namespaceAttributes[i] = null;
aoqi@0 312 }
aoqi@0 313 _namespaceAttributesIndex = 0;
aoqi@0 314 }
aoqi@0 315
aoqi@0 316 if (hasAttributes) {
aoqi@0 317 processAIIs();
aoqi@0 318 }
aoqi@0 319
aoqi@0 320 parentCurrentNode.appendChild(_currentElement);
aoqi@0 321
aoqi@0 322 while(!_terminate) {
aoqi@0 323 _b = read();
aoqi@0 324 switch(DecoderStateTables.EII(_b)) {
aoqi@0 325 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
aoqi@0 326 processEII(_elementNameTable._array[_b], false);
aoqi@0 327 break;
aoqi@0 328 case DecoderStateTables.EII_AIIS_INDEX_SMALL:
aoqi@0 329 processEII(_elementNameTable._array[_b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true);
aoqi@0 330 break;
aoqi@0 331 case DecoderStateTables.EII_INDEX_MEDIUM:
aoqi@0 332 processEII(decodeEIIIndexMedium(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
aoqi@0 333 break;
aoqi@0 334 case DecoderStateTables.EII_INDEX_LARGE:
aoqi@0 335 processEII(decodeEIIIndexLarge(), (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
aoqi@0 336 break;
aoqi@0 337 case DecoderStateTables.EII_LITERAL:
aoqi@0 338 {
aoqi@0 339 final QualifiedName qn = processLiteralQualifiedName(
aoqi@0 340 _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
aoqi@0 341 _elementNameTable.getNext());
aoqi@0 342 _elementNameTable.add(qn);
aoqi@0 343 processEII(qn, (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0);
aoqi@0 344 break;
aoqi@0 345 }
aoqi@0 346 case DecoderStateTables.EII_NAMESPACES:
aoqi@0 347 processEIIWithNamespaces();
aoqi@0 348 break;
aoqi@0 349 case DecoderStateTables.CII_UTF8_SMALL_LENGTH:
aoqi@0 350 {
aoqi@0 351 _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK)
aoqi@0 352 + 1;
aoqi@0 353 appendOrCreateTextData(processUtf8CharacterString());
aoqi@0 354 break;
aoqi@0 355 }
aoqi@0 356 case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH:
aoqi@0 357 {
aoqi@0 358 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
aoqi@0 359 appendOrCreateTextData(processUtf8CharacterString());
aoqi@0 360 break;
aoqi@0 361 }
aoqi@0 362 case DecoderStateTables.CII_UTF8_LARGE_LENGTH:
aoqi@0 363 {
aoqi@0 364 _octetBufferLength = (read() << 24) |
aoqi@0 365 (read() << 16) |
aoqi@0 366 (read() << 8) |
aoqi@0 367 read();
aoqi@0 368 _octetBufferLength += EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
aoqi@0 369 appendOrCreateTextData(processUtf8CharacterString());
aoqi@0 370 break;
aoqi@0 371 }
aoqi@0 372 case DecoderStateTables.CII_UTF16_SMALL_LENGTH:
aoqi@0 373 {
aoqi@0 374 _octetBufferLength = (_b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK)
aoqi@0 375 + 1;
aoqi@0 376 String v = decodeUtf16StringAsString();
aoqi@0 377 if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
aoqi@0 378 _characterContentChunkTable.add(_charBuffer, _charBufferLength);
aoqi@0 379 }
aoqi@0 380
aoqi@0 381 appendOrCreateTextData(v);
aoqi@0 382 break;
aoqi@0 383 }
aoqi@0 384 case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH:
aoqi@0 385 {
aoqi@0 386 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT;
aoqi@0 387 String v = decodeUtf16StringAsString();
aoqi@0 388 if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
aoqi@0 389 _characterContentChunkTable.add(_charBuffer, _charBufferLength);
aoqi@0 390 }
aoqi@0 391
aoqi@0 392 appendOrCreateTextData(v);
aoqi@0 393 break;
aoqi@0 394 }
aoqi@0 395 case DecoderStateTables.CII_UTF16_LARGE_LENGTH:
aoqi@0 396 {
aoqi@0 397 _octetBufferLength = (read() << 24) |
aoqi@0 398 (read() << 16) |
aoqi@0 399 (read() << 8) |
aoqi@0 400 read();
aoqi@0 401 _octetBufferLength += EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT;
aoqi@0 402 String v = decodeUtf16StringAsString();
aoqi@0 403 if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
aoqi@0 404 _characterContentChunkTable.add(_charBuffer, _charBufferLength);
aoqi@0 405 }
aoqi@0 406
aoqi@0 407 appendOrCreateTextData(v);
aoqi@0 408 break;
aoqi@0 409 }
aoqi@0 410 case DecoderStateTables.CII_RA:
aoqi@0 411 {
aoqi@0 412 final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 413
aoqi@0 414 // Decode resitricted alphabet integer
aoqi@0 415 _identifier = (_b & 0x02) << 6;
aoqi@0 416 _b = read();
aoqi@0 417 _identifier |= (_b & 0xFC) >> 2;
aoqi@0 418
aoqi@0 419 decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b);
aoqi@0 420
aoqi@0 421 String v = decodeRestrictedAlphabetAsString();
aoqi@0 422 if (addToTable) {
aoqi@0 423 _characterContentChunkTable.add(_charBuffer, _charBufferLength);
aoqi@0 424 }
aoqi@0 425
aoqi@0 426 appendOrCreateTextData(v);
aoqi@0 427 break;
aoqi@0 428 }
aoqi@0 429 case DecoderStateTables.CII_EA:
aoqi@0 430 {
aoqi@0 431 final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 432 // Decode encoding algorithm integer
aoqi@0 433 _identifier = (_b & 0x02) << 6;
aoqi@0 434 _b = read();
aoqi@0 435 _identifier |= (_b & 0xFC) >> 2;
aoqi@0 436
aoqi@0 437 decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(_b);
aoqi@0 438 final String s = convertEncodingAlgorithmDataToCharacters(false);
aoqi@0 439 if (addToTable) {
aoqi@0 440 _characterContentChunkTable.add(s.toCharArray(), s.length());
aoqi@0 441 }
aoqi@0 442 appendOrCreateTextData(s);
aoqi@0 443 break;
aoqi@0 444 }
aoqi@0 445 case DecoderStateTables.CII_INDEX_SMALL:
aoqi@0 446 {
aoqi@0 447 final String s = _characterContentChunkTable.getString(_b & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK);
aoqi@0 448
aoqi@0 449 appendOrCreateTextData(s);
aoqi@0 450 break;
aoqi@0 451 }
aoqi@0 452 case DecoderStateTables.CII_INDEX_MEDIUM:
aoqi@0 453 {
aoqi@0 454 final int index = (((_b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read())
aoqi@0 455 + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT;
aoqi@0 456 final String s = _characterContentChunkTable.getString(index);
aoqi@0 457
aoqi@0 458 appendOrCreateTextData(s);
aoqi@0 459 break;
aoqi@0 460 }
aoqi@0 461 case DecoderStateTables.CII_INDEX_LARGE:
aoqi@0 462 {
aoqi@0 463 int index = ((_b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16) |
aoqi@0 464 (read() << 8) |
aoqi@0 465 read();
aoqi@0 466 index += EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT;
aoqi@0 467 final String s = _characterContentChunkTable.getString(index);
aoqi@0 468
aoqi@0 469 appendOrCreateTextData(s);
aoqi@0 470 break;
aoqi@0 471 }
aoqi@0 472 case DecoderStateTables.CII_INDEX_LARGE_LARGE:
aoqi@0 473 {
aoqi@0 474 int index = (read() << 16) |
aoqi@0 475 (read() << 8) |
aoqi@0 476 read();
aoqi@0 477 index += EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT;
aoqi@0 478 final String s = _characterContentChunkTable.getString(index);
aoqi@0 479
aoqi@0 480 appendOrCreateTextData(s);
aoqi@0 481 break;
aoqi@0 482 }
aoqi@0 483 case DecoderStateTables.COMMENT_II:
aoqi@0 484 processCommentII();
aoqi@0 485 break;
aoqi@0 486 case DecoderStateTables.PROCESSING_INSTRUCTION_II:
aoqi@0 487 processProcessingII();
aoqi@0 488 break;
aoqi@0 489 case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II:
aoqi@0 490 {
aoqi@0 491 String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);
aoqi@0 492
aoqi@0 493 String system_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0)
aoqi@0 494 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : null;
aoqi@0 495 String public_identifier = ((_b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0)
aoqi@0 496 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : null;
aoqi@0 497
aoqi@0 498 // TODO create Node
aoqi@0 499 break;
aoqi@0 500 }
aoqi@0 501 case DecoderStateTables.TERMINATOR_DOUBLE:
aoqi@0 502 _doubleTerminate = true;
aoqi@0 503 case DecoderStateTables.TERMINATOR_SINGLE:
aoqi@0 504 _terminate = true;
aoqi@0 505 break;
aoqi@0 506 default:
aoqi@0 507 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII"));
aoqi@0 508 }
aoqi@0 509 }
aoqi@0 510
aoqi@0 511 _terminate = _doubleTerminate;
aoqi@0 512 _doubleTerminate = false;
aoqi@0 513
aoqi@0 514 _currentNode = parentCurrentNode;
aoqi@0 515 }
aoqi@0 516
aoqi@0 517 private void appendOrCreateTextData(String textData) {
aoqi@0 518 Node lastChild = _currentNode.getLastChild();
aoqi@0 519 if (lastChild instanceof Text) {
aoqi@0 520 ((Text) lastChild).appendData(textData);
aoqi@0 521 } else {
aoqi@0 522 _currentNode.appendChild(
aoqi@0 523 _document.createTextNode(textData));
aoqi@0 524 }
aoqi@0 525 }
aoqi@0 526
aoqi@0 527 private final String processUtf8CharacterString() throws FastInfosetException, IOException {
aoqi@0 528 if ((_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) {
aoqi@0 529 _characterContentChunkTable.ensureSize(_octetBufferLength);
aoqi@0 530 final int charactersOffset = _characterContentChunkTable._arrayIndex;
aoqi@0 531 decodeUtf8StringAsCharBuffer(_characterContentChunkTable._array, charactersOffset);
aoqi@0 532 _characterContentChunkTable.add(_charBufferLength);
aoqi@0 533 return _characterContentChunkTable.getString(_characterContentChunkTable._cachedIndex);
aoqi@0 534 } else {
aoqi@0 535 decodeUtf8StringAsCharBuffer();
aoqi@0 536 return new String(_charBuffer, 0, _charBufferLength);
aoqi@0 537 }
aoqi@0 538 }
aoqi@0 539
aoqi@0 540 protected final void processEIIWithNamespaces() throws FastInfosetException, IOException {
aoqi@0 541 final boolean hasAttributes = (_b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0;
aoqi@0 542
aoqi@0 543 if (++_prefixTable._declarationId == Integer.MAX_VALUE) {
aoqi@0 544 _prefixTable.clearDeclarationIds();
aoqi@0 545 }
aoqi@0 546
aoqi@0 547 String prefix;
aoqi@0 548 Attr a = null;
aoqi@0 549 final int start = _namespacePrefixesIndex;
aoqi@0 550 int b = read();
aoqi@0 551 while ((b & EncodingConstants.NAMESPACE_ATTRIBUTE_MASK) == EncodingConstants.NAMESPACE_ATTRIBUTE) {
aoqi@0 552 if (_namespaceAttributesIndex == _namespaceAttributes.length) {
aoqi@0 553 final Attr[] newNamespaceAttributes = new Attr[_namespaceAttributesIndex * 3 / 2 + 1];
aoqi@0 554 System.arraycopy(_namespaceAttributes, 0, newNamespaceAttributes, 0, _namespaceAttributesIndex);
aoqi@0 555 _namespaceAttributes = newNamespaceAttributes;
aoqi@0 556 }
aoqi@0 557
aoqi@0 558 if (_namespacePrefixesIndex == _namespacePrefixes.length) {
aoqi@0 559 final int[] namespaceAIIs = new int[_namespacePrefixesIndex * 3 / 2 + 1];
aoqi@0 560 System.arraycopy(_namespacePrefixes, 0, namespaceAIIs, 0, _namespacePrefixesIndex);
aoqi@0 561 _namespacePrefixes = namespaceAIIs;
aoqi@0 562 }
aoqi@0 563
aoqi@0 564
aoqi@0 565 switch (b & EncodingConstants.NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK) {
aoqi@0 566 // no prefix, no namespace
aoqi@0 567 // Undeclaration of default namespace
aoqi@0 568 case 0:
aoqi@0 569 a = createAttribute(
aoqi@0 570 EncodingConstants.XMLNS_NAMESPACE_NAME,
aoqi@0 571 EncodingConstants.XMLNS_NAMESPACE_PREFIX,
aoqi@0 572 EncodingConstants.XMLNS_NAMESPACE_PREFIX);
aoqi@0 573 a.setValue("");
aoqi@0 574
aoqi@0 575 _prefixIndex = _namespaceNameIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1;
aoqi@0 576 break;
aoqi@0 577 // no prefix, namespace
aoqi@0 578 // Declaration of default namespace
aoqi@0 579 case 1:
aoqi@0 580 a = createAttribute(
aoqi@0 581 EncodingConstants.XMLNS_NAMESPACE_NAME,
aoqi@0 582 EncodingConstants.XMLNS_NAMESPACE_PREFIX,
aoqi@0 583 EncodingConstants.XMLNS_NAMESPACE_PREFIX);
aoqi@0 584 a.setValue(decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(false));
aoqi@0 585
aoqi@0 586 _prefixIndex = _namespacePrefixes[_namespacePrefixesIndex++] = -1;
aoqi@0 587 break;
aoqi@0 588 // prefix, no namespace
aoqi@0 589 // Undeclaration of namespace
aoqi@0 590 case 2:
aoqi@0 591 prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(false);
aoqi@0 592 a = createAttribute(
aoqi@0 593 EncodingConstants.XMLNS_NAMESPACE_NAME,
aoqi@0 594 createQualifiedNameString(prefix),
aoqi@0 595 prefix);
aoqi@0 596 a.setValue("");
aoqi@0 597
aoqi@0 598 _namespaceNameIndex = -1;
aoqi@0 599 _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex;
aoqi@0 600 break;
aoqi@0 601 // prefix, namespace
aoqi@0 602 // Declaration of prefixed namespace
aoqi@0 603 case 3:
aoqi@0 604 prefix = decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(true);
aoqi@0 605 a = createAttribute(
aoqi@0 606 EncodingConstants.XMLNS_NAMESPACE_NAME,
aoqi@0 607 createQualifiedNameString(prefix),
aoqi@0 608 prefix);
aoqi@0 609 a.setValue(decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(true));
aoqi@0 610
aoqi@0 611 _namespacePrefixes[_namespacePrefixesIndex++] = _prefixIndex;
aoqi@0 612 break;
aoqi@0 613 }
aoqi@0 614
aoqi@0 615 _prefixTable.pushScope(_prefixIndex, _namespaceNameIndex);
aoqi@0 616
aoqi@0 617 _namespaceAttributes[_namespaceAttributesIndex++] = a;
aoqi@0 618
aoqi@0 619 b = read();
aoqi@0 620 }
aoqi@0 621 if (b != EncodingConstants.TERMINATOR) {
aoqi@0 622 throw new IOException(CommonResourceBundle.getInstance().getString("message.EIInamespaceNameNotTerminatedCorrectly"));
aoqi@0 623 }
aoqi@0 624 final int end = _namespacePrefixesIndex;
aoqi@0 625
aoqi@0 626 _b = read();
aoqi@0 627 switch(DecoderStateTables.EII(_b)) {
aoqi@0 628 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL:
aoqi@0 629 processEII(_elementNameTable._array[_b], hasAttributes);
aoqi@0 630 break;
aoqi@0 631 case DecoderStateTables.EII_INDEX_MEDIUM:
aoqi@0 632 processEII(decodeEIIIndexMedium(), hasAttributes);
aoqi@0 633 break;
aoqi@0 634 case DecoderStateTables.EII_INDEX_LARGE:
aoqi@0 635 processEII(decodeEIIIndexLarge(), hasAttributes);
aoqi@0 636 break;
aoqi@0 637 case DecoderStateTables.EII_LITERAL:
aoqi@0 638 {
aoqi@0 639 final QualifiedName qn = processLiteralQualifiedName(
aoqi@0 640 _b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
aoqi@0 641 _elementNameTable.getNext());
aoqi@0 642 _elementNameTable.add(qn);
aoqi@0 643 processEII(qn, hasAttributes);
aoqi@0 644 break;
aoqi@0 645 }
aoqi@0 646 default:
aoqi@0 647 throw new IOException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEIIAfterAIIs"));
aoqi@0 648 }
aoqi@0 649
aoqi@0 650 for (int i = start; i < end; i++) {
aoqi@0 651 _prefixTable.popScope(_namespacePrefixes[i]);
aoqi@0 652 }
aoqi@0 653 _namespacePrefixesIndex = start;
aoqi@0 654
aoqi@0 655 }
aoqi@0 656
aoqi@0 657 protected final QualifiedName processLiteralQualifiedName(int state, QualifiedName q)
aoqi@0 658 throws FastInfosetException, IOException {
aoqi@0 659 if (q == null) q = new QualifiedName();
aoqi@0 660
aoqi@0 661 switch (state) {
aoqi@0 662 // no prefix, no namespace
aoqi@0 663 case 0:
aoqi@0 664 return q.set(
aoqi@0 665 null,
aoqi@0 666 null,
aoqi@0 667 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
aoqi@0 668 -1,
aoqi@0 669 -1,
aoqi@0 670 _identifier,
aoqi@0 671 null);
aoqi@0 672 // no prefix, namespace
aoqi@0 673 case 1:
aoqi@0 674 return q.set(
aoqi@0 675 null,
aoqi@0 676 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(false),
aoqi@0 677 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
aoqi@0 678 -1,
aoqi@0 679 _namespaceNameIndex,
aoqi@0 680 _identifier,
aoqi@0 681 null);
aoqi@0 682 // prefix, no namespace
aoqi@0 683 case 2:
aoqi@0 684 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qNameMissingNamespaceName"));
aoqi@0 685 // prefix, namespace
aoqi@0 686 case 3:
aoqi@0 687 return q.set(
aoqi@0 688 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsPrefix(true),
aoqi@0 689 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(true),
aoqi@0 690 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
aoqi@0 691 _prefixIndex,
aoqi@0 692 _namespaceNameIndex,
aoqi@0 693 _identifier,
aoqi@0 694 _charBuffer);
aoqi@0 695 default:
aoqi@0 696 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingEII"));
aoqi@0 697 }
aoqi@0 698 }
aoqi@0 699
aoqi@0 700 protected final QualifiedName processLiteralQualifiedName(int state)
aoqi@0 701 throws FastInfosetException, IOException {
aoqi@0 702 switch (state) {
aoqi@0 703 // no prefix, no namespace
aoqi@0 704 case 0:
aoqi@0 705 return new QualifiedName(
aoqi@0 706 null,
aoqi@0 707 null,
aoqi@0 708 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
aoqi@0 709 -1,
aoqi@0 710 -1,
aoqi@0 711 _identifier,
aoqi@0 712 null);
aoqi@0 713 // no prefix, namespace
aoqi@0 714 case 1:
aoqi@0 715 return new QualifiedName(
aoqi@0 716 null,
aoqi@0 717 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(false),
aoqi@0 718 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
aoqi@0 719 -1,
aoqi@0 720 _namespaceNameIndex,
aoqi@0 721 _identifier,
aoqi@0 722 null);
aoqi@0 723 // prefix, no namespace
aoqi@0 724 case 2:
aoqi@0 725 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qNameMissingNamespaceName"));
aoqi@0 726 // prefix, namespace
aoqi@0 727 case 3:
aoqi@0 728 return new QualifiedName(
aoqi@0 729 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsPrefix(true),
aoqi@0 730 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(true),
aoqi@0 731 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName),
aoqi@0 732 _prefixIndex,
aoqi@0 733 _namespaceNameIndex,
aoqi@0 734 _identifier,
aoqi@0 735 _charBuffer);
aoqi@0 736 default:
aoqi@0 737 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingEII"));
aoqi@0 738 }
aoqi@0 739 }
aoqi@0 740
aoqi@0 741 protected final void processAIIs() throws FastInfosetException, IOException {
aoqi@0 742 QualifiedName name;
aoqi@0 743 int b;
aoqi@0 744 String value;
aoqi@0 745
aoqi@0 746 if (++_duplicateAttributeVerifier._currentIteration == Integer.MAX_VALUE) {
aoqi@0 747 _duplicateAttributeVerifier.clear();
aoqi@0 748 }
aoqi@0 749
aoqi@0 750 do {
aoqi@0 751 // AII qualified name
aoqi@0 752 b = read();
aoqi@0 753 switch (DecoderStateTables.AII(b)) {
aoqi@0 754 case DecoderStateTables.AII_INDEX_SMALL:
aoqi@0 755 name = _attributeNameTable._array[b];
aoqi@0 756 break;
aoqi@0 757 case DecoderStateTables.AII_INDEX_MEDIUM:
aoqi@0 758 {
aoqi@0 759 final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
aoqi@0 760 + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
aoqi@0 761 name = _attributeNameTable._array[i];
aoqi@0 762 break;
aoqi@0 763 }
aoqi@0 764 case DecoderStateTables.AII_INDEX_LARGE:
aoqi@0 765 {
aoqi@0 766 final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
aoqi@0 767 + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
aoqi@0 768 name = _attributeNameTable._array[i];
aoqi@0 769 break;
aoqi@0 770 }
aoqi@0 771 case DecoderStateTables.AII_LITERAL:
aoqi@0 772 name = processLiteralQualifiedName(
aoqi@0 773 b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK,
aoqi@0 774 _attributeNameTable.getNext());
aoqi@0 775 name.createAttributeValues(DuplicateAttributeVerifier.MAP_SIZE);
aoqi@0 776 _attributeNameTable.add(name);
aoqi@0 777 break;
aoqi@0 778 case DecoderStateTables.AII_TERMINATOR_DOUBLE:
aoqi@0 779 _doubleTerminate = true;
aoqi@0 780 case DecoderStateTables.AII_TERMINATOR_SINGLE:
aoqi@0 781 _terminate = true;
aoqi@0 782 // AIIs have finished break out of loop
aoqi@0 783 continue;
aoqi@0 784 default:
aoqi@0 785 throw new IOException(CommonResourceBundle.getInstance().getString("message.decodingAIIs"));
aoqi@0 786 }
aoqi@0 787
aoqi@0 788 if (name.prefixIndex > 0 && _prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) {
aoqi@0 789 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.AIIqNameNotInScope"));
aoqi@0 790 }
aoqi@0 791
aoqi@0 792 _duplicateAttributeVerifier.checkForDuplicateAttribute(name.attributeHash, name.attributeId);
aoqi@0 793
aoqi@0 794 Attr a = createAttribute(
aoqi@0 795 name.namespaceName,
aoqi@0 796 name.qName,
aoqi@0 797 name.localName);
aoqi@0 798
aoqi@0 799 // [normalized value] of AII
aoqi@0 800
aoqi@0 801 b = read();
aoqi@0 802 switch(DecoderStateTables.NISTRING(b)) {
aoqi@0 803 case DecoderStateTables.NISTRING_UTF8_SMALL_LENGTH:
aoqi@0 804 {
aoqi@0 805 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 806 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1;
aoqi@0 807 value = decodeUtf8StringAsString();
aoqi@0 808 if (addToTable) {
aoqi@0 809 _attributeValueTable.add(value);
aoqi@0 810 }
aoqi@0 811
aoqi@0 812 a.setValue(value);
aoqi@0 813 _currentElement.setAttributeNode(a);
aoqi@0 814 break;
aoqi@0 815 }
aoqi@0 816 case DecoderStateTables.NISTRING_UTF8_MEDIUM_LENGTH:
aoqi@0 817 {
aoqi@0 818 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 819 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT;
aoqi@0 820 value = decodeUtf8StringAsString();
aoqi@0 821 if (addToTable) {
aoqi@0 822 _attributeValueTable.add(value);
aoqi@0 823 }
aoqi@0 824
aoqi@0 825 a.setValue(value);
aoqi@0 826 _currentElement.setAttributeNode(a);
aoqi@0 827 break;
aoqi@0 828 }
aoqi@0 829 case DecoderStateTables.NISTRING_UTF8_LARGE_LENGTH:
aoqi@0 830 {
aoqi@0 831 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 832 final int length = (read() << 24) |
aoqi@0 833 (read() << 16) |
aoqi@0 834 (read() << 8) |
aoqi@0 835 read();
aoqi@0 836 _octetBufferLength = length + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT;
aoqi@0 837 value = decodeUtf8StringAsString();
aoqi@0 838 if (addToTable) {
aoqi@0 839 _attributeValueTable.add(value);
aoqi@0 840 }
aoqi@0 841
aoqi@0 842 a.setValue(value);
aoqi@0 843 _currentElement.setAttributeNode(a);
aoqi@0 844 break;
aoqi@0 845 }
aoqi@0 846 case DecoderStateTables.NISTRING_UTF16_SMALL_LENGTH:
aoqi@0 847 {
aoqi@0 848 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 849 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1;
aoqi@0 850 value = decodeUtf16StringAsString();
aoqi@0 851 if (addToTable) {
aoqi@0 852 _attributeValueTable.add(value);
aoqi@0 853 }
aoqi@0 854
aoqi@0 855 a.setValue(value);
aoqi@0 856 _currentElement.setAttributeNode(a);
aoqi@0 857 break;
aoqi@0 858 }
aoqi@0 859 case DecoderStateTables.NISTRING_UTF16_MEDIUM_LENGTH:
aoqi@0 860 {
aoqi@0 861 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 862 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT;
aoqi@0 863 value = decodeUtf16StringAsString();
aoqi@0 864 if (addToTable) {
aoqi@0 865 _attributeValueTable.add(value);
aoqi@0 866 }
aoqi@0 867
aoqi@0 868 a.setValue(value);
aoqi@0 869 _currentElement.setAttributeNode(a);
aoqi@0 870 break;
aoqi@0 871 }
aoqi@0 872 case DecoderStateTables.NISTRING_UTF16_LARGE_LENGTH:
aoqi@0 873 {
aoqi@0 874 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 875 final int length = (read() << 24) |
aoqi@0 876 (read() << 16) |
aoqi@0 877 (read() << 8) |
aoqi@0 878 read();
aoqi@0 879 _octetBufferLength = length + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT;
aoqi@0 880 value = decodeUtf16StringAsString();
aoqi@0 881 if (addToTable) {
aoqi@0 882 _attributeValueTable.add(value);
aoqi@0 883 }
aoqi@0 884
aoqi@0 885 a.setValue(value);
aoqi@0 886 _currentElement.setAttributeNode(a);
aoqi@0 887 break;
aoqi@0 888 }
aoqi@0 889 case DecoderStateTables.NISTRING_RA:
aoqi@0 890 {
aoqi@0 891 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 892 // Decode resitricted alphabet integer
aoqi@0 893 _identifier = (b & 0x0F) << 4;
aoqi@0 894 b = read();
aoqi@0 895 _identifier |= (b & 0xF0) >> 4;
aoqi@0 896
aoqi@0 897 decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b);
aoqi@0 898
aoqi@0 899 value = decodeRestrictedAlphabetAsString();
aoqi@0 900 if (addToTable) {
aoqi@0 901 _attributeValueTable.add(value);
aoqi@0 902 }
aoqi@0 903
aoqi@0 904 a.setValue(value);
aoqi@0 905 _currentElement.setAttributeNode(a);
aoqi@0 906 break;
aoqi@0 907 }
aoqi@0 908 case DecoderStateTables.NISTRING_EA:
aoqi@0 909 {
aoqi@0 910 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0;
aoqi@0 911 _identifier = (b & 0x0F) << 4;
aoqi@0 912 b = read();
aoqi@0 913 _identifier |= (b & 0xF0) >> 4;
aoqi@0 914
aoqi@0 915 decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b);
aoqi@0 916 value = convertEncodingAlgorithmDataToCharacters(true);
aoqi@0 917 if (addToTable) {
aoqi@0 918 _attributeValueTable.add(value);
aoqi@0 919 }
aoqi@0 920 a.setValue(value);
aoqi@0 921 _currentElement.setAttributeNode(a);
aoqi@0 922 break;
aoqi@0 923 }
aoqi@0 924 case DecoderStateTables.NISTRING_INDEX_SMALL:
aoqi@0 925 value = _attributeValueTable._array[b & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK];
aoqi@0 926
aoqi@0 927 a.setValue(value);
aoqi@0 928 _currentElement.setAttributeNode(a);
aoqi@0 929 break;
aoqi@0 930 case DecoderStateTables.NISTRING_INDEX_MEDIUM:
aoqi@0 931 {
aoqi@0 932 final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read())
aoqi@0 933 + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT;
aoqi@0 934 value = _attributeValueTable._array[index];
aoqi@0 935
aoqi@0 936 a.setValue(value);
aoqi@0 937 _currentElement.setAttributeNode(a);
aoqi@0 938 break;
aoqi@0 939 }
aoqi@0 940 case DecoderStateTables.NISTRING_INDEX_LARGE:
aoqi@0 941 {
aoqi@0 942 final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read())
aoqi@0 943 + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT;
aoqi@0 944 value = _attributeValueTable._array[index];
aoqi@0 945
aoqi@0 946 a.setValue(value);
aoqi@0 947 _currentElement.setAttributeNode(a);
aoqi@0 948 break;
aoqi@0 949 }
aoqi@0 950 case DecoderStateTables.NISTRING_EMPTY:
aoqi@0 951 a.setValue("");
aoqi@0 952 _currentElement.setAttributeNode(a);
aoqi@0 953 break;
aoqi@0 954 default:
aoqi@0 955 throw new IOException(CommonResourceBundle.getInstance().getString("message.decodingAIIValue"));
aoqi@0 956 }
aoqi@0 957
aoqi@0 958 } while (!_terminate);
aoqi@0 959
aoqi@0 960 // Reset duplication attribute verfifier
aoqi@0 961 _duplicateAttributeVerifier._poolCurrent = _duplicateAttributeVerifier._poolHead;
aoqi@0 962
aoqi@0 963 _terminate = _doubleTerminate;
aoqi@0 964 _doubleTerminate = false;
aoqi@0 965 }
aoqi@0 966
aoqi@0 967 protected final void processCommentII() throws FastInfosetException, IOException {
aoqi@0 968 switch(decodeNonIdentifyingStringOnFirstBit()) {
aoqi@0 969 case NISTRING_STRING:
aoqi@0 970 {
aoqi@0 971 final String s = new String(_charBuffer, 0, _charBufferLength);
aoqi@0 972 if (_addToTable) {
aoqi@0 973 _v.otherString.add(new CharArrayString(s, false));
aoqi@0 974 }
aoqi@0 975
aoqi@0 976 _currentNode.appendChild(_document.createComment(s));
aoqi@0 977 break;
aoqi@0 978 }
aoqi@0 979 case NISTRING_ENCODING_ALGORITHM:
aoqi@0 980 throw new IOException(CommonResourceBundle.getInstance().getString("message.commentIIAlgorithmNotSupported"));
aoqi@0 981 case NISTRING_INDEX:
aoqi@0 982 {
aoqi@0 983 final String s = _v.otherString.get(_integer).toString();
aoqi@0 984
aoqi@0 985 _currentNode.appendChild(_document.createComment(s));
aoqi@0 986 break;
aoqi@0 987 }
aoqi@0 988 case NISTRING_EMPTY_STRING:
aoqi@0 989 _currentNode.appendChild(_document.createComment(""));
aoqi@0 990 break;
aoqi@0 991 }
aoqi@0 992 }
aoqi@0 993
aoqi@0 994 protected final void processProcessingII() throws FastInfosetException, IOException {
aoqi@0 995 final String target = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName);
aoqi@0 996
aoqi@0 997 switch(decodeNonIdentifyingStringOnFirstBit()) {
aoqi@0 998 case NISTRING_STRING:
aoqi@0 999 {
aoqi@0 1000 final String data = new String(_charBuffer, 0, _charBufferLength);
aoqi@0 1001 if (_addToTable) {
aoqi@0 1002 _v.otherString.add(new CharArrayString(data, false));
aoqi@0 1003 }
aoqi@0 1004
aoqi@0 1005 _currentNode.appendChild(_document.createProcessingInstruction(target, data));
aoqi@0 1006 break;
aoqi@0 1007 }
aoqi@0 1008 case NISTRING_ENCODING_ALGORITHM:
aoqi@0 1009 throw new IOException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm"));
aoqi@0 1010 case NISTRING_INDEX:
aoqi@0 1011 {
aoqi@0 1012 final String data = _v.otherString.get(_integer).toString();
aoqi@0 1013
aoqi@0 1014 _currentNode.appendChild(_document.createProcessingInstruction(target, data));
aoqi@0 1015 break;
aoqi@0 1016 }
aoqi@0 1017 case NISTRING_EMPTY_STRING:
aoqi@0 1018 _currentNode.appendChild(_document.createProcessingInstruction(target, ""));
aoqi@0 1019 break;
aoqi@0 1020 }
aoqi@0 1021 }
aoqi@0 1022
aoqi@0 1023 protected Element createElement(String namespaceName, String qName, String localName) {
aoqi@0 1024 return _document.createElementNS(namespaceName, qName);
aoqi@0 1025 }
aoqi@0 1026
aoqi@0 1027 protected Attr createAttribute(String namespaceName, String qName, String localName) {
aoqi@0 1028 return _document.createAttributeNS(namespaceName, qName);
aoqi@0 1029 }
aoqi@0 1030
aoqi@0 1031 protected String convertEncodingAlgorithmDataToCharacters(boolean isAttributeValue) throws FastInfosetException, IOException {
aoqi@0 1032 StringBuffer buffer = new StringBuffer();
aoqi@0 1033 if (_identifier < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) {
aoqi@0 1034 Object array = BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).
aoqi@0 1035 decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
aoqi@0 1036 BuiltInEncodingAlgorithmFactory.getAlgorithm(_identifier).convertToCharacters(array, buffer);
aoqi@0 1037 } else if (_identifier == EncodingAlgorithmIndexes.CDATA) {
aoqi@0 1038 if (!isAttributeValue) {
aoqi@0 1039 // Set back buffer position to start of encoded string
aoqi@0 1040 _octetBufferOffset -= _octetBufferLength;
aoqi@0 1041 return decodeUtf8StringAsString();
aoqi@0 1042 }
aoqi@0 1043 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported"));
aoqi@0 1044 } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) {
aoqi@0 1045 final String URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START);
aoqi@0 1046 final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(URI);
aoqi@0 1047 if (ea != null) {
aoqi@0 1048 final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength);
aoqi@0 1049 ea.convertToCharacters(data, buffer);
aoqi@0 1050 } else {
aoqi@0 1051 throw new EncodingAlgorithmException(
aoqi@0 1052 CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported"));
aoqi@0 1053 }
aoqi@0 1054 }
aoqi@0 1055 return buffer.toString();
aoqi@0 1056 }
aoqi@0 1057 }

mercurial