1 16 17 package org.apache.xerces.impl.dtd; 18 19 import org.apache.xerces.impl.Constants; 20 import org.apache.xerces.impl.RevalidationHandler; 21 import org.apache.xerces.impl.XMLEntityManager; 22 import org.apache.xerces.impl.XMLErrorReporter; 23 import org.apache.xerces.impl.dtd.models.ContentModelValidator; 24 import org.apache.xerces.impl.dv.DTDDVFactory; 25 import org.apache.xerces.impl.dv.DatatypeValidator; 26 import org.apache.xerces.impl.dv.InvalidDatatypeValueException; 27 import org.apache.xerces.impl.msg.XMLMessageFormatter; 28 import org.apache.xerces.impl.validation.ValidationManager; 29 import org.apache.xerces.impl.validation.ValidationState; 30 import org.apache.xerces.util.SymbolTable; 31 import org.apache.xerces.util.XMLChar; 32 import org.apache.xerces.util.XMLSymbols; 33 import org.apache.xerces.xni.Augmentations; 34 import org.apache.xerces.xni.NamespaceContext; 35 import org.apache.xerces.xni.QName; 36 import org.apache.xerces.xni.XMLAttributes; 37 import org.apache.xerces.xni.XMLDocumentHandler; 38 import org.apache.xerces.xni.XMLLocator; 39 import org.apache.xerces.xni.XMLResourceIdentifier; 40 import org.apache.xerces.xni.XMLString; 41 import org.apache.xerces.xni.XNIException; 42 import org.apache.xerces.xni.grammars.Grammar; 43 import org.apache.xerces.xni.grammars.XMLGrammarDescription; 44 import org.apache.xerces.xni.grammars.XMLGrammarPool; 45 import org.apache.xerces.xni.parser.XMLComponent; 46 import org.apache.xerces.xni.parser.XMLComponentManager; 47 import org.apache.xerces.xni.parser.XMLConfigurationException; 48 import org.apache.xerces.xni.parser.XMLDocumentFilter; 49 import org.apache.xerces.xni.parser.XMLDocumentSource; 50 51 84 public class XMLDTDValidator 85 implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter, RevalidationHandler { 86 87 91 92 93 94 private static final int TOP_LEVEL_SCOPE = -1; 95 96 98 99 protected static final String NAMESPACES = 100 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 101 102 103 protected static final String VALIDATION = 104 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 105 106 107 protected static final String DYNAMIC_VALIDATION = 108 Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; 109 110 111 protected static final String WARN_ON_DUPLICATE_ATTDEF = 112 Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 113 114 protected static final String PARSER_SETTINGS = 115 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; 116 117 118 119 121 122 protected static final String SYMBOL_TABLE = 123 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 124 125 126 protected static final String ERROR_REPORTER = 127 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 128 129 130 protected static final String GRAMMAR_POOL = 131 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 132 133 134 protected static final String DATATYPE_VALIDATOR_FACTORY = 135 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 136 137 protected static final String VALIDATION_MANAGER = 139 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 140 141 143 144 private static final String [] RECOGNIZED_FEATURES = { 145 NAMESPACES, 146 VALIDATION, 147 DYNAMIC_VALIDATION 148 }; 149 150 151 private static final Boolean [] FEATURE_DEFAULTS = { 152 null, 153 null, 154 Boolean.FALSE, 155 }; 156 157 158 private static final String [] RECOGNIZED_PROPERTIES = { 159 SYMBOL_TABLE, 160 ERROR_REPORTER, 161 GRAMMAR_POOL, 162 DATATYPE_VALIDATOR_FACTORY, 163 VALIDATION_MANAGER 164 }; 165 166 167 private static final Object [] PROPERTY_DEFAULTS = { 168 null, 169 null, 170 null, 171 null, 172 null, 173 }; 174 175 177 178 private static final boolean DEBUG_ATTRIBUTES = false; 179 180 181 private static final boolean DEBUG_ELEMENT_CHILDREN = false; 182 183 187 protected ValidationManager fValidationManager = null; 189 190 protected ValidationState fValidationState = new ValidationState(); 192 193 195 196 protected boolean fNamespaces; 197 198 199 protected boolean fValidation; 200 201 202 protected boolean fDTDValidation; 203 204 208 protected boolean fDynamicValidation; 209 210 211 protected boolean fWarnDuplicateAttdef; 212 213 215 216 protected SymbolTable fSymbolTable; 217 218 219 protected XMLErrorReporter fErrorReporter; 220 221 protected XMLGrammarPool fGrammarPool; 223 224 225 protected DTDGrammarBucket fGrammarBucket; 226 227 228 protected XMLLocator fDocLocation; 229 230 231 protected NamespaceContext fNamespaceContext = null; 232 233 234 protected DTDDVFactory fDatatypeValidatorFactory; 235 236 238 239 protected XMLDocumentHandler fDocumentHandler; 240 241 protected XMLDocumentSource fDocumentSource; 242 244 245 protected DTDGrammar fDTDGrammar; 246 247 249 250 protected boolean fSeenDoctypeDecl = false; 251 252 253 private boolean fPerformValidation; 254 255 256 private String fSchemaType; 257 258 260 261 private final QName fCurrentElement = new QName(); 262 263 264 private int fCurrentElementIndex = -1; 265 266 267 private int fCurrentContentSpecType = -1; 268 269 270 private final QName fRootElement = new QName(); 271 272 private boolean fInCDATASection = false; 273 275 276 private int[] fElementIndexStack = new int[8]; 277 278 279 private int[] fContentSpecTypeStack = new int[8]; 280 281 282 private QName[] fElementQNamePartsStack = new QName[8]; 283 284 286 299 private QName[] fElementChildren = new QName[32]; 300 301 302 private int fElementChildrenLength = 0; 303 304 309 private int[] fElementChildrenOffsetStack = new int[32]; 310 311 312 private int fElementDepth = -1; 313 314 316 317 private boolean fSeenRootElement = false; 318 319 320 private boolean fInElementContent = false; 321 322 324 325 private XMLElementDecl fTempElementDecl = new XMLElementDecl(); 326 327 328 private XMLAttributeDecl fTempAttDecl = new XMLAttributeDecl(); 329 330 331 private XMLEntityDecl fEntityDecl = new XMLEntityDecl(); 332 333 334 private QName fTempQName = new QName(); 335 336 337 private StringBuffer fBuffer = new StringBuffer (); 338 339 341 343 344 protected DatatypeValidator fValID; 345 346 347 protected DatatypeValidator fValIDRef; 348 349 350 protected DatatypeValidator fValIDRefs; 351 352 353 protected DatatypeValidator fValENTITY; 354 355 356 protected DatatypeValidator fValENTITIES; 357 358 359 protected DatatypeValidator fValNMTOKEN; 360 361 362 protected DatatypeValidator fValNMTOKENS; 363 364 365 protected DatatypeValidator fValNOTATION; 366 367 370 374 375 public XMLDTDValidator() { 376 377 for (int i = 0; i < fElementQNamePartsStack.length; i++) { 379 fElementQNamePartsStack[i] = new QName(); 380 } 381 fGrammarBucket = new DTDGrammarBucket(); 382 383 } 385 DTDGrammarBucket getGrammarBucket() { 386 return fGrammarBucket; 387 } 389 393 407 public void reset(XMLComponentManager componentManager) 408 throws XMLConfigurationException { 409 410 fDTDGrammar = null; 412 fSeenDoctypeDecl = false; 413 fInCDATASection = false; 414 fSeenRootElement = false; 416 fInElementContent = false; 417 fCurrentElementIndex = -1; 418 fCurrentContentSpecType = -1; 419 420 fRootElement.clear(); 421 422 fValidationState.resetIDTables(); 423 424 fGrammarBucket.clear(); 425 fElementDepth = -1; 426 fElementChildrenLength = 0; 427 428 boolean parser_settings; 429 try { 430 parser_settings = componentManager.getFeature(PARSER_SETTINGS); 431 } 432 catch (XMLConfigurationException e){ 433 parser_settings = true; 434 } 435 436 if (!parser_settings){ 437 fValidationManager.addValidationState(fValidationState); 439 return; 440 } 441 442 try { 444 fNamespaces = componentManager.getFeature(NAMESPACES); 445 } 446 catch (XMLConfigurationException e) { 447 fNamespaces = true; 448 } 449 try { 450 fValidation = componentManager.getFeature(VALIDATION); 451 } 452 catch (XMLConfigurationException e) { 453 fValidation = false; 454 } 455 try { 456 fDTDValidation = !(componentManager.getFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE)); 457 } 458 catch (XMLConfigurationException e) { 459 fDTDValidation = true; 461 } 462 463 try { 465 fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION); 466 } 467 catch (XMLConfigurationException e) { 468 fDynamicValidation = false; 469 } 470 471 try { 472 fWarnDuplicateAttdef = componentManager.getFeature(WARN_ON_DUPLICATE_ATTDEF); 473 } 474 catch (XMLConfigurationException e) { 475 fWarnDuplicateAttdef = false; 476 } 477 478 try { 479 fSchemaType = (String )componentManager.getProperty (Constants.JAXP_PROPERTY_PREFIX 480 + Constants.SCHEMA_LANGUAGE); 481 } 482 catch (XMLConfigurationException e){ 483 fSchemaType = null; 484 } 485 486 fValidationManager= (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER); 487 fValidationManager.addValidationState(fValidationState); 488 fValidationState.setUsingNamespaces(fNamespaces); 489 490 fErrorReporter = (XMLErrorReporter)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.ERROR_REPORTER_PROPERTY); 492 fSymbolTable = (SymbolTable)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.SYMBOL_TABLE_PROPERTY); 493 try { 494 fGrammarPool= (XMLGrammarPool)componentManager.getProperty(GRAMMAR_POOL); 495 } catch (XMLConfigurationException e) { 496 fGrammarPool = null; 497 } 498 499 fDatatypeValidatorFactory = (DTDDVFactory)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY); 500 init(); 501 502 } 504 509 public String [] getRecognizedFeatures() { 510 return (String [])(RECOGNIZED_FEATURES.clone()); 511 } 513 528 public void setFeature(String featureId, boolean state) 529 throws XMLConfigurationException { 530 } 532 537 public String [] getRecognizedProperties() { 538 return (String [])(RECOGNIZED_PROPERTIES.clone()); 539 } 541 556 public void setProperty(String propertyId, Object value) 557 throws XMLConfigurationException { 558 } 560 569 public Boolean getFeatureDefault(String featureId) { 570 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { 571 if (RECOGNIZED_FEATURES[i].equals(featureId)) { 572 return FEATURE_DEFAULTS[i]; 573 } 574 } 575 return null; 576 } 578 587 public Object getPropertyDefault(String propertyId) { 588 for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { 589 if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { 590 return PROPERTY_DEFAULTS[i]; 591 } 592 } 593 return null; 594 } 596 600 601 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 602 fDocumentHandler = documentHandler; 603 } 605 606 public XMLDocumentHandler getDocumentHandler() { 607 return fDocumentHandler; 608 } 610 611 615 616 public void setDocumentSource(XMLDocumentSource source){ 617 fDocumentSource = source; 618 } 620 621 public XMLDocumentSource getDocumentSource (){ 622 return fDocumentSource; 623 } 625 647 public void startDocument(XMLLocator locator, String encoding, 648 NamespaceContext namespaceContext, Augmentations augs) 649 throws XNIException { 650 651 if(fGrammarPool != null) { 654 Grammar [] grammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_DTD); 655 for(int i = 0; i<grammars.length; i++) { 656 fGrammarBucket.putGrammar((DTDGrammar)grammars[i]); 657 } 658 } 659 fDocLocation = locator; 660 fNamespaceContext = namespaceContext; 661 662 if (fDocumentHandler != null) { 663 fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs); 664 } 665 666 } 668 681 public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) 682 throws XNIException { 683 684 fGrammarBucket.setStandalone(standalone != null && standalone.equals("yes")); 686 687 if (fDocumentHandler != null) { 689 fDocumentHandler.xmlDecl(version, encoding, standalone, augs); 690 } 691 692 } 694 706 public void doctypeDecl(String rootElement, String publicId, String systemId, 707 Augmentations augs) 708 throws XNIException { 709 710 fSeenDoctypeDecl = true; 712 fRootElement.setValues(null, rootElement, rootElement, null); 713 String eid = null; 715 try { 716 eid = XMLEntityManager.expandSystemId(systemId, fDocLocation.getExpandedSystemId(), false); 717 } catch (java.io.IOException e) { 718 } 719 XMLDTDDescription grammarDesc = new XMLDTDDescription(publicId, systemId, fDocLocation.getExpandedSystemId(), eid, rootElement); 720 fDTDGrammar = fGrammarBucket.getGrammar(grammarDesc); 721 if(fDTDGrammar == null) { 722 if (fGrammarPool != null && (systemId != null || publicId != null)) { 731 fDTDGrammar = (DTDGrammar)fGrammarPool.retrieveGrammar(grammarDesc); 732 } 733 } 734 if(fDTDGrammar == null) { 735 fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc); 737 } else { 738 fValidationManager.setCachedDTD(true); 741 } 742 fGrammarBucket.setActiveGrammar(fDTDGrammar); 743 744 if (fDocumentHandler != null) { 746 fDocumentHandler.doctypeDecl(rootElement, publicId, systemId, augs); 747 } 748 749 } 751 752 761 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) 762 throws XNIException { 763 764 handleStartElement(element, attributes, augs); 765 if (fDocumentHandler != null) { 767 fDocumentHandler.startElement(element, attributes, augs); 768 769 } 770 771 } 773 782 public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) 783 throws XNIException { 784 785 boolean removed = handleStartElement(element, attributes, augs); 786 787 if (fDocumentHandler !=null) { 788 fDocumentHandler.emptyElement(element, attributes, augs); 789 } 790 if (!removed) { 791 handleEndElement(element, augs, true); 792 } 793 794 795 } 797 806 public void characters(XMLString text, Augmentations augs) throws XNIException { 807 808 boolean callNextCharacters = true; 809 810 boolean allWhiteSpace = true; 814 for (int i=text.offset; i< text.offset+text.length; i++) { 815 if (!isSpace(text.ch[i])) { 816 allWhiteSpace = false; 817 break; 818 } 819 } 820 if (fInElementContent && allWhiteSpace && !fInCDATASection) { 823 if (fDocumentHandler != null) { 824 fDocumentHandler.ignorableWhitespace(text, augs); 825 callNextCharacters = false; 826 } 827 } 828 829 if (fPerformValidation) { 831 if (fInElementContent) { 832 if (fGrammarBucket.getStandalone() && 833 fDTDGrammar.getElementDeclIsExternal(fCurrentElementIndex)) { 834 if (allWhiteSpace) { 835 fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 836 "MSG_WHITE_SPACE_IN_ELEMENT_CONTENT_WHEN_STANDALONE", 837 null, XMLErrorReporter.SEVERITY_ERROR); 838 } 839 } 840 if (!allWhiteSpace) { 841 charDataInContent(); 842 } 843 844 if (augs != null && augs.getItem(Constants.CHAR_REF_PROBABLE_WS) == Boolean.TRUE) { 846 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 847 "MSG_CONTENT_INVALID_SPECIFIED", 848 new Object []{ fCurrentElement.rawname, 849 fDTDGrammar.getContentSpecAsString(fElementDepth), 850 "character reference"}, 851 XMLErrorReporter.SEVERITY_ERROR); 852 } 853 } 854 855 if (fCurrentContentSpecType == XMLElementDecl.TYPE_EMPTY) { 856 charDataInContent(); 857 } 858 } 859 860 if (callNextCharacters && fDocumentHandler != null) { 862 fDocumentHandler.characters(text, augs); 863 } 864 865 } 867 868 869 882 public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { 883 884 if (fDocumentHandler != null) { 886 fDocumentHandler.ignorableWhitespace(text, augs); 887 } 888 889 } 891 899 public void endElement(QName element, Augmentations augs) throws XNIException { 900 901 handleEndElement(element, augs, false); 902 903 } 905 911 public void startCDATA(Augmentations augs) throws XNIException { 912 913 if (fPerformValidation && fInElementContent) { 914 charDataInContent(); 915 } 916 fInCDATASection = true; 917 if (fDocumentHandler != null) { 919 fDocumentHandler.startCDATA(augs); 920 } 921 922 } 924 930 public void endCDATA(Augmentations augs) throws XNIException { 931 932 fInCDATASection = false; 933 if (fDocumentHandler != null) { 935 fDocumentHandler.endCDATA(augs); 936 } 937 938 } 940 946 public void endDocument(Augmentations augs) throws XNIException { 947 948 if (fDocumentHandler != null) { 950 fDocumentHandler.endDocument(augs); 951 } 952 953 } 955 963 public void comment(XMLString text, Augmentations augs) throws XNIException { 964 if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) { 966 fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl); 967 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 968 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 969 "MSG_CONTENT_INVALID_SPECIFIED", 970 new Object []{ fCurrentElement.rawname, 971 "EMPTY", 972 "comment"}, 973 XMLErrorReporter.SEVERITY_ERROR); 974 } 975 } 976 if (fDocumentHandler != null) { 978 fDocumentHandler.comment(text, augs); 979 } 980 981 } 983 984 1001 public void processingInstruction(String target, XMLString data, Augmentations augs) 1002 throws XNIException { 1003 1004 if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) { 1006 fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl); 1007 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 1008 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1009 "MSG_CONTENT_INVALID_SPECIFIED", 1010 new Object []{ fCurrentElement.rawname, 1011 "EMPTY", 1012 "processing instruction"}, 1013 XMLErrorReporter.SEVERITY_ERROR); 1014 } 1015 } 1016 if (fDocumentHandler != null) { 1018 fDocumentHandler.processingInstruction(target, data, augs); 1019 } 1020 } 1022 1039 public void startGeneralEntity(String name, 1040 XMLResourceIdentifier identifier, 1041 String encoding, 1042 Augmentations augs) throws XNIException { 1043 if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) { 1044 fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl); 1045 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 1047 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1048 "MSG_CONTENT_INVALID_SPECIFIED", 1049 new Object []{ fCurrentElement.rawname, 1050 "EMPTY", "ENTITY"}, 1051 XMLErrorReporter.SEVERITY_ERROR); 1052 } 1053 if (fGrammarBucket.getStandalone()) { 1054 XMLDTDLoader.checkStandaloneEntityRef(name, fDTDGrammar, fEntityDecl, fErrorReporter); 1055 } 1056 } 1057 if (fDocumentHandler != null) { 1058 fDocumentHandler.startGeneralEntity(name, identifier, encoding, augs); 1059 } 1060 } 1061 1062 1074 public void endGeneralEntity(String name, Augmentations augs) throws XNIException { 1075 if (fDocumentHandler != null) { 1077 fDocumentHandler.endGeneralEntity(name, augs); 1078 } 1079 } 1081 1095 public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { 1096 1097 if (fDocumentHandler != null) { 1099 fDocumentHandler.textDecl(version, encoding, augs); 1100 } 1101 } 1102 1103 1104 public final boolean hasGrammar(){ 1105 1106 return (fDTDGrammar != null); 1107 } 1108 1109 public final boolean validate(){ 1110 return (fSchemaType != Constants.NS_XMLSCHEMA) && 1122 (!fDynamicValidation && fValidation || 1123 fDynamicValidation && fSeenDoctypeDecl) && 1124 (fDTDValidation || fSeenDoctypeDecl); 1125 } 1126 1127 1129 1130 protected void addDTDDefaultAttrsAndValidate(QName elementName, int elementIndex, 1131 XMLAttributes attributes) 1132 throws XNIException { 1133 1134 if (elementIndex == -1 || fDTDGrammar == null) { 1136 return; 1137 } 1138 1139 int attlistIndex = fDTDGrammar.getFirstAttributeDeclIndex(elementIndex); 1145 1146 while (attlistIndex != -1) { 1147 1148 fDTDGrammar.getAttributeDecl(attlistIndex, fTempAttDecl); 1149 1150 if (DEBUG_ATTRIBUTES) { 1151 if (fTempAttDecl != null) { 1152 XMLElementDecl elementDecl = new XMLElementDecl(); 1153 fDTDGrammar.getElementDecl(elementIndex, elementDecl); 1154 System.out.println("element: "+(elementDecl.name.localpart)); 1155 System.out.println("attlistIndex " + attlistIndex + "\n"+ 1156 "attName : '"+(fTempAttDecl.name.localpart) + "'\n" 1157 + "attType : "+fTempAttDecl.simpleType.type + "\n" 1158 + "attDefaultType : "+fTempAttDecl.simpleType.defaultType + "\n" 1159 + "attDefaultValue : '"+fTempAttDecl.simpleType.defaultValue + "'\n" 1160 + attributes.getLength() +"\n" 1161 ); 1162 } 1163 } 1164 String attPrefix = fTempAttDecl.name.prefix; 1165 String attLocalpart = fTempAttDecl.name.localpart; 1166 String attRawName = fTempAttDecl.name.rawname; 1167 String attType = getAttributeTypeName(fTempAttDecl); 1168 int attDefaultType =fTempAttDecl.simpleType.defaultType; 1169 String attValue = null; 1170 1171 if (fTempAttDecl.simpleType.defaultValue != null) { 1172 attValue = fTempAttDecl.simpleType.defaultValue; 1173 } 1174 1175 boolean specified = false; 1176 boolean required = attDefaultType == XMLSimpleType.DEFAULT_TYPE_REQUIRED; 1177 boolean cdata = attType == XMLSymbols.fCDATASymbol; 1178 1179 if (!cdata || required || attValue != null) { 1180 int attrCount = attributes.getLength(); 1181 for (int i = 0; i < attrCount; i++) { 1182 if (attributes.getQName(i) == attRawName) { 1183 specified = true; 1184 break; 1185 } 1186 } 1187 } 1188 1189 if (!specified) { 1190 if (required) { 1191 if (fPerformValidation) { 1192 Object [] args = {elementName.localpart, attRawName}; 1193 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1194 "MSG_REQUIRED_ATTRIBUTE_NOT_SPECIFIED", args, 1195 XMLErrorReporter.SEVERITY_ERROR); 1196 } 1197 } 1198 else if (attValue != null) { 1199 if (fPerformValidation && fGrammarBucket.getStandalone()) { 1200 if (fDTDGrammar.getAttributeDeclIsExternal(attlistIndex)) { 1201 1202 Object [] args = { elementName.localpart, attRawName}; 1203 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1204 "MSG_DEFAULTED_ATTRIBUTE_NOT_SPECIFIED", args, 1205 XMLErrorReporter.SEVERITY_ERROR); 1206 } 1207 } 1208 1209 if (fNamespaces) { 1211 int index = attRawName.indexOf(':'); 1212 if (index != -1) { 1213 attPrefix = attRawName.substring(0, index); 1214 attPrefix = fSymbolTable.addSymbol(attPrefix); 1215 attLocalpart = attRawName.substring(index + 1); 1216 attLocalpart = fSymbolTable.addSymbol(attLocalpart); 1217 } 1218 } 1219 1220 fTempQName.setValues(attPrefix, attLocalpart, attRawName, fTempAttDecl.name.uri); 1222 int newAttr = attributes.addAttribute(fTempQName, attType, attValue); 1223 } 1224 } 1225 attlistIndex = fDTDGrammar.getNextAttributeDeclIndex(attlistIndex); 1227 } 1228 1229 int attrCount = attributes.getLength(); 1234 for (int i = 0; i < attrCount; i++) { 1235 String attrRawName = attributes.getQName(i); 1236 boolean declared = false; 1237 if (fPerformValidation) { 1238 if (fGrammarBucket.getStandalone()) { 1239 String nonNormalizedValue = attributes.getNonNormalizedValue(i); 1245 if (nonNormalizedValue != null) { 1246 String entityName = getExternalEntityRefInAttrValue(nonNormalizedValue); 1247 if (entityName != null) { 1248 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1249 "MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE", 1250 new Object []{entityName}, 1251 XMLErrorReporter.SEVERITY_ERROR); 1252 } 1253 } 1254 } 1255 } 1256 int attDefIndex = -1; 1257 int position = 1258 fDTDGrammar.getFirstAttributeDeclIndex(elementIndex); 1259 while (position != -1) { 1260 fDTDGrammar.getAttributeDecl(position, fTempAttDecl); 1261 if (fTempAttDecl.name.rawname == attrRawName) { 1262 attDefIndex = position; 1264 declared = true; 1265 break; 1266 } 1267 position = fDTDGrammar.getNextAttributeDeclIndex(position); 1268 } 1269 if (!declared) { 1270 if (fPerformValidation) { 1271 Object [] args = { elementName.rawname, attrRawName}; 1274 1275 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1276 "MSG_ATTRIBUTE_NOT_DECLARED", 1277 args,XMLErrorReporter.SEVERITY_ERROR); 1278 } 1279 continue; 1280 } 1281 1283 1287 String type = getAttributeTypeName(fTempAttDecl); 1288 attributes.setType(i, type); 1289 attributes.getAugmentations(i).putItem(Constants.ATTRIBUTE_DECLARED, Boolean.TRUE); 1290 1291 boolean changedByNormalization = false; 1292 String oldValue = attributes.getValue(i); 1293 String attrValue = oldValue; 1294 if (attributes.isSpecified(i) && type != XMLSymbols.fCDATASymbol) { 1295 changedByNormalization = normalizeAttrValue(attributes, i); 1296 attrValue = attributes.getValue(i); 1297 if (fPerformValidation && fGrammarBucket.getStandalone() 1298 && changedByNormalization 1299 && fDTDGrammar.getAttributeDeclIsExternal(position) 1300 ) { 1301 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1303 "MSG_ATTVALUE_CHANGED_DURING_NORMALIZATION_WHEN_STANDALONE", 1304 new Object []{attrRawName, oldValue, attrValue}, 1305 XMLErrorReporter.SEVERITY_ERROR); 1306 } 1307 } 1308 if (!fPerformValidation) { 1309 continue; 1310 } 1311 if (fTempAttDecl.simpleType.defaultType == 1312 XMLSimpleType.DEFAULT_TYPE_FIXED) { 1313 String defaultValue = fTempAttDecl.simpleType.defaultValue; 1314 1315 if (!attrValue.equals(defaultValue)) { 1316 Object [] args = {elementName.localpart, 1317 attrRawName, 1318 attrValue, 1319 defaultValue}; 1320 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1321 "MSG_FIXED_ATTVALUE_INVALID", 1322 args, XMLErrorReporter.SEVERITY_ERROR); 1323 } 1324 } 1325 1326 if (fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ENTITY || 1327 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ENUMERATION || 1328 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ID || 1329 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_IDREF || 1330 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NMTOKEN || 1331 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NOTATION 1332 ) { 1333 validateDTDattribute(elementName, attrValue, fTempAttDecl); 1334 } 1335 } 1337 } 1339 1340 protected String getExternalEntityRefInAttrValue(String nonNormalizedValue) { 1341 int valLength = nonNormalizedValue.length(); 1342 int ampIndex = nonNormalizedValue.indexOf('&'); 1343 while (ampIndex != -1) { 1344 if (ampIndex + 1 < valLength && 1345 nonNormalizedValue.charAt(ampIndex+1) != '#') { 1346 int semicolonIndex = nonNormalizedValue.indexOf(';', ampIndex+1); 1347 String entityName = nonNormalizedValue.substring(ampIndex+1, semicolonIndex); 1348 entityName = fSymbolTable.addSymbol(entityName); 1349 int entIndex = fDTDGrammar.getEntityDeclIndex(entityName); 1350 if (entIndex > -1) { 1351 fDTDGrammar.getEntityDecl(entIndex, fEntityDecl); 1352 if (fEntityDecl.inExternal || 1353 (entityName = getExternalEntityRefInAttrValue(fEntityDecl.value)) != null) { 1354 return entityName; 1355 } 1356 } 1357 } 1358 ampIndex = nonNormalizedValue.indexOf('&', ampIndex+1); 1359 } 1360 return null; 1361 } 1363 1366 protected void validateDTDattribute(QName element, String attValue, 1367 XMLAttributeDecl attributeDecl) 1368 throws XNIException { 1369 1370 switch (attributeDecl.simpleType.type) { 1371 case XMLSimpleType.TYPE_ENTITY: { 1372 boolean isAlistAttribute = attributeDecl.simpleType.list; 1374 1375 try { 1376 if (isAlistAttribute) { 1377 fValENTITIES.validate(attValue, fValidationState); 1378 } 1379 else { 1380 fValENTITY.validate(attValue, fValidationState); 1381 } 1382 } 1383 catch (InvalidDatatypeValueException ex) { 1384 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1385 ex.getKey(), 1386 ex.getArgs(), 1387 XMLErrorReporter.SEVERITY_ERROR ); 1388 1389 } 1390 break; 1391 } 1392 1393 case XMLSimpleType.TYPE_NOTATION: 1394 case XMLSimpleType.TYPE_ENUMERATION: { 1395 boolean found = false; 1396 String [] enumVals = attributeDecl.simpleType.enumeration; 1397 if (enumVals == null) { 1398 found = false; 1399 } 1400 else 1401 for (int i = 0; i < enumVals.length; i++) { 1402 if (attValue == enumVals[i] || attValue.equals(enumVals[i])) { 1403 found = true; 1404 break; 1405 } 1406 } 1407 1408 if (!found) { 1409 StringBuffer enumValueString = new StringBuffer (); 1410 if (enumVals != null) 1411 for (int i = 0; i < enumVals.length; i++) { 1412 enumValueString.append(enumVals[i]+" "); 1413 } 1414 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1415 "MSG_ATTRIBUTE_VALUE_NOT_IN_LIST", 1416 new Object []{attributeDecl.name.rawname, attValue, enumValueString}, 1417 XMLErrorReporter.SEVERITY_ERROR); 1418 } 1419 break; 1420 } 1421 1422 case XMLSimpleType.TYPE_ID: { 1423 try { 1424 fValID.validate(attValue, fValidationState); 1425 } 1426 catch (InvalidDatatypeValueException ex) { 1427 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1428 ex.getKey(), 1429 ex.getArgs(), 1430 XMLErrorReporter.SEVERITY_ERROR ); 1431 } 1432 break; 1433 } 1434 1435 case XMLSimpleType.TYPE_IDREF: { 1436 boolean isAlistAttribute = attributeDecl.simpleType.list; 1438 try { 1439 if (isAlistAttribute) { 1440 fValIDRefs.validate(attValue, fValidationState); 1441 } 1442 else { 1443 fValIDRef.validate(attValue, fValidationState); 1444 } 1445 } 1446 catch (InvalidDatatypeValueException ex) { 1447 if (isAlistAttribute) { 1448 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1449 "IDREFSInvalid", 1450 new Object []{attValue}, 1451 XMLErrorReporter.SEVERITY_ERROR ); 1452 } 1453 else { 1454 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1455 ex.getKey(), 1456 ex.getArgs(), 1457 XMLErrorReporter.SEVERITY_ERROR ); 1458 } 1459 1460 } 1461 break; 1462 } 1463 1464 case XMLSimpleType.TYPE_NMTOKEN: { 1465 boolean isAlistAttribute = attributeDecl.simpleType.list; try { 1468 if (isAlistAttribute) { 1469 fValNMTOKENS.validate(attValue, fValidationState); 1470 } 1471 else { 1472 fValNMTOKEN.validate(attValue, fValidationState); 1473 } 1474 } 1475 catch (InvalidDatatypeValueException ex) { 1476 if (isAlistAttribute) { 1477 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1478 "NMTOKENSInvalid", 1479 new Object [] { attValue}, 1480 XMLErrorReporter.SEVERITY_ERROR); 1481 } 1482 else { 1483 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1484 "NMTOKENInvalid", 1485 new Object [] { attValue}, 1486 XMLErrorReporter.SEVERITY_ERROR); 1487 } 1488 } 1489 break; 1490 } 1491 1492 } 1494 } 1496 1497 1498 protected boolean invalidStandaloneAttDef(QName element, QName attribute) { 1499 boolean state = true; 1501 1511 return state; 1512 } 1513 1514 1515 1519 1520 1527 private boolean normalizeAttrValue(XMLAttributes attributes, int index) { 1528 boolean leadingSpace = true; 1530 boolean spaceStart = false; 1531 boolean readingNonSpace = false; 1532 int count = 0; 1533 int eaten = 0; 1534 String attrValue = attributes.getValue(index); 1535 char[] attValue = new char[attrValue.length()]; 1536 1537 fBuffer.setLength(0); 1538 attrValue.getChars(0, attrValue.length(), attValue, 0); 1539 for (int i = 0; i < attValue.length; i++) { 1540 1541 if (attValue[i] == ' ') { 1542 1543 if (readingNonSpace) { 1545 spaceStart = true; 1546 readingNonSpace = false; 1547 } 1548 1549 if (spaceStart && !leadingSpace) { 1550 spaceStart = false; 1551 fBuffer.append(attValue[i]); 1552 count++; 1553 } 1554 else { 1555 if (leadingSpace || !spaceStart) { 1556 eaten ++; 1557 1576 } 1577 } 1578 1579 } 1580 else { 1581 readingNonSpace = true; 1582 spaceStart = false; 1583 leadingSpace = false; 1584 fBuffer.append(attValue[i]); 1585 count++; 1586 } 1587 } 1588 1589 if (count > 0 && fBuffer.charAt(count-1) == ' ') { 1591 fBuffer.setLength(count-1); 1592 1609 } 1610 String newValue = fBuffer.toString(); 1611 attributes.setValue(index, newValue); 1612 return ! attrValue.equals(newValue); 1613 } 1614 1615 1616 private final void rootElementSpecified(QName rootElement) throws XNIException { 1617 if (fPerformValidation) { 1618 String root1 = fRootElement.rawname; 1619 String root2 = rootElement.rawname; 1620 if (root1 == null || !root1.equals(root2)) { 1621 fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 1622 "RootElementTypeMustMatchDoctypedecl", 1623 new Object []{root1, root2}, 1624 XMLErrorReporter.SEVERITY_ERROR); 1625 } 1626 } 1627 } 1629 1662 private int checkContent(int elementIndex, 1663 QName[] children, 1664 int childOffset, 1665 int childCount) throws XNIException { 1666 1667 fDTDGrammar.getElementDecl(elementIndex, fTempElementDecl); 1668 1669 final String elementType = fCurrentElement.rawname; 1671 1672 final int contentType = fCurrentContentSpecType; 1674 1675 1676 if (contentType == XMLElementDecl.TYPE_EMPTY) { 1682 if (childCount != 0) { 1687 return 0; 1688 } 1689 } 1690 else if (contentType == XMLElementDecl.TYPE_ANY) { 1691 } 1696 else if (contentType == XMLElementDecl.TYPE_MIXED || 1697 contentType == XMLElementDecl.TYPE_CHILDREN) { 1698 ContentModelValidator cmElem = null; 1700 cmElem = fTempElementDecl.contentModelValidator; 1701 int result = cmElem.validate(children, childOffset, childCount); 1702 return result; 1703 } 1704 else if (contentType == -1) { 1705 1711 } 1712 else if (contentType == XMLElementDecl.TYPE_SIMPLE) { 1713 1714 1717 } 1718 else { 1719 1728 } 1729 1730 return -1; 1732 1733 } 1735 1736 private int getContentSpecType(int elementIndex) { 1737 1738 int contentSpecType = -1; 1739 if (elementIndex > -1) { 1740 if (fDTDGrammar.getElementDecl(elementIndex,fTempElementDecl)) { 1741 contentSpecType = fTempElementDecl.type; 1742 } 1743 } 1744 return contentSpecType; 1745 } 1746 1747 1748 private void charDataInContent() { 1749 1750 if (DEBUG_ELEMENT_CHILDREN) { 1751 System.out.println("charDataInContent()"); 1752 } 1753 if (fElementChildren.length <= fElementChildrenLength) { 1754 QName[] newarray = new QName[fElementChildren.length * 2]; 1755 System.arraycopy(fElementChildren, 0, newarray, 0, fElementChildren.length); 1756 fElementChildren = newarray; 1757 } 1758 QName qname = fElementChildren[fElementChildrenLength]; 1759 if (qname == null) { 1760 for (int i = fElementChildrenLength; i < fElementChildren.length; i++) { 1761 fElementChildren[i] = new QName(); 1762 } 1763 qname = fElementChildren[fElementChildrenLength]; 1764 } 1765 qname.clear(); 1766 fElementChildrenLength++; 1767 1768 } 1770 1771 private String getAttributeTypeName(XMLAttributeDecl attrDecl) { 1772 1773 switch (attrDecl.simpleType.type) { 1774 case XMLSimpleType.TYPE_ENTITY: { 1775 return attrDecl.simpleType.list ? XMLSymbols.fENTITIESSymbol : XMLSymbols.fENTITYSymbol; 1776 } 1777 case XMLSimpleType.TYPE_ENUMERATION: { 1778 StringBuffer buffer = new StringBuffer (); 1779 buffer.append('('); 1780 for (int i=0; i<attrDecl.simpleType.enumeration.length ; i++) { 1781 if (i > 0) { 1782 buffer.append("|"); 1783 } 1784 buffer.append(attrDecl.simpleType.enumeration[i]); 1785 } 1786 buffer.append(')'); 1787 return fSymbolTable.addSymbol(buffer.toString()); 1788 } 1789 case XMLSimpleType.TYPE_ID: { 1790 return XMLSymbols.fIDSymbol; 1791 } 1792 case XMLSimpleType.TYPE_IDREF: { 1793 return attrDecl.simpleType.list ? XMLSymbols.fIDREFSSymbol : XMLSymbols.fIDREFSymbol; 1794 } 1795 case XMLSimpleType.TYPE_NMTOKEN: { 1796 return attrDecl.simpleType.list ? XMLSymbols.fNMTOKENSSymbol : XMLSymbols.fNMTOKENSymbol; 1797 } 1798 case XMLSimpleType.TYPE_NOTATION: { 1799 return XMLSymbols.fNOTATIONSymbol; 1800 } 1801 } 1802 return XMLSymbols.fCDATASymbol; 1803 1804 } 1806 1807 protected void init() { 1808 1809 if (fValidation || fDynamicValidation) { 1811 try { 1812 fValID = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fIDSymbol); 1815 fValIDRef = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fIDREFSymbol); 1816 fValIDRefs = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fIDREFSSymbol); 1817 fValENTITY = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fENTITYSymbol); 1818 fValENTITIES = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fENTITIESSymbol); 1819 fValNMTOKEN = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fNMTOKENSymbol); 1820 fValNMTOKENS = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fNMTOKENSSymbol); 1821 fValNOTATION = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fNOTATIONSymbol); 1822 1823 } 1824 catch (Exception e) { 1825 e.printStackTrace(System.err); 1827 } 1828 1829 } 1830 1831 } 1833 1834 private void ensureStackCapacity ( int newElementDepth) { 1835 if (newElementDepth == fElementQNamePartsStack.length) { 1836 int[] newStack = new int[newElementDepth * 2]; 1837 1838 QName[] newStackOfQueue = new QName[newElementDepth * 2]; 1839 System.arraycopy(this.fElementQNamePartsStack, 0, newStackOfQueue, 0, newElementDepth ); 1840 fElementQNamePartsStack = newStackOfQueue; 1841 1842 QName qname = fElementQNamePartsStack[newElementDepth]; 1843 if (qname == null) { 1844 for (int i = newElementDepth; i < fElementQNamePartsStack.length; i++) { 1845 fElementQNamePartsStack[i] = new QName(); 1846 } 1847 } 1848 1849 newStack = new int[newElementDepth * 2]; 1850 System.arraycopy(fElementIndexStack, 0, newStack, 0, newElementDepth); 1851 fElementIndexStack = newStack; 1852 1853 newStack = new int[newElementDepth * 2]; 1854 System.arraycopy(fContentSpecTypeStack, 0, newStack, 0, newElementDepth); 1855 fContentSpecTypeStack = newStack; 1856 1857 } 1858 } 1860 1861 1865 1868 protected boolean handleStartElement(QName element, XMLAttributes attributes, Augmentations augs) 1869 throws XNIException { 1870 1871 1872 if (!fSeenRootElement) { 1875 fPerformValidation = validate(); 1897 fSeenRootElement = true; 1898 fValidationManager.setEntityState(fDTDGrammar); 1899 fValidationManager.setGrammarFound(fSeenDoctypeDecl); 1900 rootElementSpecified(element); 1901 } 1902 if (fDTDGrammar == null) { 1903 1904 if (!fPerformValidation) { 1905 fCurrentElementIndex = -1; 1906 fCurrentContentSpecType = -1; 1907 fInElementContent = false; 1908 } 1909 if (fPerformValidation) { 1910 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1911 "MSG_GRAMMAR_NOT_FOUND", 1912 new Object []{ element.rawname}, 1913 XMLErrorReporter.SEVERITY_ERROR); 1914 } 1915 if (fDocumentSource !=null ) { 1917 fDocumentSource.setDocumentHandler(fDocumentHandler); 1918 if (fDocumentHandler != null) 1919 fDocumentHandler.setDocumentSource(fDocumentSource); 1920 return true; 1921 } 1922 } 1923 else { 1924 fCurrentElementIndex = fDTDGrammar.getElementDeclIndex(element); 1926 fCurrentContentSpecType = fDTDGrammar.getContentSpecType(fCurrentElementIndex); 1928 if (fCurrentContentSpecType == -1 && fPerformValidation) { 1929 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1930 "MSG_ELEMENT_NOT_DECLARED", 1931 new Object []{ element.rawname}, 1932 XMLErrorReporter.SEVERITY_ERROR); 1933 } 1934 1935 addDTDDefaultAttrsAndValidate(element, fCurrentElementIndex, attributes); 1941 } 1942 1943 fInElementContent = fCurrentContentSpecType == XMLElementDecl.TYPE_CHILDREN; 1945 1946 fElementDepth++; 1949 if (fPerformValidation) { 1950 if (fElementChildrenOffsetStack.length <= fElementDepth) { 1952 int newarray[] = new int[fElementChildrenOffsetStack.length * 2]; 1953 System.arraycopy(fElementChildrenOffsetStack, 0, newarray, 0, fElementChildrenOffsetStack.length); 1954 fElementChildrenOffsetStack = newarray; 1955 } 1956 fElementChildrenOffsetStack[fElementDepth] = fElementChildrenLength; 1957 1958 if (fElementChildren.length <= fElementChildrenLength) { 1960 QName[] newarray = new QName[fElementChildrenLength * 2]; 1961 System.arraycopy(fElementChildren, 0, newarray, 0, fElementChildren.length); 1962 fElementChildren = newarray; 1963 } 1964 QName qname = fElementChildren[fElementChildrenLength]; 1965 if (qname == null) { 1966 for (int i = fElementChildrenLength; i < fElementChildren.length; i++) { 1967 fElementChildren[i] = new QName(); 1968 } 1969 qname = fElementChildren[fElementChildrenLength]; 1970 } 1971 qname.setValues(element); 1972 fElementChildrenLength++; 1973 } 1974 1975 fCurrentElement.setValues(element); 1977 ensureStackCapacity(fElementDepth); 1978 fElementQNamePartsStack[fElementDepth].setValues(fCurrentElement); 1979 fElementIndexStack[fElementDepth] = fCurrentElementIndex; 1980 fContentSpecTypeStack[fElementDepth] = fCurrentContentSpecType; 1981 startNamespaceScope(element, attributes, augs); 1982 return false; 1983 1984 } 1986 protected void startNamespaceScope(QName element, XMLAttributes attributes, Augmentations augs){ 1987 } 1988 1989 1990 protected void handleEndElement(QName element, Augmentations augs, boolean isEmpty) 1991 throws XNIException { 1992 1993 fElementDepth--; 1995 1996 if (fPerformValidation) { 1998 int elementIndex = fCurrentElementIndex; 1999 if (elementIndex != -1 && fCurrentContentSpecType != -1) { 2000 QName children[] = fElementChildren; 2001 int childrenOffset = fElementChildrenOffsetStack[fElementDepth + 1] + 1; 2002 int childrenLength = fElementChildrenLength - childrenOffset; 2003 int result = checkContent(elementIndex, 2004 children, childrenOffset, childrenLength); 2005 2006 if (result != -1) { 2007 fDTDGrammar.getElementDecl(elementIndex, fTempElementDecl); 2008 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 2009 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 2010 "MSG_CONTENT_INVALID", 2011 new Object []{ element.rawname, "EMPTY"}, 2012 XMLErrorReporter.SEVERITY_ERROR); 2013 } 2014 else { 2015 String messageKey = result != childrenLength ? 2016 "MSG_CONTENT_INVALID" : "MSG_CONTENT_INCOMPLETE"; 2017 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 2018 messageKey, 2019 new Object []{ element.rawname, 2020 fDTDGrammar.getContentSpecAsString(elementIndex)}, 2021 XMLErrorReporter.SEVERITY_ERROR); 2022 } 2023 } 2024 } 2025 fElementChildrenLength = fElementChildrenOffsetStack[fElementDepth + 1] + 1; 2026 } 2027 2028 endNamespaceScope(fCurrentElement, augs, isEmpty); 2029 2030 if (fElementDepth < -1) { 2032 throw new RuntimeException ("FWK008 Element stack underflow"); 2033 } 2034 if (fElementDepth < 0) { 2035 fCurrentElement.clear(); 2036 fCurrentElementIndex = -1; 2037 fCurrentContentSpecType = -1; 2038 fInElementContent = false; 2039 2040 if (fPerformValidation) { 2047 String value = fValidationState.checkIDRefID(); 2048 if (value != null) { 2049 fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 2050 "MSG_ELEMENT_WITH_ID_REQUIRED", 2051 new Object []{value}, 2052 XMLErrorReporter.SEVERITY_ERROR ); 2053 } 2054 } 2055 return; 2056 } 2057 2058 fCurrentElement.setValues(fElementQNamePartsStack[fElementDepth]); 2060 2061 fCurrentElementIndex = fElementIndexStack[fElementDepth]; 2062 fCurrentContentSpecType = fContentSpecTypeStack[fElementDepth]; 2063 fInElementContent = (fCurrentContentSpecType == XMLElementDecl.TYPE_CHILDREN); 2064 2065 } 2067 protected void endNamespaceScope(QName element, Augmentations augs, boolean isEmpty){ 2068 2069 if (fDocumentHandler != null && !isEmpty) { 2071 fDocumentHandler.endElement(fCurrentElement, augs); 2078 } 2079 } 2080 2081 protected boolean isSpace(int c) { 2084 return XMLChar.isSpace(c); 2085 } 2087 public boolean characterData(String data, Augmentations augs) { 2088 characters(new XMLString(data.toCharArray(), 0, data.length()), augs); 2089 return true; 2090 } 2091 2092} | Popular Tags |