1 57 58 package com.sun.org.apache.xerces.internal.impl.dtd; 59 60 import java.util.Enumeration ; 61 import java.util.Hashtable ; 62 import java.util.Locale ; 63 import java.util.StringTokenizer ; 64 import java.util.Vector ; 65 66 import com.sun.org.apache.xerces.internal.impl.Constants; 67 import com.sun.org.apache.xerces.internal.impl.XMLErrorReporter; 68 import com.sun.org.apache.xerces.internal.impl.msg.XMLMessageFormatter; 69 import com.sun.org.apache.xerces.internal.util.SymbolTable; 70 import com.sun.org.apache.xerces.internal.util.XMLChar; 71 import com.sun.org.apache.xerces.internal.util.XMLSymbols; 72 import com.sun.org.apache.xerces.internal.xni.Augmentations; 73 import com.sun.org.apache.xerces.internal.xni.XMLDTDContentModelHandler; 74 import com.sun.org.apache.xerces.internal.xni.XMLDTDHandler; 75 import com.sun.org.apache.xerces.internal.xni.XMLLocator; 76 import com.sun.org.apache.xerces.internal.xni.XMLResourceIdentifier; 77 import com.sun.org.apache.xerces.internal.xni.XMLString; 78 import com.sun.org.apache.xerces.internal.xni.XNIException; 79 import com.sun.org.apache.xerces.internal.xni.grammars.Grammar; 80 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarDescription; 81 import com.sun.org.apache.xerces.internal.xni.grammars.XMLGrammarPool; 82 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponent; 83 import com.sun.org.apache.xerces.internal.xni.parser.XMLComponentManager; 84 import com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException; 85 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDContentModelFilter; 86 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDContentModelSource; 87 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDFilter; 88 import com.sun.org.apache.xerces.internal.xni.parser.XMLDTDSource; 89 90 111 public class XMLDTDProcessor 112 implements XMLComponent, XMLDTDFilter, XMLDTDContentModelFilter { 113 114 118 119 private static final int TOP_LEVEL_SCOPE = -1; 120 121 123 124 protected static final String VALIDATION = 125 Constants.SAX_FEATURE_PREFIX + Constants.VALIDATION_FEATURE; 126 127 128 protected static final String NOTIFY_CHAR_REFS = 129 Constants.XERCES_FEATURE_PREFIX + Constants.NOTIFY_CHAR_REFS_FEATURE; 130 131 132 protected static final String WARN_ON_DUPLICATE_ATTDEF = 133 Constants.XERCES_FEATURE_PREFIX +Constants.WARN_ON_DUPLICATE_ATTDEF_FEATURE; 134 135 protected static final String PARSER_SETTINGS = 136 Constants.XERCES_FEATURE_PREFIX + Constants.PARSER_SETTINGS; 137 138 140 141 protected static final String SYMBOL_TABLE = 142 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY; 143 144 145 protected static final String ERROR_REPORTER = 146 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY; 147 148 149 protected static final String GRAMMAR_POOL = 150 Constants.XERCES_PROPERTY_PREFIX + Constants.XMLGRAMMAR_POOL_PROPERTY; 151 152 153 protected static final String DTD_VALIDATOR = 154 Constants.XERCES_PROPERTY_PREFIX + Constants.DTD_VALIDATOR_PROPERTY; 155 156 158 159 private static final String [] RECOGNIZED_FEATURES = { 160 VALIDATION, 161 WARN_ON_DUPLICATE_ATTDEF, 162 NOTIFY_CHAR_REFS, 163 }; 164 165 166 private static final Boolean [] FEATURE_DEFAULTS = { 167 null, 168 Boolean.FALSE, 169 null, 170 }; 171 172 173 private static final String [] RECOGNIZED_PROPERTIES = { 174 SYMBOL_TABLE, 175 ERROR_REPORTER, 176 GRAMMAR_POOL, 177 DTD_VALIDATOR, 178 }; 179 180 181 private static final Object [] PROPERTY_DEFAULTS = { 182 null, 183 null, 184 null, 185 null, 186 }; 187 188 190 194 196 197 protected boolean fValidation; 198 199 200 protected boolean fDTDValidation; 201 202 203 protected boolean fWarnDuplicateAttdef; 204 205 207 208 protected SymbolTable fSymbolTable; 209 210 211 protected XMLErrorReporter fErrorReporter; 212 213 214 protected DTDGrammarBucket fGrammarBucket; 215 216 protected XMLDTDValidator fValidator; 220 221 protected XMLGrammarPool fGrammarPool; 223 224 protected Locale fLocale; 226 227 229 230 protected XMLDTDHandler fDTDHandler; 231 232 233 protected XMLDTDSource fDTDSource; 234 235 236 protected XMLDTDContentModelHandler fDTDContentModelHandler; 237 238 239 protected XMLDTDContentModelSource fDTDContentModelSource; 240 241 243 244 protected DTDGrammar fDTDGrammar; 245 246 248 249 private boolean fPerformValidation; 250 251 252 protected boolean fInDTDIgnore; 253 254 256 258 259 private boolean fMixed; 260 261 263 264 private XMLEntityDecl fEntityDecl = new XMLEntityDecl(); 265 266 267 private Hashtable fNDataDeclNotations = new Hashtable (); 268 269 270 private String fDTDElementDeclName = null; 271 272 273 private Vector fMixedElementTypes = new Vector (); 274 275 276 private Vector fDTDElementDecls = new Vector (); 277 278 281 282 private Hashtable fTableOfIDAttributeNames; 283 284 285 private Hashtable fTableOfNOTATIONAttributeNames; 286 287 288 private Hashtable fNotationEnumVals; 289 290 294 295 public XMLDTDProcessor() { 296 297 299 } 301 305 319 public void reset(XMLComponentManager componentManager) throws XMLConfigurationException { 320 321 boolean parser_settings; 322 try { 323 parser_settings = componentManager.getFeature(PARSER_SETTINGS); 324 } catch (XMLConfigurationException e) { 325 parser_settings = true; 326 } 327 328 if (!parser_settings) { 329 reset(); 331 return; 332 } 333 334 try { 336 fValidation = componentManager.getFeature(VALIDATION); 337 } catch (XMLConfigurationException e) { 338 fValidation = false; 339 } 340 try { 341 fDTDValidation = 342 !(componentManager 343 .getFeature( 344 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE)); 345 } catch (XMLConfigurationException e) { 346 fDTDValidation = true; 348 } 349 350 352 try { 353 fWarnDuplicateAttdef = componentManager.getFeature(WARN_ON_DUPLICATE_ATTDEF); 354 } catch (XMLConfigurationException e) { 355 fWarnDuplicateAttdef = false; 356 } 357 358 fErrorReporter = 360 (XMLErrorReporter) componentManager.getProperty( 361 Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY); 362 fSymbolTable = 363 (SymbolTable) componentManager.getProperty( 364 Constants.XERCES_PROPERTY_PREFIX + Constants.SYMBOL_TABLE_PROPERTY); 365 try { 366 fGrammarPool = (XMLGrammarPool) componentManager.getProperty(GRAMMAR_POOL); 367 } catch (XMLConfigurationException e) { 368 fGrammarPool = null; 369 } 370 try { 371 fValidator = (XMLDTDValidator) componentManager.getProperty(DTD_VALIDATOR); 372 } catch (XMLConfigurationException e) { 373 fValidator = null; 374 } catch (ClassCastException e) { 375 fValidator = null; 376 } 377 if (fValidator != null) { 379 fGrammarBucket = fValidator.getGrammarBucket(); 380 } else { 381 fGrammarBucket = null; 382 } 383 reset(); 384 385 } 387 protected void reset() { 388 fDTDGrammar = null; 390 fInDTDIgnore = false; 392 393 fNDataDeclNotations.clear(); 394 395 if (fValidation) { 397 398 if (fNotationEnumVals == null) { 399 fNotationEnumVals = new Hashtable (); 400 } 401 fNotationEnumVals.clear(); 402 403 fTableOfIDAttributeNames = new Hashtable (); 404 fTableOfNOTATIONAttributeNames = new Hashtable (); 405 } 406 407 } 408 413 public String [] getRecognizedFeatures() { 414 return (String [])(RECOGNIZED_FEATURES.clone()); 415 } 417 432 public void setFeature(String featureId, boolean state) 433 throws XMLConfigurationException { 434 } 436 441 public String [] getRecognizedProperties() { 442 return (String [])(RECOGNIZED_PROPERTIES.clone()); 443 } 445 460 public void setProperty(String propertyId, Object value) 461 throws XMLConfigurationException { 462 } 464 473 public Boolean getFeatureDefault(String featureId) { 474 for (int i = 0; i < RECOGNIZED_FEATURES.length; i++) { 475 if (RECOGNIZED_FEATURES[i].equals(featureId)) { 476 return FEATURE_DEFAULTS[i]; 477 } 478 } 479 return null; 480 } 482 491 public Object getPropertyDefault(String propertyId) { 492 for (int i = 0; i < RECOGNIZED_PROPERTIES.length; i++) { 493 if (RECOGNIZED_PROPERTIES[i].equals(propertyId)) { 494 return PROPERTY_DEFAULTS[i]; 495 } 496 } 497 return null; 498 } 500 504 509 public void setDTDHandler(XMLDTDHandler dtdHandler) { 510 fDTDHandler = dtdHandler; 511 } 513 518 public XMLDTDHandler getDTDHandler() { 519 return fDTDHandler; 520 } 522 526 531 public void setDTDContentModelHandler(XMLDTDContentModelHandler dtdContentModelHandler) { 532 fDTDContentModelHandler = dtdContentModelHandler; 533 } 535 540 public XMLDTDContentModelHandler getDTDContentModelHandler() { 541 return fDTDContentModelHandler; 542 } 544 548 556 public void startExternalSubset(XMLResourceIdentifier identifier, 557 Augmentations augs) throws XNIException { 558 if(fDTDGrammar != null) 559 fDTDGrammar.startExternalSubset(identifier, augs); 560 if(fDTDHandler != null){ 561 fDTDHandler.startExternalSubset(identifier, augs); 562 } 563 } 564 565 573 public void endExternalSubset(Augmentations augs) throws XNIException { 574 if(fDTDGrammar != null) 575 fDTDGrammar.endExternalSubset(augs); 576 if(fDTDHandler != null){ 577 fDTDHandler.endExternalSubset(augs); 578 } 579 } 580 581 592 protected static void checkStandaloneEntityRef(String name, DTDGrammar grammar, 593 XMLEntityDecl tempEntityDecl, XMLErrorReporter errorReporter) throws XNIException { 594 int entIndex = grammar.getEntityDeclIndex(name); 596 if (entIndex > -1) { 597 grammar.getEntityDecl(entIndex, tempEntityDecl); 598 if (tempEntityDecl.inExternal) { 599 errorReporter.reportError( XMLMessageFormatter.XML_DOMAIN, 600 "MSG_REFERENCE_TO_EXTERNALLY_DECLARED_ENTITY_WHEN_STANDALONE", 601 new Object []{name}, XMLErrorReporter.SEVERITY_ERROR); 602 } 603 } 604 } 605 606 614 public void comment(XMLString text, Augmentations augs) throws XNIException { 615 616 if(fDTDGrammar != null) 618 fDTDGrammar.comment(text, augs); 619 if (fDTDHandler != null) { 620 fDTDHandler.comment(text, augs); 621 } 622 623 } 625 626 643 public void processingInstruction(String target, XMLString data, Augmentations augs) 644 throws XNIException { 645 646 if(fDTDGrammar != null) 648 fDTDGrammar.processingInstruction(target, data, augs); 649 if (fDTDHandler != null) { 650 fDTDHandler.processingInstruction(target, data, augs); 651 } 652 } 654 658 672 public void startDTD(XMLLocator locator, Augmentations augs) throws XNIException { 673 674 675 fNDataDeclNotations.clear(); 677 fDTDElementDecls.removeAllElements(); 678 679 if( !fGrammarBucket.getActiveGrammar().isImmutable()) { 684 fDTDGrammar = fGrammarBucket.getActiveGrammar(); 685 } 686 687 if(fDTDGrammar != null ) 689 fDTDGrammar.startDTD(locator, augs); 690 if (fDTDHandler != null) { 691 fDTDHandler.startDTD(locator, augs); 692 } 693 694 } 696 705 public void ignoredCharacters(XMLString text, Augmentations augs) throws XNIException { 706 707 if(fDTDGrammar != null ) 709 fDTDGrammar.ignoredCharacters(text, augs); 710 if (fDTDHandler != null) { 711 fDTDHandler.ignoredCharacters(text, augs); 712 } 713 } 714 715 729 public void textDecl(String version, String encoding, Augmentations augs) throws XNIException { 730 731 if(fDTDGrammar != null ) 733 fDTDGrammar.textDecl(version, encoding, augs); 734 if (fDTDHandler != null) { 735 fDTDHandler.textDecl(version, encoding, augs); 736 } 737 } 738 739 754 public void startParameterEntity(String name, 755 XMLResourceIdentifier identifier, 756 String encoding, 757 Augmentations augs) throws XNIException { 758 759 if (fPerformValidation && fDTDGrammar != null && 760 fGrammarBucket.getStandalone()) { 761 checkStandaloneEntityRef(name, fDTDGrammar, fEntityDecl, fErrorReporter); 762 } 763 if(fDTDGrammar != null ) 765 fDTDGrammar.startParameterEntity(name, identifier, encoding, augs); 766 if (fDTDHandler != null) { 767 fDTDHandler.startParameterEntity(name, identifier, encoding, augs); 768 } 769 } 770 771 781 public void endParameterEntity(String name, Augmentations augs) throws XNIException { 782 783 if(fDTDGrammar != null ) 785 fDTDGrammar.endParameterEntity(name, augs); 786 if (fDTDHandler != null) { 787 fDTDHandler.endParameterEntity(name, augs); 788 } 789 } 790 791 801 public void elementDecl(String name, String contentModel, Augmentations augs) 802 throws XNIException { 803 804 if (fValidation) { 806 if (fDTDElementDecls.contains(name)) { 807 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 808 "MSG_ELEMENT_ALREADY_DECLARED", 809 new Object []{ name}, 810 XMLErrorReporter.SEVERITY_ERROR); 811 } 812 else { 813 fDTDElementDecls.addElement(name); 814 } 815 } 816 817 if(fDTDGrammar != null ) 819 fDTDGrammar.elementDecl(name, contentModel, augs); 820 if (fDTDHandler != null) { 821 fDTDHandler.elementDecl(name, contentModel, augs); 822 } 823 824 } 826 836 public void startAttlist(String elementName, Augmentations augs) 837 throws XNIException { 838 839 if(fDTDGrammar != null ) 841 fDTDGrammar.startAttlist(elementName, augs); 842 if (fDTDHandler != null) { 843 fDTDHandler.startAttlist(elementName, augs); 844 } 845 846 } 848 873 public void attributeDecl(String elementName, String attributeName, 874 String type, String [] enumeration, 875 String defaultType, XMLString defaultValue, 876 XMLString nonNormalizedDefaultValue, Augmentations augs) throws XNIException { 877 878 if (type != XMLSymbols.fCDATASymbol && defaultValue != null) { 879 normalizeDefaultAttrValue(defaultValue); 880 } 881 882 if (fValidation) { 883 884 boolean duplicateAttributeDef = false ; 885 886 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar:fGrammarBucket.getActiveGrammar()); 888 int elementIndex = grammar.getElementDeclIndex( elementName); 889 if (grammar.getAttributeDeclIndex(elementIndex, attributeName) != -1) { 890 duplicateAttributeDef = true ; 892 893 if(fWarnDuplicateAttdef){ 895 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 896 "MSG_DUPLICATE_ATTRIBUTE_DEFINITION", 897 new Object []{ elementName, attributeName }, 898 XMLErrorReporter.SEVERITY_WARNING ); 899 } 900 } 901 902 903 if (type == XMLSymbols.fIDSymbol) { 908 if (defaultValue != null && defaultValue.length != 0) { 909 if (defaultType == null || 910 !(defaultType == XMLSymbols.fIMPLIEDSymbol || 911 defaultType == XMLSymbols.fREQUIREDSymbol)) { 912 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 913 "IDDefaultTypeInvalid", 914 new Object []{ attributeName}, 915 XMLErrorReporter.SEVERITY_ERROR); 916 } 917 } 918 919 if (!fTableOfIDAttributeNames.containsKey(elementName)) { 920 fTableOfIDAttributeNames.put(elementName, attributeName); 921 } 922 else { 923 935 if(!duplicateAttributeDef){ 936 String previousIDAttributeName = (String )fTableOfIDAttributeNames.get( elementName ); fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 938 "MSG_MORE_THAN_ONE_ID_ATTRIBUTE", 939 new Object []{ elementName, previousIDAttributeName, attributeName}, 940 XMLErrorReporter.SEVERITY_ERROR); 941 } 942 } 943 } 944 945 949 if (type == XMLSymbols.fNOTATIONSymbol) { 950 for (int i=0; i<enumeration.length; i++) { 953 fNotationEnumVals.put(enumeration[i], attributeName); 954 } 955 956 if (fTableOfNOTATIONAttributeNames.containsKey( elementName ) == false) { 957 fTableOfNOTATIONAttributeNames.put( elementName, attributeName); 958 } 959 else { 960 967 if(!duplicateAttributeDef){ 968 969 String previousNOTATIONAttributeName = (String ) fTableOfNOTATIONAttributeNames.get( elementName ); 970 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 971 "MSG_MORE_THAN_ONE_NOTATION_ATTRIBUTE", 972 new Object []{ elementName, previousNOTATIONAttributeName, attributeName}, 973 XMLErrorReporter.SEVERITY_ERROR); 974 } 975 } 976 } 977 978 if (type == XMLSymbols.fENUMERATIONSymbol || type == XMLSymbols.fNOTATIONSymbol) { 981 outer: 982 for (int i = 0; i < enumeration.length; ++i) { 983 for (int j = i + 1; j < enumeration.length; ++j) { 984 if (enumeration[i].equals(enumeration[j])) { 985 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 989 type == XMLSymbols.fENUMERATIONSymbol 990 ? "MSG_DISTINCT_TOKENS_IN_ENUMERATION" 991 : "MSG_DISTINCT_NOTATION_IN_ENUMERATION", 992 new Object []{ elementName, enumeration[i], attributeName }, 993 XMLErrorReporter.SEVERITY_ERROR); 994 break outer; 995 } 996 } 997 } 998 } 999 1000 boolean ok = true; 1002 if (defaultValue != null && 1003 (defaultType == null || 1004 (defaultType != null && defaultType == XMLSymbols.fFIXEDSymbol))) { 1005 1006 String value = defaultValue.toString(); 1007 if (type == XMLSymbols.fNMTOKENSSymbol || 1008 type == XMLSymbols.fENTITIESSymbol || 1009 type == XMLSymbols.fIDREFSSymbol) { 1010 1011 StringTokenizer tokenizer = new StringTokenizer (value," "); 1012 if (tokenizer.hasMoreTokens()) { 1013 while (true) { 1014 String nmtoken = tokenizer.nextToken(); 1015 if (type == XMLSymbols.fNMTOKENSSymbol) { 1016 if (!isValidNmtoken(nmtoken)) { 1017 ok = false; 1018 break; 1019 } 1020 } 1021 else if (type == XMLSymbols.fENTITIESSymbol || 1022 type == XMLSymbols.fIDREFSSymbol) { 1023 if (!isValidName(nmtoken)) { 1024 ok = false; 1025 break; 1026 } 1027 } 1028 if (!tokenizer.hasMoreTokens()) { 1029 break; 1030 } 1031 } 1032 } 1033 1034 } 1035 else { 1036 if (type == XMLSymbols.fENTITYSymbol || 1037 type == XMLSymbols.fIDSymbol || 1038 type == XMLSymbols.fIDREFSymbol || 1039 type == XMLSymbols.fNOTATIONSymbol) { 1040 1041 if (!isValidName(value)) { 1042 ok = false; 1043 } 1044 1045 } 1046 else if (type == XMLSymbols.fNMTOKENSymbol || 1047 type == XMLSymbols.fENUMERATIONSymbol) { 1048 1049 if (!isValidNmtoken(value)) { 1050 ok = false; 1051 } 1052 } 1053 1054 if (type == XMLSymbols.fNOTATIONSymbol || 1055 type == XMLSymbols.fENUMERATIONSymbol) { 1056 ok = false; 1057 for (int i=0; i<enumeration.length; i++) { 1058 if (defaultValue.equals(enumeration[i])) { 1059 ok = true; 1060 } 1061 } 1062 } 1063 1064 } 1065 if (!ok) { 1066 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1067 "MSG_ATT_DEFAULT_INVALID", 1068 new Object []{attributeName, value}, 1069 XMLErrorReporter.SEVERITY_ERROR); 1070 } 1071 } 1072 } 1073 1074 if(fDTDGrammar != null) 1076 fDTDGrammar.attributeDecl(elementName, attributeName, 1077 type, enumeration, 1078 defaultType, defaultValue, nonNormalizedDefaultValue, augs); 1079 if (fDTDHandler != null) { 1080 fDTDHandler.attributeDecl(elementName, attributeName, 1081 type, enumeration, 1082 defaultType, defaultValue, nonNormalizedDefaultValue, augs); 1083 } 1084 1085 } 1087 1095 public void endAttlist(Augmentations augs) throws XNIException { 1096 1097 if(fDTDGrammar != null) 1099 fDTDGrammar.endAttlist(augs); 1100 if (fDTDHandler != null) { 1101 fDTDHandler.endAttlist(augs); 1102 } 1103 1104 } 1106 1122 public void internalEntityDecl(String name, XMLString text, 1123 XMLString nonNormalizedText, 1124 Augmentations augs) throws XNIException { 1125 1126 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar: fGrammarBucket.getActiveGrammar()); 1127 int index = grammar.getEntityDeclIndex(name) ; 1128 1129 1133 1136 if(index == -1){ 1138 if(fDTDGrammar != null) 1140 fDTDGrammar.internalEntityDecl(name, text, nonNormalizedText, augs); 1141 if (fDTDHandler != null) { 1143 fDTDHandler.internalEntityDecl(name, text, nonNormalizedText, augs); 1144 } 1145 } 1146 1147 } 1149 1150 1163 public void externalEntityDecl(String name, XMLResourceIdentifier identifier, 1164 Augmentations augs) throws XNIException { 1165 1166 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar: fGrammarBucket.getActiveGrammar()); 1167 int index = grammar.getEntityDeclIndex(name) ; 1168 1169 1173 1176 if(index == -1){ 1178 if(fDTDGrammar != null) 1180 fDTDGrammar.externalEntityDecl(name, identifier, augs); 1181 if (fDTDHandler != null) { 1183 fDTDHandler.externalEntityDecl(name, identifier, augs); 1184 } 1185 } 1186 1187 } 1189 1201 public void unparsedEntityDecl(String name, XMLResourceIdentifier identifier, 1202 String notation, 1203 Augmentations augs) throws XNIException { 1204 1205 if (fValidation) { 1207 fNDataDeclNotations.put(name, notation); 1208 } 1209 1210 if(fDTDGrammar != null) 1212 fDTDGrammar.unparsedEntityDecl(name, identifier, notation, augs); 1213 if (fDTDHandler != null) { 1214 fDTDHandler.unparsedEntityDecl(name, identifier, notation, augs); 1215 } 1216 1217 } 1219 1230 public void notationDecl(String name, XMLResourceIdentifier identifier, 1231 Augmentations augs) throws XNIException { 1232 1233 if (fValidation) { 1235 DTDGrammar grammar = (fDTDGrammar != null ? fDTDGrammar : fGrammarBucket.getActiveGrammar()); 1236 if (grammar.getNotationDeclIndex(name) != -1) { 1237 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1238 "UniqueNotationName", 1239 new Object []{name}, 1240 XMLErrorReporter.SEVERITY_ERROR); 1241 } 1242 } 1243 1244 if(fDTDGrammar != null) 1246 fDTDGrammar.notationDecl(name, identifier, augs); 1247 if (fDTDHandler != null) { 1248 fDTDHandler.notationDecl(name, identifier, augs); 1249 } 1250 1251 } 1253 1266 public void startConditional(short type, Augmentations augs) throws XNIException { 1267 1268 fInDTDIgnore = type == XMLDTDHandler.CONDITIONAL_IGNORE; 1270 1271 if(fDTDGrammar != null) 1273 fDTDGrammar.startConditional(type, augs); 1274 if (fDTDHandler != null) { 1275 fDTDHandler.startConditional(type, augs); 1276 } 1277 1278 } 1280 1288 public void endConditional(Augmentations augs) throws XNIException { 1289 1290 fInDTDIgnore = false; 1292 1293 if(fDTDGrammar != null) 1295 fDTDGrammar.endConditional(augs); 1296 if (fDTDHandler != null) { 1297 fDTDHandler.endConditional(augs); 1298 } 1299 1300 } 1302 1310 public void endDTD(Augmentations augs) throws XNIException { 1311 1312 1313 if(fDTDGrammar != null) { 1315 fDTDGrammar.endDTD(augs); 1316 if(fGrammarPool != null) 1317 fGrammarPool.cacheGrammars(XMLGrammarDescription.XML_DTD, new Grammar[] {fDTDGrammar}); 1318 } 1319 if (fValidation) { 1321 DTDGrammar grammar = (fDTDGrammar != null? fDTDGrammar: fGrammarBucket.getActiveGrammar()); 1322 1323 Enumeration entities = fNDataDeclNotations.keys(); 1325 while (entities.hasMoreElements()) { 1326 String entity = (String ) entities.nextElement(); 1327 String notation = (String ) fNDataDeclNotations.get(entity); 1328 if (grammar.getNotationDeclIndex(notation) == -1) { 1329 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1330 "MSG_NOTATION_NOT_DECLARED_FOR_UNPARSED_ENTITYDECL", 1331 new Object []{entity, notation}, 1332 XMLErrorReporter.SEVERITY_ERROR); 1333 } 1334 } 1335 1336 Enumeration notationVals = fNotationEnumVals.keys(); 1339 while (notationVals.hasMoreElements()) { 1340 String notation = (String ) notationVals.nextElement(); 1341 String attributeName = (String ) fNotationEnumVals.get(notation); 1342 if (grammar.getNotationDeclIndex(notation) == -1) { 1343 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1344 "MSG_NOTATION_NOT_DECLARED_FOR_NOTATIONTYPE_ATTRIBUTE", 1345 new Object []{attributeName, notation}, 1346 XMLErrorReporter.SEVERITY_ERROR); 1347 } 1348 } 1349 1350 Enumeration elementsWithNotations = fTableOfNOTATIONAttributeNames.keys(); 1353 while (elementsWithNotations.hasMoreElements()) { 1354 String elementName = (String ) elementsWithNotations.nextElement(); 1355 int elementIndex = grammar.getElementDeclIndex(elementName); 1356 if (grammar.getContentSpecType(elementIndex) == XMLElementDecl.TYPE_EMPTY) { 1357 String attributeName = (String ) fTableOfNOTATIONAttributeNames.get(elementName); 1358 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1359 "NoNotationOnEmptyElement", 1360 new Object []{elementName, attributeName}, 1361 XMLErrorReporter.SEVERITY_ERROR); 1362 } 1363 } 1364 1365 fTableOfIDAttributeNames = null; fTableOfNOTATIONAttributeNames = null; 1367 } 1368 1369 if (fDTDHandler != null) { 1371 fDTDHandler.endDTD(augs); 1372 } 1373 1374 } 1376 public void setDTDSource(XMLDTDSource source ) { 1378 fDTDSource = source; 1379 } 1381 public XMLDTDSource getDTDSource() { 1383 return fDTDSource; 1384 } 1386 1390 public void setDTDContentModelSource(XMLDTDContentModelSource source ) { 1392 fDTDContentModelSource = source; 1393 } 1395 public XMLDTDContentModelSource getDTDContentModelSource() { 1397 return fDTDContentModelSource; 1398 } 1400 1401 1412 public void startContentModel(String elementName, Augmentations augs) 1413 throws XNIException { 1414 1415 if (fValidation) { 1416 fDTDElementDeclName = elementName; 1417 fMixedElementTypes.removeAllElements(); 1418 } 1419 1420 if(fDTDGrammar != null) 1422 fDTDGrammar.startContentModel(elementName, augs); 1423 if (fDTDContentModelHandler != null) { 1424 fDTDContentModelHandler.startContentModel(elementName, augs); 1425 } 1426 1427 } 1429 1440 public void any(Augmentations augs) throws XNIException { 1441 if(fDTDGrammar != null) 1442 fDTDGrammar.any(augs); 1443 if (fDTDContentModelHandler != null) { 1444 fDTDContentModelHandler.any(augs); 1445 } 1446 } 1448 1459 public void empty(Augmentations augs) throws XNIException { 1460 if(fDTDGrammar != null) 1461 fDTDGrammar.empty(augs); 1462 if (fDTDContentModelHandler != null) { 1463 fDTDContentModelHandler.empty(augs); 1464 } 1465 } 1467 1481 public void startGroup(Augmentations augs) throws XNIException { 1482 1483 fMixed = false; 1484 if(fDTDGrammar != null) 1486 fDTDGrammar.startGroup(augs); 1487 if (fDTDContentModelHandler != null) { 1488 fDTDContentModelHandler.startGroup(augs); 1489 } 1490 1491 } 1493 1505 public void pcdata(Augmentations augs) { 1506 fMixed = true; 1507 if(fDTDGrammar != null) 1508 fDTDGrammar.pcdata(augs); 1509 if (fDTDContentModelHandler != null) { 1510 fDTDContentModelHandler.pcdata(augs); 1511 } 1512 } 1514 1523 public void element(String elementName, Augmentations augs) throws XNIException { 1524 1525 if (fMixed && fValidation) { 1527 if (fMixedElementTypes.contains(elementName)) { 1528 fErrorReporter.reportError(XMLMessageFormatter.XML_DOMAIN, 1529 "DuplicateTypeInMixedContent", 1530 new Object []{fDTDElementDeclName, elementName}, 1531 XMLErrorReporter.SEVERITY_ERROR); 1532 } 1533 else { 1534 fMixedElementTypes.addElement(elementName); 1535 } 1536 } 1537 1538 if(fDTDGrammar != null) 1540 fDTDGrammar.element(elementName, augs); 1541 if (fDTDContentModelHandler != null) { 1542 fDTDContentModelHandler.element(elementName, augs); 1543 } 1544 1545 } 1547 1560 public void separator(short separator, Augmentations augs) 1561 throws XNIException { 1562 1563 if(fDTDGrammar != null) 1565 fDTDGrammar.separator(separator, augs); 1566 if (fDTDContentModelHandler != null) { 1567 fDTDContentModelHandler.separator(separator, augs); 1568 } 1569 1570 } 1572 1587 public void occurrence(short occurrence, Augmentations augs) 1588 throws XNIException { 1589 1590 if(fDTDGrammar != null) 1592 fDTDGrammar.occurrence(occurrence, augs); 1593 if (fDTDContentModelHandler != null) { 1594 fDTDContentModelHandler.occurrence(occurrence, augs); 1595 } 1596 1597 } 1599 1607 public void endGroup(Augmentations augs) throws XNIException { 1608 1609 if(fDTDGrammar != null) 1611 fDTDGrammar.endGroup(augs); 1612 if (fDTDContentModelHandler != null) { 1613 fDTDContentModelHandler.endGroup(augs); 1614 } 1615 1616 } 1618 1626 public void endContentModel(Augmentations augs) throws XNIException { 1627 1628 if(fDTDGrammar != null) 1630 fDTDGrammar.endContentModel(augs); 1631 if (fDTDContentModelHandler != null) { 1632 fDTDContentModelHandler.endContentModel(augs); 1633 } 1634 1635 } 1637 1641 1648 private boolean normalizeDefaultAttrValue(XMLString value) { 1649 1650 int oldLength = value.length; 1651 1652 boolean skipSpace = true; int current = value.offset; 1654 int end = value.offset + value.length; 1655 for (int i = value.offset; i < end; i++) { 1656 if (value.ch[i] == ' ') { 1657 if (!skipSpace) { 1658 value.ch[current++] = ' '; 1660 skipSpace = true; 1661 } 1662 else { 1663 } 1665 } 1666 else { 1667 if (current != i) { 1669 value.ch[current] = value.ch[i]; 1670 } 1671 current++; 1672 skipSpace = false; 1673 } 1674 } 1675 if (current != end) { 1676 if (skipSpace) { 1677 current--; 1679 } 1680 value.length = current - value.offset; 1682 return true; 1683 } 1684 return false; 1685 } 1686 1687 1688 protected boolean isValidNmtoken(String nmtoken) { 1689 return XMLChar.isValidNmtoken(nmtoken); 1690 } 1692 protected boolean isValidName(String name) { 1693 return XMLChar.isValidName(name); 1694 } } | Popular Tags |