1 57 58 package org.enhydra.apache.xerces.framework; 59 60 import org.enhydra.apache.xerces.readers.DefaultEntityHandler; 61 import org.enhydra.apache.xerces.readers.XMLEntityHandler; 62 import org.enhydra.apache.xerces.utils.ChunkyCharArray; 63 import org.enhydra.apache.xerces.utils.QName; 64 import org.enhydra.apache.xerces.utils.StringPool; 65 import org.enhydra.apache.xerces.utils.XMLCharacterProperties; 66 import org.enhydra.apache.xerces.utils.XMLMessages; 67 import org.enhydra.apache.xerces.validators.common.GrammarResolver; 68 69 83 public final class XMLDocumentScanner { 84 88 94 static final char[] cdata_string = { '[','C','D','A','T','A','[' }; 98 static final char[] xml_string = { 'x','m','l' }; 103 private static final char[] version_string = { 'v','e','r','s','i','o','n' }; 107 static final char[] doctype_string = { 'D','O','C','T','Y','P','E' }; 112 private static final char[] standalone_string = { 's','t','a','n','d','a','l','o','n','e' }; 117 private static final char[] encoding_string = { 'e','n','c','o','d','i','n','g' }; 121 122 125 public static final int 126 RESULT_SUCCESS = 0, 127 RESULT_FAILURE = -1, 128 RESULT_DUPLICATE_ATTR = -2; 129 130 131 static final int 132 SCANNER_STATE_XML_DECL = 0, 133 SCANNER_STATE_START_OF_MARKUP = 1, 134 SCANNER_STATE_COMMENT = 2, 135 SCANNER_STATE_PI = 3, 136 SCANNER_STATE_DOCTYPE = 4, 137 SCANNER_STATE_PROLOG = 5, 138 SCANNER_STATE_ROOT_ELEMENT = 6, 139 SCANNER_STATE_CONTENT = 7, 140 SCANNER_STATE_REFERENCE = 8, 141 SCANNER_STATE_ATTRIBUTE_LIST = 9, 142 SCANNER_STATE_ATTRIBUTE_NAME = 10, 143 SCANNER_STATE_ATTRIBUTE_VALUE = 11, 144 SCANNER_STATE_TRAILING_MISC = 12, 145 SCANNER_STATE_END_OF_INPUT = 13, 146 SCANNER_STATE_TERMINATED = 14; 147 148 152 private StringPool.CharArrayRange fCurrentElementCharArrayRange = null; 154 155 int fAttrListHandle = -1; 156 XMLAttrList fAttrList = null; 157 GrammarResolver fGrammarResolver = null; 158 XMLDTDScanner fDTDScanner = null; 159 boolean fNamespacesEnabled = false; 160 boolean fValidationEnabled = false; 161 boolean fLoadExternalDTD = true; 162 QName fElementQName = new QName(); 163 QName fAttributeQName = new QName(); 164 QName fCurrentElementQName = new QName(); 165 ScannerDispatcher fDispatcher = null; 166 EventHandler fEventHandler = null; 167 XMLDocumentHandler.DTDHandler fDTDHandler = null; 168 StringPool fStringPool = null; 169 XMLErrorReporter fErrorReporter = null; 170 XMLEntityHandler fEntityHandler = null; 171 XMLEntityHandler.EntityReader fEntityReader = null; 172 XMLEntityHandler.CharBuffer fLiteralData = null; 173 boolean fSeenRootElement = false; 174 boolean fSeenDoctypeDecl = false; 175 boolean fStandalone = false; 176 boolean fParseTextDecl = false; 177 boolean fScanningDTD = false; 178 int fScannerState = SCANNER_STATE_XML_DECL; 179 int fReaderId = -1; 180 int fAttValueReader = -1; 181 int fAttValueElementType = -1; 182 int fAttValueAttrName = -1; 183 int fAttValueOffset = -1; 184 int fAttValueMark = -1; 185 int fScannerMarkupDepth = 0; 186 187 191 196 public interface EventHandler { 197 202 public void callStandaloneIsYes() throws Exception ; 203 204 209 public void callStartDocument() throws Exception ; 210 215 public void callEndDocument() throws Exception ; 216 224 public void callXMLDecl(int version, int encoding, int standalone) throws Exception ; 225 232 public void callTextDecl(int version, int encoding) throws Exception ; 233 239 public void callStartElement(QName element) throws Exception ; 240 245 public void element(QName element) throws Exception ; 246 254 public boolean attribute(QName element, QName attrName, int attrValue) throws Exception ; 255 261 public void callEndElement(int readerId) throws Exception ; 262 266 public void callStartCDATA() throws Exception ; 267 271 public void callEndCDATA() throws Exception ; 272 278 public void callCharacters(int ch) throws Exception ; 279 286 public void callProcessingInstruction(int piTarget, int piData) throws Exception ; 287 293 public void callComment(int data) throws Exception ; 294 } 295 296 299 public XMLDocumentScanner(StringPool stringPool, 300 XMLErrorReporter errorReporter, 301 XMLEntityHandler entityHandler, 302 XMLEntityHandler.CharBuffer literalData) { 303 fStringPool = stringPool; 304 fErrorReporter = errorReporter; 305 fEntityHandler = entityHandler; 306 fLiteralData = literalData; 307 fDispatcher = new XMLDeclDispatcher(); 308 fAttrList = new XMLAttrList(fStringPool); 309 } 310 311 316 public void setEventHandler(XMLDocumentScanner.EventHandler eventHandler) { 317 fEventHandler = eventHandler; 318 } 319 320 321 public void setDTDHandler(XMLDocumentHandler.DTDHandler dtdHandler) { 322 fDTDHandler = dtdHandler; 323 } 324 325 326 public void setGrammarResolver(GrammarResolver resolver) { 327 fGrammarResolver = resolver; 328 } 329 330 335 public void reset(StringPool stringPool, XMLEntityHandler.CharBuffer literalData) { 336 fStringPool = stringPool; 337 fLiteralData = literalData; 338 fParseTextDecl = false; 339 fSeenRootElement = false; 340 fSeenDoctypeDecl = false; 341 fStandalone = false; 342 fScanningDTD = false; 343 fDispatcher = new XMLDeclDispatcher(); 344 fScannerState = SCANNER_STATE_XML_DECL; 345 fScannerMarkupDepth = 0; 346 fAttrList = new XMLAttrList(fStringPool); 347 } 348 349 375 public boolean parseSome(boolean doItAll) throws Exception 376 { 377 do { 378 if (!fDispatcher.dispatch(doItAll)) 379 return false; 380 } while (doItAll); 381 return true; 382 } 383 384 391 public void readerChange(XMLEntityHandler.EntityReader nextReader, int nextReaderId) throws Exception { 392 fEntityReader = nextReader; 393 fReaderId = nextReaderId; 394 if (fScannerState == SCANNER_STATE_ATTRIBUTE_VALUE) { 395 fAttValueOffset = fEntityReader.currentOffset(); 396 fAttValueMark = fAttValueOffset; 397 } 398 399 if (fDTDScanner != null && fScanningDTD) 401 fDTDScanner.readerChange(nextReader, nextReaderId); 402 } 403 404 411 public void endOfInput(int entityName, boolean moreToFollow) throws Exception { 412 if (fDTDScanner != null && fScanningDTD){ 413 fDTDScanner.endOfInput(entityName, moreToFollow); 414 } 415 fDispatcher.endOfInput(entityName, moreToFollow); 416 } 417 418 422 public boolean atEndOfInput() { 423 return fScannerState == SCANNER_STATE_END_OF_INPUT; 424 } 425 426 438 public int scanAttValue(QName element, QName attribute, boolean asSymbol) throws Exception { 439 boolean single; 440 if (!(single = fEntityReader.lookingAtChar('\'', true)) && !fEntityReader.lookingAtChar('\"', true)) { 441 reportFatalXMLError(XMLMessages.MSG_QUOTE_REQUIRED_IN_ATTVALUE, 442 XMLMessages.P10_QUOTE_REQUIRED, 443 element.rawname, 444 attribute.rawname); 445 return -1; 446 } 447 char qchar = single ? '\'' : '\"'; 448 fAttValueMark = fEntityReader.currentOffset(); 449 int attValue = fEntityReader.scanAttValue(qchar, asSymbol); 450 if (attValue >= 0) 451 return attValue; 452 int previousState = setScannerState(SCANNER_STATE_ATTRIBUTE_VALUE); 453 fAttValueReader = fReaderId; 454 fAttValueElementType = element.rawname; 456 fAttValueAttrName = attribute.rawname; 458 fAttValueOffset = fEntityReader.currentOffset(); 459 int dataOffset = fLiteralData.length(); 460 if (fAttValueOffset - fAttValueMark > 0) 461 fEntityReader.append(fLiteralData, fAttValueMark, fAttValueOffset - fAttValueMark); 462 fAttValueMark = fAttValueOffset; 463 boolean setMark = false; 464 boolean skippedCR; 465 while (true) { 466 if (fEntityReader.lookingAtChar(qchar, true)) { 467 if (fReaderId == fAttValueReader) 468 break; 469 } else if (fEntityReader.lookingAtChar(' ', true)) { 470 } else if ((skippedCR = fEntityReader.lookingAtChar((char)0x0D, true)) || fEntityReader.lookingAtSpace(true)) { 474 if (fAttValueOffset - fAttValueMark > 0) 475 fEntityReader.append(fLiteralData, fAttValueMark, fAttValueOffset - fAttValueMark); 476 setMark = true; 477 fLiteralData.append(' '); 478 if (skippedCR) { 479 } 485 } else if (fEntityReader.lookingAtChar('&', true)) { 486 if (fAttValueOffset - fAttValueMark > 0) 487 fEntityReader.append(fLiteralData, fAttValueMark, fAttValueOffset - fAttValueMark); 488 setMark = true; 489 if (fEntityReader.lookingAtChar('#', true)) { 493 int ch = scanCharRef(); 494 if (ch != -1) { 495 if (ch < 0x10000) 496 fLiteralData.append((char)ch); 497 else { 498 fLiteralData.append((char)(((ch-0x00010000)>>10)+0xd800)); 499 fLiteralData.append((char)(((ch-0x00010000)&0x3ff)+0xdc00)); 500 } 501 } 502 } else { 503 int nameOffset = fEntityReader.currentOffset(); 507 fEntityReader.skipPastName(';'); 508 int nameLength = fEntityReader.currentOffset() - nameOffset; 509 if (nameLength == 0) { 510 reportFatalXMLError(XMLMessages.MSG_NAME_REQUIRED_IN_REFERENCE, 511 XMLMessages.P68_NAME_REQUIRED); 512 } else if (!fEntityReader.lookingAtChar(';', true)) { 513 reportFatalXMLError(XMLMessages.MSG_SEMICOLON_REQUIRED_IN_REFERENCE, 514 XMLMessages.P68_SEMICOLON_REQUIRED, 515 fEntityReader.addString(nameOffset, nameLength)); 516 } else { 517 int entityName = fEntityReader.addSymbol(nameOffset, nameLength); 518 fEntityHandler.startReadingFromEntity(entityName, fScannerMarkupDepth, XMLEntityHandler.ENTITYREF_IN_ATTVALUE); 519 } 520 } 521 } else if (fEntityReader.lookingAtChar('<', true)) { 522 if (fAttValueOffset - fAttValueMark > 0) 523 fEntityReader.append(fLiteralData, fAttValueMark, fAttValueOffset - fAttValueMark); 524 setMark = true; 525 reportFatalXMLError(XMLMessages.MSG_LESSTHAN_IN_ATTVALUE, 526 XMLMessages.WFC_NO_LESSTHAN_IN_ATTVALUE, 527 element.rawname, 528 attribute.rawname); 529 } else if (!fEntityReader.lookingAtValidChar(true)) { 530 if (fAttValueOffset - fAttValueMark > 0) 531 fEntityReader.append(fLiteralData, fAttValueMark, fAttValueOffset - fAttValueMark); 532 setMark = true; 533 int invChar = fEntityReader.scanInvalidChar(); 534 if (fScannerState == SCANNER_STATE_END_OF_INPUT) 535 return -1; 536 if (invChar >= 0) { 537 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_ATTVALUE, 538 XMLMessages.P10_INVALID_CHARACTER, 539 fStringPool.toString(element.rawname), 540 fStringPool.toString(attribute.rawname), 541 Integer.toHexString(invChar)); 542 } 543 } 544 fAttValueOffset = fEntityReader.currentOffset(); 545 if (setMark) { 546 fAttValueMark = fAttValueOffset; 547 setMark = false; 548 } 549 } 550 restoreScannerState(previousState); 551 int dataLength = fLiteralData.length() - dataOffset; 552 if (dataLength == 0) { 553 return fEntityReader.addString(fAttValueMark, fAttValueOffset - fAttValueMark); 554 } 555 if (fAttValueOffset - fAttValueMark > 0) { 556 fEntityReader.append(fLiteralData, fAttValueMark, fAttValueOffset - fAttValueMark); 557 dataLength = fLiteralData.length() - dataOffset; 558 } 559 int value = fLiteralData.addString(dataOffset, dataLength); 560 return value; 561 } 562 563 void reportFatalXMLError(int majorCode, int minorCode) throws Exception { 567 fErrorReporter.reportError(fErrorReporter.getLocator(), 568 XMLMessages.XML_DOMAIN, 569 majorCode, 570 minorCode, 571 null, 572 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 573 } 574 void reportFatalXMLError(int majorCode, int minorCode, int stringIndex1) throws Exception { 575 Object [] args = { fStringPool.toString(stringIndex1) }; 576 fErrorReporter.reportError(fErrorReporter.getLocator(), 577 XMLMessages.XML_DOMAIN, 578 majorCode, 579 minorCode, 580 args, 581 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 582 } 583 void reportFatalXMLError(int majorCode, int minorCode, String string1) throws Exception { 584 Object [] args = { string1 }; 585 fErrorReporter.reportError(fErrorReporter.getLocator(), 586 XMLMessages.XML_DOMAIN, 587 majorCode, 588 minorCode, 589 args, 590 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 591 } 592 void reportFatalXMLError(int majorCode, int minorCode, int stringIndex1, int stringIndex2) throws Exception { 593 Object [] args = { fStringPool.toString(stringIndex1), 594 fStringPool.toString(stringIndex2) }; 595 fErrorReporter.reportError(fErrorReporter.getLocator(), 596 XMLMessages.XML_DOMAIN, 597 majorCode, 598 minorCode, 599 args, 600 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 601 } 602 void reportFatalXMLError(int majorCode, int minorCode, String string1, String string2) throws Exception { 603 Object [] args = { string1, string2 }; 604 fErrorReporter.reportError(fErrorReporter.getLocator(), 605 XMLMessages.XML_DOMAIN, 606 majorCode, 607 minorCode, 608 args, 609 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 610 } 611 void reportFatalXMLError(int majorCode, int minorCode, String string1, String string2, String string3) throws Exception { 612 Object [] args = { string1, string2, string3 }; 613 fErrorReporter.reportError(fErrorReporter.getLocator(), 614 XMLMessages.XML_DOMAIN, 615 majorCode, 616 minorCode, 617 args, 618 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 619 } 620 void abortMarkup(int majorCode, int minorCode) throws Exception { 621 reportFatalXMLError(majorCode, minorCode); 622 skipPastEndOfCurrentMarkup(); 623 } 624 void abortMarkup(int majorCode, int minorCode, int stringIndex1) throws Exception { 625 reportFatalXMLError(majorCode, minorCode, stringIndex1); 626 skipPastEndOfCurrentMarkup(); 627 } 628 void abortMarkup(int majorCode, int minorCode, String string1) throws Exception { 629 reportFatalXMLError(majorCode, minorCode, string1); 630 skipPastEndOfCurrentMarkup(); 631 } 632 void abortMarkup(int majorCode, int minorCode, int stringIndex1, int stringIndex2) throws Exception { 633 reportFatalXMLError(majorCode, minorCode, stringIndex1, stringIndex2); 634 skipPastEndOfCurrentMarkup(); 635 } 636 void skipPastEndOfCurrentMarkup() throws Exception { 637 fEntityReader.skipToChar('>'); 638 if (fEntityReader.lookingAtChar('>', true)) 639 fScannerMarkupDepth--; 640 } 641 int setScannerState(int state) { 645 int oldState = fScannerState; 646 fScannerState = state; 647 return oldState; 648 } 649 void restoreScannerState(int state) { 650 if (fScannerState != SCANNER_STATE_END_OF_INPUT) 651 fScannerState = state; 652 } 653 662 interface ScannerDispatcher { 663 670 boolean dispatch(boolean keepgoing) throws Exception ; 671 678 void endOfInput(int entityName, boolean moreToFollow) throws Exception ; 679 } 680 final class XMLDeclDispatcher implements ScannerDispatcher { 681 public boolean dispatch(boolean keepgoing) throws Exception { 682 fEventHandler.callStartDocument(); 683 if (fEntityReader.lookingAtChar('<', true)) { 684 fScannerMarkupDepth++; 685 setScannerState(SCANNER_STATE_START_OF_MARKUP); 686 if (fEntityReader.lookingAtChar('?', true)) { 687 int piTarget = fEntityReader.scanName(' '); 688 if (piTarget == -1) { 689 abortMarkup(XMLMessages.MSG_PITARGET_REQUIRED, 690 XMLMessages.P16_PITARGET_REQUIRED); 691 } else if ("xml".equals(fStringPool.toString(piTarget))) { 692 if (fEntityReader.lookingAtSpace(true)) { scanXMLDeclOrTextDecl(false); 694 } else { abortMarkup(XMLMessages.MSG_RESERVED_PITARGET, 696 XMLMessages.P17_RESERVED_PITARGET); 697 } 698 } else { scanPI(piTarget); 700 } 701 fDispatcher = new PrologDispatcher(); 702 restoreScannerState(SCANNER_STATE_PROLOG); 703 return true; 704 } 705 if (fEntityReader.lookingAtChar('!', true)) { 706 if (fEntityReader.lookingAtChar('-', true)) { if (fEntityReader.lookingAtChar('-', true)) { 708 scanComment(); } else { 710 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_PROLOG, 711 XMLMessages.P22_NOT_RECOGNIZED); 712 } 713 } else { 714 if (fEntityReader.skippedString(doctype_string)) { 715 setScannerState(SCANNER_STATE_DOCTYPE); 716 fSeenDoctypeDecl = true; 717 scanDoctypeDecl(fStandalone); fScannerMarkupDepth--; 719 fDispatcher = new PrologDispatcher(); 720 restoreScannerState(SCANNER_STATE_PROLOG); 721 return true; 722 } else { 723 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_PROLOG, 724 XMLMessages.P22_NOT_RECOGNIZED); 725 } 726 } 727 } else { 728 fDispatcher = new ContentDispatcher(); 729 restoreScannerState(SCANNER_STATE_ROOT_ELEMENT); 730 return true; 731 } 732 } else { 733 if (fEntityReader.lookingAtSpace(true)) { 734 fEntityReader.skipPastSpaces(); 735 } else if (!fEntityReader.lookingAtValidChar(false)) { 736 int invChar = fEntityReader.scanInvalidChar(); 737 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 738 if (invChar >= 0) { 739 String arg = Integer.toHexString(invChar); 740 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_PROLOG, 741 XMLMessages.P22_INVALID_CHARACTER, 742 arg); 743 } 744 } else { 745 fDispatcher = new EndOfInputDispatcher(); 746 setScannerState(SCANNER_STATE_END_OF_INPUT); 747 return true; 748 } 749 } else { 750 reportFatalXMLError(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_PROLOG, 751 XMLMessages.P22_NOT_RECOGNIZED); 752 fEntityReader.lookingAtValidChar(true); 753 } 754 } 755 fDispatcher = new PrologDispatcher(); 756 restoreScannerState(SCANNER_STATE_PROLOG); 757 return true; 758 } 759 public void endOfInput(int entityName, boolean moreToFollow) throws Exception { 760 switch (fScannerState) { 761 case SCANNER_STATE_XML_DECL: 762 case SCANNER_STATE_START_OF_MARKUP: 763 case SCANNER_STATE_DOCTYPE: 764 break; 765 case SCANNER_STATE_COMMENT: 766 if (!moreToFollow) { 767 reportFatalXMLError(XMLMessages.MSG_COMMENT_UNTERMINATED, 768 XMLMessages.P15_UNTERMINATED); 769 } else { 770 reportFatalXMLError(XMLMessages.MSG_COMMENT_NOT_IN_ONE_ENTITY, 771 XMLMessages.P78_NOT_WELLFORMED); 772 } 773 break; 774 case SCANNER_STATE_PI: 775 if (!moreToFollow) { 776 reportFatalXMLError(XMLMessages.MSG_PI_UNTERMINATED, 777 XMLMessages.P16_UNTERMINATED); 778 } else { 779 reportFatalXMLError(XMLMessages.MSG_PI_NOT_IN_ONE_ENTITY, 780 XMLMessages.P78_NOT_WELLFORMED); 781 } 782 break; 783 default: 784 throw new RuntimeException ("FWK001 1] ScannerState="+fScannerState+"\n" + "1\t"+fScannerState); 785 } 786 if (!moreToFollow) { 787 reportFatalXMLError(XMLMessages.MSG_ROOT_ELEMENT_REQUIRED, 788 XMLMessages.P1_ELEMENT_REQUIRED); 789 fDispatcher = new EndOfInputDispatcher(); 790 setScannerState(SCANNER_STATE_END_OF_INPUT); 791 } 792 } 793 } 794 final class PrologDispatcher implements ScannerDispatcher { 795 public boolean dispatch(boolean keepgoing) throws Exception { 796 do { 797 if (fEntityReader.lookingAtChar('<', true)) { 798 fScannerMarkupDepth++; 799 setScannerState(SCANNER_STATE_START_OF_MARKUP); 800 if (fEntityReader.lookingAtChar('?', true)) { 801 int piTarget = fEntityReader.scanName(' '); 802 if (piTarget == -1) { 803 abortMarkup(XMLMessages.MSG_PITARGET_REQUIRED, 804 XMLMessages.P16_PITARGET_REQUIRED); 805 } else if ("xml".equals(fStringPool.toString(piTarget))) { 806 if (fEntityReader.lookingAtSpace(true)) { abortMarkup(XMLMessages.MSG_XMLDECL_MUST_BE_FIRST, 808 XMLMessages.P22_XMLDECL_MUST_BE_FIRST); 809 } else { abortMarkup(XMLMessages.MSG_RESERVED_PITARGET, 811 XMLMessages.P17_RESERVED_PITARGET); 812 } 813 } else { scanPI(piTarget); 815 } 816 } else if (fEntityReader.lookingAtChar('!', true)) { 817 if (fEntityReader.lookingAtChar('-', true)) { if (fEntityReader.lookingAtChar('-', true)) { 819 scanComment(); } else { 821 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_PROLOG, 822 XMLMessages.P22_NOT_RECOGNIZED); 823 } 824 } else { 825 if (!fSeenDoctypeDecl && fEntityReader.skippedString(doctype_string)) { 826 setScannerState(SCANNER_STATE_DOCTYPE); 827 fSeenDoctypeDecl = true; 828 scanDoctypeDecl(fStandalone); fScannerMarkupDepth--; 830 } else { 831 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_PROLOG, 832 XMLMessages.P22_NOT_RECOGNIZED); 833 } 834 } 835 } else { 836 fDispatcher = new ContentDispatcher(); 837 restoreScannerState(SCANNER_STATE_ROOT_ELEMENT); 838 return true; 839 } 840 restoreScannerState(SCANNER_STATE_PROLOG); 841 } else if (fEntityReader.lookingAtSpace(true)) { 842 fEntityReader.skipPastSpaces(); 843 } else if (!fEntityReader.lookingAtValidChar(false)) { 844 int invChar = fEntityReader.scanInvalidChar(); 845 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 846 if (invChar >= 0) { 847 String arg = Integer.toHexString(invChar); 848 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_PROLOG, 849 XMLMessages.P22_INVALID_CHARACTER, 850 arg); 851 } 852 } 853 } else { 854 reportFatalXMLError(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_PROLOG, 855 XMLMessages.P22_NOT_RECOGNIZED); 856 fEntityReader.lookingAtValidChar(true); 857 } 858 } while (fScannerState != SCANNER_STATE_END_OF_INPUT && keepgoing); 859 return true; 860 } 861 public void endOfInput(int entityName, boolean moreToFollow) throws Exception { 862 switch (fScannerState) { 863 case SCANNER_STATE_PROLOG: 864 case SCANNER_STATE_START_OF_MARKUP: 865 case SCANNER_STATE_DOCTYPE: 866 break; 867 case SCANNER_STATE_COMMENT: 868 if (!moreToFollow) { 869 reportFatalXMLError(XMLMessages.MSG_COMMENT_UNTERMINATED, 870 XMLMessages.P15_UNTERMINATED); 871 } else { 872 reportFatalXMLError(XMLMessages.MSG_COMMENT_NOT_IN_ONE_ENTITY, 873 XMLMessages.P78_NOT_WELLFORMED); 874 } 875 break; 876 case SCANNER_STATE_PI: 877 if (!moreToFollow) { 878 reportFatalXMLError(XMLMessages.MSG_PI_UNTERMINATED, 879 XMLMessages.P16_UNTERMINATED); 880 } else { 881 reportFatalXMLError(XMLMessages.MSG_PI_NOT_IN_ONE_ENTITY, 882 XMLMessages.P78_NOT_WELLFORMED); 883 } 884 break; 885 default: 886 throw new RuntimeException ("FWK001 2] ScannerState="+fScannerState+"\n" + "2\t"+fScannerState); 887 } 888 if (!moreToFollow) { 889 reportFatalXMLError(XMLMessages.MSG_ROOT_ELEMENT_REQUIRED, 890 XMLMessages.P1_ELEMENT_REQUIRED); 891 fDispatcher = new EndOfInputDispatcher(); 892 setScannerState(SCANNER_STATE_END_OF_INPUT); 893 } 894 } 895 } 896 int fCurrentElementType = -1; 897 public int getCurrentElementType() { 898 return fCurrentElementType; 899 } 900 final class ContentDispatcher implements ScannerDispatcher { 901 private int fContentReader = -1; 902 private int fElementDepth = 0; 903 private int[] fElementTypeStack = new int[8]; 904 905 void popElementType() { 906 if (fElementDepth-- == 0) { 907 throw new RuntimeException ("FWK002 popElementType: fElementDepth-- == 0."); 908 } 909 if (fElementDepth == 0) { 910 fCurrentElementType = - 1; 911 } else { 912 fCurrentElementType = fElementTypeStack[fElementDepth - 1]; 913 } 914 } 915 916 public boolean dispatch(boolean keepgoing) throws Exception { 917 do { 918 switch (fScannerState) { 919 case SCANNER_STATE_ROOT_ELEMENT: 920 { 921 scanElementType(fEntityReader, '>', fElementQName); 922 if (fElementQName.rawname != -1) { 923 fContentReader = fReaderId; 927 fSeenRootElement = true; 928 if (fEntityReader.lookingAtChar('>', true)) { 932 fEventHandler.callStartElement(fElementQName); 936 fScannerMarkupDepth--; 937 if (fElementDepth == fElementTypeStack.length) { 938 int[] newStack = new int[fElementDepth * 2]; 939 System.arraycopy(fElementTypeStack, 0, newStack, 0, fElementDepth); 940 fElementTypeStack = newStack; 941 } 942 fCurrentElementType = fElementQName.rawname; 943 fElementTypeStack[fElementDepth] = fElementQName.rawname; 944 fElementDepth++; 945 restoreScannerState(SCANNER_STATE_CONTENT); 946 } else if (scanElement(fElementQName)) { 947 if (fElementDepth == fElementTypeStack.length) { 951 int[] newStack = new int[fElementDepth * 2]; 952 System.arraycopy(fElementTypeStack, 0, newStack, 0, fElementDepth); 953 fElementTypeStack = newStack; 954 } 955 fCurrentElementType = fElementQName.rawname; 956 fElementTypeStack[fElementDepth] = fElementQName.rawname; 957 fElementDepth++; 958 restoreScannerState(SCANNER_STATE_CONTENT); 959 } else { 960 fDispatcher = new TrailingMiscDispatcher(); 961 restoreScannerState(SCANNER_STATE_TRAILING_MISC); 962 return true; 963 } 964 } else { 965 reportFatalXMLError(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_PROLOG, 966 XMLMessages.P22_NOT_RECOGNIZED); 967 fDispatcher = new PrologDispatcher(); 968 restoreScannerState(SCANNER_STATE_PROLOG); 969 return true; 970 } 971 break; 972 } 973 case SCANNER_STATE_START_OF_MARKUP: 974 if (fEntityReader.lookingAtChar('?', true)) { 975 int piTarget = fEntityReader.scanName(' '); 976 if (piTarget == -1) { 977 abortMarkup(XMLMessages.MSG_PITARGET_REQUIRED, 978 XMLMessages.P16_PITARGET_REQUIRED); 979 } else if ("xml".equals(fStringPool.toString(piTarget))) { 980 if (fEntityReader.lookingAtSpace(true)) { if (fParseTextDecl) { 982 scanXMLDeclOrTextDecl(true); 983 fParseTextDecl = false; 984 } else { 985 abortMarkup(XMLMessages.MSG_TEXTDECL_MUST_BE_FIRST, 986 XMLMessages.P30_TEXTDECL_MUST_BE_FIRST); 987 } 988 } else { abortMarkup(XMLMessages.MSG_RESERVED_PITARGET, 990 XMLMessages.P17_RESERVED_PITARGET); 991 } 992 } else { scanPI(piTarget); 994 } 995 restoreScannerState(SCANNER_STATE_CONTENT); 996 } else if (fEntityReader.lookingAtChar('!', true)) { 997 if (fEntityReader.lookingAtChar('-', true)) { if (fEntityReader.lookingAtChar('-', true)) { 999 scanComment(); } else { 1001 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_CONTENT, 1002 XMLMessages.P43_NOT_RECOGNIZED); 1003 } 1004 } else { 1005 if (fEntityReader.skippedString(cdata_string)) { 1006 fEntityReader.setInCDSect(true); 1007 fEventHandler.callStartCDATA(); 1008 } else { 1009 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_CONTENT, 1010 XMLMessages.P43_NOT_RECOGNIZED); 1011 } 1012 } 1013 } else { 1014 if (fEntityReader.lookingAtChar('/', true)) { 1015 if (!scanExpectedElementType(fEntityReader, '>', fCurrentElementType)) { 1019 abortMarkup(XMLMessages.MSG_ETAG_REQUIRED, 1020 XMLMessages.P39_UNTERMINATED, 1021 fCurrentElementType); 1022 } else { 1023 if (!fEntityReader.lookingAtChar('>', true)) { 1024 fEntityReader.skipPastSpaces(); 1025 if (!fEntityReader.lookingAtChar('>', true)) { 1026 reportFatalXMLError(XMLMessages.MSG_ETAG_UNTERMINATED, 1027 XMLMessages.P42_UNTERMINATED, 1028 fCurrentElementType); 1029 } 1030 } 1031 fScannerMarkupDepth--; 1032 fEventHandler.callEndElement(fReaderId); 1033 if (fElementDepth-- == 0) { 1034 throw new RuntimeException ("FWK002 popElementType: fElementDepth-- == 0."); 1035 } 1036 if (fElementDepth == 0) { 1037 fCurrentElementType = - 1; 1038 fDispatcher = new TrailingMiscDispatcher(); 1039 restoreScannerState(SCANNER_STATE_TRAILING_MISC); 1040 return true; 1041 } else { 1042 fCurrentElementType = fElementTypeStack[fElementDepth - 1]; 1043 } 1044 } 1045 } else { 1046 scanElementType(fEntityReader, '>', fElementQName); 1047 if (fElementQName.rawname != -1) { 1048 if (fEntityReader.lookingAtChar('>', true)) { 1052 fEventHandler.callStartElement(fElementQName); 1053 fScannerMarkupDepth--; 1054 if (fElementDepth == fElementTypeStack.length) { 1055 int[] newStack = new int[fElementDepth * 2]; 1056 System.arraycopy(fElementTypeStack, 0, newStack, 0, fElementDepth); 1057 fElementTypeStack = newStack; 1058 } 1059 fCurrentElementType = fElementQName.rawname; 1060 fElementTypeStack[fElementDepth] = fElementQName.rawname; 1061 fElementDepth++; 1062 } else { 1063 if (scanElement(fElementQName)) { 1064 if (fElementDepth == fElementTypeStack.length) { 1065 int[] newStack = new int[fElementDepth * 2]; 1066 System.arraycopy(fElementTypeStack, 0, newStack, 0, fElementDepth); 1067 fElementTypeStack = newStack; 1068 } 1069 fCurrentElementType = fElementQName.rawname; 1070 fElementTypeStack[fElementDepth] = fElementQName.rawname; 1071 fElementDepth++; 1072 } 1073 } 1074 } else { 1075 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_CONTENT, 1076 XMLMessages.P43_NOT_RECOGNIZED); 1077 } 1078 } 1079 } 1080 restoreScannerState(SCANNER_STATE_CONTENT); 1081 break; 1082 case SCANNER_STATE_CONTENT: 1083 if (fParseTextDecl && fEntityReader.lookingAtChar('<', true)) { 1084 fScannerMarkupDepth++; 1085 setScannerState(SCANNER_STATE_START_OF_MARKUP); 1086 continue; 1087 } 1088 fCurrentElementQName.setValues(-1, -1, fCurrentElementType); 1091 switch (fEntityReader.scanContent(fCurrentElementQName)) { 1092 case XMLEntityHandler.CONTENT_RESULT_START_OF_PI: 1093 fScannerMarkupDepth++; 1094 int piTarget = fEntityReader.scanName(' '); 1095 if (piTarget == -1) { 1096 abortMarkup(XMLMessages.MSG_PITARGET_REQUIRED, 1097 XMLMessages.P16_PITARGET_REQUIRED); 1098 } else if ("xml".equals(fStringPool.toString(piTarget))) { 1099 if (fEntityReader.lookingAtSpace(true)) { if (fReaderId == fContentReader) { 1101 abortMarkup(XMLMessages.MSG_XMLDECL_MUST_BE_FIRST, 1102 XMLMessages.P22_XMLDECL_MUST_BE_FIRST); 1103 } else { 1104 abortMarkup(XMLMessages.MSG_TEXTDECL_MUST_BE_FIRST, 1105 XMLMessages.P30_TEXTDECL_MUST_BE_FIRST); 1106 } 1107 } else { abortMarkup(XMLMessages.MSG_RESERVED_PITARGET, 1109 XMLMessages.P17_RESERVED_PITARGET); 1110 } 1111 } else { scanPI(piTarget); 1113 } 1114 break; 1115 case XMLEntityHandler.CONTENT_RESULT_START_OF_COMMENT: 1116 fScannerMarkupDepth++; 1117 fParseTextDecl = false; 1118 scanComment(); break; 1120 case XMLEntityHandler.CONTENT_RESULT_START_OF_CDSECT: 1121 fScannerMarkupDepth++; 1122 fParseTextDecl = false; 1123 fEntityReader.setInCDSect(true); 1124 fEventHandler.callStartCDATA(); 1125 break; 1126 case XMLEntityHandler.CONTENT_RESULT_START_OF_ETAG: 1127 fScannerMarkupDepth++; 1128 fParseTextDecl = false; 1129 if (!scanExpectedElementType(fEntityReader, '>', fCurrentElementType)) { 1133 abortMarkup(XMLMessages.MSG_ETAG_REQUIRED, 1134 XMLMessages.P39_UNTERMINATED, 1135 fCurrentElementType); 1136 } else { 1137 if (!fEntityReader.lookingAtChar('>', true)) { 1138 fEntityReader.skipPastSpaces(); 1139 if (!fEntityReader.lookingAtChar('>', true)) { 1140 reportFatalXMLError(XMLMessages.MSG_ETAG_UNTERMINATED, 1141 XMLMessages.P42_UNTERMINATED, 1142 fCurrentElementType); 1143 } 1144 } 1145 fScannerMarkupDepth--; 1146 fEventHandler.callEndElement(fReaderId); 1147 if (fElementDepth-- == 0) { 1148 throw new RuntimeException ("FWK002 popElementType: fElementDepth-- == 0."); 1149 } 1150 if (fElementDepth == 0) { 1151 fCurrentElementType = - 1; 1152 fDispatcher = new TrailingMiscDispatcher(); 1153 restoreScannerState(SCANNER_STATE_TRAILING_MISC); 1154 return true; 1155 } else { 1156 fCurrentElementType = fElementTypeStack[fElementDepth - 1]; 1157 } 1158 } 1159 restoreScannerState(SCANNER_STATE_CONTENT); 1160 break; 1161 case XMLEntityHandler.CONTENT_RESULT_START_OF_ELEMENT: 1162 { 1163 fScannerMarkupDepth++; 1164 fParseTextDecl = false; 1165 scanElementType(fEntityReader, '>', fElementQName); 1166 if (fElementQName.rawname != -1) { 1167 if (fEntityReader.lookingAtChar('>', true)) { 1168 fEventHandler.callStartElement(fElementQName); 1169 fScannerMarkupDepth--; 1170 if (fElementDepth == fElementTypeStack.length) { 1171 int[] newStack = new int[fElementDepth * 2]; 1172 System.arraycopy(fElementTypeStack, 0, newStack, 0, fElementDepth); 1173 fElementTypeStack = newStack; 1174 } 1175 fCurrentElementType = fElementQName.rawname; 1176 fElementTypeStack[fElementDepth] = fElementQName.rawname; 1177 fElementDepth++; 1178 } else { 1179 if (scanElement(fElementQName)) { 1180 if (fElementDepth == fElementTypeStack.length) { 1181 int[] newStack = new int[fElementDepth * 2]; 1182 System.arraycopy(fElementTypeStack, 0, newStack, 0, fElementDepth); 1183 fElementTypeStack = newStack; 1184 } 1185 fCurrentElementType = fElementQName.rawname; 1186 fElementTypeStack[fElementDepth] = fElementQName.rawname; 1187 fElementDepth++; 1188 } 1189 } 1190 } else { 1191 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_CONTENT, 1192 XMLMessages.P43_NOT_RECOGNIZED); 1193 } 1194 if (fScannerState != SCANNER_STATE_END_OF_INPUT) 1195 fScannerState = SCANNER_STATE_CONTENT; 1196 break; 1197 } 1198 case XMLEntityHandler.CONTENT_RESULT_MATCHING_ETAG: 1199 { 1200 fParseTextDecl = false; 1201 fEventHandler.callEndElement(fReaderId); 1202 if (fElementDepth-- == 0) { 1203 throw new RuntimeException ("FWK002 popElementType: fElementDepth-- == 0."); 1204 } 1205 if (fElementDepth == 0) { 1206 fCurrentElementType = - 1; 1207 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1208 fDispatcher = new TrailingMiscDispatcher(); 1209 fScannerState = SCANNER_STATE_TRAILING_MISC; 1210 } 1211 return true; 1212 } else { 1213 fCurrentElementType = fElementTypeStack[fElementDepth - 1]; 1214 } 1215 if (fScannerState != SCANNER_STATE_END_OF_INPUT) 1216 fScannerState = SCANNER_STATE_CONTENT; 1217 break; 1218 } 1219 case XMLEntityHandler.CONTENT_RESULT_START_OF_CHARREF: 1220 fParseTextDecl = false; 1221 setScannerState(SCANNER_STATE_REFERENCE); 1227 int num = scanCharRef(); 1228 if (num != -1) 1230 fEventHandler.callCharacters(num); 1231 restoreScannerState(SCANNER_STATE_CONTENT); 1232 break; 1233 case XMLEntityHandler.CONTENT_RESULT_REFERENCE_END_OF_INPUT: 1234 case XMLEntityHandler.CONTENT_RESULT_START_OF_ENTITYREF: 1241 fParseTextDecl = false; 1242 setScannerState(SCANNER_STATE_REFERENCE); 1246 int nameOffset = fEntityReader.currentOffset(); 1247 fEntityReader.skipPastName(';'); 1248 int nameLength = fEntityReader.currentOffset() - nameOffset; 1249 if (nameLength == 0) { 1250 reportFatalXMLError(XMLMessages.MSG_NAME_REQUIRED_IN_REFERENCE, 1251 XMLMessages.P68_NAME_REQUIRED); 1252 restoreScannerState(SCANNER_STATE_CONTENT); 1253 } else if (!fEntityReader.lookingAtChar(';', true)) { 1254 reportFatalXMLError(XMLMessages.MSG_SEMICOLON_REQUIRED_IN_REFERENCE, 1255 XMLMessages.P68_SEMICOLON_REQUIRED, 1256 fEntityReader.addString(nameOffset, nameLength)); 1257 restoreScannerState(SCANNER_STATE_CONTENT); 1258 } else { 1259 restoreScannerState(SCANNER_STATE_CONTENT); 1260 int entityName = fEntityReader.addSymbol(nameOffset, nameLength); 1261 fParseTextDecl = fEntityHandler.startReadingFromEntity(entityName, fElementDepth, XMLEntityHandler.ENTITYREF_IN_CONTENT); 1262 } 1263 break; 1264 case XMLEntityHandler.CONTENT_RESULT_END_OF_CDSECT: 1265 fParseTextDecl = false; 1266 if (fEntityReader.getInCDSect()) { 1271 fEntityReader.setInCDSect(false); 1272 fEventHandler.callEndCDATA(); 1273 fScannerMarkupDepth--; 1274 } else { 1275 reportFatalXMLError(XMLMessages.MSG_CDEND_IN_CONTENT, 1276 XMLMessages.P14_INVALID); 1277 } 1278 restoreScannerState(SCANNER_STATE_CONTENT); 1279 break; 1280 case XMLEntityHandler.CONTENT_RESULT_INVALID_CHAR: 1281 fParseTextDecl = false; 1282 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1288 if (!fEntityReader.lookingAtValidChar(false)) { 1289 int invChar = fEntityReader.scanInvalidChar(); 1294 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1295 if (invChar >= 0) { 1296 if (fEntityReader.getInCDSect()) { 1297 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_CDSECT, 1298 XMLMessages.P20_INVALID_CHARACTER, 1299 Integer.toHexString(invChar)); 1300 } else { 1301 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_CONTENT, 1302 XMLMessages.P43_INVALID_CHARACTER, 1303 Integer.toHexString(invChar)); 1304 } 1305 } 1306 } 1307 } 1308 restoreScannerState(SCANNER_STATE_CONTENT); 1309 } 1310 break; 1311 case XMLEntityHandler.CONTENT_RESULT_MARKUP_NOT_RECOGNIZED: 1312 fParseTextDecl = false; 1313 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_CONTENT, 1314 XMLMessages.P43_NOT_RECOGNIZED); 1315 break; 1316 case XMLEntityHandler.CONTENT_RESULT_MARKUP_END_OF_INPUT: 1317 fScannerMarkupDepth++; 1321 fParseTextDecl = false; 1322 fScannerState = SCANNER_STATE_START_OF_MARKUP; 1323 break; 1324 default: 1325 throw new RuntimeException ("FWK001 3] ScannerState="+fScannerState+"\n" + "3\t"+fScannerState); } 1327 break; 1328 default: 1329 throw new RuntimeException ("FWK001 4] ScannerState="+fScannerState+"\n" + "4\t"+fScannerState); 1330 } 1331 } while (fScannerState != SCANNER_STATE_END_OF_INPUT && keepgoing); 1332 return true; 1333 } 1334 public void endOfInput(int entityName, boolean moreToFollow) throws Exception { 1335 switch (fScannerState) { 1336 case SCANNER_STATE_ROOT_ELEMENT: 1337 case SCANNER_STATE_START_OF_MARKUP: 1338 break; 1339 case SCANNER_STATE_CONTENT: 1340 if (fEntityReader.getInCDSect()) { 1341 reportFatalXMLError(XMLMessages.MSG_CDSECT_UNTERMINATED, 1342 XMLMessages.P18_UNTERMINATED); 1343 } 1344 break; 1345 case SCANNER_STATE_ATTRIBUTE_LIST: 1346 if (!moreToFollow) { 1347 } else { 1349 } 1351 break; 1352 case SCANNER_STATE_ATTRIBUTE_NAME: 1353 if (!moreToFollow) { 1354 } else { 1356 } 1358 break; 1359 case SCANNER_STATE_ATTRIBUTE_VALUE: 1360 if (!moreToFollow) { 1361 reportFatalXMLError(XMLMessages.MSG_ATTRIBUTE_VALUE_UNTERMINATED, 1362 XMLMessages.P10_UNTERMINATED, 1363 fAttValueElementType, 1364 fAttValueAttrName); 1365 } else if (fReaderId == fAttValueReader) { 1366 } else { 1368 fEntityReader.append(fLiteralData, fAttValueMark, fAttValueOffset - fAttValueMark); 1369 } 1370 break; 1371 case SCANNER_STATE_COMMENT: 1372 if (!moreToFollow) { 1373 reportFatalXMLError(XMLMessages.MSG_COMMENT_UNTERMINATED, 1374 XMLMessages.P15_UNTERMINATED); 1375 } else { 1376 reportFatalXMLError(XMLMessages.MSG_COMMENT_NOT_IN_ONE_ENTITY, 1377 XMLMessages.P78_NOT_WELLFORMED); 1378 } 1379 break; 1380 case SCANNER_STATE_PI: 1381 if (!moreToFollow) { 1382 reportFatalXMLError(XMLMessages.MSG_PI_UNTERMINATED, 1383 XMLMessages.P16_UNTERMINATED); 1384 } else { 1385 reportFatalXMLError(XMLMessages.MSG_PI_NOT_IN_ONE_ENTITY, 1386 XMLMessages.P78_NOT_WELLFORMED); 1387 } 1388 break; 1389 case SCANNER_STATE_REFERENCE: 1390 if (!moreToFollow) { 1391 reportFatalXMLError(XMLMessages.MSG_REFERENCE_UNTERMINATED, 1392 XMLMessages.P67_UNTERMINATED); 1393 } else { 1394 reportFatalXMLError(XMLMessages.MSG_REFERENCE_NOT_IN_ONE_ENTITY, 1395 XMLMessages.P78_NOT_WELLFORMED); 1396 } 1397 break; 1398 default: 1399 throw new RuntimeException ("FWK001 5] ScannerState="+fScannerState+"\n" + "5\t"+fScannerState); 1400 } 1401 if (!moreToFollow) { 1402 if (fElementDepth > 0) { 1403 reportFatalXMLError(XMLMessages.MSG_ETAG_REQUIRED, 1404 XMLMessages.P39_UNTERMINATED, 1405 fCurrentElementType); 1406 } else { 1407 reportFatalXMLError(XMLMessages.MSG_ROOT_ELEMENT_REQUIRED, 1408 XMLMessages.P1_ELEMENT_REQUIRED, 1409 null); 1410 } 1411 fDispatcher = new EndOfInputDispatcher(); 1412 setScannerState(SCANNER_STATE_END_OF_INPUT); 1413 } 1414 } 1415 } 1416 final class TrailingMiscDispatcher implements ScannerDispatcher { 1417 public boolean dispatch(boolean keepgoing) throws Exception { 1418 do { 1419 if (fEntityReader.lookingAtChar('<', true)) { 1420 fScannerMarkupDepth++; 1421 setScannerState(SCANNER_STATE_START_OF_MARKUP); 1422 if (fEntityReader.lookingAtChar('?', true)) { 1423 int piTarget = fEntityReader.scanName(' '); 1424 if (piTarget == -1) { 1425 abortMarkup(XMLMessages.MSG_PITARGET_REQUIRED, 1426 XMLMessages.P16_PITARGET_REQUIRED); 1427 } else if ("xml".equals(fStringPool.toString(piTarget))) { 1428 if (fEntityReader.lookingAtSpace(true)) { abortMarkup(XMLMessages.MSG_XMLDECL_MUST_BE_FIRST, 1430 XMLMessages.P22_XMLDECL_MUST_BE_FIRST); 1431 } else { abortMarkup(XMLMessages.MSG_RESERVED_PITARGET, 1433 XMLMessages.P17_RESERVED_PITARGET); 1434 } 1435 } else { scanPI(piTarget); 1437 } 1438 } else if (fEntityReader.lookingAtChar('!', true)) { 1439 if (fEntityReader.lookingAtChar('-', true) && 1440 fEntityReader.lookingAtChar('-', true)) { scanComment(); } else { 1443 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_MISC, 1444 XMLMessages.P27_NOT_RECOGNIZED); 1445 } 1446 } else { 1447 abortMarkup(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_MISC, 1448 XMLMessages.P27_NOT_RECOGNIZED); 1449 } 1450 restoreScannerState(SCANNER_STATE_TRAILING_MISC); 1451 } else if (fEntityReader.lookingAtSpace(true)) { 1452 fEntityReader.skipPastSpaces(); 1453 } else if (!fEntityReader.lookingAtValidChar(false)) { 1454 int invChar = fEntityReader.scanInvalidChar(); 1455 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1456 if (invChar >= 0) { 1457 String arg = Integer.toHexString(invChar); 1458 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_MISC, 1459 XMLMessages.P27_INVALID_CHARACTER, 1460 arg); 1461 } 1462 } 1463 } else { 1464 reportFatalXMLError(XMLMessages.MSG_MARKUP_NOT_RECOGNIZED_IN_MISC, 1465 XMLMessages.P27_NOT_RECOGNIZED); 1466 fEntityReader.lookingAtValidChar(true); 1467 } 1468 } while (fScannerState != SCANNER_STATE_END_OF_INPUT && keepgoing); 1469 return true; 1470 } 1471 public void endOfInput(int entityName, boolean moreToFollow) throws Exception { 1472 if (moreToFollow) 1473 throw new RuntimeException ("FWK003 TrailingMiscDispatcher.endOfInput moreToFollow"); 1474 switch (fScannerState) { 1475 case SCANNER_STATE_TRAILING_MISC: 1476 case SCANNER_STATE_START_OF_MARKUP: 1477 break; 1478 case SCANNER_STATE_COMMENT: 1479 reportFatalXMLError(XMLMessages.MSG_COMMENT_UNTERMINATED, 1480 XMLMessages.P15_UNTERMINATED); 1481 break; 1482 case SCANNER_STATE_PI: 1483 reportFatalXMLError(XMLMessages.MSG_PI_UNTERMINATED, 1484 XMLMessages.P16_UNTERMINATED); 1485 break; 1486 default: 1487 throw new RuntimeException ("FWK001 6] ScannerState="+fScannerState+"\n" + "6\t"+fScannerState); 1488 } 1489 fDispatcher = new EndOfInputDispatcher(); 1490 setScannerState(SCANNER_STATE_END_OF_INPUT); 1491 } 1492 } 1493 final class EndOfInputDispatcher implements ScannerDispatcher { 1494 public boolean dispatch(boolean keepgoing) throws Exception { 1495 if (fScannerState != SCANNER_STATE_TERMINATED) 1496 fEventHandler.callEndDocument(); 1497 setScannerState(SCANNER_STATE_TERMINATED); 1498 return false; 1499 } 1500 public void endOfInput(int entityName, boolean moreToFollow) throws Exception { 1501 throw new RuntimeException ("FWK001 7] ScannerState="+fScannerState+"\n" + "7\t"+fScannerState); 1502 } 1503 } 1504 void scanXMLDeclOrTextDecl(boolean scanningTextDecl) throws Exception 1517 { 1518 int version = -1; 1519 int encoding = -1; 1520 int standalone = -1; 1521 final int XMLDECL_START = 0; 1522 final int XMLDECL_VERSION = 1; 1523 final int XMLDECL_ENCODING = 2; 1524 final int XMLDECL_STANDALONE = 3; 1525 final int XMLDECL_FINISHED = 4; 1526 int state = XMLDECL_START; 1527 do { 1528 fEntityReader.skipPastSpaces(); 1529 int offset = fEntityReader.currentOffset(); 1530 if (scanningTextDecl) { 1531 if (state == XMLDECL_START && fEntityReader.skippedString(version_string)) { 1532 state = XMLDECL_VERSION; 1533 } else if (fEntityReader.skippedString(encoding_string)) { 1534 state = XMLDECL_ENCODING; 1535 } else { 1536 abortMarkup(XMLMessages.MSG_ENCODINGDECL_REQUIRED, 1537 XMLMessages.P77_ENCODINGDECL_REQUIRED); 1538 return; 1539 } 1540 } else { 1541 if (state == XMLDECL_START) { 1542 if (!fEntityReader.skippedString(version_string)) { 1543 abortMarkup(XMLMessages.MSG_VERSIONINFO_REQUIRED, 1544 XMLMessages.P23_VERSIONINFO_REQUIRED); 1545 return; 1546 } 1547 state = XMLDECL_VERSION; 1548 } else { 1549 if (state == XMLDECL_VERSION) { 1550 if (fEntityReader.skippedString(encoding_string)) 1551 state = XMLDECL_ENCODING; 1552 else 1553 state = XMLDECL_STANDALONE; 1554 } else 1555 state = XMLDECL_STANDALONE; 1556 if (state == XMLDECL_STANDALONE && !fEntityReader.skippedString(standalone_string)) 1557 break; 1558 } 1559 } 1560 int length = fEntityReader.currentOffset() - offset; 1561 fEntityReader.skipPastSpaces(); 1562 if (!fEntityReader.lookingAtChar('=', true)) { 1563 int majorCode = scanningTextDecl ? 1564 XMLMessages.MSG_EQ_REQUIRED_IN_TEXTDECL : 1565 XMLMessages.MSG_EQ_REQUIRED_IN_XMLDECL; 1566 int minorCode = state == XMLDECL_VERSION ? 1567 XMLMessages.P24_EQ_REQUIRED : 1568 (state == XMLDECL_ENCODING ? 1569 XMLMessages.P80_EQ_REQUIRED : 1570 XMLMessages.P32_EQ_REQUIRED); 1571 abortMarkup(majorCode, minorCode, fEntityReader.addString(offset, length)); 1572 return; 1573 } 1574 fEntityReader.skipPastSpaces(); 1575 int result = fEntityReader.scanStringLiteral(); 1576 switch (result) { 1577 case XMLEntityHandler.STRINGLIT_RESULT_QUOTE_REQUIRED: 1578 { 1579 int majorCode = scanningTextDecl ? 1580 XMLMessages.MSG_QUOTE_REQUIRED_IN_TEXTDECL : 1581 XMLMessages.MSG_QUOTE_REQUIRED_IN_XMLDECL; 1582 int minorCode = state == XMLDECL_VERSION ? 1583 XMLMessages.P24_QUOTE_REQUIRED : 1584 (state == XMLDECL_ENCODING ? 1585 XMLMessages.P80_QUOTE_REQUIRED : 1586 XMLMessages.P32_QUOTE_REQUIRED); 1587 abortMarkup(majorCode, minorCode, fEntityReader.addString(offset, length)); 1588 return; 1589 } 1590 case XMLEntityHandler.STRINGLIT_RESULT_INVALID_CHAR: 1591 int invChar = fEntityReader.scanInvalidChar(); 1592 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1593 if (invChar >= 0) { 1594 int majorCode = scanningTextDecl ? 1595 XMLMessages.MSG_INVALID_CHAR_IN_TEXTDECL : 1596 XMLMessages.MSG_INVALID_CHAR_IN_XMLDECL; 1597 int minorCode = state == XMLDECL_VERSION ? 1598 XMLMessages.P26_INVALID_CHARACTER : 1599 (state == XMLDECL_ENCODING ? 1600 XMLMessages.P81_INVALID_CHARACTER : 1601 XMLMessages.P32_INVALID_CHARACTER); 1602 reportFatalXMLError(majorCode, minorCode, Integer.toHexString(invChar)); 1603 } 1604 skipPastEndOfCurrentMarkup(); 1605 } 1606 return; 1607 default: 1608 break; 1609 } 1610 switch (state) { 1611 case XMLDECL_VERSION: 1612 version = result; 1616 String versionString = fStringPool.toString(version); 1617 if (!"1.0".equals(versionString)) { 1618 if (!validVersionNum(versionString)) { 1619 abortMarkup(XMLMessages.MSG_VERSIONINFO_INVALID, 1620 XMLMessages.P26_INVALID_VALUE, 1621 versionString); 1622 return; 1623 } 1624 Object [] args = { versionString }; 1626 fErrorReporter.reportError(fErrorReporter.getLocator(), 1627 XMLMessages.XML_DOMAIN, 1628 XMLMessages.MSG_VERSION_NOT_SUPPORTED, 1629 XMLMessages.P26_NOT_SUPPORTED, 1630 args, 1631 XMLErrorReporter.ERRORTYPE_RECOVERABLE_ERROR); 1632 } 1636 if (!fEntityReader.lookingAtSpace(true)) { 1637 if (scanningTextDecl) { 1638 abortMarkup(XMLMessages.MSG_SPACE_REQUIRED_IN_TEXTDECL, 1639 XMLMessages.P80_WHITESPACE_REQUIRED); 1640 return; 1641 } 1642 state = XMLDECL_FINISHED; 1643 } 1644 break; 1645 case XMLDECL_ENCODING: 1646 encoding = result; 1650 String encodingString = fStringPool.toString(encoding); 1651 if (!validEncName(encodingString)) { 1652 abortMarkup(XMLMessages.MSG_ENCODINGDECL_INVALID, 1653 XMLMessages.P81_INVALID_VALUE, 1654 encodingString); 1655 return; 1656 } 1657 if (!fEntityReader.lookingAtSpace(true)) { 1658 state = XMLDECL_FINISHED; 1659 } else if (scanningTextDecl) { 1660 fEntityReader.skipPastSpaces(); 1661 state = XMLDECL_FINISHED; 1662 } 1663 break; 1664 case XMLDECL_STANDALONE: 1665 standalone = result; 1669 String standaloneString = fStringPool.toString(standalone); 1670 boolean yes = "yes".equals(standaloneString); 1671 if (!yes && !"no".equals(standaloneString)) { 1672 abortMarkup(XMLMessages.MSG_SDDECL_INVALID, 1673 XMLMessages.P32_INVALID_VALUE, 1674 standaloneString); 1675 return; 1676 } 1677 fStandalone = yes; 1678 fEntityReader.skipPastSpaces(); 1679 state = XMLDECL_FINISHED; 1680 break; 1681 } 1682 } while (state != XMLDECL_FINISHED); 1683 if (!fEntityReader.lookingAtChar('?', true) || !fEntityReader.lookingAtChar('>', true)) { 1684 int majorCode, minorCode; 1685 if (scanningTextDecl) { 1686 majorCode = XMLMessages.MSG_TEXTDECL_UNTERMINATED; 1687 minorCode = XMLMessages.P77_UNTERMINATED; 1688 } else { 1689 majorCode = XMLMessages.MSG_XMLDECL_UNTERMINATED; 1690 minorCode = XMLMessages.P23_UNTERMINATED; 1691 } 1692 abortMarkup(majorCode, minorCode); 1693 return; 1694 } 1695 fScannerMarkupDepth--; 1696 if (scanningTextDecl) { 1697 fEventHandler.callTextDecl(version, encoding); 1698 } else { 1699 fEventHandler.callXMLDecl(version, encoding, standalone); 1704 if (fStandalone) { 1706 fEventHandler.callStandaloneIsYes(); 1707 } 1708 } 1709 } 1710 boolean scanElement(QName element) throws Exception 1727 { 1728 boolean greater = false; 1732 boolean slash = false; 1733 if (greater = fEntityReader.lookingAtChar('>', true)) { 1734 } else if (fEntityReader.lookingAtSpace(true)) { 1736 int previousState = setScannerState(SCANNER_STATE_ATTRIBUTE_LIST); 1737 while (true) { 1738 fEntityReader.skipPastSpaces(); 1739 if ((greater = fEntityReader.lookingAtChar('>', true)) || (slash = fEntityReader.lookingAtChar('/', true))) 1743 break; 1744 setScannerState(SCANNER_STATE_ATTRIBUTE_NAME); 1748 scanAttributeName(fEntityReader, element, fAttributeQName); 1749 if (fAttributeQName.rawname == -1) { 1750 break; 1751 } 1752 fEntityReader.skipPastSpaces(); 1756 if (!fEntityReader.lookingAtChar('=', true)) { 1757 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1758 abortMarkup(XMLMessages.MSG_EQ_REQUIRED_IN_ATTRIBUTE, 1759 XMLMessages.P41_EQ_REQUIRED, 1760 element.rawname, fAttributeQName.rawname); 1761 restoreScannerState(previousState); 1762 } 1763 return false; 1764 } 1765 fEntityReader.skipPastSpaces(); 1766 int result = scanAttValue(element, fAttributeQName, false); 1767 if (result == RESULT_FAILURE) { 1768 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1769 skipPastEndOfCurrentMarkup(); 1770 restoreScannerState(previousState); 1771 } 1772 return false; 1773 } else if (result == RESULT_DUPLICATE_ATTR) { 1774 reportFatalXMLError(XMLMessages.MSG_ATTRIBUTE_NOT_UNIQUE, 1775 XMLMessages.WFC_UNIQUE_ATT_SPEC, 1776 element.rawname, fAttributeQName.rawname); 1777 } 1778 if ( fEventHandler.attribute(element, fAttributeQName, result) ) { 1780 reportFatalXMLError(XMLMessages.MSG_ATTRIBUTE_NOT_UNIQUE, 1781 XMLMessages.WFC_UNIQUE_ATT_SPEC, 1782 element.rawname, fAttributeQName.rawname); 1783 } 1784 restoreScannerState(SCANNER_STATE_ATTRIBUTE_LIST); 1785 if (!fEntityReader.lookingAtSpace(true)) { 1786 if (!(greater = fEntityReader.lookingAtChar('>', true))) 1787 slash = fEntityReader.lookingAtChar('/', true); 1788 break; 1789 } 1790 } 1791 restoreScannerState(previousState); 1792 } else { 1793 slash = fEntityReader.lookingAtChar('/', true); 1794 } 1795 if (!greater && (!slash || !fEntityReader.lookingAtChar('>', true))) { if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1797 abortMarkup(XMLMessages.MSG_ELEMENT_UNTERMINATED, 1798 XMLMessages.P40_UNTERMINATED, 1799 element.rawname); 1800 } 1801 return false; 1802 } 1803 fEventHandler.callStartElement(element); 1804 fScannerMarkupDepth--; 1805 if (slash) { fEventHandler.callEndElement(fReaderId); 1807 return false; 1808 } else { 1809 return true; 1810 } 1811 } 1812 int scanCharRef() throws Exception { 1816 int valueOffset = fEntityReader.currentOffset(); 1817 boolean hex = fEntityReader.lookingAtChar('x', true); 1818 int num = fEntityReader.scanCharRef(hex); 1819 if (num < 0) { 1820 switch (num) { 1821 case XMLEntityHandler.CHARREF_RESULT_SEMICOLON_REQUIRED: 1822 reportFatalXMLError(XMLMessages.MSG_SEMICOLON_REQUIRED_IN_CHARREF, 1823 XMLMessages.P66_SEMICOLON_REQUIRED); 1824 return -1; 1825 case XMLEntityHandler.CHARREF_RESULT_INVALID_CHAR: 1826 int majorCode = hex ? XMLMessages.MSG_HEXDIGIT_REQUIRED_IN_CHARREF : 1827 XMLMessages.MSG_DIGIT_REQUIRED_IN_CHARREF; 1828 int minorCode = hex ? XMLMessages.P66_HEXDIGIT_REQUIRED : 1829 XMLMessages.P66_DIGIT_REQUIRED; 1830 reportFatalXMLError(majorCode, minorCode); 1831 return -1; 1832 case XMLEntityHandler.CHARREF_RESULT_OUT_OF_RANGE: 1833 num = 0x110000; break; 1835 } 1836 } 1837 if (num < 0x20) { 1842 if (num == 0x09 || num == 0x0A || num == 0x0D) { 1843 return num; 1844 } 1845 } else if (num <= 0xD7FF || (num >= 0xE000 && (num <= 0xFFFD || (num >= 0x10000 && num <= 0x10FFFF)))) { 1846 return num; 1847 } 1848 int valueLength = fEntityReader.currentOffset() - valueOffset; 1849 reportFatalXMLError(XMLMessages.MSG_INVALID_CHARREF, 1850 XMLMessages.WFC_LEGAL_CHARACTER, 1851 fEntityReader.addString(valueOffset, valueLength)); 1852 return -1; 1853 } 1854 void scanComment() throws Exception 1862 { 1863 int commentOffset = fEntityReader.currentOffset(); 1864 boolean sawDashDash = false; 1865 int previousState = setScannerState(SCANNER_STATE_COMMENT); 1866 while (fScannerState == SCANNER_STATE_COMMENT) { 1867 if (fEntityReader.lookingAtChar('-', false)) { 1868 int nextEndOffset = fEntityReader.currentOffset(); 1869 int endOffset = 0; 1870 fEntityReader.lookingAtChar('-', true); 1871 int offset = fEntityReader.currentOffset(); 1872 int count = 1; 1873 while (fEntityReader.lookingAtChar('-', true)) { 1874 count++; 1875 endOffset = nextEndOffset; 1876 nextEndOffset = offset; 1877 offset = fEntityReader.currentOffset(); 1878 } 1879 if (count > 1) { 1880 if (fEntityReader.lookingAtChar('>', true)) { 1881 if (!sawDashDash && count > 2) { 1882 reportFatalXMLError(XMLMessages.MSG_DASH_DASH_IN_COMMENT, 1883 XMLMessages.P15_DASH_DASH); 1884 sawDashDash = true; 1885 } 1886 fScannerMarkupDepth--; 1887 fEventHandler.callComment(fEntityReader.addString(commentOffset, endOffset - commentOffset)); 1888 restoreScannerState(previousState); 1889 return; 1890 } else if (!sawDashDash) { 1891 reportFatalXMLError(XMLMessages.MSG_DASH_DASH_IN_COMMENT, 1892 XMLMessages.P15_DASH_DASH); 1893 sawDashDash = true; 1894 } 1895 } 1896 } else { 1897 if (!fEntityReader.lookingAtValidChar(true)) { 1898 int invChar = fEntityReader.scanInvalidChar(); 1899 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1900 if (invChar >= 0) { 1901 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_COMMENT, 1902 XMLMessages.P15_INVALID_CHARACTER, 1903 Integer.toHexString(invChar)); 1904 } 1905 } 1906 } 1907 } 1908 } 1909 restoreScannerState(previousState); 1910 } 1911 void scanPI(int piTarget) throws Exception 1918 { 1919 String piTargetString = fStringPool.toString(piTarget); 1920 if (piTargetString.length() == 3 && 1921 (piTargetString.charAt(0) == 'X' || piTargetString.charAt(0) == 'x') && 1922 (piTargetString.charAt(1) == 'M' || piTargetString.charAt(1) == 'm') && 1923 (piTargetString.charAt(2) == 'L' || piTargetString.charAt(2) == 'l')) { 1924 abortMarkup(XMLMessages.MSG_RESERVED_PITARGET, 1925 XMLMessages.P17_RESERVED_PITARGET); 1926 return; 1927 } 1928 int prevState = setScannerState(SCANNER_STATE_PI); 1929 int piDataOffset = -1; 1930 int piDataLength = -1; 1931 if (!fEntityReader.lookingAtSpace(true)) { 1932 if (!fEntityReader.lookingAtChar('?', true) || !fEntityReader.lookingAtChar('>', true)) { 1933 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1934 abortMarkup(XMLMessages.MSG_SPACE_REQUIRED_IN_PI, 1935 XMLMessages.P16_WHITESPACE_REQUIRED); 1936 restoreScannerState(prevState); 1937 } 1938 return; 1939 } 1940 piDataLength = 0; 1941 } else { 1942 fEntityReader.skipPastSpaces(); 1943 piDataOffset = fEntityReader.currentOffset(); 1944 while (fScannerState == SCANNER_STATE_PI) { 1945 while (fEntityReader.lookingAtChar('?', false)) { 1946 int offset = fEntityReader.currentOffset(); 1947 fEntityReader.lookingAtChar('?', true); 1948 if (fEntityReader.lookingAtChar('>', true)) { 1949 piDataLength = offset - piDataOffset; 1950 break; 1951 } 1952 } 1953 if (piDataLength >= 0) 1954 break; 1955 if (!fEntityReader.lookingAtValidChar(true)) { 1956 int invChar = fEntityReader.scanInvalidChar(); 1957 if (fScannerState != SCANNER_STATE_END_OF_INPUT) { 1958 if (invChar >= 0) { 1959 reportFatalXMLError(XMLMessages.MSG_INVALID_CHAR_IN_PI, 1960 XMLMessages.P16_INVALID_CHARACTER, 1961 Integer.toHexString(invChar)); 1962 } 1963 skipPastEndOfCurrentMarkup(); 1964 restoreScannerState(prevState); 1965 } 1966 return; 1967 } 1968 } 1969 } 1970 fScannerMarkupDepth--; 1971 restoreScannerState(prevState); 1972 int piData = piDataLength == 0 ? 1973 StringPool.EMPTY_STRING : fEntityReader.addString(piDataOffset, piDataLength); 1974 fEventHandler.callProcessingInstruction(piTarget, piData); 1975 } 1976 1977 1978 public void setNamespacesEnabled(boolean enabled) { 1979 fNamespacesEnabled = enabled; 1980 } 1981 1982 1983 public boolean getNamespacesEnabled() { 1984 return fNamespacesEnabled; 1985 } 1986 1987 1988 public void setValidationEnabled(boolean enabled) { 1989 fValidationEnabled = enabled; 1990 if (fDTDScanner != null) { 1991 fDTDScanner.setValidationEnabled(enabled); 1992 } 1993 } 1994 1995 1996 public boolean getValidationEnabled() { 1997 return fValidationEnabled; 1998 } 1999 2000 2001 public void setLoadExternalDTD(boolean enabled) { 2002 fLoadExternalDTD = enabled; 2003 if (fDTDScanner != null) { 2004 fDTDScanner.setLoadExternalDTD(enabled); 2005 } 2006 } 2007 2008 2009 public boolean getLoadExternalDTD() { 2010 return fLoadExternalDTD; 2011 } 2012 2013 2015 2016 private void scanElementType(XMLEntityHandler.EntityReader entityReader, 2017 char fastchar, QName element) throws Exception { 2018 2019 if (!fNamespacesEnabled) { 2020 element.clear(); 2021 element.localpart = entityReader.scanName(fastchar); 2022 element.rawname = element.localpart; 2023 } 2024 else { 2025 entityReader.scanQName(fastchar, element); 2026 if (entityReader.lookingAtChar(':', false)) { 2027 fErrorReporter.reportError(fErrorReporter.getLocator(), 2028 XMLMessages.XML_DOMAIN, 2029 XMLMessages.MSG_TWO_COLONS_IN_QNAME, 2030 XMLMessages.P5_INVALID_CHARACTER, 2031 null, 2032 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 2033 entityReader.skipPastNmtoken(' '); 2034 } 2035 } 2036 2037 fEventHandler.element(element); 2038 2039 } 2041 2042 private boolean scanExpectedElementType(XMLEntityHandler.EntityReader entityReader, 2043 char fastchar, int elementType) 2044 throws Exception { 2045 2046 2047 if (fCurrentElementCharArrayRange == null) { 2051 fCurrentElementCharArrayRange = fStringPool.createCharArrayRange(); 2052 } 2053 fStringPool.getCharArrayRange(elementType, fCurrentElementCharArrayRange); 2054 return entityReader.scanExpectedName(fastchar, fCurrentElementCharArrayRange); 2055 2059 2060 } 2062 2063 private void scanAttributeName(XMLEntityHandler.EntityReader entityReader, 2064 QName element, QName attribute) 2065 throws Exception { 2066 2067 2075 2076 if (!fNamespacesEnabled) { 2077 attribute.clear(); 2078 attribute.localpart = entityReader.scanName('='); 2079 attribute.rawname = attribute.localpart; 2080 } 2081 else { 2082 entityReader.scanQName('=', attribute); 2083 if (entityReader.lookingAtChar(':', false)) { 2084 fErrorReporter.reportError(fErrorReporter.getLocator(), 2085 XMLMessages.XML_DOMAIN, 2086 XMLMessages.MSG_TWO_COLONS_IN_QNAME, 2087 XMLMessages.P5_INVALID_CHARACTER, 2088 null, 2089 XMLErrorReporter.ERRORTYPE_FATAL_ERROR); 2090 entityReader.skipPastNmtoken(' '); 2091 } 2092 } 2093 2094 } 2096 2097 private void scanDoctypeDecl(boolean standalone) throws Exception { 2098 2099 fScanningDTD = true; 2100 2101 2105 fSeenDoctypeDecl = true; 2106 2130 if (fDTDScanner == null) { 2131 fDTDScanner = new XMLDTDScanner(fStringPool, fErrorReporter, fEntityHandler, new ChunkyCharArray(fStringPool)); 2132 fDTDScanner.setValidationEnabled(fValidationEnabled); 2133 fDTDScanner.setNamespacesEnabled(fNamespacesEnabled); 2134 fDTDScanner.setLoadExternalDTD(fLoadExternalDTD); 2135 } 2136 else { 2137 fDTDScanner.reset(fStringPool, new ChunkyCharArray(fStringPool)); 2138 } 2139 fDTDScanner.setDTDHandler(fDTDHandler); 2140 fDTDScanner.setGrammarResolver(fGrammarResolver); 2141 if (fDTDScanner.scanDoctypeDecl()) { 2143 if (fDTDScanner.getReadingExternalEntity()) { 2144 fDTDScanner.scanDecls(true); 2145 } 2146 } 2148 if (fValidationEnabled) { 2150 ((DefaultEntityHandler)fEntityHandler).checkRequiredNotations(); 2151 } 2152 2153 fScanningDTD = false; 2154 2155 } 2157 2158 private int scanAttValue(QName element, QName attribute) throws Exception { 2159 2160 int attValue = scanAttValue(element, attribute, fValidationEnabled); 2162 if (attValue == -1) { 2163 return XMLDocumentScanner.RESULT_FAILURE; 2164 } 2165 2166 2167 2180 2181 2210 2211 2229 2230 return XMLDocumentScanner.RESULT_SUCCESS; 2231 2232 } 2234 2235 private boolean validVersionNum(String version) { 2236 return XMLCharacterProperties.validVersionNum(version); 2237 } 2238 2239 2240 private boolean validEncName(String encoding) { 2241 return XMLCharacterProperties.validEncName(encoding); 2242 } 2243 2244} | Popular Tags |