1 57 58 package org.enhydra.apache.xerces.framework; 59 60 import java.io.IOException ; 61 import java.io.InputStream ; 62 import java.io.Reader ; 63 import java.util.Locale ; 64 65 import org.enhydra.apache.xerces.readers.DefaultEntityHandler; 66 import org.enhydra.apache.xerces.readers.XMLDeclRecognizer; 67 import org.enhydra.apache.xerces.readers.XMLEntityReaderFactory; 68 import org.enhydra.apache.xerces.utils.ChunkyCharArray; 69 import org.enhydra.apache.xerces.utils.ImplementationMessages; 70 import org.enhydra.apache.xerces.utils.StringPool; 71 import org.enhydra.apache.xerces.utils.XMLMessageProvider; 72 import org.enhydra.apache.xerces.utils.XMLMessages; 73 import org.enhydra.apache.xerces.validators.common.GrammarResolver; 74 import org.enhydra.apache.xerces.validators.common.GrammarResolverImpl; 75 import org.enhydra.apache.xerces.validators.common.XMLValidator; 76 import org.enhydra.apache.xerces.validators.datatype.DatatypeMessageProvider; 77 import org.enhydra.apache.xerces.validators.schema.SchemaMessageProvider; 78 import org.xml.sax.EntityResolver ; 79 import org.xml.sax.ErrorHandler ; 80 import org.xml.sax.InputSource ; 81 import org.xml.sax.Locator ; 82 import org.xml.sax.SAXException ; 83 import org.xml.sax.SAXNotRecognizedException ; 84 import org.xml.sax.SAXNotSupportedException ; 85 import org.xml.sax.SAXParseException ; 86 87 92 public abstract class XMLParser 93 implements XMLErrorReporter, XMLDocumentHandler.DTDHandler { 94 95 99 101 102 protected static final String SAX2_FEATURES_PREFIX = "http://xml.org/sax/features/"; 103 104 105 protected static final String SAX2_PROPERTIES_PREFIX = "http://xml.org/sax/properties/"; 106 107 108 protected static final String XERCES_FEATURES_PREFIX = "http://apache.org/xml/features/"; 109 110 111 protected static final String XERCES_PROPERTIES_PREFIX = "http://apache.org/xml/properties/"; 112 113 115 116 private static final String RECOGNIZED_FEATURES[] = { 117 "http://xml.org/sax/features/validation", 119 "http://xml.org/sax/features/external-general-entities", 120 "http://xml.org/sax/features/external-parameter-entities", 121 "http://xml.org/sax/features/namespaces", 122 "http://apache.org/xml/features/validation/schema", 124 "http://apache.org/xml/features/validation/schema-full-checking", 126 "http://apache.org/xml/features/validation/dynamic", 127 "http://apache.org/xml/features/validation/default-attribute-values", 128 129 "http://apache.org/xml/features/validation/validate-content-models", 130 "http://apache.org/xml/features/validation/validate-datatypes", 131 "http://apache.org/xml/features/validation/warn-on-duplicate-attdef", 132 "http://apache.org/xml/features/validation/warn-on-undeclared-elemdef", 133 "http://apache.org/xml/features/allow-java-encodings", 134 "http://apache.org/xml/features/continue-after-fatal-error", 135 "http://apache.org/xml/features/nonvalidating/load-dtd-grammar", 136 "http://apache.org/xml/features/nonvalidating/load-external-dtd" 137 }; 138 139 140 private static final String RECOGNIZED_PROPERTIES[] = { 141 "http://xml.org/sax/properties/xml-string", 143 "http://apache.org/xml/properties/schema/external-schemaLocation", 145 "http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation" 146 }; 147 148 150 151 private static final boolean PRINT_EXCEPTION_STACK_TRACE = false; 152 153 157 protected GrammarResolver fGrammarResolver = null; 158 159 161 protected boolean fParseInProgress = false; 162 private boolean fNeedReset = false; 163 164 166 167 private boolean fContinueAfterFatalError = false; 168 169 171 172 private ErrorHandler fErrorHandler = null; 173 174 176 private Locale fLocale = null; 177 178 180 private static XMLMessageProvider fgXMLMessages = new XMLMessages(); 181 private static XMLMessageProvider fgImplementationMessages = new ImplementationMessages(); 182 private static XMLMessageProvider fgSchemaMessages = new SchemaMessageProvider(); 183 private static XMLMessageProvider fgDatatypeMessages= new DatatypeMessageProvider(); 184 185 protected StringPool fStringPool = null; 189 protected XMLErrorReporter fErrorReporter = null; 190 protected DefaultEntityHandler fEntityHandler = null; 191 protected XMLDocumentScanner fScanner = null; 192 protected XMLValidator fValidator = null; 193 194 198 201 protected XMLParser() { 202 this(new StringPool()); 203 } 204 205 protected XMLParser(StringPool stringPool) { 206 fStringPool = stringPool; 207 fErrorReporter = this; 208 fEntityHandler = new DefaultEntityHandler(fStringPool, fErrorReporter); 209 fScanner = new XMLDocumentScanner(fStringPool, fErrorReporter, fEntityHandler, new ChunkyCharArray(fStringPool)); 210 fValidator = new XMLValidator(fStringPool, fErrorReporter, fEntityHandler, fScanner); 211 fGrammarResolver = new GrammarResolverImpl(); 212 fScanner.setGrammarResolver(fGrammarResolver); 213 fValidator.setGrammarResolver(fGrammarResolver); 214 try { 215 setNamespaces(true); 217 } 218 catch (Exception e) { 219 } 221 } 222 223 226 protected void initHandlers(boolean sendCharDataAsCharArray, 227 XMLDocumentHandler docHandler, 228 XMLDocumentHandler.DTDHandler dtdHandler) 229 { 230 fValidator.initHandlers(sendCharDataAsCharArray, docHandler, dtdHandler); 231 fScanner.setDTDHandler(this); 232 } 233 234 238 240 249 public String [] getFeaturesRecognized() { 250 return RECOGNIZED_FEATURES; 251 } 252 253 260 public boolean isFeatureRecognized(String featureId) { 261 String [] recognizedFeatures = getFeaturesRecognized(); 262 for (int i = 0; i < recognizedFeatures.length; i++) { 263 if (featureId.equals(recognizedFeatures[i])) 264 return true; 265 } 266 return false; 267 } 268 269 278 public String [] getPropertiesRecognized() { 279 return RECOGNIZED_PROPERTIES; 280 } 281 282 289 public boolean isPropertyRecognized(String propertyId) { 290 String [] recognizedProperties = getPropertiesRecognized(); 291 for (int i = 0; i < recognizedProperties.length; i++) { 292 if (propertyId.equals(recognizedProperties[i])) 293 return true; 294 } 295 return false; 296 } 297 298 300 306 public boolean parseSomeSetup(InputSource source) throws Exception { 307 if (fNeedReset) 308 resetOrCopy(); 309 fParseInProgress = true; 310 fNeedReset = true; 311 return fEntityHandler.startReadingFromDocument(source); 312 } 313 314 319 public boolean parseSome() throws Exception { 320 if (!fScanner.parseSome(false)) { 321 fParseInProgress = false; 322 return false; 323 } 324 return true; 325 } 326 327 329 330 public void reset() throws Exception { 331 fGrammarResolver.clearGrammarResolver(); 332 fStringPool.reset(); 333 fEntityHandler.reset(fStringPool); 334 fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool)); 335 fValidator.reset(fStringPool); 336 fNeedReset = false; 337 } 338 339 341 346 public final Locator getLocator() { 347 return fEntityHandler; 348 } 349 350 351 356 public final Locale getfLocale() { 357 return fLocale; 358 } 359 360 365 public final XMLMessageProvider getfgXMLMessages() { 366 return fgXMLMessages; 367 } 368 369 374 public final XMLMessageProvider getfgImplementationMessages() { 375 return fgImplementationMessages; 376 } 377 378 383 public final XMLMessageProvider getfgSchemaMessages() { 384 return fgSchemaMessages; 385 } 386 387 392 public final XMLMessageProvider getfgDatatypeMessages() { 393 return fgDatatypeMessages; 394 } 395 396 399 public void setReaderFactory(XMLEntityReaderFactory readerFactory) { 400 fEntityHandler.setReaderFactory(readerFactory); 401 } 402 403 408 public void addRecognizer(XMLDeclRecognizer recognizer) { 409 fEntityHandler.addRecognizer(recognizer); 410 } 411 412 416 418 431 protected void setValidation(boolean validate) 432 throws SAXNotRecognizedException , SAXNotSupportedException { 433 if (fParseInProgress) { 434 throw new SAXNotSupportedException ("PAR004 Cannot setFeature(http://xml.org/sax/features/validation): parse is in progress.\n"+ 435 "http://xml.org/sax/features/validation"); 436 } 437 try { 438 fScanner.setValidationEnabled(validate); 441 fValidator.setValidationEnabled(validate); 442 } 443 catch (Exception ex) { 444 throw new SAXNotSupportedException (ex.getMessage()); 445 } 446 } 447 448 453 protected boolean getValidation() 454 throws SAXNotRecognizedException , SAXNotSupportedException { 455 return fValidator.getValidationEnabled(); 456 } 457 458 476 protected void setExternalGeneralEntities(boolean expand) 477 throws SAXNotRecognizedException , SAXNotSupportedException { 478 if (fParseInProgress) { 479 throw new SAXNotSupportedException ("PAR004 Cannot setFeature(http://xml.org/sax/features/external-general-entities): parse is in progress.\n"+ 480 "http://xml.org/sax/features/external-general-entities"); 481 } 482 if (!expand) { 483 throw new SAXNotSupportedException ("http://xml.org/sax/features/external-general-entities"); 484 } 485 } 486 487 494 protected boolean getExternalGeneralEntities() 495 throws SAXNotRecognizedException , SAXNotSupportedException { 496 return true; 497 } 498 499 517 protected void setExternalParameterEntities(boolean expand) 518 throws SAXNotRecognizedException , SAXNotSupportedException { 519 if (fParseInProgress) { 520 throw new SAXNotSupportedException ("PAR004 Cannot setFeature(http://xml.org/sax/features/external-general-entities): parse is in progress.\n"+ 521 "http://xml.org/sax/features/external-general-entities"); 522 } 523 if (!expand) { 524 throw new SAXNotSupportedException ("http://xml.org/sax/features/external-parameter-entities"); 525 } 526 } 527 528 535 protected boolean getExternalParameterEntities() 536 throws SAXNotRecognizedException , SAXNotSupportedException { 537 return true; 538 } 539 540 553 protected void setNamespaces(boolean process) 554 throws SAXNotRecognizedException , SAXNotSupportedException { 555 if (fParseInProgress) { 556 throw new SAXNotSupportedException ("PAR004 Cannot setFeature(http://xml.org/sax/features/namespaces): parse is in progress.\n"+ 557 "http://xml.org/sax/features/namespaces"); 558 } 559 fScanner.setNamespacesEnabled(process); 560 fValidator.setNamespacesEnabled(process); 563 } 564 565 570 protected boolean getNamespaces() 571 throws SAXNotRecognizedException , SAXNotSupportedException { 572 return fValidator.getNamespacesEnabled(); 573 } 574 575 577 590 protected void setValidationSchema(boolean schema) 591 throws SAXNotRecognizedException , SAXNotSupportedException { 592 if (fParseInProgress) { 593 throw new SAXNotSupportedException ("http://apache.org/xml/features/validation/schema: parse is in progress"); 595 } 596 fValidator.setSchemaValidationEnabled(schema); 597 } 598 599 604 protected boolean getValidationSchema() 605 throws SAXNotRecognizedException , SAXNotSupportedException { 606 return fValidator.getSchemaValidationEnabled(); 607 } 608 609 624 protected void setValidationSchemaFullChecking(boolean schemaFullChecking) 625 throws SAXNotRecognizedException , SAXNotSupportedException { 626 if (fParseInProgress) { 627 throw new SAXNotSupportedException ("http://apache.org/xml/features/validation/schema-full-checking: parse is in progress"); 629 } 630 fValidator.setSchemaFullCheckingEnabled(schemaFullChecking); 631 } 632 633 634 642 protected void setNormalizeContents(boolean normalize) { 643 fValidator.setNormalizeContents(normalize); 644 } 645 protected boolean getNormalizeContents() { 646 return fValidator.getNormalizeConents(); 647 } 648 649 663 protected void setExternalSchemaLocation(Object value) 664 throws SAXNotRecognizedException , SAXNotSupportedException { 665 if (fParseInProgress) { 666 throw new SAXNotSupportedException ("http://apache.org/xml/properties/validation/schema/external-schemaLocation: parse is in progress"); 668 } 669 fValidator.setExternalSchemas(value); 670 } 671 672 684 protected void setExternalNoNamespaceSchemaLocation(Object value) 685 throws SAXNotRecognizedException , SAXNotSupportedException { 686 if (fParseInProgress) { 687 throw new SAXNotSupportedException ("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation: parse is in progress"); 689 } 690 fValidator.setExternalNoNamespaceSchema(value); 691 } 692 693 698 protected boolean getValidationSchemaFullChecking() 699 throws SAXNotRecognizedException , SAXNotSupportedException { 700 return fValidator.getSchemaFullCheckingEnabled(); 701 } 702 703 704 720 protected void setValidationDynamic(boolean dynamic) 721 throws SAXNotRecognizedException , SAXNotSupportedException { 722 if (fParseInProgress) { 723 throw new SAXNotSupportedException ("http://apache.org/xml/features/validation/dynamic: parse is in progress"); 725 } 726 try { 727 fValidator.setDynamicValidationEnabled(dynamic); 728 } 729 catch (Exception ex) { 730 throw new SAXNotSupportedException (ex.getMessage()); 731 } 732 } 733 734 740 protected boolean getValidationDynamic() 741 throws SAXNotRecognizedException , SAXNotSupportedException { 742 return fValidator.getDynamicValidationEnabled(); 743 } 744 745 748 protected void setNormalizeAttributeValues(boolean normalize) { 749 fValidator.setNormalizeAttributeValues(normalize); 750 } 751 752 767 protected void setLoadDTDGrammar(boolean loadDTDGrammar) 768 throws SAXNotRecognizedException , SAXNotSupportedException { 769 if (fParseInProgress) { 770 throw new SAXNotSupportedException ("http://apache.org/xml/features/nonvalidating/load-dtd-grammar: parse is in progress"); 772 } 773 try { 774 fValidator.setLoadDTDGrammar(loadDTDGrammar); 775 } 776 catch (Exception ex) { 777 throw new SAXNotSupportedException (ex.getMessage()); 778 } 779 } 780 781 786 protected boolean getLoadDTDGrammar() 787 throws SAXNotRecognizedException , SAXNotSupportedException { 788 return fValidator.getLoadDTDGrammar(); 789 } 790 791 806 protected void setLoadExternalDTD(boolean loadExternalDTD) 807 throws SAXNotRecognizedException , SAXNotSupportedException { 808 if (fParseInProgress) { 809 throw new SAXNotSupportedException ("http://apache.org/xml/features/nonvalidating/load-external-dtd: parse is in progress"); 811 } 812 try { 813 fScanner.setLoadExternalDTD(loadExternalDTD); 814 } 815 catch (Exception ex) { 816 throw new SAXNotSupportedException (ex.getMessage()); 817 } 818 } 819 820 825 protected boolean getLoadExternalDTD() 826 throws SAXNotRecognizedException , SAXNotSupportedException { 827 return fScanner.getLoadExternalDTD(); 828 } 829 830 844 protected void setValidationWarnOnDuplicateAttdef(boolean warn) 845 throws SAXNotRecognizedException , SAXNotSupportedException { 846 fValidator.setWarningOnDuplicateAttDef(warn); 847 } 848 849 855 protected boolean getValidationWarnOnDuplicateAttdef() 856 throws SAXNotRecognizedException , SAXNotSupportedException { 857 return fValidator.getWarningOnDuplicateAttDef(); 858 } 859 860 875 protected void setValidationWarnOnUndeclaredElemdef(boolean warn) 876 throws SAXNotRecognizedException , SAXNotSupportedException { 877 fValidator.setWarningOnUndeclaredElements(warn); 878 } 879 880 886 protected boolean getValidationWarnOnUndeclaredElemdef() 887 throws SAXNotRecognizedException , SAXNotSupportedException { 888 return fValidator.getWarningOnUndeclaredElements(); 889 } 890 891 905 protected void setAllowJavaEncodings(boolean allow) 906 throws SAXNotRecognizedException , SAXNotSupportedException { 907 fEntityHandler.setAllowJavaEncodings(allow); 908 } 909 910 915 protected boolean getAllowJavaEncodings() 916 throws SAXNotRecognizedException , SAXNotSupportedException { 917 return fEntityHandler.getAllowJavaEncodings(); 918 } 919 920 935 protected void setContinueAfterFatalError(boolean continueAfterFatalError) 936 throws SAXNotRecognizedException , SAXNotSupportedException { 937 fContinueAfterFatalError = continueAfterFatalError; 938 } 939 940 945 protected boolean getContinueAfterFatalError() 946 throws SAXNotRecognizedException , SAXNotSupportedException { 947 return fContinueAfterFatalError; 948 } 949 950 952 971 982 983 988 994 995 1003 protected String getXMLString() 1004 throws SAXNotRecognizedException , SAXNotSupportedException { 1005 throw new SAXNotSupportedException ("http://xml.org/sax/properties/xml-string"); 1006 } 1007 1008 1010 1014 protected void resetOrCopy() throws Exception { 1015 fStringPool = new StringPool(); 1016 fEntityHandler.reset(fStringPool); 1017 fScanner.reset(fStringPool, new ChunkyCharArray(fStringPool)); 1018 fValidator.resetOrCopy(fStringPool); 1019 fNeedReset = false; 1020 fGrammarResolver.clearGrammarResolver(); 1023 fScanner.setGrammarResolver(fGrammarResolver); 1024 fValidator.setGrammarResolver(fGrammarResolver); 1025 } 1026 1027 1033 1035 1042 public void setEntityResolver(EntityResolver resolver) { 1043 fEntityHandler.setEntityResolver(resolver); 1044 } 1045 1046 1053 public EntityResolver getEntityResolver() { 1054 return fEntityHandler.getEntityResolver(); 1055 } 1056 1057 1062 public void setErrorHandler(ErrorHandler handler) { 1063 fErrorHandler = handler; 1064 } 1065 1066 1073 public ErrorHandler getErrorHandler() { 1074 return fErrorHandler; 1075 } 1076 1077 1079 1087 public void parse(InputSource source) 1088 throws SAXException , IOException { 1089 if (fParseInProgress) { 1090 throw new org.xml.sax.SAXException ("FWK005 parse may not be called while parsing."); } 1092 1093 try { 1094 if (parseSomeSetup(source)) { 1095 fScanner.parseSome(true); 1096 } 1097 } catch (org.xml.sax.SAXException ex) { 1098 if (PRINT_EXCEPTION_STACK_TRACE) 1099 ex.printStackTrace(); 1100 throw ex; 1101 } catch (IOException ex) { 1102 if (PRINT_EXCEPTION_STACK_TRACE) 1103 ex.printStackTrace(); 1104 throw ex; 1105 } catch (Exception ex) { 1106 if (PRINT_EXCEPTION_STACK_TRACE) 1107 ex.printStackTrace(); 1108 throw new org.xml.sax.SAXException (ex); 1109 } 1110 finally { 1111 fParseInProgress = false; 1112 } 1113 1114 } 1116 1131 public void parse(String systemId) 1132 throws SAXException , IOException { 1133 1134 InputSource source = new InputSource (systemId); 1135 try { 1136 parse(source); 1137 } 1138 finally { 1139 try { 1142 Reader reader = source.getCharacterStream(); 1143 if (reader != null) { 1144 reader.close(); 1145 } 1146 else { 1147 InputStream is = source.getByteStream(); 1148 if (is != null) { 1149 is.close(); 1150 } 1151 } 1152 } 1153 catch (IOException e) { 1154 } 1156 } 1157 1158 } 1160 1162 1172 public void setLocale(Locale locale) throws SAXException { 1173 1174 if (fParseInProgress) { 1175 throw new org.xml.sax.SAXException ("FWK006 setLocale may not be called while parsing"); } 1177 1178 fLocale = locale; 1179 fgXMLMessages.setLocale(locale); 1180 fgImplementationMessages.setLocale(locale); 1181 1182 } 1184 1188 1203 public void reportError(Locator locator, String errorDomain, 1204 int majorCode, int minorCode, Object args[], 1205 int errorType) throws Exception { 1206 1207 SAXParseException spe; 1209 if (errorDomain.equals(XMLMessages.XML_DOMAIN)) { 1210 spe = new SAXParseException (fgXMLMessages.createMessage(fLocale, majorCode, minorCode, args), locator); 1211 } 1212 else if (errorDomain.equals(XMLMessages.XMLNS_DOMAIN)) { 1213 spe = new SAXParseException (fgXMLMessages.createMessage(fLocale, majorCode, minorCode, args), locator); 1214 } 1215 else if (errorDomain.equals(ImplementationMessages.XERCES_IMPLEMENTATION_DOMAIN)) { 1216 spe = new SAXParseException (fgImplementationMessages.createMessage(fLocale, majorCode, minorCode, args), locator); 1217 } else if (errorDomain.equals(SchemaMessageProvider.SCHEMA_DOMAIN)) { 1218 spe = new SAXParseException (fgSchemaMessages.createMessage(fLocale, majorCode, minorCode, args), locator); 1219 } else if (errorDomain.equals(DatatypeMessageProvider.DATATYPE_DOMAIN)) { 1220 spe = new SAXParseException (fgDatatypeMessages.createMessage(fLocale, majorCode, minorCode, args), locator); 1221 } else { 1222 throw new RuntimeException ("FWK007 Unknown error domain \"" + errorDomain + "\"."+"\n"+errorDomain); 1223 } 1224 1225 if (fErrorHandler == null) { 1227 if (errorType == XMLErrorReporter.ERRORTYPE_FATAL_ERROR && 1228 !fContinueAfterFatalError) { 1229 throw spe; 1230 } 1231 return; 1232 } 1233 1234 if (errorType == XMLErrorReporter.ERRORTYPE_WARNING) { 1236 fErrorHandler.warning(spe); 1237 } 1238 else if (errorType == XMLErrorReporter.ERRORTYPE_FATAL_ERROR) { 1239 fErrorHandler.fatalError(spe); 1240 if (!fContinueAfterFatalError) { 1241 Object [] fatalArgs = { spe.getMessage() }; 1242 throw new SAXException (fgImplementationMessages.createMessage(fLocale, ImplementationMessages.FATAL_ERROR, 0, fatalArgs)); 1243 } 1244 } 1245 else { 1246 fErrorHandler.error(spe); 1247 } 1248 1249 } 1251 1255 1273 public void setFeature(String featureId, boolean state) 1274 throws SAXNotRecognizedException , SAXNotSupportedException { 1275 1276 1280 if (featureId.startsWith(SAX2_FEATURES_PREFIX)) { 1281 String feature = featureId.substring(SAX2_FEATURES_PREFIX.length()); 1282 if (feature.equals("validation")) { 1287 setValidation(state); 1288 return; 1289 } 1290 if (feature.equals("external-general-entities")) { 1295 setExternalGeneralEntities(state); 1296 return; 1297 } 1298 if (feature.equals("external-parameter-entities")) { 1303 setExternalParameterEntities(state); 1304 return; 1305 } 1306 if (feature.equals("namespaces")) { 1312 setNamespaces(state); 1313 return; 1314 } 1315 } 1319 1320 1324 else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) { 1325 String feature = featureId.substring(XERCES_FEATURES_PREFIX.length()); 1326 if (feature.equals("validation/schema")) { 1331 setValidationSchema(state); 1332 return; 1333 } 1334 if (feature.equals("validation/schema-full-checking")) { 1339 setValidationSchemaFullChecking(state); 1340 return; 1341 } 1342 1343 if (feature.equals("validation/dynamic")) { 1350 setValidationDynamic(state); 1351 return; 1352 } 1353 if (feature.equals("validation/default-attribute-values")) { 1357 throw new SAXNotSupportedException (featureId); 1359 } 1360 1361 if (feature.equals("schema/expose-normalized-values")) { 1362 setNormalizeContents(state); 1363 return; 1364 } 1365 if (feature.equals("validation/normalize-attribute-values")) { 1369 setNormalizeAttributeValues(state); 1370 } 1371 if (feature.equals("validation/validate-content-models")) { 1375 throw new SAXNotSupportedException (featureId); 1377 } 1378 if (feature.equals("nonvalidating/load-dtd-grammar")) { 1382 setLoadDTDGrammar(state); 1383 return; 1384 } 1385 if (feature.equals("nonvalidating/load-external-dtd")) { 1389 setLoadExternalDTD(state); 1390 return; 1391 } 1392 1393 if (feature.equals("validation/validate-datatypes")) { 1397 throw new SAXNotSupportedException (featureId); 1399 } 1400 if (feature.equals("validation/warn-on-duplicate-attdef")) { 1405 setValidationWarnOnDuplicateAttdef(state); 1406 return; 1407 } 1408 if (feature.equals("validation/warn-on-undeclared-elemdef")) { 1415 setValidationWarnOnUndeclaredElemdef(state); 1416 return; 1417 } 1418 if (feature.equals("allow-java-encodings")) { 1424 setAllowJavaEncodings(state); 1425 return; 1426 } 1427 if (feature.equals("continue-after-fatal-error")) { 1433 setContinueAfterFatalError(state); 1434 return; 1435 } 1436 } 1440 1441 1445 throw new SAXNotRecognizedException (featureId); 1446 1447 } 1449 1463 public boolean getFeature(String featureId) 1464 throws SAXNotRecognizedException , SAXNotSupportedException { 1465 1466 1470 if (featureId.startsWith(SAX2_FEATURES_PREFIX)) { 1471 String feature = featureId.substring(SAX2_FEATURES_PREFIX.length()); 1472 if (feature.equals("validation")) { 1477 return getValidation(); 1478 } 1479 if (feature.equals("external-general-entities")) { 1484 return getExternalGeneralEntities(); 1485 } 1486 if (feature.equals("external-parameter-entities")) { 1491 return getExternalParameterEntities(); 1492 } 1493 if (feature.equals("namespaces")) { 1499 return getNamespaces(); 1500 } 1501 } 1505 1506 1510 else if (featureId.startsWith(XERCES_FEATURES_PREFIX)) { 1511 String feature = featureId.substring(XERCES_FEATURES_PREFIX.length()); 1512 if (feature.equals("validation/schema")) { 1517 return getValidationSchema(); 1518 } 1519 if (feature.equals("validation/schema-full-checking")) { 1523 return getValidationSchemaFullChecking(); 1524 } 1525 if (feature.equals("validation/dynamic")) { 1533 return getValidationDynamic(); 1534 } 1535 if (feature.equals("validation/default-attribute-values")) { 1539 throw new SAXNotRecognizedException (featureId); 1541 } 1542 if (feature.equals("validation/normalize-element-contents")) { 1543 return getNormalizeContents(); 1544 } 1545 if (feature.equals("validation/validate-content-models")) { 1549 throw new SAXNotRecognizedException (featureId); 1551 } 1552 if (feature.equals("nonvalidating/load-dtd-grammar")) { 1556 return getLoadDTDGrammar(); 1557 } 1558 if (feature.equals("nonvalidating/load-external-dtd")) { 1562 return getLoadExternalDTD(); 1563 } 1564 if (feature.equals("validation/validate-datatypes")) { 1568 throw new SAXNotRecognizedException (featureId); 1570 } 1571 if (feature.equals("validation/warn-on-duplicate-attdef")) { 1576 return getValidationWarnOnDuplicateAttdef(); 1577 } 1578 if (feature.equals("validation/warn-on-undeclared-elemdef")) { 1585 return getValidationWarnOnUndeclaredElemdef(); 1586 } 1587 if (feature.equals("allow-java-encodings")) { 1593 return getAllowJavaEncodings(); 1594 } 1595 if (feature.equals("continue-after-fatal-error")) { 1601 return getContinueAfterFatalError(); 1602 } 1603 } 1607 1608 1612 throw new SAXNotRecognizedException (featureId); 1613 1614 } 1616 1634 public void setProperty(String propertyId, Object value) 1635 throws SAXNotRecognizedException , SAXNotSupportedException { 1636 1637 String property; 1641 if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) { 1642 property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length()); 1643 1644 1665 1666 if (property.equals("xml-string")) { 1676 throw new SAXNotSupportedException (propertyId); 1680 } 1681 } 1685 1686 1690 1691 if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) { 1692 property = propertyId.substring(XERCES_PROPERTIES_PREFIX.length()); 1693 1694 if (property.equals("schema/external-schemaLocation")) { 1695 setExternalSchemaLocation(value); 1696 return; 1697 } 1698 else if (property.equals("schema/external-noNamespaceSchemaLocation")) { 1699 setExternalNoNamespaceSchemaLocation(value); 1700 return; 1701 } 1702 1703 1704 } 1705 1706 1707 1711 throw new SAXNotRecognizedException (propertyId); 1712 1713 } 1715 1730 public Object getProperty(String propertyId) 1731 throws SAXNotRecognizedException , SAXNotSupportedException { 1732 1733 1737 if (propertyId.startsWith(SAX2_PROPERTIES_PREFIX)) { 1738 String property = propertyId.substring(SAX2_PROPERTIES_PREFIX.length()); 1739 1754 if (property.equals("xml-string")) { 1764 return getXMLString(); 1765 } 1766 } 1770 1771 1775 1776 else if (propertyId.startsWith(XERCES_PROPERTIES_PREFIX)) { 1777 1781 String property = propertyId.substring(XERCES_PROPERTIES_PREFIX.length()); 1782 if (property.equals("schema/external-schemaLocation")) { 1787 return fValidator.getExternalSchemas(); 1788 } 1789 if (property.equals("schema/external-noNamespaceSchemaLocation")) { 1790 return fValidator.getExternalNoNamespaceSchema(); 1791 } 1792 } 1793 1794 1795 1799 throw new SAXNotRecognizedException (propertyId); 1800 1801 } 1803} 1804 | Popular Tags |