1 38 39 40 package com.sun.xml.fastinfoset.stax; 41 42 import com.sun.xml.fastinfoset.Decoder; 43 import com.sun.xml.fastinfoset.DecoderStateTables; 44 import com.sun.xml.fastinfoset.EncodingConstants; 45 import com.sun.xml.fastinfoset.QualifiedName; 46 import com.sun.xml.fastinfoset.algorithm.BuiltInEncodingAlgorithmFactory; 47 import com.sun.xml.fastinfoset.sax.AttributesHolder; 48 import com.sun.xml.fastinfoset.util.CharArray; 49 import com.sun.xml.fastinfoset.util.CharArrayString; 50 import com.sun.xml.fastinfoset.util.XMLChar; 51 import com.sun.xml.fastinfoset.util.EventLocation; 52 import java.io.IOException ; 53 import java.io.InputStream ; 54 import java.util.Iterator ; 55 import java.util.NoSuchElementException ; 56 import javax.xml.namespace.NamespaceContext ; 57 import javax.xml.namespace.QName ; 58 import javax.xml.stream.Location; 59 import javax.xml.stream.XMLStreamException; 60 import javax.xml.stream.XMLStreamReader; 61 import org.jvnet.fastinfoset.EncodingAlgorithm; 62 import org.jvnet.fastinfoset.EncodingAlgorithmException; 63 import org.jvnet.fastinfoset.EncodingAlgorithmIndexes; 64 import org.jvnet.fastinfoset.FastInfosetException; 65 import com.sun.xml.fastinfoset.CommonResourceBundle; 66 67 public class StAXDocumentParser extends Decoder implements XMLStreamReader { 68 protected static final int INTERNAL_STATE_START_DOCUMENT = 0; 69 protected static final int INTERNAL_STATE_START_ELEMENT_TERMINATE = 1; 70 protected static final int INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES = 2; 71 protected static final int INTERNAL_STATE_DOUBLE_TERMINATE_ELEMENT = 3; 72 protected static final int INTERNAL_STATE_END_DOCUMENT = 4; 73 protected static final int INTERNAL_STATE_VOID = -1; 74 75 protected int _internalState; 76 77 80 protected int _eventType; 81 82 85 protected QualifiedName[] _qNameStack = new QualifiedName[32]; 86 protected int[] _namespaceAIIsStartStack = new int[32]; 87 protected int[] _namespaceAIIsEndStack = new int[32]; 88 protected int _stackCount = -1; 89 90 protected String [] _namespaceAIIsPrefix = new String [32]; 91 protected String [] _namespaceAIIsNamespaceName = new String [32]; 92 protected int[] _namespaceAIIsPrefixIndex = new int[32]; 93 protected int _namespaceAIIsIndex; 94 95 98 protected int _currentNamespaceAIIsStart; 99 protected int _currentNamespaceAIIsEnd; 100 101 104 protected QualifiedName _qualifiedName; 105 106 109 protected AttributesHolder _attributes = new AttributesHolder(); 110 111 protected boolean _clearAttributes = false; 112 113 116 protected char[] _characters; 117 protected int _charactersOffset; 118 protected int _charactersLength; 119 120 protected String _algorithmURI; 121 protected int _algorithmId; 122 protected byte[] _algorithmData; 123 protected int _algorithmDataOffset; 124 protected int _algorithmDataLength; 125 126 129 protected String _piTarget; 130 protected String _piData; 131 132 protected NamespaceContextImpl _nsContext = new NamespaceContextImpl(); 133 134 protected String _characterEncodingScheme; 135 136 protected StAXManager _manager; 137 138 public StAXDocumentParser() { 139 reset(); 140 } 141 142 public StAXDocumentParser(InputStream s) { 143 this(); 144 setInputStream(s); 145 } 146 147 public StAXDocumentParser(InputStream s, StAXManager manager) { 148 this(s); 149 _manager = manager; 150 } 151 152 public void setInputStream(InputStream s) { 153 super.setInputStream(s); 154 reset(); 155 } 156 157 public void reset() { 158 super.reset(); 159 if (_internalState != INTERNAL_STATE_START_DOCUMENT && 160 _internalState != INTERNAL_STATE_END_DOCUMENT) { 161 162 for (int i = _namespaceAIIsIndex - 1; i >= 0; i--) { 163 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]); 164 } 165 166 _stackCount = -1; 167 168 _namespaceAIIsIndex = 0; 169 _characters = null; 170 _algorithmData = null; 171 } 172 173 _characterEncodingScheme = "UTF-8"; 174 _eventType = START_DOCUMENT; 175 _internalState = INTERNAL_STATE_START_DOCUMENT; 176 } 177 178 protected void resetOnError() { 179 super.reset(); 180 181 if (_v != null) { 182 _prefixTable.clearCompletely(); 183 } 184 _duplicateAttributeVerifier.clear(); 185 186 _stackCount = -1; 187 188 _namespaceAIIsIndex = 0; 189 _characters = null; 190 _algorithmData = null; 191 192 _eventType = START_DOCUMENT; 193 _internalState = INTERNAL_STATE_START_DOCUMENT; 194 } 195 196 198 public Object getProperty(java.lang.String name) 199 throws java.lang.IllegalArgumentException { 200 if (_manager != null) { 201 return _manager.getProperty(name); 202 } 203 return null; 204 } 205 206 public int next() throws XMLStreamException { 207 try { 208 if (_internalState != INTERNAL_STATE_VOID) { 209 switch (_internalState) { 210 case INTERNAL_STATE_START_DOCUMENT: 211 decodeHeader(); 212 processDII(); 213 214 _internalState = INTERNAL_STATE_VOID; 215 break; 216 case INTERNAL_STATE_START_ELEMENT_TERMINATE: 217 if (_currentNamespaceAIIsEnd > 0) { 218 for (int i = _currentNamespaceAIIsEnd - 1; i >= _currentNamespaceAIIsStart; i--) { 219 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]); 220 } 221 _namespaceAIIsIndex = _currentNamespaceAIIsStart; 222 } 223 224 popStack(); 226 227 _internalState = INTERNAL_STATE_VOID; 228 return _eventType = END_ELEMENT; 229 case INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES: 230 for (int i = _currentNamespaceAIIsEnd - 1; i >= _currentNamespaceAIIsStart; i--) { 232 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]); 233 } 234 _namespaceAIIsIndex = _currentNamespaceAIIsStart; 235 _internalState = INTERNAL_STATE_VOID; 236 break; 237 case INTERNAL_STATE_DOUBLE_TERMINATE_ELEMENT: 238 if (_currentNamespaceAIIsEnd > 0) { 240 for (int i = _currentNamespaceAIIsEnd - 1; i >= _currentNamespaceAIIsStart; i--) { 241 _prefixTable.popScopeWithPrefixEntry(_namespaceAIIsPrefixIndex[i]); 242 } 243 _namespaceAIIsIndex = _currentNamespaceAIIsStart; 244 } 245 246 if (_stackCount == -1) { 247 _internalState = INTERNAL_STATE_END_DOCUMENT; 248 return _eventType = END_DOCUMENT; 249 } 250 251 popStack(); 253 254 _internalState = (_currentNamespaceAIIsEnd > 0) ? 255 INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES : 256 INTERNAL_STATE_VOID; 257 return _eventType = END_ELEMENT; 258 case INTERNAL_STATE_END_DOCUMENT: 259 throw new NoSuchElementException (CommonResourceBundle.getInstance().getString("message.noMoreEvents")); 260 } 261 } 262 263 _characters = null; 265 _algorithmData = null; 266 _currentNamespaceAIIsEnd = 0; 267 268 final int b = read(); 270 switch(DecoderStateTables.EII[b]) { 271 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: 272 processEII(_elementNameTable._array[b], false); 273 return _eventType; 274 case DecoderStateTables.EII_AIIS_INDEX_SMALL: 275 processEII(_elementNameTable._array[b & EncodingConstants.INTEGER_3RD_BIT_SMALL_MASK], true); 276 return _eventType; 277 case DecoderStateTables.EII_INDEX_MEDIUM: 278 processEII(processEIIIndexMedium(b), (b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 279 return _eventType; 280 case DecoderStateTables.EII_INDEX_LARGE: 281 processEII(processEIIIndexLarge(b), (b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 282 return _eventType; 283 case DecoderStateTables.EII_LITERAL: 284 { 285 final QualifiedName qn = processLiteralQualifiedName( 286 b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK); 287 _elementNameTable.add(qn); 288 processEII(qn, (b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 289 return _eventType; 290 } 291 case DecoderStateTables.EII_NAMESPACES: 292 processEIIWithNamespaces((b & EncodingConstants.ELEMENT_ATTRIBUTE_FLAG) > 0); 293 return _eventType; 294 case DecoderStateTables.CII_UTF8_SMALL_LENGTH: 295 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) 296 + 1; 297 decodeUtf8StringAsCharBuffer(); 298 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 299 _characterContentChunkTable.add(_charBuffer, _charBufferLength); 300 } 301 302 _characters = _charBuffer; 303 _charactersOffset = 0; 304 _charactersLength = _charBufferLength; 305 return _eventType = CHARACTERS; 306 case DecoderStateTables.CII_UTF8_MEDIUM_LENGTH: 307 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; 308 decodeUtf8StringAsCharBuffer(); 309 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 310 _characterContentChunkTable.add(_charBuffer, _charBufferLength); 311 } 312 313 _characters = _charBuffer; 314 _charactersOffset = 0; 315 _charactersLength = _charBufferLength; 316 return _eventType = CHARACTERS; 317 case DecoderStateTables.CII_UTF8_LARGE_LENGTH: 318 _octetBufferLength = ((read() << 24) | 319 (read() << 16) | 320 (read() << 8) | 321 read()) 322 + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; 323 decodeUtf8StringAsCharBuffer(); 324 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 325 _characterContentChunkTable.add(_charBuffer, _charBufferLength); 326 } 327 328 _characters = _charBuffer; 329 _charactersOffset = 0; 330 _charactersLength = _charBufferLength; 331 return _eventType = CHARACTERS; 332 case DecoderStateTables.CII_UTF16_SMALL_LENGTH: 333 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_MASK) 334 + 1; 335 decodeUtf16StringAsCharBuffer(); 336 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 337 _characterContentChunkTable.add(_charBuffer, _charBufferLength); 338 } 339 340 _characters = _charBuffer; 341 _charactersOffset = 0; 342 _charactersLength = _charBufferLength; 343 return _eventType = CHARACTERS; 344 case DecoderStateTables.CII_UTF16_MEDIUM_LENGTH: 345 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_SMALL_LIMIT; 346 decodeUtf16StringAsCharBuffer(); 347 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 348 _characterContentChunkTable.add(_charBuffer, _charBufferLength); 349 } 350 351 _characters = _charBuffer; 352 _charactersOffset = 0; 353 _charactersLength = _charBufferLength; 354 return _eventType = CHARACTERS; 355 case DecoderStateTables.CII_UTF16_LARGE_LENGTH: 356 _octetBufferLength = ((read() << 24) | 357 (read() << 16) | 358 (read() << 8) | 359 read()) 360 + EncodingConstants.OCTET_STRING_LENGTH_7TH_BIT_MEDIUM_LIMIT; 361 decodeUtf16StringAsCharBuffer(); 362 if ((b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0) { 363 _characterContentChunkTable.add(_charBuffer, _charBufferLength); 364 } 365 366 _characters = _charBuffer; 367 _charactersOffset = 0; 368 _charactersLength = _charBufferLength; 369 return _eventType = CHARACTERS; 370 case DecoderStateTables.CII_RA: 371 { 372 final boolean addToTable = (_b & EncodingConstants.CHARACTER_CHUNK_ADD_TO_TABLE_FLAG) > 0; 373 374 _identifier = (b & 0x02) << 6; 375 final int b2 = read(); 376 _identifier |= (b2 & 0xFC) >> 2; 377 378 decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(b2); 379 380 decodeRestrictedAlphabetAsCharBuffer(); 381 382 if (addToTable) { 383 _characterContentChunkTable.add(_charBuffer, _charBufferLength); 384 } 385 386 _characters = _charBuffer; 387 _charactersOffset = 0; 388 _charactersLength = _charBufferLength; 389 return _eventType = CHARACTERS; 390 } 391 case DecoderStateTables.CII_EA: 392 { 393 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 394 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.addToTableNotSupported")); 395 } 396 397 _algorithmId = (b & 0x02) << 6; 399 final int b2 = read(); 400 _algorithmId |= (b2 & 0xFC) >> 2; 401 402 decodeOctetsOnSeventhBitOfNonIdentifyingStringOnThirdBit(b2); 403 processCIIEncodingAlgorithm(); 404 405 return _eventType = CHARACTERS; 406 } 407 case DecoderStateTables.CII_INDEX_SMALL: 408 { 409 final int index = b & EncodingConstants.INTEGER_4TH_BIT_SMALL_MASK; 410 411 _characters = _characterContentChunkTable._array; 412 _charactersOffset = _characterContentChunkTable._offset[index]; 413 _charactersLength = _characterContentChunkTable._length[index]; 414 return _eventType = CHARACTERS; 415 } 416 case DecoderStateTables.CII_INDEX_MEDIUM: 417 { 418 final int index = (((b & EncodingConstants.INTEGER_4TH_BIT_MEDIUM_MASK) << 8) | read()) 419 + EncodingConstants.INTEGER_4TH_BIT_SMALL_LIMIT; 420 421 _characters = _characterContentChunkTable._array; 422 _charactersOffset = _characterContentChunkTable._offset[index]; 423 _charactersLength = _characterContentChunkTable._length[index]; 424 return _eventType = CHARACTERS; 425 } 426 case DecoderStateTables.CII_INDEX_LARGE: 427 { 428 final int index = (((b & EncodingConstants.INTEGER_4TH_BIT_LARGE_MASK) << 16) | 429 (read() << 8) | 430 read()) 431 + EncodingConstants.INTEGER_4TH_BIT_MEDIUM_LIMIT; 432 433 _characters = _characterContentChunkTable._array; 434 _charactersOffset = _characterContentChunkTable._offset[index]; 435 _charactersLength = _characterContentChunkTable._length[index]; 436 return _eventType = CHARACTERS; 437 } 438 case DecoderStateTables.CII_INDEX_LARGE_LARGE: 439 { 440 final int index = ((read() << 16) | 441 (read() << 8) | 442 read()) 443 + EncodingConstants.INTEGER_4TH_BIT_LARGE_LIMIT; 444 445 _characters = _characterContentChunkTable._array; 446 _charactersOffset = _characterContentChunkTable._offset[index]; 447 _charactersLength = _characterContentChunkTable._length[index]; 448 return _eventType = CHARACTERS; 449 } 450 case DecoderStateTables.COMMENT_II: 451 processCommentII(); 452 return _eventType; 453 case DecoderStateTables.PROCESSING_INSTRUCTION_II: 454 processProcessingII(); 455 return _eventType; 456 case DecoderStateTables.UNEXPANDED_ENTITY_REFERENCE_II: 457 { 458 462 String entity_reference_name = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); 463 464 String system_identifier = ((b & EncodingConstants.UNEXPANDED_ENTITY_SYSTEM_IDENTIFIER_FLAG) > 0) 465 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 466 String public_identifier = ((b & EncodingConstants.UNEXPANDED_ENTITY_PUBLIC_IDENTIFIER_FLAG) > 0) 467 ? decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherURI) : ""; 468 return _eventType; 469 } 470 case DecoderStateTables.TERMINATOR_DOUBLE: 471 if (_stackCount != -1) { 472 popStack(); 474 475 _internalState = INTERNAL_STATE_DOUBLE_TERMINATE_ELEMENT; 476 return _eventType = END_ELEMENT; 477 } 478 479 _internalState = INTERNAL_STATE_END_DOCUMENT; 480 return _eventType = END_DOCUMENT; 481 case DecoderStateTables.TERMINATOR_SINGLE: 482 if (_stackCount != -1) { 483 popStack(); 485 486 if (_currentNamespaceAIIsEnd > 0) { 487 _internalState = INTERNAL_STATE_SINGLE_TERMINATE_ELEMENT_WITH_NAMESPACES; 488 } 489 return _eventType = END_ELEMENT; 490 } 491 492 _internalState = INTERNAL_STATE_END_DOCUMENT; 493 return _eventType = END_DOCUMENT; 494 default: 495 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEII")); 496 } 497 } catch (IOException e) { 498 resetOnError(); 499 e.printStackTrace(); 500 throw new XMLStreamException(e); 501 } catch (FastInfosetException e) { 502 resetOnError(); 503 e.printStackTrace(); 504 throw new XMLStreamException(e); 505 } catch (RuntimeException e) { 506 resetOnError(); 507 e.printStackTrace(); 508 throw e; 509 } 510 } 511 512 private final void popStack() { 513 _qualifiedName = _qNameStack[_stackCount]; 515 _currentNamespaceAIIsStart = _namespaceAIIsStartStack[_stackCount]; 516 _currentNamespaceAIIsEnd = _namespaceAIIsEndStack[_stackCount]; 517 _qNameStack[_stackCount--] = null; 518 } 519 520 527 public final void require(int type, String namespaceURI, String localName) 528 throws XMLStreamException { 529 if( type != _eventType) 530 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.eventTypeNotMatch", new Object []{getEventTypeString(type)})); 531 if( namespaceURI != null && !namespaceURI.equals(getNamespaceURI()) ) 532 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.namespaceURINotMatch", new Object []{namespaceURI})); 533 if(localName != null && !localName.equals(getLocalName())) 534 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.localNameNotMatch", new Object []{localName})); 535 536 return; 537 } 538 539 545 public final String getElementText() throws XMLStreamException { 546 547 if(getEventType() != START_ELEMENT) { 548 throw new XMLStreamException( 549 CommonResourceBundle.getInstance().getString("message.mustBeOnSTARTELEMENT"), getLocation()); 550 } 551 int eventType = next(); 553 return getElementText(true); 554 } 555 558 public final String getElementText(boolean startElementRead) throws XMLStreamException { 559 if (!startElementRead) { 560 throw new XMLStreamException( 561 CommonResourceBundle.getInstance().getString("message.mustBeOnSTARTELEMENT"), getLocation()); 562 } 563 int eventType = getEventType(); 564 StringBuffer content = new StringBuffer (); 565 while(eventType != END_ELEMENT ) { 566 if(eventType == CHARACTERS 567 || eventType == CDATA 568 || eventType == SPACE 569 || eventType == ENTITY_REFERENCE) { 570 content.append(getText()); 571 } else if(eventType == PROCESSING_INSTRUCTION 572 || eventType == COMMENT) { 573 } else if(eventType == END_DOCUMENT) { 575 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.unexpectedEOF")); 576 } else if(eventType == START_ELEMENT) { 577 throw new XMLStreamException( 578 CommonResourceBundle.getInstance().getString("message.getElementTextExpectTextOnly"), getLocation()); 579 } else { 580 throw new XMLStreamException( 581 CommonResourceBundle.getInstance().getString("message.unexpectedEventType")+ getEventTypeString(eventType), getLocation()); 582 } 583 eventType = next(); 584 } 585 return content.toString(); 586 } 587 588 601 public final int nextTag() throws XMLStreamException { 602 int eventType = next(); 603 return nextTag(true); 604 } 605 608 public final int nextTag(boolean currentTagRead) throws XMLStreamException { 609 int eventType = getEventType(); 610 if (!currentTagRead) { 611 eventType = next(); 612 } 613 while((eventType == CHARACTERS && isWhiteSpace()) || (eventType == CDATA && isWhiteSpace()) 615 || eventType == SPACE 616 || eventType == PROCESSING_INSTRUCTION 617 || eventType == COMMENT) { 618 eventType = next(); 619 } 620 if (eventType != START_ELEMENT && eventType != END_ELEMENT) { 621 throw new XMLStreamException(CommonResourceBundle.getInstance().getString("message.expectedStartOrEnd"), getLocation()); 622 } 623 return eventType; 624 } 625 626 public final boolean hasNext() throws XMLStreamException { 627 return (_eventType != END_DOCUMENT); 628 } 629 630 public void close() throws XMLStreamException { 631 } 632 633 public final String getNamespaceURI(String prefix) { 634 String namespace = getNamespaceDecl(prefix); 635 if (namespace == null) { 636 if (prefix == null) { 637 throw new IllegalArgumentException (CommonResourceBundle.getInstance().getString("message.nullPrefix")); 638 } 639 return null; } 641 return namespace; 642 } 643 644 public final boolean isStartElement() { 645 return (_eventType == START_ELEMENT); 646 } 647 648 public final boolean isEndElement() { 649 return (_eventType == END_ELEMENT); 650 } 651 652 public final boolean isCharacters() { 653 return (_eventType == CHARACTERS); 654 } 655 656 662 public final boolean isWhiteSpace() { 663 if(isCharacters() || (_eventType == CDATA)){ 664 char [] ch = this.getTextCharacters(); 665 int start = this.getTextStart(); 666 int length = this.getTextLength(); 667 for (int i=start; i< length;i++){ 668 if(!XMLChar.isSpace(ch[i])){ 669 return false; 670 } 671 } 672 return true; 673 } 674 return false; 675 } 676 677 public final String getAttributeValue(String namespaceURI, String localName) { 678 if (_eventType != START_ELEMENT) { 679 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 680 } 681 682 for (int i = 0; i < _attributes.getLength(); i++) { 684 if (_attributes.getLocalName(i).equals(localName) && 685 _attributes.getURI(i).equals(namespaceURI)) { 686 return _attributes.getValue(i); 687 } 688 } 689 return null; 690 } 691 692 public final int getAttributeCount() { 693 if (_eventType != START_ELEMENT) { 694 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 695 } 696 697 return _attributes.getLength(); 698 } 699 700 public final javax.xml.namespace.QName getAttributeName(int index) { 701 if (_eventType != START_ELEMENT) { 702 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 703 } 704 return _attributes.getQualifiedName(index).getQName(); 705 } 706 707 public final String getAttributeNamespace(int index) { 708 if (_eventType != START_ELEMENT) { 709 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 710 } 711 712 return _attributes.getURI(index); 713 } 714 715 public final String getAttributeLocalName(int index) { 716 if (_eventType != START_ELEMENT) { 717 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 718 } 719 return _attributes.getLocalName(index); 720 } 721 722 public final String getAttributePrefix(int index) { 723 if (_eventType != START_ELEMENT) { 724 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 725 } 726 return _attributes.getPrefix(index); 727 } 728 729 public final String getAttributeType(int index) { 730 if (_eventType != START_ELEMENT) { 731 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 732 } 733 return _attributes.getType(index); 734 } 735 736 public final String getAttributeValue(int index) { 737 if (_eventType != START_ELEMENT) { 738 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 739 } 740 return _attributes.getValue(index); 741 } 742 743 public final boolean isAttributeSpecified(int index) { 744 return false; } 746 747 public final int getNamespaceCount() { 748 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 749 return (_currentNamespaceAIIsEnd > 0) ? (_currentNamespaceAIIsEnd - _currentNamespaceAIIsStart) : 0; 750 } else { 751 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespaceCount")); 752 } 753 } 754 755 public final String getNamespacePrefix(int index) { 756 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 757 return _namespaceAIIsPrefix[_currentNamespaceAIIsStart + index]; 758 } else { 759 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespacePrefix")); 760 } 761 } 762 763 public final String getNamespaceURI(int index) { 764 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 765 return _namespaceAIIsNamespaceName[_currentNamespaceAIIsStart + index]; 766 } else { 767 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespacePrefix")); 768 } 769 } 770 771 public final NamespaceContext getNamespaceContext() { 772 return _nsContext; 773 } 774 775 public final int getEventType() { 776 return _eventType; 777 } 778 779 public final String getText() { 780 if (_characters == null) { 781 checkTextState(); 782 } 783 784 return new String (_characters, 785 _charactersOffset, 786 _charactersLength); 787 } 788 789 public final char[] getTextCharacters() { 790 if (_characters == null) { 791 checkTextState(); 792 } 793 794 return _characters; 795 } 796 797 public final int getTextStart() { 798 if (_characters == null) { 799 checkTextState(); 800 } 801 802 return _charactersOffset; 803 } 804 805 public final int getTextLength() { 806 if (_characters == null) { 807 checkTextState(); 808 } 809 810 return _charactersLength; 811 } 812 813 public final int getTextCharacters(int sourceStart, char[] target, 814 int targetStart, int length) throws XMLStreamException { 815 if (_characters == null) { 816 checkTextState(); 817 } 818 819 try { 820 System.arraycopy(_characters, sourceStart, target, 821 targetStart, length); 822 return length; 823 } catch (IndexOutOfBoundsException e) { 824 throw new XMLStreamException(e); 825 } 826 } 827 828 protected final void checkTextState() { 829 if (_algorithmData == null) { 830 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.InvalidStateForText")); 831 } 832 833 try { 834 convertEncodingAlgorithmDataToCharacters(); 835 } catch (Exception e) { 836 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.InvalidStateForText")); 837 } 838 } 839 840 public final String getEncoding() { 841 return _characterEncodingScheme; 842 } 843 844 public final boolean hasText() { 845 return (_characters != null); 846 } 847 848 public final Location getLocation() { 849 return EventLocation.getNilLocation(); 852 } 853 854 public final QName getName() { 855 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 856 return _qualifiedName.getQName(); 857 } else { 858 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetName")); 859 } 860 } 861 862 public final String getLocalName() { 863 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 864 return _qualifiedName.localName; 865 } else { 866 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetLocalName")); 867 } 868 } 869 870 public final boolean hasName() { 871 return (_eventType == START_ELEMENT || _eventType == END_ELEMENT); 872 } 873 874 public final String getNamespaceURI() { 875 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 876 return _qualifiedName.namespaceName; 877 } else { 878 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetNamespaceURI")); 879 } 880 } 881 882 public final String getPrefix() { 883 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 884 return _qualifiedName.prefix; 885 } else { 886 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetPrefix")); 887 } 888 } 889 890 public final String getVersion() { 891 return null; 892 } 893 894 public final boolean isStandalone() { 895 return false; 896 } 897 898 public final boolean standaloneSet() { 899 return false; 900 } 901 902 public final String getCharacterEncodingScheme() { 903 return null; 904 } 905 906 public final String getPITarget() { 907 if (_eventType != PROCESSING_INSTRUCTION) { 908 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetPITarget")); 909 } 910 911 return _piTarget; 912 } 913 914 public final String getPIData() { 915 if (_eventType != PROCESSING_INSTRUCTION) { 916 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetPIData")); 917 } 918 919 return _piData; 920 } 921 922 923 924 925 public final String getNameString() { 926 if (_eventType == START_ELEMENT || _eventType == END_ELEMENT) { 927 return _qualifiedName.getQNameString(); 928 } else { 929 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetName")); 930 } 931 } 932 933 public final String getAttributeNameString(int index) { 934 if (_eventType != START_ELEMENT) { 935 throw new IllegalStateException (CommonResourceBundle.getInstance().getString("message.invalidCallingGetAttributeValue")); 936 } 937 return _attributes.getQualifiedName(index).getQNameString(); 938 } 939 940 941 public final String getTextAlgorithmURI() { 942 return _algorithmURI; 943 } 944 945 public final int getTextAlgorithmIndex() { 946 return _algorithmId; 947 } 948 949 public final byte[] getTextAlgorithmBytes() { 950 return _algorithmData; 951 } 952 953 public final byte[] getTextAlgorithmBytesClone() { 954 if (_algorithmData == null) { 955 return null; 956 } 957 958 byte[] algorithmData = new byte[_algorithmDataLength]; 959 System.arraycopy(_algorithmData, _algorithmDataOffset, algorithmData, 0, _algorithmDataLength); 960 return algorithmData; 961 } 962 963 public final int getTextAlgorithmStart() { 964 return _algorithmDataOffset; 965 } 966 967 public final int getTextAlgorithmLength() { 968 return _algorithmDataLength; 969 } 970 971 public final int getTextAlgorithmBytes(int sourceStart, byte[] target, 972 int targetStart, int length) throws XMLStreamException { 973 try { 974 System.arraycopy(_algorithmData, sourceStart, target, 975 targetStart, length); 976 return length; 977 } catch (IndexOutOfBoundsException e) { 978 throw new XMLStreamException(e); 979 } 980 } 981 982 983 984 986 protected final void processDII() throws FastInfosetException, IOException { 987 final int b = read(); 988 if (b > 0) { 989 processDIIOptionalProperties(b); 990 } 991 } 992 993 protected final void processDIIOptionalProperties(int b) throws FastInfosetException, IOException { 994 if (b == EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) { 996 decodeInitialVocabulary(); 997 return; 998 } 999 1000 if ((b & EncodingConstants.DOCUMENT_ADDITIONAL_DATA_FLAG) > 0) { 1001 decodeAdditionalData(); 1002 1006 } 1007 1008 if ((b & EncodingConstants.DOCUMENT_INITIAL_VOCABULARY_FLAG) > 0) { 1009 decodeInitialVocabulary(); 1010 } 1011 1012 if ((b & EncodingConstants.DOCUMENT_NOTATIONS_FLAG) > 0) { 1013 decodeNotations(); 1014 1021 } 1022 1023 if ((b & EncodingConstants.DOCUMENT_UNPARSED_ENTITIES_FLAG) > 0) { 1024 decodeUnparsedEntities(); 1025 1032 } 1033 1034 if ((b & EncodingConstants.DOCUMENT_CHARACTER_ENCODING_SCHEME) > 0) { 1035 _characterEncodingScheme = decodeCharacterEncodingScheme(); 1036 } 1037 1038 if ((b & EncodingConstants.DOCUMENT_STANDALONE_FLAG) > 0) { 1039 boolean standalone = (read() > 0) ? true : false ; 1040 1044 } 1045 1046 if ((b & EncodingConstants.DOCUMENT_VERSION_FLAG) > 0) { 1047 String version = decodeVersion(); 1048 1052 } 1053 } 1054 1055 1056 protected final void resizeNamespaceAIIs() { 1057 final String [] namespaceAIIsPrefix = new String [_namespaceAIIsIndex * 2]; 1058 System.arraycopy(_namespaceAIIsPrefix, 0, namespaceAIIsPrefix, 0, _namespaceAIIsIndex); 1059 _namespaceAIIsPrefix = namespaceAIIsPrefix; 1060 1061 final String [] namespaceAIIsNamespaceName = new String [_namespaceAIIsIndex * 2]; 1062 System.arraycopy(_namespaceAIIsNamespaceName, 0, namespaceAIIsNamespaceName, 0, _namespaceAIIsIndex); 1063 _namespaceAIIsNamespaceName = namespaceAIIsNamespaceName; 1064 1065 final int[] namespaceAIIsPrefixIndex = new int[_namespaceAIIsIndex * 2]; 1066 System.arraycopy(_namespaceAIIsPrefixIndex, 0, namespaceAIIsPrefixIndex, 0, _namespaceAIIsIndex); 1067 _namespaceAIIsPrefixIndex = namespaceAIIsPrefixIndex; 1068 } 1069 1070 protected final void processEIIWithNamespaces(boolean hasAttributes) throws FastInfosetException, IOException { 1071 if (++_prefixTable._declarationId == Integer.MAX_VALUE) { 1072 _prefixTable.clearDeclarationIds(); 1073 } 1074 1075 _currentNamespaceAIIsStart = _namespaceAIIsIndex; 1076 String prefix = "", namespaceName = ""; 1077 int b = read(); 1078 while ((b & EncodingConstants.NAMESPACE_ATTRIBUTE_MASK) == EncodingConstants.NAMESPACE_ATTRIBUTE) { 1079 if (_namespaceAIIsIndex == _namespaceAIIsPrefix.length) { 1080 resizeNamespaceAIIs(); 1081 } 1082 1083 switch (b & EncodingConstants.NAMESPACE_ATTRIBUTE_PREFIX_NAME_MASK) { 1084 case 0: 1087 prefix = namespaceName = 1088 _namespaceAIIsPrefix[_namespaceAIIsIndex] = 1089 _namespaceAIIsNamespaceName[_namespaceAIIsIndex] = ""; 1090 1091 _namespaceNameIndex = _prefixIndex = _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = -1; 1092 break; 1093 case 1: 1096 prefix = _namespaceAIIsPrefix[_namespaceAIIsIndex] = ""; 1097 namespaceName = _namespaceAIIsNamespaceName[_namespaceAIIsIndex] = 1098 decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(false); 1099 1100 _prefixIndex = _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = -1; 1101 break; 1102 case 2: 1105 prefix = _namespaceAIIsPrefix[_namespaceAIIsIndex] = 1106 decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(false); 1107 namespaceName = _namespaceAIIsNamespaceName[_namespaceAIIsIndex] = ""; 1108 1109 _namespaceNameIndex = -1; 1110 _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = _prefixIndex; 1111 break; 1112 case 3: 1115 prefix = _namespaceAIIsPrefix[_namespaceAIIsIndex] = 1116 decodeIdentifyingNonEmptyStringOnFirstBitAsPrefix(true); 1117 namespaceName = _namespaceAIIsNamespaceName[_namespaceAIIsIndex] = 1118 decodeIdentifyingNonEmptyStringOnFirstBitAsNamespaceName(true); 1119 1120 _namespaceAIIsPrefixIndex[_namespaceAIIsIndex++] = _prefixIndex; 1121 break; 1122 } 1123 1124 _prefixTable.pushScopeWithPrefixEntry(prefix, namespaceName, _prefixIndex, _namespaceNameIndex); 1126 1127 b = read(); 1128 } 1129 if (b != EncodingConstants.TERMINATOR) { 1130 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.EIInamespaceNameNotTerminatedCorrectly")); 1131 } 1132 _currentNamespaceAIIsEnd = _namespaceAIIsIndex; 1133 1134 b = read(); 1135 switch(DecoderStateTables.EII[b]) { 1136 case DecoderStateTables.EII_NO_AIIS_INDEX_SMALL: 1137 processEII(_elementNameTable._array[b], hasAttributes); 1138 break; 1139 case DecoderStateTables.EII_INDEX_MEDIUM: 1140 processEII(processEIIIndexMedium(b), hasAttributes); 1141 break; 1142 case DecoderStateTables.EII_INDEX_LARGE: 1143 processEII(processEIIIndexLarge(b), hasAttributes); 1144 break; 1145 case DecoderStateTables.EII_LITERAL: 1146 { 1147 final QualifiedName qn = processLiteralQualifiedName( 1148 b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK); 1149 _elementNameTable.add(qn); 1150 processEII(qn, hasAttributes); 1151 break; 1152 } 1153 default: 1154 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.IllegalStateDecodingEIIAfterAIIs")); 1155 } 1156 } 1157 1158 protected final void processEII(QualifiedName name, boolean hasAttributes) throws FastInfosetException, IOException { 1159 if (_prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) { 1160 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qnameOfEIINotInScope")); 1161 } 1162 1163 _eventType = START_ELEMENT; 1164 _qualifiedName = name; 1165 1166 if (_clearAttributes) { 1167 _attributes.clear(); 1168 _clearAttributes = false; 1169 } 1170 1171 if (hasAttributes) { 1172 processAIIs(); 1173 } 1174 1175 _stackCount++; 1177 if (_stackCount == _qNameStack.length) { 1178 QualifiedName[] qNameStack = new QualifiedName[_qNameStack.length * 2]; 1179 System.arraycopy(_qNameStack, 0, qNameStack, 0, _qNameStack.length); 1180 _qNameStack = qNameStack; 1181 1182 int[] namespaceAIIsStartStack = new int[_namespaceAIIsStartStack.length * 2]; 1183 System.arraycopy(_namespaceAIIsStartStack, 0, namespaceAIIsStartStack, 0, _namespaceAIIsStartStack.length); 1184 _namespaceAIIsStartStack = namespaceAIIsStartStack; 1185 1186 int[] namespaceAIIsEndStack = new int[_namespaceAIIsEndStack.length * 2]; 1187 System.arraycopy(_namespaceAIIsEndStack, 0, namespaceAIIsEndStack, 0, _namespaceAIIsEndStack.length); 1188 _namespaceAIIsEndStack = namespaceAIIsEndStack; 1189 } 1190 _qNameStack[_stackCount] = _qualifiedName; 1191 _namespaceAIIsStartStack[_stackCount] = _currentNamespaceAIIsStart; 1192 _namespaceAIIsEndStack[_stackCount] = _currentNamespaceAIIsEnd; 1193 } 1194 1195 protected final void processAIIs() throws FastInfosetException, IOException { 1196 QualifiedName name; 1197 int b; 1198 String value; 1199 1200 if (++_duplicateAttributeVerifier._currentIteration == Integer.MAX_VALUE) { 1201 _duplicateAttributeVerifier.clear(); 1202 } 1203 1204 _clearAttributes = true; 1205 boolean terminate = false; 1206 do { 1207 b = read(); 1209 switch (DecoderStateTables.AII[b]) { 1210 case DecoderStateTables.AII_INDEX_SMALL: 1211 name = _attributeNameTable._array[b]; 1212 break; 1213 case DecoderStateTables.AII_INDEX_MEDIUM: 1214 { 1215 final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read()) 1216 + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT; 1217 name = _attributeNameTable._array[i]; 1218 break; 1219 } 1220 case DecoderStateTables.AII_INDEX_LARGE: 1221 { 1222 final int i = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read()) 1223 + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT; 1224 name = _attributeNameTable._array[i]; 1225 break; 1226 } 1227 case DecoderStateTables.AII_LITERAL: 1228 name = processLiteralQualifiedName( 1229 b & EncodingConstants.LITERAL_QNAME_PREFIX_NAMESPACE_NAME_MASK); 1230 name.createAttributeValues(_duplicateAttributeVerifier.MAP_SIZE); 1231 _attributeNameTable.add(name); 1232 break; 1233 case DecoderStateTables.AII_TERMINATOR_DOUBLE: 1234 _internalState = INTERNAL_STATE_START_ELEMENT_TERMINATE; 1235 case DecoderStateTables.AII_TERMINATOR_SINGLE: 1236 terminate = true; 1237 continue; 1239 default: 1240 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingAIIs")); 1241 } 1242 1243 1245 if (name.prefixIndex > 0 && _prefixTable._currentInScope[name.prefixIndex] != name.namespaceNameIndex) { 1246 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.AIIqNameNotInScope")); 1247 } 1248 1249 _duplicateAttributeVerifier.checkForDuplicateAttribute(name.attributeHash, name.attributeId); 1250 1251 b = read(); 1252 switch(DecoderStateTables.NISTRING[b]) { 1253 case DecoderStateTables.NISTRING_UTF8_SMALL_LENGTH: 1254 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1; 1255 value = decodeUtf8StringAsString(); 1256 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1257 _attributeValueTable.add(value); 1258 } 1259 1260 _attributes.addAttribute(name, value); 1261 break; 1262 case DecoderStateTables.NISTRING_UTF8_MEDIUM_LENGTH: 1263 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT; 1264 value = decodeUtf8StringAsString(); 1265 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1266 _attributeValueTable.add(value); 1267 } 1268 1269 _attributes.addAttribute(name, value); 1270 break; 1271 case DecoderStateTables.NISTRING_UTF8_LARGE_LENGTH: 1272 _octetBufferLength = ((read() << 24) | 1273 (read() << 16) | 1274 (read() << 8) | 1275 read()) 1276 + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT; 1277 value = decodeUtf8StringAsString(); 1278 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1279 _attributeValueTable.add(value); 1280 } 1281 1282 _attributes.addAttribute(name, value); 1283 break; 1284 case DecoderStateTables.NISTRING_UTF16_SMALL_LENGTH: 1285 _octetBufferLength = (b & EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_MASK) + 1; 1286 value = decodeUtf16StringAsString(); 1287 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1288 _attributeValueTable.add(value); 1289 } 1290 1291 _attributes.addAttribute(name, value); 1292 break; 1293 case DecoderStateTables.NISTRING_UTF16_MEDIUM_LENGTH: 1294 _octetBufferLength = read() + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_SMALL_LIMIT; 1295 value = decodeUtf16StringAsString(); 1296 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1297 _attributeValueTable.add(value); 1298 } 1299 1300 _attributes.addAttribute(name, value); 1301 break; 1302 case DecoderStateTables.NISTRING_UTF16_LARGE_LENGTH: 1303 _octetBufferLength = ((read() << 24) | 1304 (read() << 16) | 1305 (read() << 8) | 1306 read()) 1307 + EncodingConstants.OCTET_STRING_LENGTH_5TH_BIT_MEDIUM_LIMIT; 1308 value = decodeUtf16StringAsString(); 1309 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1310 _attributeValueTable.add(value); 1311 } 1312 1313 _attributes.addAttribute(name, value); 1314 break; 1315 case DecoderStateTables.NISTRING_RA: 1316 { 1317 final boolean addToTable = (b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0; 1318 _identifier = (b & 0x0F) << 4; 1320 b = read(); 1321 _identifier |= (b & 0xF0) >> 4; 1322 1323 decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b); 1324 1325 value = decodeRestrictedAlphabetAsString(); 1326 if (addToTable) { 1327 _attributeValueTable.add(value); 1328 } 1329 1330 _attributes.addAttribute(name, value); 1331 break; 1332 } 1333 case DecoderStateTables.NISTRING_EA: 1334 { 1335 if ((b & EncodingConstants.NISTRING_ADD_TO_TABLE_FLAG) > 0) { 1336 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.addToTableNotSupported")); 1337 } 1338 1339 _identifier = (b & 0x0F) << 4; 1341 b = read(); 1342 _identifier |= (b & 0xF0) >> 4; 1343 1344 decodeOctetsOnFifthBitOfNonIdentifyingStringOnFirstBit(b); 1345 processAIIEncodingAlgorithm(name); 1346 break; 1347 } 1348 case DecoderStateTables.NISTRING_INDEX_SMALL: 1349 _attributes.addAttribute(name, 1350 _attributeValueTable._array[b & EncodingConstants.INTEGER_2ND_BIT_SMALL_MASK]); 1351 break; 1352 case DecoderStateTables.NISTRING_INDEX_MEDIUM: 1353 { 1354 final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_MEDIUM_MASK) << 8) | read()) 1355 + EncodingConstants.INTEGER_2ND_BIT_SMALL_LIMIT; 1356 1357 _attributes.addAttribute(name, 1358 _attributeValueTable._array[index]); 1359 break; 1360 } 1361 case DecoderStateTables.NISTRING_INDEX_LARGE: 1362 { 1363 final int index = (((b & EncodingConstants.INTEGER_2ND_BIT_LARGE_MASK) << 16) | (read() << 8) | read()) 1364 + EncodingConstants.INTEGER_2ND_BIT_MEDIUM_LIMIT; 1365 1366 _attributes.addAttribute(name, 1367 _attributeValueTable._array[index]); 1368 break; 1369 } 1370 case DecoderStateTables.NISTRING_EMPTY: 1371 _attributes.addAttribute(name, ""); 1372 break; 1373 default: 1374 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingAIIValue")); 1375 } 1376 1377 } while (!terminate); 1378 1379 _duplicateAttributeVerifier._poolCurrent = _duplicateAttributeVerifier._poolHead; 1381 } 1382 1383 protected final QualifiedName processEIIIndexMedium(int b) throws FastInfosetException, IOException { 1384 final int i = (((b & EncodingConstants.INTEGER_3RD_BIT_MEDIUM_MASK) << 8) | read()) 1385 + EncodingConstants.INTEGER_3RD_BIT_SMALL_LIMIT; 1386 return _elementNameTable._array[i]; 1387 } 1388 1389 protected final QualifiedName processEIIIndexLarge(int b) throws FastInfosetException, IOException { 1390 int i; 1391 if ((b & EncodingConstants.INTEGER_3RD_BIT_LARGE_LARGE_FLAG) == 0x20) { 1392 i = (((b & EncodingConstants.INTEGER_3RD_BIT_LARGE_MASK) << 16) | (read() << 8) | read()) 1394 + EncodingConstants.INTEGER_3RD_BIT_MEDIUM_LIMIT; 1395 } else { 1396 i = (((read() & EncodingConstants.INTEGER_3RD_BIT_LARGE_LARGE_MASK) << 16) | (read() << 8) | read()) 1398 + EncodingConstants.INTEGER_3RD_BIT_LARGE_LIMIT; 1399 } 1400 return _elementNameTable._array[i]; 1401 } 1402 1403 protected final QualifiedName processLiteralQualifiedName(int state) throws FastInfosetException, IOException { 1404 switch (state) { 1405 case 0: 1407 return new QualifiedName( 1408 "", 1409 "", 1410 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName), 1411 "", 1412 0, 1413 -1, 1414 -1, 1415 _identifier); 1416 case 1: 1418 return new QualifiedName( 1419 "", 1420 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(false), 1421 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName), 1422 "", 1423 0, 1424 -1, 1425 _namespaceNameIndex, 1426 _identifier); 1427 case 2: 1429 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.qNameMissingNamespaceName")); 1430 case 3: 1432 return new QualifiedName( 1433 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsPrefix(true), 1434 decodeIdentifyingNonEmptyStringIndexOnFirstBitAsNamespaceName(true), 1435 decodeIdentifyingNonEmptyStringOnFirstBit(_v.localName), 1436 "", 1437 0, 1438 _prefixIndex, 1439 _namespaceNameIndex, 1440 _identifier); 1441 default: 1442 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.decodingEII")); 1443 } 1444 } 1445 1446 protected final void processCommentII() throws FastInfosetException, IOException { 1447 _eventType = COMMENT; 1448 1449 switch(decodeNonIdentifyingStringOnFirstBit()) { 1450 case NISTRING_STRING: 1451 if (_addToTable) { 1452 _v.otherString.add(new CharArray(_charBuffer, 0, _charBufferLength, true)); 1453 } 1454 1455 _characters = _charBuffer; 1456 _charactersOffset = 0; 1457 _charactersLength = _charBufferLength; 1458 break; 1459 case NISTRING_ENCODING_ALGORITHM: 1460 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.commentIIAlgorithmNotSupported")); 1461 case NISTRING_INDEX: 1462 final CharArray ca = _v.otherString.get(_integer); 1463 1464 _characters = ca.ch; 1465 _charactersOffset = ca.start; 1466 _charactersLength = ca.length; 1467 break; 1468 case NISTRING_EMPTY_STRING: 1469 _characters = _charBuffer; 1470 _charactersOffset = 0; 1471 _charactersLength = 0; 1472 break; 1473 } 1474 } 1475 1476 protected final void processProcessingII() throws FastInfosetException, IOException { 1477 _eventType = PROCESSING_INSTRUCTION; 1478 1479 _piTarget = decodeIdentifyingNonEmptyStringOnFirstBit(_v.otherNCName); 1480 1481 switch(decodeNonIdentifyingStringOnFirstBit()) { 1482 case NISTRING_STRING: 1483 _piData = new String (_charBuffer, 0, _charBufferLength); 1484 if (_addToTable) { 1485 _v.otherString.add(new CharArrayString(_piData)); 1486 } 1487 break; 1488 case NISTRING_ENCODING_ALGORITHM: 1489 throw new FastInfosetException(CommonResourceBundle.getInstance().getString("message.processingIIWithEncodingAlgorithm")); 1490 case NISTRING_INDEX: 1491 _piData = _v.otherString.get(_integer).toString(); 1492 break; 1493 case NISTRING_EMPTY_STRING: 1494 _piData = ""; 1495 break; 1496 } 1497 } 1498 1499 protected final void processCIIEncodingAlgorithm() throws FastInfosetException, IOException { 1500 _algorithmData = _octetBuffer; 1501 _algorithmDataOffset = _octetBufferStart; 1502 _algorithmDataLength = _octetBufferLength; 1503 1504 if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { 1505 _algorithmURI = _v.encodingAlgorithm.get(_algorithmId - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START); 1506 if (_algorithmURI == null) { 1507 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent", new Object []{new Integer (_identifier)})); 1508 } 1509 } else if (_algorithmId > EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { 1510 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved")); 1514 } 1515 } 1516 1517 protected final void processAIIEncodingAlgorithm(QualifiedName name) throws FastInfosetException, IOException { 1518 String URI = null; 1519 if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { 1520 URI = _v.encodingAlgorithm.get(_identifier - EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START); 1521 if (URI == null) { 1522 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.URINotPresent", new Object []{new Integer (_identifier)})); 1523 } 1524 } else if (_identifier >= EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { 1525 if (_identifier == EncodingAlgorithmIndexes.CDATA) { 1526 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.CDATAAlgorithmNotSupported")); 1527 } 1528 1529 throw new EncodingAlgorithmException(CommonResourceBundle.getInstance().getString("message.identifiers10to31Reserved")); 1533 } 1534 1535 final byte[] data = new byte[_octetBufferLength]; 1536 System.arraycopy(_octetBuffer, _octetBufferStart, data, 0, _octetBufferLength); 1537 _attributes.addAttributeWithAlgorithmData(name, URI, _identifier, data); 1538 } 1539 1540 protected final void convertEncodingAlgorithmDataToCharacters() throws FastInfosetException, IOException { 1541 StringBuffer buffer = new StringBuffer (); 1542 if (_algorithmId < EncodingConstants.ENCODING_ALGORITHM_BUILTIN_END) { 1543 Object array = BuiltInEncodingAlgorithmFactory.table[_algorithmId]. 1544 decodeFromBytes(_algorithmData, _algorithmDataOffset, _algorithmDataLength); 1545 BuiltInEncodingAlgorithmFactory.table[_algorithmId].convertToCharacters(array, buffer); 1546 } else if (_algorithmId == EncodingAlgorithmIndexes.CDATA) { 1547 _octetBufferOffset -= _octetBufferLength; 1548 decodeUtf8StringIntoCharBuffer(); 1549 1550 _characters = _charBuffer; 1551 _charactersOffset = 0; 1552 _charactersLength = _charBufferLength; 1553 return; 1554 } else if (_algorithmId >= EncodingConstants.ENCODING_ALGORITHM_APPLICATION_START) { 1555 final EncodingAlgorithm ea = (EncodingAlgorithm)_registeredEncodingAlgorithms.get(_algorithmURI); 1556 if (ea != null) { 1557 final Object data = ea.decodeFromBytes(_octetBuffer, _octetBufferStart, _octetBufferLength); 1558 ea.convertToCharacters(data, buffer); 1559 } else { 1560 throw new EncodingAlgorithmException( 1561 CommonResourceBundle.getInstance().getString("message.algorithmDataCannotBeReported")); 1562 } 1563 } 1564 1565 _characters = new char[buffer.length()]; 1566 buffer.getChars(0, buffer.length(), _characters, 0); 1567 _charactersOffset = 0; 1568 _charactersLength = _characters.length; 1569 } 1570 1571 protected class NamespaceContextImpl implements NamespaceContext { 1572 public final String getNamespaceURI(String prefix) { 1573 return _prefixTable.getNamespaceFromPrefix(prefix); 1574 } 1575 1576 public final String getPrefix(String namespaceURI) { 1577 return _prefixTable.getPrefixFromNamespace(namespaceURI); 1578 } 1579 1580 public final Iterator getPrefixes(String namespaceURI) { 1581 return _prefixTable.getPrefixesFromNamespace(namespaceURI); 1582 } 1583 } 1584 1585 public final String getNamespaceDecl(String prefix) { 1586 return _prefixTable.getNamespaceFromPrefix(prefix); 1587 } 1588 1589 public final String getURI(String prefix) { 1590 return getNamespaceDecl(prefix); 1591 } 1592 1593 public final Iterator getPrefixes() { 1594 return _prefixTable.getPrefixes(); 1595 } 1596 1597 public final AttributesHolder getAttributesHolder() { 1598 return _attributes; 1599 } 1600 1601 public final void setManager(StAXManager manager) { 1602 _manager = manager; 1603 } 1604 1605 final static String getEventTypeString(int eventType) { 1606 switch (eventType){ 1607 case START_ELEMENT: 1608 return "START_ELEMENT"; 1609 case END_ELEMENT: 1610 return "END_ELEMENT"; 1611 case PROCESSING_INSTRUCTION: 1612 return "PROCESSING_INSTRUCTION"; 1613 case CHARACTERS: 1614 return "CHARACTERS"; 1615 case COMMENT: 1616 return "COMMENT"; 1617 case START_DOCUMENT: 1618 return "START_DOCUMENT"; 1619 case END_DOCUMENT: 1620 return "END_DOCUMENT"; 1621 case ENTITY_REFERENCE: 1622 return "ENTITY_REFERENCE"; 1623 case ATTRIBUTE: 1624 return "ATTRIBUTE"; 1625 case DTD: 1626 return "DTD"; 1627 case CDATA: 1628 return "CDATA"; 1629 } 1630 return "UNKNOWN_EVENT_TYPE"; 1631 } 1632 1633} 1634 | Popular Tags |