1 57 58 package com.sun.org.apache.xerces.internal.impl; 59 60 import java.io.IOException ; 61 62 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 63 import com.sun.org.apache.xerces.internal.util.SymbolTable; 64 import com.sun.org.apache.xerces.internal.util.XMLAttributesImpl; 65 import com.sun.org.apache.xerces.internal.util.XMLChar; 66 import com.sun.org.apache.xerces.internal.util.XMLStringBuffer; 67 import com.sun.org.apache.xerces.internal.xni.Augmentations; 68 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; 69 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; 70 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 71 import com.sun.org.apache.xerces.internal.xni.XMLString; 72 import com.sun.org.apache.xerces.internal.xni.XNIException; 73 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 74 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 75 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 76 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDScanner; 77 import com.sun.org.apache.xerces.internal.xni.parser.XMLInputSource; 78 79 102 public class XMLDTDScannerImpl 103 extends XMLScanner 104 implements XMLDTDScanner, XMLComponent, XMLEntityHandler { 105 106 110 112 113 protected static final int SCANNER_STATE_END_OF_INPUT = 0; 114 115 116 protected static final int SCANNER_STATE_TEXT_DECL = 1; 117 118 119 protected static final int SCANNER_STATE_MARKUP_DECL = 2; 120 121 123 124 private static final String [] RECOGNIZED_FEATURES = { 125 VALIDATION, 126 NOTIFY_CHAR_REFS, 127 }; 128 129 130 private static final Boolean [] FEATURE_DEFAULTS = { 131 null, 132 Boolean.FALSE, 133 }; 134 135 136 private static final String [] RECOGNIZED_PROPERTIES = { 137 SYMBOL_TABLE, 138 ERROR_REPORTER, 139 ENTITY_MANAGER, 140 }; 141 142 143 private static final Object [] PROPERTY_DEFAULTS = { 144 null, 145 null, 146 null, 147 }; 148 149 151 152 private static final boolean DEBUG_SCANNER_STATE = false; 153 154 158 160 161 protected XMLDTDHandler fDTDHandler; 162 163 164 protected XMLDTDContentModelHandler fDTDContentModelHandler; 165 166 168 169 protected int fScannerState; 170 171 172 protected boolean fStandalone; 173 174 175 protected boolean fSeenExternalDTD; 176 177 178 protected boolean fSeenExternalPE; 179 180 182 183 private boolean fStartDTDCalled; 184 185 186 private XMLAttributesImpl fAttributes = new XMLAttributesImpl(); 187 188 192 private int[] fContentStack = new int[5]; 193 194 195 private int fContentDepth; 196 197 198 private int[] fPEStack = new int[5]; 199 200 201 202 private boolean[] fPEReport = new boolean[5]; 203 204 205 private int fPEDepth; 206 207 208 private int fMarkUpDepth; 209 210 211 private int fExtEntityDepth; 212 213 214 private int fIncludeSectDepth; 215 216 218 219 private String [] fStrings = new String [3]; 220 221 222 private XMLString fString = new XMLString(); 223 224 225 private XMLStringBuffer fStringBuffer = new XMLStringBuffer(); 226 227 228 private XMLStringBuffer fStringBuffer2 = new XMLStringBuffer(); 229 230 231 private XMLString fLiteral = new XMLString(); 232 233 234 private XMLString fLiteral2 = new XMLString(); 235 236 237 private String [] fEnumeration = new String [5]; 238 239 240 private int fEnumerationCount; 241 242 243 private XMLStringBuffer fIgnoreConditionalBuffer = new XMLStringBuffer(128); 244 245 249 250 public XMLDTDScannerImpl() {} 252 253 public XMLDTDScannerImpl(SymbolTable symbolTable, 254 XMLErrorReporter errorReporter, XMLEntityManager entityManager) { 255 fSymbolTable = symbolTable; 256 fErrorReporter = errorReporter; 257 fEntityManager = entityManager; 258 entityManager.setProperty(SYMBOL_TABLE, fSymbolTable); 259 } 260 261 265 272 public void setInputSource(XMLInputSource inputSource) throws IOException { 273 if (inputSource == null) { 274 if (fDTDHandler != null) { 276 fDTDHandler.startDTD(null, null); 277 fDTDHandler.endDTD(null); 278 } 279 return; 280 } 281 fEntityManager.setEntityHandler(this); 282 fEntityManager.startDTDEntity(inputSource); 283 } 285 298 public boolean scanDTDExternalSubset(boolean complete) 299 throws IOException , XNIException { 300 301 fEntityManager.setEntityHandler(this); 302 if (fScannerState == SCANNER_STATE_TEXT_DECL) { 303 fSeenExternalDTD = true; 304 boolean textDecl = scanTextDecl(); 305 if (fScannerState == SCANNER_STATE_END_OF_INPUT) { 306 return false; 307 } 308 else { 309 setScannerState(SCANNER_STATE_MARKUP_DECL); 312 if (textDecl && !complete) { 313 return true; 314 } 315 } 316 } 317 do { 319 if (!scanDecls(complete)) { 320 return false; 321 } 322 } while (complete); 323 324 return true; 326 327 } 329 349 public boolean scanDTDInternalSubset(boolean complete, boolean standalone, 350 boolean hasExternalSubset) 351 throws IOException , XNIException { 352 fEntityScanner = fEntityManager.getEntityScanner(); 354 fEntityManager.setEntityHandler(this); 355 fStandalone = standalone; 356 if (fScannerState == SCANNER_STATE_TEXT_DECL) { 357 if (fDTDHandler != null) { 359 fDTDHandler.startDTD(fEntityScanner, null); 360 fStartDTDCalled = true; 361 } 362 setScannerState(SCANNER_STATE_MARKUP_DECL); 364 } 365 do { 367 if (!scanDecls(complete)) { 368 if (fDTDHandler != null && hasExternalSubset == false) { 370 fDTDHandler.endDTD(null); 371 } 372 setScannerState(SCANNER_STATE_TEXT_DECL); 374 return false; 375 } 376 } while (complete); 377 378 return true; 380 381 } 383 387 392 public void reset(XMLComponentManager componentManager) 393 throws XMLConfigurationException { 394 395 super.reset(componentManager); 396 init(); 397 398 } 400 public void reset() { 402 super.reset(); 403 init(); 404 } 405 406 411 public String [] getRecognizedFeatures() { 412 return (String [])(RECOGNIZED_FEATURES.clone()); 413 } 415 420 public String [] getRecognizedProperties() { 421 return (String [])(RECOGNIZED_PROPERTIES.clone()); 422 } 424 433 public Boolean getFeatureDefault(String featureId) { 434 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { 435 if (RECOGNIZED_FEATURES[i].equals(featureId)) { 436 return FEATURE_DEFAULTS[i]; 437 } 438 } 439 return null; 440 } 442 451 public Object getPropertyDefault(String propertyId) { 452 for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { 453 if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { 454 return PROPERTY_DEFAULTS[i]; 455 } 456 } 457 return null; 458 } 460 464 469 public void setDTDHandler(XMLDTDHandler dtdHandler) { 470 fDTDHandler = dtdHandler; 471 } 473 478 public XMLDTDHandler getDTDHandler() { 479 return fDTDHandler; 480 } 482 486 491 public void setDTDContentModelHandler(XMLDTDContentModelHandler 492 dtdContentModelHandler) { 493 fDTDContentModelHandler = dtdContentModelHandler; 494 } 496 501 public XMLDTDContentModelHandler getDTDContentModelHandler() { 502 return fDTDContentModelHandler ; 503 } 505 509 525 public void startEntity(String name, 526 XMLResourceIdentifier identifier, 527 String encoding, Augmentations augs) throws XNIException { 528 529 super.startEntity(name, identifier, encoding, augs); 530 531 boolean dtdEntity = name.equals("[dtd]"); 532 if (dtdEntity) { 533 if (fDTDHandler != null && !fStartDTDCalled ) { 535 fDTDHandler.startDTD(fEntityScanner, null); 536 } 537 if (fDTDHandler != null) { 538 fDTDHandler.startExternalSubset(identifier,null); 539 } 540 fEntityManager.startExternalSubset(); 541 fExtEntityDepth++; 542 } 543 else if (name.charAt(0) == '%') { 544 pushPEStack(fMarkUpDepth, fReportEntity); 545 if (fEntityScanner.isExternal()) { 546 fExtEntityDepth++; 547 } 548 } 549 550 if (fDTDHandler != null && !dtdEntity && fReportEntity) { 552 fDTDHandler.startParameterEntity(name, identifier, encoding, augs); 553 } 554 555 } 557 567 public void endEntity(String name, Augmentations augs) 568 throws XNIException { 569 570 super.endEntity(name, augs); 571 572 if (fScannerState == SCANNER_STATE_END_OF_INPUT) 575 return; 576 577 boolean reportEntity = fReportEntity; 579 if (name.startsWith("%")) { 580 reportEntity = peekReportEntity(); 581 int startMarkUpDepth = popPEStack(); 583 if(startMarkUpDepth == 0 && 586 startMarkUpDepth < fMarkUpDepth) { 587 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 588 "ILL_FORMED_PARAMETER_ENTITY_WHEN_USED_IN_DECL", 589 new Object []{ fEntityManager.fCurrentEntity.name}, 590 XMLErrorReporter.SEVERITY_FATAL_ERROR); 591 } 592 if (startMarkUpDepth != fMarkUpDepth) { 593 reportEntity = false; 594 if (fValidation) { 595 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 598 "ImproperDeclarationNesting", 599 new Object []{ name }, 600 XMLErrorReporter.SEVERITY_ERROR); 601 } 602 } 603 if (fEntityScanner.isExternal()) { 604 fExtEntityDepth--; 605 } 606 } 607 608 boolean dtdEntity = name.equals("[dtd]"); 610 if (fDTDHandler != null && !dtdEntity && reportEntity) { 611 fDTDHandler.endParameterEntity(name, augs); 612 } 613 614 if (dtdEntity) { 616 if (fIncludeSectDepth != 0) { 617 reportFatalError("IncludeSectUnterminated", null); 618 } 619 fScannerState = SCANNER_STATE_END_OF_INPUT; 620 fEntityManager.endExternalSubset(); 622 if (fDTDHandler != null) { 623 fDTDHandler.endExternalSubset(null); 624 fDTDHandler.endDTD(null); 625 } 626 fExtEntityDepth--; 627 } 628 629 } 631 633 638 protected final void setScannerState(int state) { 639 640 fScannerState = state; 641 if (DEBUG_SCANNER_STATE) { 642 System.out.print("### setScannerState: "); 643 System.out.print(getScannerStateName(state)); 644 System.out.println(); 645 } 646 647 } 649 653 654 private static String getScannerStateName(int state) { 655 656 if (DEBUG_SCANNER_STATE) { 657 switch (state) { 658 case SCANNER_STATE_END_OF_INPUT: return "SCANNER_STATE_END_OF_INPUT"; 659 case SCANNER_STATE_TEXT_DECL: return "SCANNER_STATE_TEXT_DECL"; 660 case SCANNER_STATE_MARKUP_DECL: return "SCANNER_STATE_MARKUP_DECL"; 661 } 662 } 663 664 return "??? ("+state+')'; 665 666 } 668 protected final boolean scanningInternalSubset() { 669 return fExtEntityDepth == 0; 670 } 671 672 678 protected void startPE(String name, boolean literal) 679 throws IOException , XNIException { 680 int depth = fPEDepth; 681 String pName = "%"+name; 682 if (fValidation && !fEntityManager.isDeclaredEntity(pName)) { 683 fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN,"EntityNotDeclared", 684 new Object []{name}, XMLErrorReporter.SEVERITY_ERROR); 685 } 686 fEntityManager.startEntity(fSymbolTable.addSymbol(pName), 687 literal); 688 if (depth != fPEDepth && fEntityScanner.isExternal()) { 691 scanTextDecl(); 692 } 693 } 694 695 707 protected final boolean scanTextDecl() 708 throws IOException , XNIException { 709 710 boolean textDecl = false; 712 if (fEntityScanner.skipString("<?xml")) { 713 fMarkUpDepth++; 714 if (isValidNameChar(fEntityScanner.peekChar())) { 717 fStringBuffer.clear(); 718 fStringBuffer.append("xml"); 719 if (fNamespaces) { 720 while (isValidNCName(fEntityScanner.peekChar())) { 721 fStringBuffer.append((char)fEntityScanner.scanChar()); 722 } 723 } 724 else { 725 while (isValidNameChar(fEntityScanner.peekChar())) { 726 fStringBuffer.append((char)fEntityScanner.scanChar()); 727 } 728 } 729 String target = 730 fSymbolTable.addSymbol(fStringBuffer.ch, 731 fStringBuffer.offset, 732 fStringBuffer.length); 733 scanPIData(target, fString); 734 } 735 736 else { 738 String version = null; 740 String encoding = null; 741 742 scanXMLDeclOrTextDecl(true, fStrings); 743 textDecl = true; 744 fMarkUpDepth--; 745 746 version = fStrings[0]; 747 encoding = fStrings[1]; 748 749 fEntityScanner.setEncoding(encoding); 750 751 if (fDTDHandler != null) { 753 fDTDHandler.textDecl(version, encoding, null); 754 } 755 } 756 } 757 fEntityManager.fCurrentEntity.mayReadChunks = true; 758 759 return textDecl; 760 761 } 763 771 protected final void scanPIData(String target, XMLString data) 772 throws IOException , XNIException { 773 774 super.scanPIData(target, data); 775 fMarkUpDepth--; 776 777 if (fDTDHandler != null) { 779 fDTDHandler.processingInstruction(target, data, null); 780 } 781 782 } 784 793 protected final void scanComment() throws IOException , XNIException { 794 795 fReportEntity = false; 796 scanComment(fStringBuffer); 797 fMarkUpDepth--; 798 799 if (fDTDHandler != null) { 801 fDTDHandler.comment(fStringBuffer, null); 802 } 803 fReportEntity = true; 804 805 } 807 817 protected final void scanElementDecl() throws IOException , XNIException { 818 819 fReportEntity = false; 821 if (!skipSeparator(true, !scanningInternalSubset())) { 822 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ELEMENT_TYPE_IN_ELEMENTDECL", 823 null); 824 } 825 826 String name = fEntityScanner.scanName(); 828 if (name == null) { 829 reportFatalError("MSG_ELEMENT_TYPE_REQUIRED_IN_ELEMENTDECL", 830 null); 831 } 832 833 if (!skipSeparator(true, !scanningInternalSubset())) { 835 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_CONTENTSPEC_IN_ELEMENTDECL", 836 new Object []{name}); 837 } 838 839 if (fDTDContentModelHandler != null) { 841 fDTDContentModelHandler.startContentModel(name, null); 842 } 843 String contentModel = null; 844 fReportEntity = true; 845 if (fEntityScanner.skipString("EMPTY")) { 846 contentModel = "EMPTY"; 847 if (fDTDContentModelHandler != null) { 849 fDTDContentModelHandler.empty(null); 850 } 851 } 852 else if (fEntityScanner.skipString("ANY")) { 853 contentModel = "ANY"; 854 if (fDTDContentModelHandler != null) { 856 fDTDContentModelHandler.any(null); 857 } 858 } 859 else { 860 if (!fEntityScanner.skipChar('(')) { 861 reportFatalError("MSG_OPEN_PAREN_OR_ELEMENT_TYPE_REQUIRED_IN_CHILDREN", 862 new Object []{name}); 863 } 864 if (fDTDContentModelHandler != null) { 865 fDTDContentModelHandler.startGroup(null); 866 } 867 fStringBuffer.clear(); 868 fStringBuffer.append('('); 869 fMarkUpDepth++; 870 skipSeparator(false, !scanningInternalSubset()); 871 872 if (fEntityScanner.skipString("#PCDATA")) { 874 scanMixed(name); 875 } 876 else { scanChildren(name); 878 } 879 contentModel = fStringBuffer.toString(); 880 } 881 882 if (fDTDContentModelHandler != null) { 884 fDTDContentModelHandler.endContentModel(null); 885 } 886 887 fReportEntity = false; 888 skipSeparator(false, !scanningInternalSubset()); 889 if (!fEntityScanner.skipChar('>')) { 891 reportFatalError("ElementDeclUnterminated", new Object []{name}); 892 } 893 fReportEntity = true; 894 fMarkUpDepth--; 895 896 if (fDTDHandler != null) { 898 fDTDHandler.elementDecl(name, contentModel, null); 899 } 900 901 } 903 916 private final void scanMixed(String elName) 917 throws IOException , XNIException { 918 919 String childName = null; 920 921 fStringBuffer.append("#PCDATA"); 922 if (fDTDContentModelHandler != null) { 924 fDTDContentModelHandler.pcdata(null); 925 } 926 skipSeparator(false, !scanningInternalSubset()); 927 while (fEntityScanner.skipChar('|')) { 928 fStringBuffer.append('|'); 929 if (fDTDContentModelHandler != null) { 931 fDTDContentModelHandler.separator(XMLDTDContentModelHandler.SEPARATOR_CHOICE, 932 null); 933 } 934 skipSeparator(false, !scanningInternalSubset()); 935 936 childName = fEntityScanner.scanName(); 937 if (childName == null) { 938 reportFatalError("MSG_ELEMENT_TYPE_REQUIRED_IN_MIXED_CONTENT", 939 new Object []{elName}); 940 } 941 fStringBuffer.append(childName); 942 if (fDTDContentModelHandler != null) { 944 fDTDContentModelHandler.element(childName, null); 945 } 946 skipSeparator(false, !scanningInternalSubset()); 947 } 948 if (fEntityScanner.skipString(")*")) { 953 fStringBuffer.append(")*"); 954 if (fDTDContentModelHandler != null) { 956 fDTDContentModelHandler.endGroup(null); 957 fDTDContentModelHandler.occurrence(XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE, 958 null); 959 } 960 } 961 else if (childName != null) { 962 reportFatalError("MixedContentUnterminated", 963 new Object []{elName}); 964 } 965 else if (fEntityScanner.skipChar(')')){ 966 fStringBuffer.append(')'); 967 if (fDTDContentModelHandler != null) { 969 fDTDContentModelHandler.endGroup(null); 970 } 971 } 972 else { 973 reportFatalError("MSG_CLOSE_PAREN_REQUIRED_IN_CHILDREN", 974 new Object []{elName}); 975 } 976 fMarkUpDepth--; 977 } 979 980 995 private final void scanChildren(String elName) 996 throws IOException , XNIException { 997 998 fContentDepth = 0; 999 pushContentStack(0); 1000 int currentOp = 0; 1001 int c; 1002 while (true) { 1003 if (fEntityScanner.skipChar('(')) { 1004 fMarkUpDepth++; 1005 fStringBuffer.append('('); 1006 if (fDTDContentModelHandler != null) { 1008 fDTDContentModelHandler.startGroup(null); 1009 } 1010 pushContentStack(currentOp); 1012 currentOp = 0; 1013 skipSeparator(false, !scanningInternalSubset()); 1014 continue; 1015 } 1016 skipSeparator(false, !scanningInternalSubset()); 1017 String childName = fEntityScanner.scanName(); 1018 if (childName == null) { 1019 reportFatalError("MSG_OPEN_PAREN_OR_ELEMENT_TYPE_REQUIRED_IN_CHILDREN", 1020 new Object []{elName}); 1021 return; 1022 } 1023 if (fDTDContentModelHandler != null) { 1025 fDTDContentModelHandler.element(childName, null); 1026 } 1027 fStringBuffer.append(childName); 1028 c = fEntityScanner.peekChar(); 1029 if (c == '?' || c == '*' || c == '+') { 1030 if (fDTDContentModelHandler != null) { 1032 short oc; 1033 if (c == '?') { 1034 oc = XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE; 1035 } 1036 else if (c == '*') { 1037 oc = XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE; 1038 } 1039 else { 1040 oc = XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE; 1041 } 1042 fDTDContentModelHandler.occurrence(oc, null); 1043 } 1044 fEntityScanner.scanChar(); 1045 fStringBuffer.append((char)c); 1046 } 1047 while (true) { 1048 skipSeparator(false, !scanningInternalSubset()); 1049 c = fEntityScanner.peekChar(); 1050 if (c == ',' && currentOp != '|') { 1051 currentOp = c; 1052 if (fDTDContentModelHandler != null) { 1054 fDTDContentModelHandler.separator(XMLDTDContentModelHandler.SEPARATOR_SEQUENCE, 1055 null); 1056 } 1057 fEntityScanner.scanChar(); 1058 fStringBuffer.append(','); 1059 break; 1060 } 1061 else if (c == '|' && currentOp != ',') { 1062 currentOp = c; 1063 if (fDTDContentModelHandler != null) { 1065 fDTDContentModelHandler.separator(XMLDTDContentModelHandler.SEPARATOR_CHOICE, 1066 null); 1067 } 1068 fEntityScanner.scanChar(); 1069 fStringBuffer.append('|'); 1070 break; 1071 } 1072 else if (c != ')') { 1073 reportFatalError("MSG_CLOSE_PAREN_REQUIRED_IN_CHILDREN", 1074 new Object []{elName}); 1075 } 1076 if (fDTDContentModelHandler != null) { 1078 fDTDContentModelHandler.endGroup(null); 1079 } 1080 currentOp = popContentStack(); 1082 short oc; 1083 if (fEntityScanner.skipString(")?")) { 1089 fStringBuffer.append(")?"); 1090 if (fDTDContentModelHandler != null) { 1092 oc = XMLDTDContentModelHandler.OCCURS_ZERO_OR_ONE; 1093 fDTDContentModelHandler.occurrence(oc, null); 1094 } 1095 } 1096 else if (fEntityScanner.skipString(")+")) { 1097 fStringBuffer.append(")+"); 1098 if (fDTDContentModelHandler != null) { 1100 oc = XMLDTDContentModelHandler.OCCURS_ONE_OR_MORE; 1101 fDTDContentModelHandler.occurrence(oc, null); 1102 } 1103 } 1104 else if (fEntityScanner.skipString(")*")) { 1105 fStringBuffer.append(")*"); 1106 if (fDTDContentModelHandler != null) { 1108 oc = XMLDTDContentModelHandler.OCCURS_ZERO_OR_MORE; 1109 fDTDContentModelHandler.occurrence(oc, null); 1110 } 1111 } 1112 else { 1113 fEntityScanner.scanChar(); 1115 fStringBuffer.append(')'); 1116 } 1117 fMarkUpDepth--; 1118 if (fContentDepth == 0) { 1119 return; 1120 } 1121 } 1122 skipSeparator(false, !scanningInternalSubset()); 1123 } 1124 } 1125 1126 1136 protected final void scanAttlistDecl() throws IOException , XNIException { 1137 1138 fReportEntity = false; 1140 if (!skipSeparator(true, !scanningInternalSubset())) { 1141 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ELEMENT_TYPE_IN_ATTLISTDECL", 1142 null); 1143 } 1144 1145 String elName = fEntityScanner.scanName(); 1147 if (elName == null) { 1148 reportFatalError("MSG_ELEMENT_TYPE_REQUIRED_IN_ATTLISTDECL", 1149 null); 1150 } 1151 1152 if (fDTDHandler != null) { 1154 fDTDHandler.startAttlist(elName, null); 1155 } 1156 1157 if (!skipSeparator(true, !scanningInternalSubset())) { 1159 if (fEntityScanner.skipChar('>')) { 1161 if (fDTDHandler != null) { 1164 fDTDHandler.endAttlist(null); 1165 } 1166 fMarkUpDepth--; 1167 return; 1168 } 1169 else { 1170 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ATTRIBUTE_NAME_IN_ATTDEF", 1171 new Object []{elName}); 1172 } 1173 } 1174 1175 while (!fEntityScanner.skipChar('>')) { 1177 String name = fEntityScanner.scanName(); 1178 if (name == null) { 1179 reportFatalError("AttNameRequiredInAttDef", 1180 new Object []{elName}); 1181 } 1182 if (!skipSeparator(true, !scanningInternalSubset())) { 1184 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ATTTYPE_IN_ATTDEF", 1185 new Object []{elName, name}); 1186 } 1187 String type = scanAttType(elName, name); 1189 1190 if (!skipSeparator(true, !scanningInternalSubset())) { 1192 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_DEFAULTDECL_IN_ATTDEF", 1193 new Object []{elName, name}); 1194 } 1195 1196 String defaultType = scanAttDefaultDecl(elName, name, 1198 type, 1199 fLiteral, fLiteral2); 1200 1204 if (fDTDHandler != null) { 1206 String [] enumeration = null; 1207 if (fEnumerationCount != 0) { 1208 enumeration = new String [fEnumerationCount]; 1209 System.arraycopy(fEnumeration, 0, enumeration, 1210 0, fEnumerationCount); 1211 } 1212 if (defaultType!=null && (defaultType.equals("#REQUIRED") || 1215 defaultType.equals("#IMPLIED"))) { 1216 fDTDHandler.attributeDecl(elName, name, type, enumeration, 1217 defaultType, null, null, null); 1218 } 1219 else { 1220 fDTDHandler.attributeDecl(elName, name, type, enumeration, 1221 defaultType, fLiteral, fLiteral2, null); 1222 } 1223 } 1224 skipSeparator(false, !scanningInternalSubset()); 1225 } 1226 1227 if (fDTDHandler != null) { 1229 fDTDHandler.endAttlist(null); 1230 } 1231 fMarkUpDepth--; 1232 fReportEntity = true; 1233 1234 } 1236 1259 private final String scanAttType(String elName, String atName) 1260 throws IOException , XNIException { 1261 1262 String type = null; 1263 fEnumerationCount = 0; 1264 1269 if (fEntityScanner.skipString("CDATA")) { 1270 type = "CDATA"; 1271 } 1272 else if (fEntityScanner.skipString("IDREFS")) { 1273 type = "IDREFS"; 1274 } 1275 else if (fEntityScanner.skipString("IDREF")) { 1276 type = "IDREF"; 1277 } 1278 else if (fEntityScanner.skipString("ID")) { 1279 type = "ID"; 1280 } 1281 else if (fEntityScanner.skipString("ENTITY")) { 1282 type = "ENTITY"; 1283 } 1284 else if (fEntityScanner.skipString("ENTITIES")) { 1285 type = "ENTITIES"; 1286 } 1287 else if (fEntityScanner.skipString("NMTOKENS")) { 1288 type = "NMTOKENS"; 1289 } 1290 else if (fEntityScanner.skipString("NMTOKEN")) { 1291 type = "NMTOKEN"; 1292 } 1293 else if (fEntityScanner.skipString("NOTATION")) { 1294 type = "NOTATION"; 1295 if (!skipSeparator(true, !scanningInternalSubset())) { 1297 reportFatalError("MSG_SPACE_REQUIRED_AFTER_NOTATION_IN_NOTATIONTYPE", 1298 new Object []{elName, atName}); 1299 } 1300 int c = fEntityScanner.scanChar(); 1302 if (c != '(') { 1303 reportFatalError("MSG_OPEN_PAREN_REQUIRED_IN_NOTATIONTYPE", 1304 new Object []{elName, atName}); 1305 } 1306 fMarkUpDepth++; 1307 do { 1308 skipSeparator(false, !scanningInternalSubset()); 1309 String aName = fEntityScanner.scanName(); 1310 if (aName == null) { 1311 reportFatalError("MSG_NAME_REQUIRED_IN_NOTATIONTYPE", 1312 new Object []{elName, atName}); 1313 } 1314 ensureEnumerationSize(fEnumerationCount + 1); 1315 fEnumeration[fEnumerationCount++] = aName; 1316 skipSeparator(false, !scanningInternalSubset()); 1317 c = fEntityScanner.scanChar(); 1318 } while (c == '|'); 1319 if (c != ')') { 1320 reportFatalError("NotationTypeUnterminated", 1321 new Object []{elName, atName}); 1322 } 1323 fMarkUpDepth--; 1324 } 1325 else { type = "ENUMERATION"; 1327 int c = fEntityScanner.scanChar(); 1329 if (c != '(') { 1330 reportFatalError("AttTypeRequiredInAttDef", 1332 new Object []{elName, atName}); 1333 } 1334 fMarkUpDepth++; 1335 do { 1336 skipSeparator(false, !scanningInternalSubset()); 1337 String token = fEntityScanner.scanNmtoken(); 1338 if (token == null) { 1339 reportFatalError("MSG_NMTOKEN_REQUIRED_IN_ENUMERATION", 1340 new Object []{elName, atName}); 1341 } 1342 ensureEnumerationSize(fEnumerationCount + 1); 1343 fEnumeration[fEnumerationCount++] = token; 1344 skipSeparator(false, !scanningInternalSubset()); 1345 c = fEntityScanner.scanChar(); 1346 } while (c == '|'); 1347 if (c != ')') { 1348 reportFatalError("EnumerationUnterminated", 1349 new Object []{elName, atName}); 1350 } 1351 fMarkUpDepth--; 1352 } 1353 return type; 1354 1355 } 1357 1358 1368 protected final String scanAttDefaultDecl(String elName, String atName, 1369 String type, 1370 XMLString defaultVal, 1371 XMLString nonNormalizedDefaultVal) 1372 throws IOException , XNIException { 1373 1374 String defaultType = null; 1375 fString.clear(); 1376 defaultVal.clear(); 1377 if (fEntityScanner.skipString("#REQUIRED")) { 1378 defaultType = "#REQUIRED"; 1379 } 1380 else if (fEntityScanner.skipString("#IMPLIED")) { 1381 defaultType = "#IMPLIED"; 1382 } 1383 else { 1384 if (fEntityScanner.skipString("#FIXED")) { 1385 defaultType = "#FIXED"; 1386 if (!skipSeparator(true, !scanningInternalSubset())) { 1388 reportFatalError("MSG_SPACE_REQUIRED_AFTER_FIXED_IN_DEFAULTDECL", 1389 new Object []{elName, atName}); 1390 } 1391 } 1392 boolean isVC = !fStandalone && (fSeenExternalDTD || fSeenExternalPE) ; 1394 scanAttributeValue(defaultVal, nonNormalizedDefaultVal, atName, isVC, elName); 1395 } 1396 return defaultType; 1397 1398 } 1400 1416 private final void scanEntityDecl() throws IOException , XNIException { 1417 1418 boolean isPEDecl = false; 1419 boolean sawPERef = false; 1420 fReportEntity = false; 1421 if (fEntityScanner.skipSpaces()) { 1422 if (!fEntityScanner.skipChar('%')) { 1423 isPEDecl = false; } 1425 else if (skipSeparator(true, !scanningInternalSubset())) { 1426 isPEDecl = true; 1428 } 1429 else if (scanningInternalSubset()) { 1430 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ENTITY_NAME_IN_ENTITYDECL", 1431 null); 1432 isPEDecl = true; 1433 } 1434 else if (fEntityScanner.peekChar() == '%') { 1435 skipSeparator(false, !scanningInternalSubset()); 1437 isPEDecl = true; 1438 } 1439 else { 1440 sawPERef = true; 1441 } 1442 } 1443 else if (scanningInternalSubset() || !fEntityScanner.skipChar('%')) { 1444 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_ENTITY_NAME_IN_ENTITYDECL", 1446 null); 1447 isPEDecl = false; 1448 } 1449 else if (fEntityScanner.skipSpaces()) { 1450 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_PERCENT_IN_PEDECL", 1452 null); 1453 isPEDecl = false; 1454 } 1455 else { 1456 sawPERef = true; 1457 } 1458 if (sawPERef) { 1459 while (true) { 1460 String peName = fEntityScanner.scanName(); 1461 if (peName == null) { 1462 reportFatalError("NameRequiredInPEReference", null); 1463 } 1464 else if (!fEntityScanner.skipChar(';')) { 1465 reportFatalError("SemicolonRequiredInPEReference", 1466 new Object []{peName}); 1467 } 1468 else { 1469 startPE(peName, false); 1470 } 1471 fEntityScanner.skipSpaces(); 1472 if (!fEntityScanner.skipChar('%')) 1473 break; 1474 if (!isPEDecl) { 1475 if (skipSeparator(true, !scanningInternalSubset())) { 1476 isPEDecl = true; 1477 break; 1478 } 1479 isPEDecl = fEntityScanner.skipChar('%'); 1480 } 1481 } 1482 } 1483 1484 String name = null; 1486 if(fNamespaces) { 1487 name = fEntityScanner.scanNCName(); 1488 } else { 1489 name = fEntityScanner.scanName(); 1490 } 1491 if (name == null) { 1492 reportFatalError("MSG_ENTITY_NAME_REQUIRED_IN_ENTITYDECL", null); 1493 } 1494 if (!skipSeparator(true, !scanningInternalSubset())) { 1496 if(fNamespaces && fEntityScanner.peekChar() == ':') { 1497 fEntityScanner.scanChar(); 1498 XMLStringBuffer colonName = new XMLStringBuffer(name); 1499 colonName.append(":"); 1500 String str = fEntityScanner.scanName(); 1501 if (str != null) 1502 colonName.append(str); 1503 reportFatalError("ColonNotLegalWithNS", new Object [] {colonName.toString()}); 1504 if (!skipSeparator(true, !scanningInternalSubset())) { 1505 reportFatalError("MSG_SPACE_REQUIRED_AFTER_ENTITY_NAME_IN_ENTITYDECL", 1506 new Object []{name}); 1507 } 1508 } else { 1509 reportFatalError("MSG_SPACE_REQUIRED_AFTER_ENTITY_NAME_IN_ENTITYDECL", 1510 new Object []{name}); 1511 } 1512 } 1513 1514 scanExternalID(fStrings, false); 1516 String systemId = fStrings[0]; 1517 String publicId = fStrings[1]; 1518 1519 if (isPEDecl && systemId != null) { 1520 fSeenExternalPE = true; 1521 } 1522 1523 String notation = null; 1524 boolean sawSpace = skipSeparator(true, !scanningInternalSubset()); 1526 if (!isPEDecl && fEntityScanner.skipString("NDATA")) { 1527 if (!sawSpace) { 1529 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_NDATA_IN_UNPARSED_ENTITYDECL", 1530 new Object []{name}); 1531 } 1532 1533 if (!skipSeparator(true, !scanningInternalSubset())) { 1535 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_NOTATION_NAME_IN_UNPARSED_ENTITYDECL", 1536 new Object []{name}); 1537 } 1538 notation = fEntityScanner.scanName(); 1539 if (notation == null) { 1540 reportFatalError("MSG_NOTATION_NAME_REQUIRED_FOR_UNPARSED_ENTITYDECL", 1541 new Object []{name}); 1542 } 1543 } 1544 1545 if (systemId == null) { 1547 scanEntityValue(fLiteral, fLiteral2); 1548 fStringBuffer.clear(); 1551 fStringBuffer2.clear(); 1552 fStringBuffer.append(fLiteral.ch, fLiteral.offset, fLiteral.length); 1553 fStringBuffer2.append(fLiteral2.ch, fLiteral2.offset, fLiteral2.length); 1554 } 1555 1556 skipSeparator(false, !scanningInternalSubset()); 1558 1559 if (!fEntityScanner.skipChar('>')) { 1561 reportFatalError("EntityDeclUnterminated", new Object []{name}); 1562 } 1563 fMarkUpDepth--; 1564 1565 if (isPEDecl) { 1567 name = "%" + name; 1568 } 1569 if (systemId != null) { 1570 String baseSystemId = fEntityScanner.getBaseSystemId(); 1571 if (notation != null) { 1572 fEntityManager.addUnparsedEntity(name, publicId, systemId, baseSystemId, notation); 1573 } 1574 else { 1575 fEntityManager.addExternalEntity(name, publicId, systemId, 1576 baseSystemId); 1577 } 1578 if (fDTDHandler != null) { 1579 fResourceIdentifier.setValues(publicId, systemId, baseSystemId, XMLEntityManager.expandSystemId(systemId, baseSystemId, false)); 1580 if (notation != null) { 1581 fDTDHandler.unparsedEntityDecl(name, fResourceIdentifier, 1582 notation, null); 1583 } 1584 else { 1585 fDTDHandler.externalEntityDecl(name, fResourceIdentifier, null); 1586 } 1587 } 1588 } 1589 else { 1590 fEntityManager.addInternalEntity(name, fStringBuffer.toString()); 1591 if (fDTDHandler != null) { 1592 fDTDHandler.internalEntityDecl(name, fStringBuffer, fStringBuffer2, null); 1593 } 1594 } 1595 fReportEntity = true; 1596 1597 } 1599 1610 protected final void scanEntityValue(XMLString value, 1611 XMLString nonNormalizedValue) 1612 throws IOException , XNIException 1613 { 1614 int quote = fEntityScanner.scanChar(); 1615 if (quote != '\'' && quote != '"') { 1616 reportFatalError("OpenQuoteMissingInDecl", null); 1617 } 1618 int entityDepth = fEntityDepth; 1620 1621 XMLString literal = fString; 1622 XMLString literal2 = fString; 1623 if (fEntityScanner.scanLiteral(quote, fString) != quote) { 1624 fStringBuffer.clear(); 1625 fStringBuffer2.clear(); 1626 do { 1627 fStringBuffer.append(fString); 1628 fStringBuffer2.append(fString); 1629 if (fEntityScanner.skipChar('&')) { 1630 if (fEntityScanner.skipChar('#')) { 1631 fStringBuffer2.append("&#"); 1632 scanCharReferenceValue(fStringBuffer, fStringBuffer2); 1633 } 1634 else { 1635 fStringBuffer.append('&'); 1636 fStringBuffer2.append('&'); 1637 String eName = fEntityScanner.scanName(); 1638 if (eName == null) { 1639 reportFatalError("NameRequiredInReference", 1640 null); 1641 } 1642 else { 1643 fStringBuffer.append(eName); 1644 fStringBuffer2.append(eName); 1645 } 1646 if (!fEntityScanner.skipChar(';')) { 1647 reportFatalError("SemicolonRequiredInReference", 1648 new Object []{eName}); 1649 } 1650 else { 1651 fStringBuffer.append(';'); 1652 fStringBuffer2.append(';'); 1653 } 1654 } 1655 } 1656 else if (fEntityScanner.skipChar('%')) { 1657 while (true) { 1658 fStringBuffer2.append('%'); 1659 String peName = fEntityScanner.scanName(); 1660 if (peName == null) { 1661 reportFatalError("NameRequiredInPEReference", 1662 null); 1663 } 1664 else if (!fEntityScanner.skipChar(';')) { 1665 reportFatalError("SemicolonRequiredInPEReference", 1666 new Object []{peName}); 1667 } 1668 else { 1669 if (scanningInternalSubset()) { 1670 reportFatalError("PEReferenceWithinMarkup", 1671 new Object []{peName}); 1672 } 1673 fStringBuffer2.append(peName); 1674 fStringBuffer2.append(';'); 1675 } 1676 startPE(peName, true); 1677 fEntityScanner.skipSpaces(); 1681 if (!fEntityScanner.skipChar('%')) 1682 break; 1683 } 1684 } 1685 else { 1686 int c = fEntityScanner.peekChar(); 1687 if (XMLChar.isHighSurrogate(c)) { 1688 scanSurrogates(fStringBuffer2); 1689 } 1690 else if (isInvalidLiteral(c)) { 1691 reportFatalError("InvalidCharInLiteral", 1692 new Object []{Integer.toHexString(c)}); 1693 fEntityScanner.scanChar(); 1694 } 1695 else if (c != quote || entityDepth != fEntityDepth) { 1699 fStringBuffer.append((char)c); 1700 fStringBuffer2.append((char)c); 1701 fEntityScanner.scanChar(); 1702 } 1703 } 1704 } while (fEntityScanner.scanLiteral(quote, fString) != quote); 1705 fStringBuffer.append(fString); 1706 fStringBuffer2.append(fString); 1707 literal = fStringBuffer; 1708 literal2 = fStringBuffer2; 1709 } 1710 value.setValues(literal); 1711 nonNormalizedValue.setValues(literal2); 1712 if (!fEntityScanner.skipChar(quote)) { 1713 reportFatalError("CloseQuoteMissingInDecl", null); 1714 } 1715 } 1717 1727 private final void scanNotationDecl() throws IOException , XNIException { 1728 1729 fReportEntity = false; 1731 if (!skipSeparator(true, !scanningInternalSubset())) { 1732 reportFatalError("MSG_SPACE_REQUIRED_BEFORE_NOTATION_NAME_IN_NOTATIONDECL", 1733 null); 1734 } 1735 1736 String name = null; 1738 if(fNamespaces) { 1739 name = fEntityScanner.scanNCName(); 1740 } else { 1741 name = fEntityScanner.scanName(); 1742 } 1743 if (name == null) { 1744 reportFatalError("MSG_NOTATION_NAME_REQUIRED_IN_NOTATIONDECL", 1745 null); 1746 } 1747 1748 if (!skipSeparator(true, !scanningInternalSubset())) { 1750 if(fNamespaces && fEntityScanner.peekChar() == ':') { 1752 fEntityScanner.scanChar(); 1753 XMLStringBuffer colonName = new XMLStringBuffer(name); 1754 colonName.append(":"); 1755 colonName.append(fEntityScanner.scanName()); 1756 reportFatalError("ColonNotLegalWithNS", new Object [] {colonName.toString()}); 1757 skipSeparator(true, !scanningInternalSubset()); 1758 } else { 1759 reportFatalError("MSG_SPACE_REQUIRED_AFTER_NOTATION_NAME_IN_NOTATIONDECL", 1760 new Object []{name}); 1761 } 1762 } 1763 1764 scanExternalID(fStrings, true); 1766 String systemId = fStrings[0]; 1767 String publicId = fStrings[1]; 1768 String baseSystemId = fEntityScanner.getBaseSystemId(); 1769 1770 if (systemId == null && publicId == null) { 1771 reportFatalError("ExternalIDorPublicIDRequired", 1772 new Object []{name}); 1773 } 1774 1775 skipSeparator(false, !scanningInternalSubset()); 1777 1778 if (!fEntityScanner.skipChar('>')) { 1780 reportFatalError("NotationDeclUnterminated", new Object []{name}); 1781 } 1782 fMarkUpDepth--; 1783 1784 if (fDTDHandler != null) { 1786 fResourceIdentifier.setValues(publicId, systemId, baseSystemId, XMLEntityManager.expandSystemId(systemId, baseSystemId, false)); 1787 fDTDHandler.notationDecl(name, fResourceIdentifier, null); 1788 } 1789 fReportEntity = true; 1790 1791 } 1793 1809 private final void scanConditionalSect(int currPEDepth) 1810 throws IOException , XNIException { 1811 1812 fReportEntity = false; 1813 skipSeparator(false, !scanningInternalSubset()); 1814 1815 if (fEntityScanner.skipString("INCLUDE")) { 1816 skipSeparator(false, !scanningInternalSubset()); 1817 if(currPEDepth != fPEDepth && fValidation) { 1818 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1819 "INVALID_PE_IN_CONDITIONAL", 1820 new Object []{ fEntityManager.fCurrentEntity.name}, 1821 XMLErrorReporter.SEVERITY_ERROR); 1822 } 1823 if (!fEntityScanner.skipChar('[')) { 1825 reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null); 1826 } 1827 1828 if (fDTDHandler != null) { 1829 fDTDHandler.startConditional(XMLDTDHandler.CONDITIONAL_INCLUDE, 1830 null); 1831 } 1832 fIncludeSectDepth++; 1833 fReportEntity = true; 1835 } 1836 else if (fEntityScanner.skipString("IGNORE")) { 1837 skipSeparator(false, !scanningInternalSubset()); 1838 if(currPEDepth != fPEDepth && fValidation) { 1839 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1840 "INVALID_PE_IN_CONDITIONAL", 1841 new Object []{ fEntityManager.fCurrentEntity.name}, 1842 XMLErrorReporter.SEVERITY_ERROR); 1843 } 1844 if (fDTDHandler != null) { 1846 fDTDHandler.startConditional(XMLDTDHandler.CONDITIONAL_IGNORE, 1847 null); 1848 } 1849 if (!fEntityScanner.skipChar('[')) { 1850 reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null); 1851 } 1852 fReportEntity = true; 1853 int initialDepth = ++fIncludeSectDepth; 1854 if (fDTDHandler != null) { 1855 fIgnoreConditionalBuffer.clear(); 1856 } 1857 while (true) { 1858 if (fEntityScanner.skipChar('<')) { 1859 if (fDTDHandler != null) { 1860 fIgnoreConditionalBuffer.append('<'); 1861 } 1862 if (fEntityScanner.skipChar('!')) { 1867 if(fEntityScanner.skipChar('[')) { 1868 if (fDTDHandler != null) { 1869 fIgnoreConditionalBuffer.append("!["); 1870 } 1871 fIncludeSectDepth++; 1872 } else { 1873 if (fDTDHandler != null) { 1874 fIgnoreConditionalBuffer.append("!"); 1875 } 1876 } 1877 } 1878 } 1879 else if (fEntityScanner.skipChar(']')) { 1880 if (fDTDHandler != null) { 1881 fIgnoreConditionalBuffer.append(']'); 1882 } 1883 if (fEntityScanner.skipChar(']')) { 1887 if (fDTDHandler != null) { 1888 fIgnoreConditionalBuffer.append(']'); 1889 } 1890 while (fEntityScanner.skipChar(']')) { 1891 1892 if (fDTDHandler != null) { 1893 fIgnoreConditionalBuffer.append(']'); 1894 } 1895 } 1896 if (fEntityScanner.skipChar('>')) { 1897 if (fIncludeSectDepth-- == initialDepth) { 1898 fMarkUpDepth--; 1899 if (fDTDHandler != null) { 1901 fLiteral.setValues(fIgnoreConditionalBuffer.ch, 0, 1902 fIgnoreConditionalBuffer.length - 2); 1903 fDTDHandler.ignoredCharacters(fLiteral, null); 1904 fDTDHandler.endConditional(null); 1905 } 1906 return; 1907 } else if(fDTDHandler != null) { 1908 fIgnoreConditionalBuffer.append('>'); 1909 } 1910 } 1911 } 1912 } 1913 else { 1914 int c = fEntityScanner.scanChar(); 1915 if (fScannerState == SCANNER_STATE_END_OF_INPUT) { 1916 reportFatalError("IgnoreSectUnterminated", null); 1917 return; 1918 } 1919 if (fDTDHandler != null) { 1920 fIgnoreConditionalBuffer.append((char)c); 1921 } 1922 } 1923 } 1924 } 1925 else { 1926 reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null); 1927 } 1928 1929 } 1931 1943 protected final boolean scanDecls(boolean complete) 1944 throws IOException , XNIException { 1945 1946 skipSeparator(false, true); 1947 boolean again = true; 1948 while (again && fScannerState == SCANNER_STATE_MARKUP_DECL) { 1949 again = complete; 1950 if (fEntityScanner.skipChar('<')) { 1951 fMarkUpDepth++; 1952 if (fEntityScanner.skipChar('?')) { 1953 scanPI(); 1954 } 1955 else if (fEntityScanner.skipChar('!')) { 1956 if (fEntityScanner.skipChar('-')) { 1957 if (!fEntityScanner.skipChar('-')) { 1958 reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", 1959 null); 1960 } else { 1961 scanComment(); 1962 } 1963 } 1964 else if (fEntityScanner.skipString("ELEMENT")) { 1965 scanElementDecl(); 1966 } 1967 else if (fEntityScanner.skipString("ATTLIST")) { 1968 scanAttlistDecl(); 1969 } 1970 else if (fEntityScanner.skipString("ENTITY")) { 1971 scanEntityDecl(); 1972 } 1973 else if (fEntityScanner.skipString("NOTATION")) { 1974 scanNotationDecl(); 1975 } 1976 else if (fEntityScanner.skipChar('[') && 1977 !scanningInternalSubset()) { 1978 scanConditionalSect(fPEDepth); 1979 } 1980 else { 1981 fMarkUpDepth--; 1982 reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", 1983 null); 1984 } 1985 } 1986 else { 1987 fMarkUpDepth--; 1988 reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null); 1989 } 1990 } 1991 else if (fIncludeSectDepth > 0 && fEntityScanner.skipChar(']')) { 1992 if (!fEntityScanner.skipChar(']') 1994 || !fEntityScanner.skipChar('>')) { 1995 reportFatalError("IncludeSectUnterminated", null); 1996 } 1997 if (fDTDHandler != null) { 1999 fDTDHandler.endConditional(null); 2000 } 2001 fIncludeSectDepth--; 2003 fMarkUpDepth--; 2004 } 2005 else if (scanningInternalSubset() && 2006 fEntityScanner.peekChar() == ']') { 2007 return false; 2009 } 2010 else if (fEntityScanner.skipSpaces()) { 2011 } 2013 else { 2014 reportFatalError("MSG_MARKUP_NOT_RECOGNIZED_IN_DTD", null); 2015 int ch; 2017 do { 2018 fEntityScanner.scanChar(); 2020 skipSeparator(false, true); 2022 ch = fEntityScanner.peekChar(); 2025 } while (ch != '<' && ch != ']' && !XMLChar.isSpace(ch)); 2026 } 2027 skipSeparator(false, true); 2028 } 2029 return fScannerState != SCANNER_STATE_END_OF_INPUT; 2030 } 2031 2032 2048 private boolean skipSeparator(boolean spaceRequired, boolean lookForPERefs) 2049 throws IOException , XNIException 2050 { 2051 int depth = fPEDepth; 2052 boolean sawSpace = fEntityScanner.skipSpaces(); 2053 if (!lookForPERefs || !fEntityScanner.skipChar('%')) { 2054 return !spaceRequired || sawSpace || (depth != fPEDepth); 2055 } 2056 while (true) { 2057 String name = fEntityScanner.scanName(); 2058 if (name == null) { 2059 reportFatalError("NameRequiredInPEReference", null); 2060 } 2061 else if (!fEntityScanner.skipChar(';')) { 2062 reportFatalError("SemicolonRequiredInPEReference", 2063 new Object []{name}); 2064 } 2065 startPE(name, false); 2066 fEntityScanner.skipSpaces(); 2067 if (!fEntityScanner.skipChar('%')) 2068 return true; 2069 } 2070 } 2071 2072 2073 2076 private final void pushContentStack(int c) { 2077 if (fContentStack.length == fContentDepth) { 2078 int[] newStack = new int[fContentDepth * 2]; 2079 System.arraycopy(fContentStack, 0, newStack, 0, fContentDepth); 2080 fContentStack = newStack; 2081 } 2082 fContentStack[fContentDepth++] = c; 2083 } 2084 2085 private final int popContentStack() { 2086 return fContentStack[--fContentDepth]; 2087 } 2088 2089 2090 2093 private final void pushPEStack(int depth, boolean report) { 2094 if (fPEStack.length == fPEDepth) { 2095 int[] newIntStack = new int[fPEDepth * 2]; 2096 System.arraycopy(fPEStack, 0, newIntStack, 0, fPEDepth); 2097 fPEStack = newIntStack; 2098 boolean[] newBooleanStack = new boolean[fPEDepth * 2]; 2100 System.arraycopy(fPEReport, 0, newBooleanStack, 0, fPEDepth); 2101 fPEReport = newBooleanStack; 2102 2103 } 2104 fPEReport[fPEDepth] = report; 2105 fPEStack[fPEDepth++] = depth; 2106 } 2107 2108 2109 private final int popPEStack() { 2110 return fPEStack[--fPEDepth]; 2111 } 2112 2113 2114 private final boolean peekReportEntity() { 2115 return fPEReport[fPEDepth-1]; 2116 } 2117 2118 2119 2122 private final void ensureEnumerationSize(int size) { 2123 if (fEnumeration.length == size) { 2124 String [] newEnum = new String [size * 2]; 2125 System.arraycopy(fEnumeration, 0, newEnum, 0, size); 2126 fEnumeration = newEnum; 2127 } 2128 } 2129 2130 private void init() { 2132 fStartDTDCalled = false; 2134 fExtEntityDepth = 0; 2135 fIncludeSectDepth = 0; 2136 fMarkUpDepth = 0; 2137 fPEDepth = 0; 2138 2139 fStandalone = false; 2140 fSeenExternalDTD = false; 2141 fSeenExternalPE = false; 2142 2143 setScannerState(SCANNER_STATE_TEXT_DECL); 2145 } 2146 2147} | Popular Tags |