1 57 58 package com.sun.org.apache.xerces.internal.impl.dtd; 59 60 import com.sun.org.apache.xerces.internal.impl.Constants; 61 import com.sun.org.apache.xerces.internal.impl.XMLEntityManager; 62 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 63 import com.sun.org.apache.xerces.internal.impl.dtd.models.ContentModelValidator; 64 import com.sun.org.apache.xerces.internal.impl.dv.DTDDVFactory; 65 import com.sun.org.apache.xerces.internal.impl.dv.DatatypeValidator; 66 import com.sun.org.apache.xerces.internal.impl.dv.InvalidDatatypeValueException; 67 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 68 import com.sun.org.apache.xerces.internal.impl.validation.ValidationManager; 69 import com.sun.org.apache.xerces.internal.impl.validation.ValidationState; 70 import com.sun.org.apache.xerces.internal.util.SymbolTable; 71 import com.sun.org.apache.xerces.internal.util.XMLChar; 72 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 73 import com.sun.org.apache.xerces.internal.xni.Augmentations; 74 import com.sun.org.apache.xerces.internal.xni.NamespaceContext; 75 import com.sun.org.apache.xerces.internal.xni.QName; 76 import com.sun.org.apache.xerces.internal.xni.XMLAttributes; 77 import com.sun.org.apache.xerces.internal.xni.XMLDocumentHandler; 78 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 79 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 80 import com.sun.org.apache.xerces.internal.xni.XMLString; 81 import com.sun.org.apache.xerces.internal.xni.XNIException; 82 import com.sun.org.apache.xerces.internal.xni.grammars.Grammar; 83 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 84 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 85 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 86 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 87 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 88 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentFilter; 89 import com.sun.org.apache.xerces.internal.xni.parser.XMLDocumentSource; 90 91 122 public class XMLDTDValidator 123 implements XMLComponent, XMLDocumentFilter, XMLDTDValidatorFilter { 124 125 129 130 131 132 private static final int TOP_LEVEL_SCOPE = -1; 133 134 136 137 protected static final String NAMESPACES = 138 Constants.SAX_FEATURE_PREFIX + Constants.NAMESPACES_FEATURE; 139 140 141 protected static final String VALIDATION = 142 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 143 144 145 protected static final String DYNAMIC_VALIDATION = 146 Constants.XERCES_FEATURE_PREFIX + Constants.DYNAMIC_VALIDATION_FEATURE; 147 148 149 protected static final String WARN_ON_DUPLICATE_ATTDEF = 150 Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 151 152 protected static final String PARSER_SETTINGS = 153 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; 154 155 156 157 159 160 protected static final String SYMBOL_TABLE = 161 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 162 163 164 protected static final String ERROR_REPORTER = 165 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 166 167 168 protected static final String GRAMMAR_POOL = 169 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 170 171 172 protected static final String DATATYPE_VALIDATOR_FACTORY = 173 Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY; 174 175 protected static final String VALIDATION_MANAGER = 177 Constants.XERCES_PROPERTY_PREFIX + Constants.VALIDATION_MANAGER_PROPERTY; 178 179 181 182 private static final String [] RECOGNIZED_FEATURES = { 183 NAMESPACES, 184 VALIDATION, 185 DYNAMIC_VALIDATION 186 }; 187 188 189 private static final Boolean [] FEATURE_DEFAULTS = { 190 null, 191 null, 192 Boolean.FALSE, 193 }; 194 195 196 private static final String [] RECOGNIZED_PROPERTIES = { 197 SYMBOL_TABLE, 198 ERROR_REPORTER, 199 GRAMMAR_POOL, 200 DATATYPE_VALIDATOR_FACTORY, 201 VALIDATION_MANAGER 202 }; 203 204 205 private static final Object [] PROPERTY_DEFAULTS = { 206 null, 207 null, 208 null, 209 null, 210 null, 211 }; 212 213 215 216 private static final boolean DEBUG_ATTRIBUTES = false; 217 218 219 private static final boolean DEBUG_ELEMENT_CHILDREN = false; 220 221 225 protected ValidationManager fValidationManager = null; 227 228 protected ValidationState fValidationState = new ValidationState(); 230 231 233 234 protected boolean fNamespaces; 235 236 237 protected boolean fValidation; 238 239 240 protected boolean fDTDValidation; 241 242 246 protected boolean fDynamicValidation; 247 248 249 protected boolean fWarnDuplicateAttdef; 250 251 253 254 protected SymbolTable fSymbolTable; 255 256 257 protected XMLErrorReporter fErrorReporter; 258 259 protected XMLGrammarPool fGrammarPool; 261 262 263 protected DTDGrammarBucket fGrammarBucket; 264 265 266 protected XMLLocator fDocLocation; 267 268 269 protected NamespaceContext fNamespaceContext = null; 270 271 272 protected DTDDVFactory fDatatypeValidatorFactory; 273 274 276 277 protected XMLDocumentHandler fDocumentHandler; 278 279 protected XMLDocumentSource fDocumentSource; 280 282 283 protected DTDGrammar fDTDGrammar; 284 285 287 288 protected boolean fSeenDoctypeDecl = false; 289 290 291 private boolean fPerformValidation; 292 293 294 private String fSchemaType; 295 296 298 299 private final QName fCurrentElement = new QName(); 300 301 302 private int fCurrentElementIndex = -1; 303 304 305 private int fCurrentContentSpecType = -1; 306 307 308 private final QName fRootElement = new QName(); 309 310 private boolean fInCDATASection = false; 311 313 314 private int[] fElementIndexStack = new int[8]; 315 316 317 private int[] fContentSpecTypeStack = new int[8]; 318 319 320 private QName[] fElementQNamePartsStack = new QName[8]; 321 322 324 337 private QName[] fElementChildren = new QName[32]; 338 339 340 private int fElementChildrenLength = 0; 341 342 347 private int[] fElementChildrenOffsetStack = new int[32]; 348 349 350 private int fElementDepth = -1; 351 352 354 355 private boolean fSeenRootElement = false; 356 357 358 private boolean fInElementContent = false; 359 360 362 363 private XMLElementDecl fTempElementDecl = new XMLElementDecl(); 364 365 366 private XMLAttributeDecl fTempAttDecl = new XMLAttributeDecl(); 367 368 369 private XMLEntityDecl fEntityDecl = new XMLEntityDecl(); 370 371 372 private QName fTempQName = new QName(); 373 374 375 private StringBuffer fBuffer = new StringBuffer (); 376 377 379 381 382 protected DatatypeValidator fValID; 383 384 385 protected DatatypeValidator fValIDRef; 386 387 388 protected DatatypeValidator fValIDRefs; 389 390 391 protected DatatypeValidator fValENTITY; 392 393 394 protected DatatypeValidator fValENTITIES; 395 396 397 protected DatatypeValidator fValNMTOKEN; 398 399 400 protected DatatypeValidator fValNMTOKENS; 401 402 403 protected DatatypeValidator fValNOTATION; 404 405 408 412 413 public XMLDTDValidator() { 414 415 for (int i = 0; i < fElementQNamePartsStack.length; i++) { 417 fElementQNamePartsStack[i] = new QName(); 418 } 419 fGrammarBucket = new DTDGrammarBucket(); 420 421 } 423 DTDGrammarBucket getGrammarBucket() { 424 return fGrammarBucket; 425 } 427 431 445 public void reset(XMLComponentManager componentManager) 446 throws XMLConfigurationException { 447 448 fDTDGrammar = null; 450 fSeenDoctypeDecl = false; 451 fInCDATASection = false; 452 fSeenRootElement = false; 454 fInElementContent = false; 455 fCurrentElementIndex = -1; 456 fCurrentContentSpecType = -1; 457 458 fRootElement.clear(); 459 460 fValidationState.resetIDTables(); 461 462 fGrammarBucket.clear(); 463 fElementDepth = -1; 464 fElementChildrenLength = 0; 465 466 boolean parser_settings; 467 try { 468 parser_settings = componentManager.getFeature(PARSER_SETTINGS); 469 } 470 catch (XMLConfigurationException e){ 471 parser_settings = true; 472 } 473 474 if (!parser_settings){ 475 fValidationManager.addValidationState(fValidationState); 477 return; 478 } 479 480 try { 482 fNamespaces = componentManager.getFeature(NAMESPACES); 483 } 484 catch (XMLConfigurationException e) { 485 fNamespaces = true; 486 } 487 try { 488 fValidation = componentManager.getFeature(VALIDATION); 489 } 490 catch (XMLConfigurationException e) { 491 fValidation = false; 492 } 493 try { 494 fDTDValidation = !(componentManager.getFeature(Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE)); 495 } 496 catch (XMLConfigurationException e) { 497 fDTDValidation = true; 499 } 500 501 try { 503 fDynamicValidation = componentManager.getFeature(DYNAMIC_VALIDATION); 504 } 505 catch (XMLConfigurationException e) { 506 fDynamicValidation = false; 507 } 508 509 try { 510 fWarnDuplicateAttdef = componentManager.getFeature(WARN_ON_DUPLICATE_ATTDEF); 511 } 512 catch (XMLConfigurationException e) { 513 fWarnDuplicateAttdef = false; 514 } 515 516 try { 517 fSchemaType = (String )componentManager.getProperty (Constants.JAXP_PROPERTY_PREFIX 518 + Constants.SCHEMA_LANGUAGE); 519 } 520 catch (XMLConfigurationException e){ 521 fSchemaType = null; 522 } 523 524 fValidationManager= (ValidationManager)componentManager.getProperty(VALIDATION_MANAGER); 525 fValidationManager.addValidationState(fValidationState); 526 fValidationState.setUsingNamespaces(fNamespaces); 527 528 fErrorReporter = (XMLErrorReporter)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.ERROR_REPORTER_PROPERTY); 530 fSymbolTable = (SymbolTable)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX+Constants.SYMBOL_TABLE_PROPERTY); 531 try { 532 fGrammarPool= (XMLGrammarPool)componentManager.getProperty(GRAMMAR_POOL); 533 } catch (XMLConfigurationException e) { 534 fGrammarPool = null; 535 } 536 537 fDatatypeValidatorFactory = (DTDDVFactory)componentManager.getProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.DATATYPE_VALIDATOR_FACTORY_PROPERTY); 538 init(); 539 540 } 542 547 public String [] getRecognizedFeatures() { 548 return (String [])(RECOGNIZED_FEATURES.clone()); 549 } 551 566 public void setFeature(String featureId, boolean state) 567 throws XMLConfigurationException { 568 } 570 575 public String [] getRecognizedProperties() { 576 return (String [])(RECOGNIZED_PROPERTIES.clone()); 577 } 579 594 public void setProperty(String propertyId, Object value) 595 throws XMLConfigurationException { 596 } 598 607 public Boolean getFeatureDefault(String featureId) { 608 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { 609 if (RECOGNIZED_FEATURES[i].equals(featureId)) { 610 return FEATURE_DEFAULTS[i]; 611 } 612 } 613 return null; 614 } 616 625 public Object getPropertyDefault(String propertyId) { 626 for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { 627 if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { 628 return PROPERTY_DEFAULTS[i]; 629 } 630 } 631 return null; 632 } 634 638 639 public void setDocumentHandler(XMLDocumentHandler documentHandler) { 640 fDocumentHandler = documentHandler; 641 } 643 644 public XMLDocumentHandler getDocumentHandler() { 645 return fDocumentHandler; 646 } 648 649 653 654 public void setDocumentSource(XMLDocumentSource source){ 655 fDocumentSource = source; 656 } 658 659 public XMLDocumentSource getDocumentSource (){ 660 return fDocumentSource; 661 } 663 685 public void startDocument(XMLLocator locator, String encoding, 686 NamespaceContext namespaceContext, Augmentations augs) 687 throws XNIException { 688 689 if(fGrammarPool != null) { 692 Grammar [] grammars = fGrammarPool.retrieveInitialGrammarSet(XMLGrammarDescription.XML_DTD); 693 for(int i = 0; i<grammars.length; i++) { 694 fGrammarBucket.putGrammar((DTDGrammar)grammars[i]); 695 } 696 } 697 fDocLocation = locator; 698 fNamespaceContext = namespaceContext; 699 700 if (fDocumentHandler != null) { 701 fDocumentHandler.startDocument(locator, encoding, namespaceContext, augs); 702 } 703 704 } 706 719 public void xmlDecl(String version, String encoding, String standalone, Augmentations augs) 720 throws XNIException { 721 722 fGrammarBucket.setStandalone(standalone != null && standalone.equals("yes")); 724 725 if (fDocumentHandler != null) { 727 fDocumentHandler.xmlDecl(version, encoding, standalone, augs); 728 } 729 730 } 732 744 public void doctypeDecl(String rootElement, String publicId, String systemId, 745 Augmentations augs) 746 throws XNIException { 747 748 fSeenDoctypeDecl = true; 750 fRootElement.setValues(null, rootElement, rootElement, null); 751 String eid = null; 753 try { 754 eid = XMLEntityManager.expandSystemId(systemId, fDocLocation.getExpandedSystemId(), false); 755 } catch (java.io.IOException e) { 756 } 757 XMLDTDDescription grammarDesc = new XMLDTDDescription(publicId, systemId, fDocLocation.getExpandedSystemId(), eid, rootElement); 758 fDTDGrammar = fGrammarBucket.getGrammar(grammarDesc); 759 if(fDTDGrammar == null) { 760 if(fGrammarPool != null) { 762 fDTDGrammar = (DTDGrammar)fGrammarPool.retrieveGrammar(grammarDesc); 763 } 764 } 765 if(fDTDGrammar == null) { 766 fDTDGrammar = new DTDGrammar(fSymbolTable, grammarDesc); 768 } else { 769 fValidationManager.setCachedDTD(true); 772 } 773 fGrammarBucket.setActiveGrammar(fDTDGrammar); 774 775 if (fDocumentHandler != null) { 777 fDocumentHandler.doctypeDecl(rootElement, publicId, systemId, augs); 778 } 779 780 } 782 783 792 public void startElement(QName element, XMLAttributes attributes, Augmentations augs) 793 throws XNIException { 794 795 handleStartElement(element, attributes, augs); 796 if (fDocumentHandler != null) { 798 fDocumentHandler.startElement(element, attributes, augs); 799 800 } 801 802 } 804 813 public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs) 814 throws XNIException { 815 816 boolean removed = handleStartElement(element, attributes, augs); 817 818 if (fDocumentHandler !=null) { 819 fDocumentHandler.emptyElement(element, attributes, augs); 820 } 821 if (!removed) { 822 handleEndElement(element, augs, true); 823 } 824 825 826 } 828 837 public void characters(XMLString text, Augmentations augs) throws XNIException { 838 839 boolean callNextCharacters = true; 840 841 boolean allWhiteSpace = true; 845 for (int i=text.offset; i< text.offset+text.length; i++) { 846 if (!isSpace(text.ch[i])) { 847 allWhiteSpace = false; 848 break; 849 } 850 } 851 if (fInElementContent && allWhiteSpace && !fInCDATASection) { 854 if (fDocumentHandler != null) { 855 fDocumentHandler.ignorableWhitespace(text, augs); 856 callNextCharacters = false; 857 } 858 } 859 860 if (fPerformValidation) { 862 if (fInElementContent) { 863 if (fGrammarBucket.getStandalone() && 864 fDTDGrammar.getElementDeclIsExternal(fCurrentElementIndex)) { 865 if (allWhiteSpace) { 866 fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 867 "MSG_WHITE_SPACE_IN_ELEMENT_CONTENT_WHEN_STANDALONE", 868 null, XMLErrorReporter.SEVERITY_ERROR); 869 } 870 } 871 if (!allWhiteSpace) { 872 charDataInContent(); 873 } 874 875 if (augs != null && augs.getItem(Constants.CHAR_REF_PROBABLE_WS) == Boolean.TRUE) { 877 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 878 "MSG_CONTENT_INVALID_SPECIFIED", 879 new Object []{ fCurrentElement.rawname, 880 fDTDGrammar.getContentSpecAsString(fElementDepth), 881 "character reference"}, 882 XMLErrorReporter.SEVERITY_ERROR); 883 } 884 } 885 886 if (fCurrentContentSpecType == XMLElementDecl.TYPE_EMPTY) { 887 charDataInContent(); 888 } 889 } 890 891 if (callNextCharacters && fDocumentHandler != null) { 893 fDocumentHandler.characters(text, augs); 894 } 895 896 } 898 899 900 913 public void ignorableWhitespace(XMLString text, Augmentations augs) throws XNIException { 914 915 if (fDocumentHandler != null) { 917 fDocumentHandler.ignorableWhitespace(text, augs); 918 } 919 920 } 922 930 public void endElement(QName element, Augmentations augs) throws XNIException { 931 932 handleEndElement(element, augs, false); 933 934 } 936 942 public void startCDATA(Augmentations augs) throws XNIException { 943 944 if (fPerformValidation && fInElementContent) { 945 charDataInContent(); 946 } 947 fInCDATASection = true; 948 if (fDocumentHandler != null) { 950 fDocumentHandler.startCDATA(augs); 951 } 952 953 } 955 961 public void endCDATA(Augmentations augs) throws XNIException { 962 963 fInCDATASection = false; 964 if (fDocumentHandler != null) { 966 fDocumentHandler.endCDATA(augs); 967 } 968 969 } 971 977 public void endDocument(Augmentations augs) throws XNIException { 978 979 if (fDocumentHandler != null) { 981 fDocumentHandler.endDocument(augs); 982 } 983 984 } 986 994 public void comment(XMLString text, Augmentations augs) throws XNIException { 995 if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) { 997 fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl); 998 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 999 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1000 "MSG_CONTENT_INVALID_SPECIFIED", 1001 new Object []{ fCurrentElement.rawname, 1002 "EMPTY", 1003 "comment"}, 1004 XMLErrorReporter.SEVERITY_ERROR); 1005 } 1006 } 1007 if (fDocumentHandler != null) { 1009 fDocumentHandler.comment(text, augs); 1010 } 1011 1012 } 1014 1015 1032 public void processingInstruction(String target, XMLString data, Augmentations augs) 1033 throws XNIException { 1034 1035 if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) { 1037 fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl); 1038 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 1039 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1040 "MSG_CONTENT_INVALID_SPECIFIED", 1041 new Object []{ fCurrentElement.rawname, 1042 "EMPTY", 1043 "processing instruction"}, 1044 XMLErrorReporter.SEVERITY_ERROR); 1045 } 1046 } 1047 if (fDocumentHandler != null) { 1049 fDocumentHandler.processingInstruction(target, data, augs); 1050 } 1051 } 1053 1070 public void startGeneralEntity(String name, 1071 XMLResourceIdentifier identifier, 1072 String encoding, 1073 Augmentations augs) throws XNIException { 1074 if (fPerformValidation && fElementDepth >= 0 && fDTDGrammar != null) { 1075 fDTDGrammar.getElementDecl(fCurrentElementIndex, fTempElementDecl); 1076 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 1078 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1079 "MSG_CONTENT_INVALID_SPECIFIED", 1080 new Object []{ fCurrentElement.rawname, 1081 "EMPTY", "ENTITY"}, 1082 XMLErrorReporter.SEVERITY_ERROR); 1083 } 1084 if (fGrammarBucket.getStandalone()) { 1085 XMLDTDLoader.checkStandaloneEntityRef(name, fDTDGrammar, fEntityDecl, fErrorReporter); 1086 } 1087 } 1088 if (fDocumentHandler != null) { 1089 fDocumentHandler.startGeneralEntity(name, identifier, encoding, augs); 1090 } 1091 } 1092 1093 1105 public void endGeneralEntity(String name, Augmentations augs) throws XNIException { 1106 if (fDocumentHandler != null) { 1108 fDocumentHandler.endGeneralEntity(name, augs); 1109 } 1110 } 1112 1126 public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { 1127 1128 if (fDocumentHandler != null) { 1130 fDocumentHandler.textDecl(version, encoding, augs); 1131 } 1132 } 1133 1134 1135 public final boolean hasGrammar(){ 1136 1137 return (fDTDGrammar != null); 1138 } 1139 1140 public final boolean validate(){ 1141 return (fSchemaType != Constants.NS_XMLSCHEMA) && 1153 (!fDynamicValidation && fValidation || 1154 fDynamicValidation && fSeenDoctypeDecl) && 1155 (fDTDValidation || fSeenDoctypeDecl); 1156 } 1157 1158 1160 1161 protected void addDTDDefaultAttrsAndValidate(QName elementName, int elementIndex, 1162 XMLAttributes attributes) 1163 throws XNIException { 1164 1165 if (elementIndex == -1 || fDTDGrammar == null) { 1167 return; 1168 } 1169 1170 int attlistIndex = fDTDGrammar.getFirstAttributeDeclIndex(elementIndex); 1176 1177 while (attlistIndex != -1) { 1178 1179 fDTDGrammar.getAttributeDecl(attlistIndex, fTempAttDecl); 1180 1181 if (DEBUG_ATTRIBUTES) { 1182 if (fTempAttDecl != null) { 1183 XMLElementDecl elementDecl = new XMLElementDecl(); 1184 fDTDGrammar.getElementDecl(elementIndex, elementDecl); 1185 System.out.println("element: "+(elementDecl.name.localpart)); 1186 System.out.println("attlistIndex " + attlistIndex + "\n"+ 1187 "attName : '"+(fTempAttDecl.name.localpart) + "'\n" 1188 + "attType : "+fTempAttDecl.simpleType.type + "\n" 1189 + "attDefaultType : "+fTempAttDecl.simpleType.defaultType + "\n" 1190 + "attDefaultValue : '"+fTempAttDecl.simpleType.defaultValue + "'\n" 1191 + attributes.getLength() +"\n" 1192 ); 1193 } 1194 } 1195 String attPrefix = fTempAttDecl.name.prefix; 1196 String attLocalpart = fTempAttDecl.name.localpart; 1197 String attRawName = fTempAttDecl.name.rawname; 1198 String attType = getAttributeTypeName(fTempAttDecl); 1199 int attDefaultType =fTempAttDecl.simpleType.defaultType; 1200 String attValue = null; 1201 1202 if (fTempAttDecl.simpleType.defaultValue != null) { 1203 attValue = fTempAttDecl.simpleType.defaultValue; 1204 } 1205 1206 boolean specified = false; 1207 boolean required = attDefaultType == XMLSimpleType.DEFAULT_TYPE_REQUIRED; 1208 boolean cdata = attType == XMLSymbols.fCDATASymbol; 1209 1210 if (!cdata || required || attValue != null) { 1211 int attrCount = attributes.getLength(); 1212 for (int i = 0; i < attrCount; i++) { 1213 if (attributes.getQName(i) == attRawName) { 1214 specified = true; 1215 break; 1216 } 1217 } 1218 } 1219 1220 if (!specified) { 1221 if (required) { 1222 if (fPerformValidation) { 1223 Object [] args = {elementName.localpart, attRawName}; 1224 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1225 "MSG_REQUIRED_ATTRIBUTE_NOT_SPECIFIED", args, 1226 XMLErrorReporter.SEVERITY_ERROR); 1227 } 1228 } 1229 else if (attValue != null) { 1230 if (fPerformValidation && fGrammarBucket.getStandalone()) { 1231 if (fDTDGrammar.getAttributeDeclIsExternal(attlistIndex)) { 1232 1233 Object [] args = { elementName.localpart, attRawName}; 1234 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1235 "MSG_DEFAULTED_ATTRIBUTE_NOT_SPECIFIED", args, 1236 XMLErrorReporter.SEVERITY_ERROR); 1237 } 1238 } 1239 1240 if (fNamespaces) { 1242 int index = attRawName.indexOf(':'); 1243 if (index != -1) { 1244 attPrefix = attRawName.substring(0, index); 1245 attPrefix = fSymbolTable.addSymbol(attPrefix); 1246 attLocalpart = attRawName.substring(index + 1); 1247 attLocalpart = fSymbolTable.addSymbol(attLocalpart); 1248 } 1249 } 1250 1251 fTempQName.setValues(attPrefix, attLocalpart, attRawName, fTempAttDecl.name.uri); 1253 int newAttr = attributes.addAttribute(fTempQName, attType, attValue); 1254 } 1255 } 1256 attlistIndex = fDTDGrammar.getNextAttributeDeclIndex(attlistIndex); 1258 } 1259 1260 int attrCount = attributes.getLength(); 1265 for (int i = 0; i < attrCount; i++) { 1266 String attrRawName = attributes.getQName(i); 1267 boolean declared = false; 1268 if (fPerformValidation) { 1269 if (fGrammarBucket.getStandalone()) { 1270 String nonNormalizedValue = attributes.getNonNormalizedValue(i); 1276 if (nonNormalizedValue != null) { 1277 String entityName = getExternalEntityRefInAttrValue(nonNormalizedValue); 1278 if (entityName != null) { 1279 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1280 "MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE", 1281 new Object []{entityName}, 1282 XMLErrorReporter.SEVERITY_ERROR); 1283 } 1284 } 1285 } 1286 } 1287 int attDefIndex = -1; 1288 int position = 1289 fDTDGrammar.getFirstAttributeDeclIndex(elementIndex); 1290 while (position != -1) { 1291 fDTDGrammar.getAttributeDecl(position, fTempAttDecl); 1292 if (fTempAttDecl.name.rawname == attrRawName) { 1293 attDefIndex = position; 1295 declared = true; 1296 break; 1297 } 1298 position = fDTDGrammar.getNextAttributeDeclIndex(position); 1299 } 1300 if (!declared) { 1301 if (fPerformValidation) { 1302 Object [] args = { elementName.rawname, attrRawName}; 1305 1306 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1307 "MSG_ATTRIBUTE_NOT_DECLARED", 1308 args,XMLErrorReporter.SEVERITY_ERROR); 1309 } 1310 continue; 1311 } 1312 1314 1318 String type = getAttributeTypeName(fTempAttDecl); 1319 attributes.setType(i, type); 1320 attributes.getAugmentations(i).putItem(Constants.ATTRIBUTE_DECLARED, Boolean.TRUE); 1321 1322 boolean changedByNormalization = false; 1323 String oldValue = attributes.getValue(i); 1324 String attrValue = oldValue; 1325 if (attributes.isSpecified(i) && type != XMLSymbols.fCDATASymbol) { 1326 changedByNormalization = normalizeAttrValue(attributes, i); 1327 attrValue = attributes.getValue(i); 1328 if (fPerformValidation && fGrammarBucket.getStandalone() 1329 && changedByNormalization 1330 && fDTDGrammar.getAttributeDeclIsExternal(position) 1331 ) { 1332 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1334 "MSG_ATTVALUE_CHANGED_DURING_NORMALIZATION_WHEN_STANDALONE", 1335 new Object []{attrRawName, oldValue, attrValue}, 1336 XMLErrorReporter.SEVERITY_ERROR); 1337 } 1338 } 1339 if (!fPerformValidation) { 1340 continue; 1341 } 1342 if (fTempAttDecl.simpleType.defaultType == 1343 XMLSimpleType.DEFAULT_TYPE_FIXED) { 1344 String defaultValue = fTempAttDecl.simpleType.defaultValue; 1345 1346 if (!attrValue.equals(defaultValue)) { 1347 Object [] args = {elementName.localpart, 1348 attrRawName, 1349 attrValue, 1350 defaultValue}; 1351 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1352 "MSG_FIXED_ATTVALUE_INVALID", 1353 args, XMLErrorReporter.SEVERITY_ERROR); 1354 } 1355 } 1356 1357 if (fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ENTITY || 1358 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ENUMERATION || 1359 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_ID || 1360 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_IDREF || 1361 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NMTOKEN || 1362 fTempAttDecl.simpleType.type == XMLSimpleType.TYPE_NOTATION 1363 ) { 1364 validateDTDattribute(elementName, attrValue, fTempAttDecl); 1365 } 1366 } 1368 } 1370 1371 protected String getExternalEntityRefInAttrValue(String nonNormalizedValue) { 1372 int valLength = nonNormalizedValue.length(); 1373 int ampIndex = nonNormalizedValue.indexOf('&'); 1374 while (ampIndex != -1) { 1375 if (ampIndex + 1 < valLength && 1376 nonNormalizedValue.charAt(ampIndex+1) != '#') { 1377 int semicolonIndex = nonNormalizedValue.indexOf(';', ampIndex+1); 1378 String entityName = nonNormalizedValue.substring(ampIndex+1, semicolonIndex); 1379 entityName = fSymbolTable.addSymbol(entityName); 1380 int entIndex = fDTDGrammar.getEntityDeclIndex(entityName); 1381 if (entIndex > -1) { 1382 fDTDGrammar.getEntityDecl(entIndex, fEntityDecl); 1383 if (fEntityDecl.inExternal || 1384 (entityName = getExternalEntityRefInAttrValue(fEntityDecl.value)) != null) { 1385 return entityName; 1386 } 1387 } 1388 } 1389 ampIndex = nonNormalizedValue.indexOf('&', ampIndex+1); 1390 } 1391 return null; 1392 } 1394 1397 protected void validateDTDattribute(QName element, String attValue, 1398 XMLAttributeDecl attributeDecl) 1399 throws XNIException { 1400 1401 switch (attributeDecl.simpleType.type) { 1402 case XMLSimpleType.TYPE_ENTITY: { 1403 boolean isAlistAttribute = attributeDecl.simpleType.list; 1405 1406 try { 1407 if (isAlistAttribute) { 1408 fValENTITIES.validate(attValue, fValidationState); 1409 } 1410 else { 1411 fValENTITY.validate(attValue, fValidationState); 1412 } 1413 } 1414 catch (InvalidDatatypeValueException ex) { 1415 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1416 ex.getKey(), 1417 ex.getArgs(), 1418 XMLErrorReporter.SEVERITY_ERROR ); 1419 1420 } 1421 break; 1422 } 1423 1424 case XMLSimpleType.TYPE_NOTATION: 1425 case XMLSimpleType.TYPE_ENUMERATION: { 1426 boolean found = false; 1427 String [] enumVals = attributeDecl.simpleType.enumeration; 1428 if (enumVals == null) { 1429 found = false; 1430 } 1431 else 1432 for (int i = 0; i < enumVals.length; i++) { 1433 if (attValue == enumVals[i] || attValue.equals(enumVals[i])) { 1434 found = true; 1435 break; 1436 } 1437 } 1438 1439 if (!found) { 1440 StringBuffer enumValueString = new StringBuffer (); 1441 if (enumVals != null) 1442 for (int i = 0; i < enumVals.length; i++) { 1443 enumValueString.append(enumVals[i]+" "); 1444 } 1445 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1446 "MSG_ATTRIBUTE_VALUE_NOT_IN_LIST", 1447 new Object []{attributeDecl.name.rawname, attValue, enumValueString}, 1448 XMLErrorReporter.SEVERITY_ERROR); 1449 } 1450 break; 1451 } 1452 1453 case XMLSimpleType.TYPE_ID: { 1454 try { 1455 fValID.validate(attValue, fValidationState); 1456 } 1457 catch (InvalidDatatypeValueException ex) { 1458 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1459 ex.getKey(), 1460 ex.getArgs(), 1461 XMLErrorReporter.SEVERITY_ERROR ); 1462 } 1463 break; 1464 } 1465 1466 case XMLSimpleType.TYPE_IDREF: { 1467 boolean isAlistAttribute = attributeDecl.simpleType.list; 1469 try { 1470 if (isAlistAttribute) { 1471 fValIDRefs.validate(attValue, fValidationState); 1472 } 1473 else { 1474 fValIDRef.validate(attValue, fValidationState); 1475 } 1476 } 1477 catch (InvalidDatatypeValueException ex) { 1478 if (isAlistAttribute) { 1479 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1480 "IDREFSInvalid", 1481 new Object []{attValue}, 1482 XMLErrorReporter.SEVERITY_ERROR ); 1483 } 1484 else { 1485 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1486 ex.getKey(), 1487 ex.getArgs(), 1488 XMLErrorReporter.SEVERITY_ERROR ); 1489 } 1490 1491 } 1492 break; 1493 } 1494 1495 case XMLSimpleType.TYPE_NMTOKEN: { 1496 boolean isAlistAttribute = attributeDecl.simpleType.list; try { 1499 if (isAlistAttribute) { 1500 fValNMTOKENS.validate(attValue, fValidationState); 1501 } 1502 else { 1503 fValNMTOKEN.validate(attValue, fValidationState); 1504 } 1505 } 1506 catch (InvalidDatatypeValueException ex) { 1507 if (isAlistAttribute) { 1508 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1509 "NMTOKENSInvalid", 1510 new Object [] { attValue}, 1511 XMLErrorReporter.SEVERITY_ERROR); 1512 } 1513 else { 1514 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1515 "NMTOKENInvalid", 1516 new Object [] { attValue}, 1517 XMLErrorReporter.SEVERITY_ERROR); 1518 } 1519 } 1520 break; 1521 } 1522 1523 } 1525 } 1527 1528 1529 protected boolean invalidStandaloneAttDef(QName element, QName attribute) { 1530 boolean state = true; 1532 1542 return state; 1543 } 1544 1545 1546 1550 1551 1558 private boolean normalizeAttrValue(XMLAttributes attributes, int index) { 1559 boolean leadingSpace = true; 1561 boolean spaceStart = false; 1562 boolean readingNonSpace = false; 1563 int count = 0; 1564 int eaten = 0; 1565 String attrValue = attributes.getValue(index); 1566 char[] attValue = new char[attrValue.length()]; 1567 1568 fBuffer.setLength(0); 1569 attrValue.getChars(0, attrValue.length(), attValue, 0); 1570 for (int i = 0; i < attValue.length; i++) { 1571 1572 if (attValue[i] == ' ') { 1573 1574 if (readingNonSpace) { 1576 spaceStart = true; 1577 readingNonSpace = false; 1578 } 1579 1580 if (spaceStart && !leadingSpace) { 1581 spaceStart = false; 1582 fBuffer.append(attValue[i]); 1583 count++; 1584 } 1585 else { 1586 if (leadingSpace || !spaceStart) { 1587 eaten ++; 1588 1607 } 1608 } 1609 1610 } 1611 else { 1612 readingNonSpace = true; 1613 spaceStart = false; 1614 leadingSpace = false; 1615 fBuffer.append(attValue[i]); 1616 count++; 1617 } 1618 } 1619 1620 if (count > 0 && fBuffer.charAt(count-1) == ' ') { 1622 fBuffer.setLength(count-1); 1623 1640 } 1641 String newValue = fBuffer.toString(); 1642 attributes.setValue(index, newValue); 1643 return ! attrValue.equals(newValue); 1644 } 1645 1646 1647 private final void rootElementSpecified(QName rootElement) throws XNIException { 1648 if (fPerformValidation) { 1649 String root1 = fRootElement.rawname; 1650 String root2 = rootElement.rawname; 1651 if (root1 == null || !root1.equals(root2)) { 1652 fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 1653 "RootElementTypeMustMatchDoctypedecl", 1654 new Object []{root1, root2}, 1655 XMLErrorReporter.SEVERITY_ERROR); 1656 } 1657 } 1658 } 1660 1693 private int checkContent(int elementIndex, 1694 QName[] children, 1695 int childOffset, 1696 int childCount) throws XNIException { 1697 1698 fDTDGrammar.getElementDecl(elementIndex, fTempElementDecl); 1699 1700 final String elementType = fCurrentElement.rawname; 1702 1703 final int contentType = fCurrentContentSpecType; 1705 1706 1707 if (contentType == XMLElementDecl.TYPE_EMPTY) { 1713 if (childCount != 0) { 1718 return 0; 1719 } 1720 } 1721 else if (contentType == XMLElementDecl.TYPE_ANY) { 1722 } 1727 else if (contentType == XMLElementDecl.TYPE_MIXED || 1728 contentType == XMLElementDecl.TYPE_CHILDREN) { 1729 ContentModelValidator cmElem = null; 1731 cmElem = fTempElementDecl.contentModelValidator; 1732 int result = cmElem.validate(children, childOffset, childCount); 1733 return result; 1734 } 1735 else if (contentType == -1) { 1736 1742 } 1743 else if (contentType == XMLElementDecl.TYPE_SIMPLE) { 1744 1745 1748 } 1749 else { 1750 1759 } 1760 1761 return -1; 1763 1764 } 1766 1767 private int getContentSpecType(int elementIndex) { 1768 1769 int contentSpecType = -1; 1770 if (elementIndex > -1) { 1771 if (fDTDGrammar.getElementDecl(elementIndex,fTempElementDecl)) { 1772 contentSpecType = fTempElementDecl.type; 1773 } 1774 } 1775 return contentSpecType; 1776 } 1777 1778 1779 private void charDataInContent() { 1780 1781 if (DEBUG_ELEMENT_CHILDREN) { 1782 System.out.println("charDataInContent()"); 1783 } 1784 if (fElementChildren.length <= fElementChildrenLength) { 1785 QName[] newarray = new QName[fElementChildren.length * 2]; 1786 System.arraycopy(fElementChildren, 0, newarray, 0, fElementChildren.length); 1787 fElementChildren = newarray; 1788 } 1789 QName qname = fElementChildren[fElementChildrenLength]; 1790 if (qname == null) { 1791 for (int i = fElementChildrenLength; i < fElementChildren.length; i++) { 1792 fElementChildren[i] = new QName(); 1793 } 1794 qname = fElementChildren[fElementChildrenLength]; 1795 } 1796 qname.clear(); 1797 fElementChildrenLength++; 1798 1799 } 1801 1802 private String getAttributeTypeName(XMLAttributeDecl attrDecl) { 1803 1804 switch (attrDecl.simpleType.type) { 1805 case XMLSimpleType.TYPE_ENTITY: { 1806 return attrDecl.simpleType.list ? XMLSymbols.fENTITIESSymbol : XMLSymbols.fENTITYSymbol; 1807 } 1808 case XMLSimpleType.TYPE_ENUMERATION: { 1809 StringBuffer buffer = new StringBuffer (); 1810 buffer.append('('); 1811 for (int i=0; i<attrDecl.simpleType.enumeration.length ; i++) { 1812 if (i > 0) { 1813 buffer.append("|"); 1814 } 1815 buffer.append(attrDecl.simpleType.enumeration[i]); 1816 } 1817 buffer.append(')'); 1818 return fSymbolTable.addSymbol(buffer.toString()); 1819 } 1820 case XMLSimpleType.TYPE_ID: { 1821 return XMLSymbols.fIDSymbol; 1822 } 1823 case XMLSimpleType.TYPE_IDREF: { 1824 return attrDecl.simpleType.list ? XMLSymbols.fIDREFSSymbol : XMLSymbols.fIDREFSymbol; 1825 } 1826 case XMLSimpleType.TYPE_NMTOKEN: { 1827 return attrDecl.simpleType.list ? XMLSymbols.fNMTOKENSSymbol : XMLSymbols.fNMTOKENSymbol; 1828 } 1829 case XMLSimpleType.TYPE_NOTATION: { 1830 return XMLSymbols.fNOTATIONSymbol; 1831 } 1832 } 1833 return XMLSymbols.fCDATASymbol; 1834 1835 } 1837 1838 protected void init() { 1839 1840 if (fValidation || fDynamicValidation) { 1842 try { 1843 fValID = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fIDSymbol); 1846 fValIDRef = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fIDREFSymbol); 1847 fValIDRefs = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fIDREFSSymbol); 1848 fValENTITY = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fENTITYSymbol); 1849 fValENTITIES = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fENTITIESSymbol); 1850 fValNMTOKEN = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fNMTOKENSymbol); 1851 fValNMTOKENS = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fNMTOKENSSymbol); 1852 fValNOTATION = fDatatypeValidatorFactory.getBuiltInDV(XMLSymbols.fNOTATIONSymbol); 1853 1854 } 1855 catch (Exception e) { 1856 e.printStackTrace(System.err); 1858 } 1859 1860 } 1861 1862 } 1864 1865 private void ensureStackCapacity ( int newElementDepth) { 1866 if (newElementDepth == fElementQNamePartsStack.length) { 1867 int[] newStack = new int[newElementDepth * 2]; 1868 1869 QName[] newStackOfQueue = new QName[newElementDepth * 2]; 1870 System.arraycopy(this.fElementQNamePartsStack, 0, newStackOfQueue, 0, newElementDepth ); 1871 fElementQNamePartsStack = newStackOfQueue; 1872 1873 QName qname = fElementQNamePartsStack[newElementDepth]; 1874 if (qname == null) { 1875 for (int i = newElementDepth; i < fElementQNamePartsStack.length; i++) { 1876 fElementQNamePartsStack[i] = new QName(); 1877 } 1878 } 1879 1880 newStack = new int[newElementDepth * 2]; 1881 System.arraycopy(fElementIndexStack, 0, newStack, 0, newElementDepth); 1882 fElementIndexStack = newStack; 1883 1884 newStack = new int[newElementDepth * 2]; 1885 System.arraycopy(fContentSpecTypeStack, 0, newStack, 0, newElementDepth); 1886 fContentSpecTypeStack = newStack; 1887 1888 } 1889 } 1891 1892 1896 1899 protected boolean handleStartElement(QName element, XMLAttributes attributes, Augmentations augs) 1900 throws XNIException { 1901 1902 1903 if (!fSeenRootElement) { 1906 fPerformValidation = validate(); 1928 fSeenRootElement = true; 1929 fValidationManager.setEntityState(fDTDGrammar); 1930 fValidationManager.setGrammarFound(fSeenDoctypeDecl); 1931 rootElementSpecified(element); 1932 } 1933 if (fDTDGrammar == null) { 1934 1935 if (!fPerformValidation) { 1936 fCurrentElementIndex = -1; 1937 fCurrentContentSpecType = -1; 1938 fInElementContent = false; 1939 } 1940 if (fPerformValidation) { 1941 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1942 "MSG_GRAMMAR_NOT_FOUND", 1943 new Object []{ element.rawname}, 1944 XMLErrorReporter.SEVERITY_ERROR); 1945 } 1946 if (fDocumentSource !=null ) { 1948 fDocumentSource.setDocumentHandler(fDocumentHandler); 1949 if (fDocumentHandler != null) 1950 fDocumentHandler.setDocumentSource(fDocumentSource); 1951 return true; 1952 } 1953 } 1954 else { 1955 fCurrentElementIndex = fDTDGrammar.getElementDeclIndex(element); 1957 fCurrentContentSpecType = fDTDGrammar.getContentSpecType(fCurrentElementIndex); 1959 if (fCurrentContentSpecType == -1 && fPerformValidation) { 1960 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1961 "MSG_ELEMENT_NOT_DECLARED", 1962 new Object []{ element.rawname}, 1963 XMLErrorReporter.SEVERITY_ERROR); 1964 } 1965 1966 addDTDDefaultAttrsAndValidate(element, fCurrentElementIndex, attributes); 1972 } 1973 1974 fInElementContent = fCurrentContentSpecType == XMLElementDecl.TYPE_CHILDREN; 1976 1977 fElementDepth++; 1980 if (fPerformValidation) { 1981 if (fElementChildrenOffsetStack.length <= fElementDepth) { 1983 int newarray[] = new int[fElementChildrenOffsetStack.length * 2]; 1984 System.arraycopy(fElementChildrenOffsetStack, 0, newarray, 0, fElementChildrenOffsetStack.length); 1985 fElementChildrenOffsetStack = newarray; 1986 } 1987 fElementChildrenOffsetStack[fElementDepth] = fElementChildrenLength; 1988 1989 if (fElementChildren.length <= fElementChildrenLength) { 1991 QName[] newarray = new QName[fElementChildrenLength * 2]; 1992 System.arraycopy(fElementChildren, 0, newarray, 0, fElementChildren.length); 1993 fElementChildren = newarray; 1994 } 1995 QName qname = fElementChildren[fElementChildrenLength]; 1996 if (qname == null) { 1997 for (int i = fElementChildrenLength; i < fElementChildren.length; i++) { 1998 fElementChildren[i] = new QName(); 1999 } 2000 qname = fElementChildren[fElementChildrenLength]; 2001 } 2002 qname.setValues(element); 2003 fElementChildrenLength++; 2004 } 2005 2006 fCurrentElement.setValues(element); 2008 ensureStackCapacity(fElementDepth); 2009 fElementQNamePartsStack[fElementDepth].setValues(fCurrentElement); 2010 fElementIndexStack[fElementDepth] = fCurrentElementIndex; 2011 fContentSpecTypeStack[fElementDepth] = fCurrentContentSpecType; 2012 startNamespaceScope(element, attributes, augs); 2013 return false; 2014 2015 } 2017 protected void startNamespaceScope(QName element, XMLAttributes attributes, Augmentations augs){ 2018 } 2019 2020 2021 protected void handleEndElement(QName element, Augmentations augs, boolean isEmpty) 2022 throws XNIException { 2023 2024 fElementDepth--; 2026 2027 if (fPerformValidation) { 2029 int elementIndex = fCurrentElementIndex; 2030 if (elementIndex != -1 && fCurrentContentSpecType != -1) { 2031 QName children[] = fElementChildren; 2032 int childrenOffset = fElementChildrenOffsetStack[fElementDepth + 1] + 1; 2033 int childrenLength = fElementChildrenLength - childrenOffset; 2034 int result = checkContent(elementIndex, 2035 children, childrenOffset, childrenLength); 2036 2037 if (result != -1) { 2038 fDTDGrammar.getElementDecl(elementIndex, fTempElementDecl); 2039 if (fTempElementDecl.type == XMLElementDecl.TYPE_EMPTY) { 2040 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 2041 "MSG_CONTENT_INVALID", 2042 new Object []{ element.rawname, "EMPTY"}, 2043 XMLErrorReporter.SEVERITY_ERROR); 2044 } 2045 else { 2046 String messageKey = result != childrenLength ? 2047 "MSG_CONTENT_INVALID" : "MSG_CONTENT_INCOMPLETE"; 2048 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 2049 messageKey, 2050 new Object []{ element.rawname, 2051 fDTDGrammar.getContentSpecAsString(elementIndex)}, 2052 XMLErrorReporter.SEVERITY_ERROR); 2053 } 2054 } 2055 } 2056 fElementChildrenLength = fElementChildrenOffsetStack[fElementDepth + 1] + 1; 2057 } 2058 2059 endNamespaceScope(fCurrentElement, augs, isEmpty); 2060 2061 if (fElementDepth < -1) { 2063 throw new RuntimeException ("FWK008 Element stack underflow"); 2064 } 2065 if (fElementDepth < 0) { 2066 fCurrentElement.clear(); 2067 fCurrentElementIndex = -1; 2068 fCurrentContentSpecType = -1; 2069 fInElementContent = false; 2070 2071 if (fPerformValidation) { 2078 String value = fValidationState.checkIDRefID(); 2079 if (value != null) { 2080 fErrorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 2081 "MSG_ELEMENT_WITH_ID_REQUIRED", 2082 new Object []{value}, 2083 XMLErrorReporter.SEVERITY_ERROR ); 2084 } 2085 } 2086 return; 2087 } 2088 2089 fCurrentElement.setValues(fElementQNamePartsStack[fElementDepth]); 2091 2092 fCurrentElementIndex = fElementIndexStack[fElementDepth]; 2093 fCurrentContentSpecType = fContentSpecTypeStack[fElementDepth]; 2094 fInElementContent = (fCurrentContentSpecType == XMLElementDecl.TYPE_CHILDREN); 2095 2096 } 2098 protected void endNamespaceScope(QName element, Augmentations augs, boolean isEmpty){ 2099 2100 if (fDocumentHandler != null && !isEmpty) { 2102 fDocumentHandler.endElement(fCurrentElement, augs); 2109 } 2110 } 2111 2112 protected boolean isSpace(int c) { 2115 return XMLChar.isSpace(c); 2116 } 2118} | Popular Tags |