1 16 17 package org.apache.xerces.parsers; 18 19 import org.apache.xerces.impl.Constants; 20 import org.apache.xerces.impl.xs.XMLSchemaValidator; 21 import org.apache.xerces.impl.xs.XSMessageFormatter; 22 import org.apache.xerces.util.SymbolTable; 23 import org.apache.xerces.xni.grammars.XMLGrammarPool; 24 import org.apache.xerces.xni.parser.XMLComponentManager; 25 import org.apache.xerces.xni.parser.XMLConfigurationException; 26 27 62 public class StandardParserConfiguration 63 extends DTDConfiguration { 64 65 69 71 72 protected static final String NORMALIZE_DATA = 73 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_NORMALIZED_VALUE; 74 75 76 77 protected static final String SCHEMA_ELEMENT_DEFAULT = 78 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_ELEMENT_DEFAULT; 79 80 81 82 protected static final String SCHEMA_AUGMENT_PSVI = 83 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_AUGMENT_PSVI; 84 85 86 87 protected static final String XMLSCHEMA_VALIDATION = 88 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_VALIDATION_FEATURE; 89 90 91 protected static final String XMLSCHEMA_FULL_CHECKING = 92 Constants.XERCES_FEATURE_PREFIX + Constants.SCHEMA_FULL_CHECKING; 93 94 95 protected static final String GENERATE_SYNTHETIC_ANNOTATIONS = 96 Constants.XERCES_FEATURE_PREFIX + Constants.GENERATE_SYNTHETIC_ANNOTATIONS_FEATURE; 97 98 99 protected static final String VALIDATE_ANNOTATIONS = 100 Constants.XERCES_FEATURE_PREFIX + Constants.VALIDATE_ANNOTATIONS_FEATURE; 101 102 103 protected static final String HONOUR_ALL_SCHEMALOCATIONS = 104 Constants.XERCES_FEATURE_PREFIX + Constants.HONOUR_ALL_SCHEMALOCATIONS_FEATURE; 105 106 108 109 protected static final String SCHEMA_VALIDATOR = 110 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_VALIDATOR_PROPERTY; 111 112 113 protected static final String SCHEMA_LOCATION = 114 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_LOCATION; 115 116 117 protected static final String SCHEMA_NONS_LOCATION = 118 Constants.XERCES_PROPERTY_PREFIX + Constants.SCHEMA_NONS_LOCATION; 119 120 124 126 127 protected XMLSchemaValidator fSchemaValidator; 128 129 133 134 public StandardParserConfiguration() { 135 this(null, null, null); 136 } 138 143 public StandardParserConfiguration(SymbolTable symbolTable) { 144 this(symbolTable, null, null); 145 } 147 158 public StandardParserConfiguration(SymbolTable symbolTable, 159 XMLGrammarPool grammarPool) { 160 this(symbolTable, grammarPool, null); 161 } 163 175 public StandardParserConfiguration(SymbolTable symbolTable, 176 XMLGrammarPool grammarPool, 177 XMLComponentManager parentSettings) { 178 super(symbolTable, grammarPool, parentSettings); 179 180 final String [] recognizedFeatures = { 182 NORMALIZE_DATA, 183 SCHEMA_ELEMENT_DEFAULT, 184 SCHEMA_AUGMENT_PSVI, 185 GENERATE_SYNTHETIC_ANNOTATIONS, 186 VALIDATE_ANNOTATIONS, 187 HONOUR_ALL_SCHEMALOCATIONS, 188 XMLSCHEMA_VALIDATION, 193 XMLSCHEMA_FULL_CHECKING, 194 }; 195 addRecognizedFeatures(recognizedFeatures); 196 197 setFeature(SCHEMA_ELEMENT_DEFAULT, true); 199 setFeature(NORMALIZE_DATA, true); 200 setFeature(SCHEMA_AUGMENT_PSVI, true); 201 setFeature(GENERATE_SYNTHETIC_ANNOTATIONS, false); 202 setFeature(VALIDATE_ANNOTATIONS, false); 203 setFeature(HONOUR_ALL_SCHEMALOCATIONS, false); 204 205 207 final String [] recognizedProperties = { 208 SCHEMA_LOCATION, 213 SCHEMA_NONS_LOCATION, 214 }; 215 216 addRecognizedProperties(recognizedProperties); 217 218 } 220 224 225 protected void configurePipeline() { 226 super.configurePipeline(); 227 if ( getFeature(XMLSCHEMA_VALIDATION )) { 228 if (fSchemaValidator == null) { 230 fSchemaValidator = new XMLSchemaValidator(); 231 232 fProperties.put(SCHEMA_VALIDATOR, fSchemaValidator); 234 addComponent(fSchemaValidator); 235 if (fErrorReporter.getMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN) == null) { 237 XSMessageFormatter xmft = new XSMessageFormatter(); 238 fErrorReporter.putMessageFormatter(XSMessageFormatter.SCHEMA_DOMAIN, xmft); 239 } 240 241 } 242 fLastComponent = fSchemaValidator; 243 fNamespaceBinder.setDocumentHandler(fSchemaValidator); 244 245 fSchemaValidator.setDocumentHandler(fDocumentHandler); 246 fSchemaValidator.setDocumentSource(fNamespaceBinder); 247 } 248 249 250 } 252 254 266 protected void checkFeature(String featureId) 267 throws XMLConfigurationException { 268 269 273 if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) { 274 final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length(); 275 276 if (suffixLength == Constants.SCHEMA_VALIDATION_FEATURE.length() && 281 featureId.endsWith(Constants.SCHEMA_VALIDATION_FEATURE)) { 282 return; 283 } 284 if (suffixLength == Constants.SCHEMA_FULL_CHECKING.length() && 286 featureId.endsWith(Constants.SCHEMA_FULL_CHECKING)) { 287 return; 288 } 289 if (suffixLength == Constants.SCHEMA_NORMALIZED_VALUE.length() && 292 featureId.endsWith(Constants.SCHEMA_NORMALIZED_VALUE)) { 293 return; 294 } 295 if (suffixLength == Constants.SCHEMA_ELEMENT_DEFAULT.length() && 298 featureId.endsWith(Constants.SCHEMA_ELEMENT_DEFAULT)) { 299 return; 300 } 301 } 302 303 307 super.checkFeature(featureId); 308 309 } 311 324 protected void checkProperty(String propertyId) 325 throws XMLConfigurationException { 326 327 331 if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) { 332 final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length(); 333 334 if (suffixLength == Constants.SCHEMA_LOCATION.length() && 335 propertyId.endsWith(Constants.SCHEMA_LOCATION)) { 336 return; 337 } 338 if (suffixLength == Constants.SCHEMA_NONS_LOCATION.length() && 339 propertyId.endsWith(Constants.SCHEMA_NONS_LOCATION)) { 340 return; 341 } 342 } 343 344 if (propertyId.startsWith(Constants.JAXP_PROPERTY_PREFIX)) { 345 final int suffixLength = propertyId.length() - Constants.JAXP_PROPERTY_PREFIX.length(); 346 347 if (suffixLength == Constants.SCHEMA_SOURCE.length() && 348 propertyId.endsWith(Constants.SCHEMA_SOURCE)) { 349 return; 350 } 351 } 352 353 357 super.checkProperty(propertyId); 358 359 } 361 } | Popular Tags |