1 16 17 package org.apache.xerces.impl.dtd; 18 19 import java.util.Enumeration ; 20 import java.util.Hashtable ; 21 import java.util.Locale ; 22 import java.util.StringTokenizer ; 23 import java.util.Vector ; 24 25 import org.apache.xerces.impl.Constants; 26 import org.apache.xerces.impl.XMLErrorReporter; 27 import org.apache.xerces.impl.msg.XMLMessageFormatter; 28 import org.apache.xerces.util.SymbolTable; 29 import org.apache.xerces.util.XMLChar; 30 import org.apache.xerces.util.XMLSymbols; 31 import org.apache.xerces.xni.Augmentations; 32 import org.apache.xerces.xni.XMLDTDContentModelHandler; 33 import org.apache.xerces.xni.XMLDTDHandler; 34 import org.apache.xerces.xni.XMLLocator; 35 import org.apache.xerces.xni.XMLResourceIdentifier; 36 import org.apache.xerces.xni.XMLString; 37 import org.apache.xerces.xni.XNIException; 38 import org.apache.xerces.xni.grammars.Grammar; 39 import org.apache.xerces.xni.grammars.XMLGrammarDescription; 40 import org.apache.xerces.xni.grammars.XMLGrammarPool; 41 import org.apache.xerces.xni.parser.XMLComponent; 42 import org.apache.xerces.xni.parser.XMLComponentManager; 43 import org.apache.xerces.xni.parser.XMLConfigurationException; 44 import org.apache.xerces.xni.parser.XMLDTDContentModelFilter; 45 import org.apache.xerces.xni.parser.XMLDTDContentModelSource; 46 import org.apache.xerces.xni.parser.XMLDTDFilter; 47 import org.apache.xerces.xni.parser.XMLDTDSource; 48 49 72 public class XMLDTDProcessor 73 implements XMLComponent, XMLDTDFilter, XMLDTDContentModelFilter { 74 75 79 80 private static final int TOP_LEVEL_SCOPE = -1; 81 82 84 85 protected static final String VALIDATION = 86 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 87 88 89 protected static final String NOTIFY_CHAR_REFS = 90 Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE; 91 92 93 protected static final String WARN_ON_DUPLICATE_ATTDEF = 94 Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 95 96 protected static final String PARSER_SETTINGS = 97 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; 98 99 101 102 protected static final String SYMBOL_TABLE = 103 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 104 105 106 protected static final String ERROR_REPORTER = 107 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 108 109 110 protected static final String GRAMMAR_POOL = 111 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 112 113 114 protected static final String DTD_VALIDATOR = 115 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; 116 117 119 120 private static final String [] RECOGNIZED_FEATURES = { 121 VALIDATION, 122 WARN_ON_DUPLICATE_ATTDEF, 123 NOTIFY_CHAR_REFS, 124 }; 125 126 127 private static final Boolean [] FEATURE_DEFAULTS = { 128 null, 129 Boolean.FALSE, 130 null, 131 }; 132 133 134 private static final String [] RECOGNIZED_PROPERTIES = { 135 SYMBOL_TABLE, 136 ERROR_REPORTER, 137 GRAMMAR_POOL, 138 DTD_VALIDATOR, 139 }; 140 141 142 private static final Object [] PROPERTY_DEFAULTS = { 143 null, 144 null, 145 null, 146 null, 147 }; 148 149 151 155 157 158 protected boolean fValidation; 159 160 161 protected boolean fDTDValidation; 162 163 164 protected boolean fWarnDuplicateAttdef; 165 166 168 169 protected SymbolTable fSymbolTable; 170 171 172 protected XMLErrorReporter fErrorReporter; 173 174 175 protected DTDGrammarBucket fGrammarBucket; 176 177 protected XMLDTDValidator fValidator; 181 182 protected XMLGrammarPool fGrammarPool; 184 185 protected Locale fLocale; 187 188 190 191 protected XMLDTDHandler fDTDHandler; 192 193 194 protected XMLDTDSource fDTDSource; 195 196 197 protected XMLDTDContentModelHandler fDTDContentModelHandler; 198 199 200 protected XMLDTDContentModelSource fDTDContentModelSource; 201 202 204 205 protected DTDGrammar fDTDGrammar; 206 207 209 210 private boolean fPerformValidation; 211 212 213 protected boolean fInDTDIgnore; 214 215 217 219 220 private boolean fMixed; 221 222 224 225 private XMLEntityDecl fEntityDecl = new XMLEntityDecl(); 226 227 228 private Hashtable fNDataDeclNotations = new Hashtable (); 229 230 231 private String fDTDElementDeclName = null; 232 233 234 private Vector fMixedElementTypes = new Vector (); 235 236 237 private Vector fDTDElementDecls = new Vector (); 238 239 242 243 private Hashtable fTableOfIDAttributeNames; 244 245 246 private Hashtable fTableOfNOTATIONAttributeNames; 247 248 249 private Hashtable fNotationEnumVals; 250 251 255 256 public XMLDTDProcessor() { 257 258 260 } 262 266 280 public void reset(XMLComponentManager componentManager) throws XMLConfigurationException { 281 282 boolean parser_settings; 283 try { 284 parser_settings = componentManager.getFeature(PARSER_SETTINGS); 285 } catch (XMLConfigurationException e) { 286 parser_settings = true; 287 } 288 289 if (!parser_settings) { 290 reset(); 292 return; 293 } 294 295 try { 297 fValidation = componentManager.getFeature(VALIDATION); 298 } catch (XMLConfigurationException e) { 299 fValidation = false; 300 } 301 try { 302 fDTDValidation = 303 !(componentManager 304 .getFeature( 305 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE)); 306 } catch (XMLConfigurationException e) { 307 fDTDValidation = true; 309 } 310 311 313 try { 314 fWarnDuplicateAttdef = componentManager.getFeature(WARN_ON_DUPLICATE_ATTDEF); 315 } catch (XMLConfigurationException e) { 316 fWarnDuplicateAttdef = false; 317 } 318 319 fErrorReporter = 321 (XMLErrorReporter) componentManager.getProperty( 322 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY); 323 fSymbolTable = 324 (SymbolTable) componentManager.getProperty( 325 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY); 326 try { 327 fGrammarPool = (XMLGrammarPool) componentManager.getProperty(GRAMMAR_POOL); 328 } catch (XMLConfigurationException e) { 329 fGrammarPool = null; 330 } 331 try { 332 fValidator = (XMLDTDValidator) componentManager.getProperty(DTD_VALIDATOR); 333 } catch (XMLConfigurationException e) { 334 fValidator = null; 335 } catch (ClassCastException e) { 336 fValidator = null; 337 } 338 if (fValidator != null) { 340 fGrammarBucket = fValidator.getGrammarBucket(); 341 } else { 342 fGrammarBucket = null; 343 } 344 reset(); 345 346 } 348 protected void reset() { 349 fDTDGrammar = null; 351 fInDTDIgnore = false; 353 354 fNDataDeclNotations.clear(); 355 356 if (fValidation) { 358 359 if (fNotationEnumVals == null) { 360 fNotationEnumVals = new Hashtable (); 361 } 362 fNotationEnumVals.clear(); 363 364 fTableOfIDAttributeNames = new Hashtable (); 365 fTableOfNOTATIONAttributeNames = new Hashtable (); 366 } 367 368 } 369 374 public String [] getRecognizedFeatures() { 375 return (String [])(RECOGNIZED_FEATURES.clone()); 376 } 378 393 public void setFeature(String featureId, boolean state) 394 throws XMLConfigurationException { 395 } 397 402 public String [] getRecognizedProperties() { 403 return (String [])(RECOGNIZED_PROPERTIES.clone()); 404 } 406 421 public void setProperty(String propertyId, Object value) 422 throws XMLConfigurationException { 423 } 425 434 public Boolean getFeatureDefault(String featureId) { 435 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { 436 if (RECOGNIZED_FEATURES[i].equals(featureId)) { 437 return FEATURE_DEFAULTS[i]; 438 } 439 } 440 return null; 441 } 443 452 public Object getPropertyDefault(String propertyId) { 453 for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { 454 if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { 455 return PROPERTY_DEFAULTS[i]; 456 } 457 } 458 return null; 459 } 461 465 470 public void setDTDHandler(XMLDTDHandler dtdHandler) { 471 fDTDHandler = dtdHandler; 472 } 474 479 public XMLDTDHandler getDTDHandler() { 480 return fDTDHandler; 481 } 483 487 492 public void setDTDContentModelHandler(XMLDTDContentModelHandler dtdContentModelHandler) { 493 fDTDContentModelHandler = dtdContentModelHandler; 494 } 496 501 public XMLDTDContentModelHandler getDTDContentModelHandler() { 502 return fDTDContentModelHandler; 503 } 505 509 517 public void startExternalSubset(XMLResourceIdentifier identifier, 518 Augmentations augs) throws XNIException { 519 if(fDTDGrammar != null) 520 fDTDGrammar.startExternalSubset(identifier, augs); 521 if(fDTDHandler != null){ 522 fDTDHandler.startExternalSubset(identifier, augs); 523 } 524 } 525 526 534 public void endExternalSubset(Augmentations augs) throws XNIException { 535 if(fDTDGrammar != null) 536 fDTDGrammar.endExternalSubset(augs); 537 if(fDTDHandler != null){ 538 fDTDHandler.endExternalSubset(augs); 539 } 540 } 541 542 553 protected static void checkStandaloneEntityRef(String name, DTDGrammar grammar, 554 XMLEntityDecl tempEntityDecl, XMLErrorReporter errorReporter) throws XNIException { 555 int entIndex = grammar.getEntityDeclIndex(name); 557 if (entIndex > -1) { 558 grammar.getEntityDecl(entIndex, tempEntityDecl); 559 if (tempEntityDecl.inExternal) { 560 errorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 561 "MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE", 562 new Object []{name}, XMLErrorReporter.SEVERITY_ERROR); 563 } 564 } 565 } 566 567 575 public void comment(XMLString text, Augmentations augs) throws XNIException { 576 577 if(fDTDGrammar != null) 579 fDTDGrammar.comment(text, augs); 580 if (fDTDHandler != null) { 581 fDTDHandler.comment(text, augs); 582 } 583 584 } 586 587 604 public void processingInstruction(String target, XMLString data, Augmentations augs) 605 throws XNIException { 606 607 if(fDTDGrammar != null) 609 fDTDGrammar.processingInstruction(target, data, augs); 610 if (fDTDHandler != null) { 611 fDTDHandler.processingInstruction(target, data, augs); 612 } 613 } 615 619 633 public void startDTD(XMLLocator locator, Augmentations augs) throws XNIException { 634 635 636 fNDataDeclNotations.clear(); 638 fDTDElementDecls.removeAllElements(); 639 640 if( !fGrammarBucket.getActiveGrammar().isImmutable()) { 645 fDTDGrammar = fGrammarBucket.getActiveGrammar(); 646 } 647 648 if(fDTDGrammar != null ) 650 fDTDGrammar.startDTD(locator, augs); 651 if (fDTDHandler != null) { 652 fDTDHandler.startDTD(locator, augs); 653 } 654 655 } 657 666 public void ignoredCharacters(XMLString text, Augmentations augs) throws XNIException { 667 668 if(fDTDGrammar != null ) 670 fDTDGrammar.ignoredCharacters(text, augs); 671 if (fDTDHandler != null) { 672 fDTDHandler.ignoredCharacters(text, augs); 673 } 674 } 675 676 690 public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { 691 692 if(fDTDGrammar != null ) 694 fDTDGrammar.textDecl(version, encoding, augs); 695 if (fDTDHandler != null) { 696 fDTDHandler.textDecl(version, encoding, augs); 697 } 698 } 699 700 715 public void startParameterEntity(String name, 716 XMLResourceIdentifier identifier, 717 String encoding, 718 Augmentations augs) throws XNIException { 719 720 if (fPerformValidation && fDTDGrammar != null && 721 fGrammarBucket.getStandalone()) { 722 checkStandaloneEntityRef(name, fDTDGrammar, fEntityDecl, fErrorReporter); 723 } 724 if(fDTDGrammar != null ) 726 fDTDGrammar.startParameterEntity(name, identifier, encoding, augs); 727 if (fDTDHandler != null) { 728 fDTDHandler.startParameterEntity(name, identifier, encoding, augs); 729 } 730 } 731 732 742 public void endParameterEntity(String name, Augmentations augs) throws XNIException { 743 744 if(fDTDGrammar != null ) 746 fDTDGrammar.endParameterEntity(name, augs); 747 if (fDTDHandler != null) { 748 fDTDHandler.endParameterEntity(name, augs); 749 } 750 } 751 752 762 public void elementDecl(String name, String contentModel, Augmentations augs) 763 throws XNIException { 764 765 if (fValidation) { 767 if (fDTDElementDecls.contains(name)) { 768 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 769 "MSG_ELEMENT_ALREADY_DECLARED", 770 new Object []{ name}, 771 XMLErrorReporter.SEVERITY_ERROR); 772 } 773 else { 774 fDTDElementDecls.addElement(name); 775 } 776 } 777 778 if(fDTDGrammar != null ) 780 fDTDGrammar.elementDecl(name, contentModel, augs); 781 if (fDTDHandler != null) { 782 fDTDHandler.elementDecl(name, contentModel, augs); 783 } 784 785 } 787 797 public void startAttlist(String elementName, Augmentations augs) 798 throws XNIException { 799 800 if(fDTDGrammar != null ) 802 fDTDGrammar.startAttlist(elementName, augs); 803 if (fDTDHandler != null) { 804 fDTDHandler.startAttlist(elementName, augs); 805 } 806 807 } 809 834 public void attributeDecl(String elementName, String attributeName, 835 String type, String [] enumeration, 836 String defaultType, XMLString defaultValue, 837 XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException { 838 839 if (type != XMLSymbols.fCDATASymbol && defaultValue != null) { 840 normalizeDefaultAttrValue(defaultValue); 841 } 842 843 if (fValidation) { 844 845 boolean duplicateAttributeDef = false ; 846 847 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar:fGrammarBucket.getActiveGrammar()); 849 int elementIndex = grammar.getElementDeclIndex( elementName); 850 if (grammar.getAttributeDeclIndex(elementIndex, attributeName) != -1) { 851 duplicateAttributeDef = true ; 853 854 if(fWarnDuplicateAttdef){ 856 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 857 "MSG_DUPLICATE_ATTRIBUTE_DEFINITION", 858 new Object []{ elementName, attributeName }, 859 XMLErrorReporter.SEVERITY_WARNING ); 860 } 861 } 862 863 864 if (type == XMLSymbols.fIDSymbol) { 869 if (defaultValue != null && defaultValue.length != 0) { 870 if (defaultType == null || 871 !(defaultType == XMLSymbols.fIMPLIEDSymbol || 872 defaultType == XMLSymbols.fREQUIREDSymbol)) { 873 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 874 "IDDefaultTypeInvalid", 875 new Object []{ attributeName}, 876 XMLErrorReporter.SEVERITY_ERROR); 877 } 878 } 879 880 if (!fTableOfIDAttributeNames.containsKey(elementName)) { 881 fTableOfIDAttributeNames.put(elementName, attributeName); 882 } 883 else { 884 896 if(!duplicateAttributeDef){ 897 String previousIDAttributeName = (String )fTableOfIDAttributeNames.get( elementName ); fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 899 "MSG_MORE_THAN_ONE_ID_ATTRIBUTE", 900 new Object []{ elementName, previousIDAttributeName, attributeName}, 901 XMLErrorReporter.SEVERITY_ERROR); 902 } 903 } 904 } 905 906 910 if (type == XMLSymbols.fNOTATIONSymbol) { 911 for (int i=0; i<enumeration.length; i++) { 914 fNotationEnumVals.put(enumeration[i], attributeName); 915 } 916 917 if (fTableOfNOTATIONAttributeNames.containsKey( elementName ) == false) { 918 fTableOfNOTATIONAttributeNames.put( elementName, attributeName); 919 } 920 else { 921 928 if(!duplicateAttributeDef){ 929 930 String previousNOTATIONAttributeName = (String ) fTableOfNOTATIONAttributeNames.get( elementName ); 931 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 932 "MSG_MORE_THAN_ONE_NOTATION_ATTRIBUTE", 933 new Object []{ elementName, previousNOTATIONAttributeName, attributeName}, 934 XMLErrorReporter.SEVERITY_ERROR); 935 } 936 } 937 } 938 939 if (type == XMLSymbols.fENUMERATIONSymbol || type == XMLSymbols.fNOTATIONSymbol) { 942 outer: 943 for (int i = 0; i < enumeration.length; ++i) { 944 for (int j = i + 1; j < enumeration.length; ++j) { 945 if (enumeration[i].equals(enumeration[j])) { 946 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 950 type == XMLSymbols.fENUMERATIONSymbol 951 ? "MSG_DISTINCT_TOKENS_IN_ENUMERATION" 952 : "MSG_DISTINCT_NOTATION_IN_ENUMERATION", 953 new Object []{ elementName, enumeration[i], attributeName }, 954 XMLErrorReporter.SEVERITY_ERROR); 955 break outer; 956 } 957 } 958 } 959 } 960 961 boolean ok = true; 963 if (defaultValue != null && 964 (defaultType == null || 965 (defaultType != null && defaultType == XMLSymbols.fFIXEDSymbol))) { 966 967 String value = defaultValue.toString(); 968 if (type == XMLSymbols.fNMTOKENSSymbol || 969 type == XMLSymbols.fENTITIESSymbol || 970 type == XMLSymbols.fIDREFSSymbol) { 971 972 StringTokenizer tokenizer = new StringTokenizer (value," "); 973 if (tokenizer.hasMoreTokens()) { 974 while (true) { 975 String nmtoken = tokenizer.nextToken(); 976 if (type == XMLSymbols.fNMTOKENSSymbol) { 977 if (!isValidNmtoken(nmtoken)) { 978 ok = false; 979 break; 980 } 981 } 982 else if (type == XMLSymbols.fENTITIESSymbol || 983 type == XMLSymbols.fIDREFSSymbol) { 984 if (!isValidName(nmtoken)) { 985 ok = false; 986 break; 987 } 988 } 989 if (!tokenizer.hasMoreTokens()) { 990 break; 991 } 992 } 993 } 994 995 } 996 else { 997 if (type == XMLSymbols.fENTITYSymbol || 998 type == XMLSymbols.fIDSymbol || 999 type == XMLSymbols.fIDREFSymbol || 1000 type == XMLSymbols.fNOTATIONSymbol) { 1001 1002 if (!isValidName(value)) { 1003 ok = false; 1004 } 1005 1006 } 1007 else if (type == XMLSymbols.fNMTOKENSymbol || 1008 type == XMLSymbols.fENUMERATIONSymbol) { 1009 1010 if (!isValidNmtoken(value)) { 1011 ok = false; 1012 } 1013 } 1014 1015 if (type == XMLSymbols.fNOTATIONSymbol || 1016 type == XMLSymbols.fENUMERATIONSymbol) { 1017 ok = false; 1018 for (int i=0; i<enumeration.length; i++) { 1019 if (defaultValue.equals(enumeration[i])) { 1020 ok = true; 1021 } 1022 } 1023 } 1024 1025 } 1026 if (!ok) { 1027 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1028 "MSG_ATT_DEFAULT_INVALID", 1029 new Object []{attributeName, value}, 1030 XMLErrorReporter.SEVERITY_ERROR); 1031 } 1032 } 1033 } 1034 1035 if(fDTDGrammar != null) 1037 fDTDGrammar.attributeDecl(elementName, attributeName, 1038 type, enumeration, 1039 defaultType, defaultValue, nonNormalizedDefaultValue, augs); 1040 if (fDTDHandler != null) { 1041 fDTDHandler.attributeDecl(elementName, attributeName, 1042 type, enumeration, 1043 defaultType, defaultValue, nonNormalizedDefaultValue, augs); 1044 } 1045 1046 } 1048 1056 public void endAttlist(Augmentations augs) throws XNIException { 1057 1058 if(fDTDGrammar != null) 1060 fDTDGrammar.endAttlist(augs); 1061 if (fDTDHandler != null) { 1062 fDTDHandler.endAttlist(augs); 1063 } 1064 1065 } 1067 1083 public void internalEntityDecl(String name, XMLString text, 1084 XMLString nonNormalizedText, 1085 Augmentations augs) throws XNIException { 1086 1087 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar: fGrammarBucket.getActiveGrammar()); 1088 int index = grammar.getEntityDeclIndex(name) ; 1089 1090 1094 1097 if(index == -1){ 1099 if(fDTDGrammar != null) 1101 fDTDGrammar.internalEntityDecl(name, text, nonNormalizedText, augs); 1102 if (fDTDHandler != null) { 1104 fDTDHandler.internalEntityDecl(name, text, nonNormalizedText, augs); 1105 } 1106 } 1107 1108 } 1110 1111 1124 public void externalEntityDecl(String name, XMLResourceIdentifier identifier, 1125 Augmentations augs) throws XNIException { 1126 1127 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar: fGrammarBucket.getActiveGrammar()); 1128 int index = grammar.getEntityDeclIndex(name) ; 1129 1130 1134 1137 if(index == -1){ 1139 if(fDTDGrammar != null) 1141 fDTDGrammar.externalEntityDecl(name, identifier, augs); 1142 if (fDTDHandler != null) { 1144 fDTDHandler.externalEntityDecl(name, identifier, augs); 1145 } 1146 } 1147 1148 } 1150 1162 public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, 1163 String notation, 1164 Augmentations augs) throws XNIException { 1165 1166 if (fValidation) { 1168 fNDataDeclNotations.put(name, notation); 1169 } 1170 1171 if(fDTDGrammar != null) 1173 fDTDGrammar.unparsedEntityDecl(name, identifier, notation, augs); 1174 if (fDTDHandler != null) { 1175 fDTDHandler.unparsedEntityDecl(name, identifier, notation, augs); 1176 } 1177 1178 } 1180 1191 public void notationDecl(String name, XMLResourceIdentifier identifier, 1192 Augmentations augs) throws XNIException { 1193 1194 if (fValidation) { 1196 DTDGrammar grammar = (fDTDGrammar != null ? fDTDGrammar : fGrammarBucket.getActiveGrammar()); 1197 if (grammar.getNotationDeclIndex(name) != -1) { 1198 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1199 "UniqueNotationName", 1200 new Object []{name}, 1201 XMLErrorReporter.SEVERITY_ERROR); 1202 } 1203 } 1204 1205 if(fDTDGrammar != null) 1207 fDTDGrammar.notationDecl(name, identifier, augs); 1208 if (fDTDHandler != null) { 1209 fDTDHandler.notationDecl(name, identifier, augs); 1210 } 1211 1212 } 1214 1227 public void startConditional(short type, Augmentations augs) throws XNIException { 1228 1229 fInDTDIgnore = type == XMLDTDHandler.CONDITIONAL_IGNORE; 1231 1232 if(fDTDGrammar != null) 1234 fDTDGrammar.startConditional(type, augs); 1235 if (fDTDHandler != null) { 1236 fDTDHandler.startConditional(type, augs); 1237 } 1238 1239 } 1241 1249 public void endConditional(Augmentations augs) throws XNIException { 1250 1251 fInDTDIgnore = false; 1253 1254 if(fDTDGrammar != null) 1256 fDTDGrammar.endConditional(augs); 1257 if (fDTDHandler != null) { 1258 fDTDHandler.endConditional(augs); 1259 } 1260 1261 } 1263 1271 public void endDTD(Augmentations augs) throws XNIException { 1272 1273 1274 if(fDTDGrammar != null) { 1276 fDTDGrammar.endDTD(augs); 1277 if(fGrammarPool != null) 1278 fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_DTD, new Grammar[] {fDTDGrammar}); 1279 } 1280 if (fValidation) { 1282 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar: fGrammarBucket.getActiveGrammar()); 1283 1284 Enumeration entities = fNDataDeclNotations.keys(); 1286 while (entities.hasMoreElements()) { 1287 String entity = (String ) entities.nextElement(); 1288 String notation = (String ) fNDataDeclNotations.get(entity); 1289 if (grammar.getNotationDeclIndex(notation) == -1) { 1290 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1291 "MSG_NOTATION_NOT_DECLARED_FOR_UNPARSED_ENTITYDECL", 1292 new Object []{entity, notation}, 1293 XMLErrorReporter.SEVERITY_ERROR); 1294 } 1295 } 1296 1297 Enumeration notationVals = fNotationEnumVals.keys(); 1300 while (notationVals.hasMoreElements()) { 1301 String notation = (String ) notationVals.nextElement(); 1302 String attributeName = (String ) fNotationEnumVals.get(notation); 1303 if (grammar.getNotationDeclIndex(notation) == -1) { 1304 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1305 "MSG_NOTATION_NOT_DECLARED_FOR_NOTATIONTYPE_ATTRIBUTE", 1306 new Object []{attributeName, notation}, 1307 XMLErrorReporter.SEVERITY_ERROR); 1308 } 1309 } 1310 1311 Enumeration elementsWithNotations = fTableOfNOTATIONAttributeNames.keys(); 1314 while (elementsWithNotations.hasMoreElements()) { 1315 String elementName = (String ) elementsWithNotations.nextElement(); 1316 int elementIndex = grammar.getElementDeclIndex(elementName); 1317 if (grammar.getContentSpecType(elementIndex) == XMLElementDecl.TYPE_EMPTY) { 1318 String attributeName = (String ) fTableOfNOTATIONAttributeNames.get(elementName); 1319 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1320 "NoNotationOnEmptyElement", 1321 new Object []{elementName, attributeName}, 1322 XMLErrorReporter.SEVERITY_ERROR); 1323 } 1324 } 1325 1326 fTableOfIDAttributeNames = null; fTableOfNOTATIONAttributeNames = null; 1328 } 1329 1330 if (fDTDHandler != null) { 1332 fDTDHandler.endDTD(augs); 1333 } 1334 1335 } 1337 public void setDTDSource(XMLDTDSource source ) { 1339 fDTDSource = source; 1340 } 1342 public XMLDTDSource getDTDSource() { 1344 return fDTDSource; 1345 } 1347 1351 public void setDTDContentModelSource(XMLDTDContentModelSource source ) { 1353 fDTDContentModelSource = source; 1354 } 1356 public XMLDTDContentModelSource getDTDContentModelSource() { 1358 return fDTDContentModelSource; 1359 } 1361 1362 1373 public void startContentModel(String elementName, Augmentations augs) 1374 throws XNIException { 1375 1376 if (fValidation) { 1377 fDTDElementDeclName = elementName; 1378 fMixedElementTypes.removeAllElements(); 1379 } 1380 1381 if(fDTDGrammar != null) 1383 fDTDGrammar.startContentModel(elementName, augs); 1384 if (fDTDContentModelHandler != null) { 1385 fDTDContentModelHandler.startContentModel(elementName, augs); 1386 } 1387 1388 } 1390 1401 public void any(Augmentations augs) throws XNIException { 1402 if(fDTDGrammar != null) 1403 fDTDGrammar.any(augs); 1404 if (fDTDContentModelHandler != null) { 1405 fDTDContentModelHandler.any(augs); 1406 } 1407 } 1409 1420 public void empty(Augmentations augs) throws XNIException { 1421 if(fDTDGrammar != null) 1422 fDTDGrammar.empty(augs); 1423 if (fDTDContentModelHandler != null) { 1424 fDTDContentModelHandler.empty(augs); 1425 } 1426 } 1428 1442 public void startGroup(Augmentations augs) throws XNIException { 1443 1444 fMixed = false; 1445 if(fDTDGrammar != null) 1447 fDTDGrammar.startGroup(augs); 1448 if (fDTDContentModelHandler != null) { 1449 fDTDContentModelHandler.startGroup(augs); 1450 } 1451 1452 } 1454 1466 public void pcdata(Augmentations augs) { 1467 fMixed = true; 1468 if(fDTDGrammar != null) 1469 fDTDGrammar.pcdata(augs); 1470 if (fDTDContentModelHandler != null) { 1471 fDTDContentModelHandler.pcdata(augs); 1472 } 1473 } 1475 1484 public void element(String elementName, Augmentations augs) throws XNIException { 1485 1486 if (fMixed && fValidation) { 1488 if (fMixedElementTypes.contains(elementName)) { 1489 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1490 "DuplicateTypeInMixedContent", 1491 new Object []{fDTDElementDeclName, elementName}, 1492 XMLErrorReporter.SEVERITY_ERROR); 1493 } 1494 else { 1495 fMixedElementTypes.addElement(elementName); 1496 } 1497 } 1498 1499 if(fDTDGrammar != null) 1501 fDTDGrammar.element(elementName, augs); 1502 if (fDTDContentModelHandler != null) { 1503 fDTDContentModelHandler.element(elementName, augs); 1504 } 1505 1506 } 1508 1521 public void separator(short separator, Augmentations augs) 1522 throws XNIException { 1523 1524 if(fDTDGrammar != null) 1526 fDTDGrammar.separator(separator, augs); 1527 if (fDTDContentModelHandler != null) { 1528 fDTDContentModelHandler.separator(separator, augs); 1529 } 1530 1531 } 1533 1548 public void occurrence(short occurrence, Augmentations augs) 1549 throws XNIException { 1550 1551 if(fDTDGrammar != null) 1553 fDTDGrammar.occurrence(occurrence, augs); 1554 if (fDTDContentModelHandler != null) { 1555 fDTDContentModelHandler.occurrence(occurrence, augs); 1556 } 1557 1558 } 1560 1568 public void endGroup(Augmentations augs) throws XNIException { 1569 1570 if(fDTDGrammar != null) 1572 fDTDGrammar.endGroup(augs); 1573 if (fDTDContentModelHandler != null) { 1574 fDTDContentModelHandler.endGroup(augs); 1575 } 1576 1577 } 1579 1587 public void endContentModel(Augmentations augs) throws XNIException { 1588 1589 if(fDTDGrammar != null) 1591 fDTDGrammar.endContentModel(augs); 1592 if (fDTDContentModelHandler != null) { 1593 fDTDContentModelHandler.endContentModel(augs); 1594 } 1595 1596 } 1598 1602 1609 private boolean normalizeDefaultAttrValue(XMLString value) { 1610 1611 boolean skipSpace = true; int current = value.offset; 1613 int end = value.offset + value.length; 1614 for (int i = value.offset; i < end; i++) { 1615 if (value.ch[i] == ' ') { 1616 if (!skipSpace) { 1617 value.ch[current++] = ' '; 1619 skipSpace = true; 1620 } 1621 else { 1622 } 1624 } 1625 else { 1626 if (current != i) { 1628 value.ch[current] = value.ch[i]; 1629 } 1630 current++; 1631 skipSpace = false; 1632 } 1633 } 1634 if (current != end) { 1635 if (skipSpace) { 1636 current--; 1638 } 1639 value.length = current - value.offset; 1641 return true; 1642 } 1643 return false; 1644 } 1645 1646 1647 protected boolean isValidNmtoken(String nmtoken) { 1648 return XMLChar.isValidNmtoken(nmtoken); 1649 } 1651 protected boolean isValidName(String name) { 1652 return XMLChar.isValidName(name); 1653 } } | Popular Tags |