Fields Summary |
---|
protected static final String | WARN_ON_DUPLICATE_ATTDEFFeature identifier: warn on duplicate attribute definition. |
protected static final String | WARN_ON_DUPLICATE_ENTITYDEFFeature identifier: warn on duplicate entity definition. |
protected static final String | WARN_ON_UNDECLARED_ELEMDEFFeature identifier: warn on undeclared element definition. |
protected static final String | ALLOW_JAVA_ENCODINGSFeature identifier: allow Java encodings. |
protected static final String | CONTINUE_AFTER_FATAL_ERRORFeature identifier: continue after fatal error. |
protected static final String | LOAD_EXTERNAL_DTDFeature identifier: load external DTD. |
protected static final String | NOTIFY_BUILTIN_REFSFeature identifier: notify built-in refereces. |
protected static final String | NOTIFY_CHAR_REFSFeature identifier: notify character refereces. |
protected static final String | ERROR_REPORTERProperty identifier: error reporter. |
protected static final String | ENTITY_MANAGERProperty identifier: entity manager. |
protected static final String | DOCUMENT_SCANNERProperty identifier document scanner: |
protected static final String | DTD_SCANNERProperty identifier: DTD scanner. |
protected static final String | XMLGRAMMAR_POOLProperty identifier: grammar pool. |
protected static final String | DTD_PROCESSORProperty identifier: DTD loader. |
protected static final String | DTD_VALIDATORProperty identifier: DTD validator. |
protected static final String | NAMESPACE_BINDERProperty identifier: namespace binder. |
protected static final String | DATATYPE_VALIDATOR_FACTORYProperty identifier: datatype validator factory. |
protected static final String | VALIDATION_MANAGER |
protected static final String | JAXP_SCHEMA_LANGUAGEProperty identifier: JAXP schema language / DOM schema-type. |
protected static final String | JAXP_SCHEMA_SOURCEProperty identifier: JAXP schema source/ DOM schema-location. |
protected static final boolean | PRINT_EXCEPTION_STACK_TRACESet to true and recompile to print exception stack trace. |
protected org.apache.xerces.xni.grammars.XMLGrammarPool | fGrammarPoolGrammar pool. |
protected org.apache.xerces.impl.dv.DTDDVFactory | fDatatypeValidatorFactoryDatatype validator factory. |
protected org.apache.xerces.impl.XMLErrorReporter | fErrorReporterError reporter. |
protected org.apache.xerces.impl.XMLEntityManager | fEntityManagerEntity manager. |
protected org.apache.xerces.xni.parser.XMLDocumentScanner | fScannerDocument scanner. |
protected org.apache.xerces.xni.parser.XMLInputSource | fInputSourceInput Source |
protected org.apache.xerces.xni.parser.XMLDTDScanner | fDTDScannerDTD scanner. |
protected org.apache.xerces.impl.dtd.XMLDTDProcessor | fDTDProcessorDTD Processor . |
protected org.apache.xerces.impl.dtd.XMLDTDValidator | fDTDValidatorDTD Validator. |
protected org.apache.xerces.impl.XMLNamespaceBinder | fNamespaceBinderNamespace binder. |
protected org.apache.xerces.impl.validation.ValidationManager | fValidationManager |
protected org.apache.xerces.xni.XMLLocator | fLocatorLocator |
protected boolean | fParseInProgressTrue if a parse is in progress. This state is needed because
some features/properties cannot be set while parsing (e.g.
validation and namespaces). |
Constructors Summary |
---|
public DTDConfiguration()Default constructor.
//
// Constructors
//
this(null, null, null);
|
public DTDConfiguration(org.apache.xerces.util.SymbolTable symbolTable)Constructs a parser configuration using the specified symbol table.
this(symbolTable, null, null);
|
public DTDConfiguration(org.apache.xerces.util.SymbolTable symbolTable, org.apache.xerces.xni.grammars.XMLGrammarPool grammarPool)Constructs a parser configuration using the specified symbol table and
grammar pool.
REVISIT:
Grammar pool will be updated when the new validation engine is
implemented.
this(symbolTable, grammarPool, null);
|
public DTDConfiguration(org.apache.xerces.util.SymbolTable symbolTable, org.apache.xerces.xni.grammars.XMLGrammarPool grammarPool, org.apache.xerces.xni.parser.XMLComponentManager parentSettings)Constructs a parser configuration using the specified symbol table,
grammar pool, and parent settings.
REVISIT:
Grammar pool will be updated when the new validation engine is
implemented.
super(symbolTable, parentSettings);
// add default recognized features
final String[] recognizedFeatures = {
//WARN_ON_DUPLICATE_ATTDEF, // from XMLDTDScannerImpl
//WARN_ON_UNDECLARED_ELEMDEF, // from XMLDTDScannerImpl
//ALLOW_JAVA_ENCODINGS, // from XMLEntityManager
CONTINUE_AFTER_FATAL_ERROR,
LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
//NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl
//WARN_ON_DUPLICATE_ENTITYDEF, // from XMLEntityManager
};
addRecognizedFeatures(recognizedFeatures);
// set state for default features
//setFeature(WARN_ON_DUPLICATE_ATTDEF, false); // from XMLDTDScannerImpl
//setFeature(WARN_ON_UNDECLARED_ELEMDEF, false); // from XMLDTDScannerImpl
//setFeature(ALLOW_JAVA_ENCODINGS, false); // from XMLEntityManager
setFeature(CONTINUE_AFTER_FATAL_ERROR, false);
setFeature(LOAD_EXTERNAL_DTD, true); // from XMLDTDScannerImpl
//setFeature(NOTIFY_BUILTIN_REFS, false); // from XMLDocumentFragmentScannerImpl
//setFeature(NOTIFY_CHAR_REFS, false); // from XMLDocumentFragmentScannerImpl
//setFeature(WARN_ON_DUPLICATE_ENTITYDEF, false); // from XMLEntityManager
// add default recognized properties
final String[] recognizedProperties = {
ERROR_REPORTER,
ENTITY_MANAGER,
DOCUMENT_SCANNER,
DTD_SCANNER,
DTD_PROCESSOR,
DTD_VALIDATOR,
NAMESPACE_BINDER,
XMLGRAMMAR_POOL,
DATATYPE_VALIDATOR_FACTORY,
VALIDATION_MANAGER,
JAXP_SCHEMA_SOURCE,
JAXP_SCHEMA_LANGUAGE
};
addRecognizedProperties(recognizedProperties);
fGrammarPool = grammarPool;
if(fGrammarPool != null){
setProperty(XMLGRAMMAR_POOL, fGrammarPool);
}
fEntityManager = createEntityManager();
setProperty(ENTITY_MANAGER, fEntityManager);
addComponent(fEntityManager);
fErrorReporter = createErrorReporter();
fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
setProperty(ERROR_REPORTER, fErrorReporter);
addComponent(fErrorReporter);
fScanner = createDocumentScanner();
setProperty(DOCUMENT_SCANNER, fScanner);
if (fScanner instanceof XMLComponent) {
addComponent((XMLComponent)fScanner);
}
fDTDScanner = createDTDScanner();
if (fDTDScanner != null) {
setProperty(DTD_SCANNER, fDTDScanner);
if (fDTDScanner instanceof XMLComponent) {
addComponent((XMLComponent)fDTDScanner);
}
}
fDTDProcessor = createDTDProcessor();
if (fDTDProcessor != null) {
setProperty(DTD_PROCESSOR, fDTDProcessor);
addComponent(fDTDProcessor);
}
fDTDValidator = createDTDValidator();
if (fDTDValidator != null) {
setProperty(DTD_VALIDATOR, fDTDValidator);
addComponent(fDTDValidator);
}
fNamespaceBinder = createNamespaceBinder();
if (fNamespaceBinder != null) {
setProperty(NAMESPACE_BINDER, fNamespaceBinder);
addComponent(fNamespaceBinder);
}
fDatatypeValidatorFactory = createDatatypeValidatorFactory();
if (fDatatypeValidatorFactory != null) {
setProperty(DATATYPE_VALIDATOR_FACTORY,
fDatatypeValidatorFactory);
}
fValidationManager = createValidationManager();
if (fValidationManager != null) {
setProperty (VALIDATION_MANAGER, fValidationManager);
}
// add message formatters
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
XMLMessageFormatter xmft = new XMLMessageFormatter();
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
}
// set locale
try {
setLocale(Locale.getDefault());
}
catch (XNIException e) {
// do nothing
// REVISIT: What is the right thing to do? -Ac
}
|
Methods Summary |
---|
protected void | checkFeature(java.lang.String featureId)Check a feature. If feature is know and supported, this method simply
returns. Otherwise, the appropriate exception is thrown.
//
// Xerces Features
//
if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
//
// http://apache.org/xml/features/validation/dynamic
// Allows the parser to validate a document only when it
// contains a grammar. Validation is turned on/off based
// on each document instance, automatically.
//
if (suffixLength == Constants.DYNAMIC_VALIDATION_FEATURE.length() &&
featureId.endsWith(Constants.DYNAMIC_VALIDATION_FEATURE)) {
return;
}
//
// http://apache.org/xml/features/validation/default-attribute-values
//
if (suffixLength == Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE.length() &&
featureId.endsWith(Constants.DEFAULT_ATTRIBUTE_VALUES_FEATURE)) {
// REVISIT
short type = XMLConfigurationException.NOT_SUPPORTED;
throw new XMLConfigurationException(type, featureId);
}
//
// http://apache.org/xml/features/validation/default-attribute-values
//
if (suffixLength == Constants.VALIDATE_CONTENT_MODELS_FEATURE.length() &&
featureId.endsWith(Constants.VALIDATE_CONTENT_MODELS_FEATURE)) {
// REVISIT
short type = XMLConfigurationException.NOT_SUPPORTED;
throw new XMLConfigurationException(type, featureId);
}
//
// http://apache.org/xml/features/validation/nonvalidating/load-dtd-grammar
//
if (suffixLength == Constants.LOAD_DTD_GRAMMAR_FEATURE.length() &&
featureId.endsWith(Constants.LOAD_DTD_GRAMMAR_FEATURE)) {
return;
}
//
// http://apache.org/xml/features/validation/nonvalidating/load-external-dtd
//
if (suffixLength == Constants.LOAD_EXTERNAL_DTD_FEATURE.length() &&
featureId.endsWith(Constants.LOAD_EXTERNAL_DTD_FEATURE)) {
return;
}
//
// http://apache.org/xml/features/validation/default-attribute-values
//
if (suffixLength == Constants.VALIDATE_DATATYPES_FEATURE.length() &&
featureId.endsWith(Constants.VALIDATE_DATATYPES_FEATURE)) {
short type = XMLConfigurationException.NOT_SUPPORTED;
throw new XMLConfigurationException(type, featureId);
}
}
//
// Not recognized
//
super.checkFeature(featureId);
|
protected void | checkProperty(java.lang.String propertyId)Check a property. If the property is know and supported, this method
simply returns. Otherwise, the appropriate exception is thrown.
//
// Xerces Properties
//
if (propertyId.startsWith(Constants.XERCES_PROPERTY_PREFIX)) {
final int suffixLength = propertyId.length() - Constants.XERCES_PROPERTY_PREFIX.length();
if (suffixLength == Constants.DTD_SCANNER_PROPERTY.length() &&
propertyId.endsWith(Constants.DTD_SCANNER_PROPERTY)) {
return;
}
}
//
// Not recognized
//
super.checkProperty(propertyId);
|
public void | cleanup()If the application decides to terminate parsing before the xml document
is fully parsed, the application should call this method to free any
resource allocated during parsing. For example, close all opened streams.
fEntityManager.closeReaders();
|
protected void | configureDTDPipeline()
// setup dtd pipeline
if (fDTDScanner != null) {
fProperties.put(DTD_SCANNER, fDTDScanner);
if (fDTDProcessor != null) {
fProperties.put(DTD_PROCESSOR, fDTDProcessor);
fDTDScanner.setDTDHandler(fDTDProcessor);
fDTDProcessor.setDTDSource(fDTDScanner);
fDTDProcessor.setDTDHandler(fDTDHandler);
if (fDTDHandler != null) {
fDTDHandler.setDTDSource(fDTDProcessor);
}
fDTDScanner.setDTDContentModelHandler(fDTDProcessor);
fDTDProcessor.setDTDContentModelSource(fDTDScanner);
fDTDProcessor.setDTDContentModelHandler(fDTDContentModelHandler);
if (fDTDContentModelHandler != null) {
fDTDContentModelHandler.setDTDContentModelSource(fDTDProcessor);
}
}
else {
fDTDScanner.setDTDHandler(fDTDHandler);
if (fDTDHandler != null) {
fDTDHandler.setDTDSource(fDTDScanner);
}
fDTDScanner.setDTDContentModelHandler(fDTDContentModelHandler);
if (fDTDContentModelHandler != null) {
fDTDContentModelHandler.setDTDContentModelSource(fDTDScanner);
}
}
}
|
protected void | configurePipeline()Configures the pipeline.
// REVISIT: This should be better designed. In other words, we
// need to figure out what is the best way for people to
// re-use *most* of the standard configuration but do
// things common things such as remove a component (e.g.
// the validator), insert a new component (e.g. XInclude),
// etc... -Ac
// setup document pipeline
if (fDTDValidator != null) {
fScanner.setDocumentHandler(fDTDValidator);
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
// filters
fDTDValidator.setDocumentHandler(fNamespaceBinder);
fDTDValidator.setDocumentSource(fScanner);
fNamespaceBinder.setDocumentHandler(fDocumentHandler);
fNamespaceBinder.setDocumentSource(fDTDValidator);
fLastComponent = fNamespaceBinder;
}
else {
fDTDValidator.setDocumentHandler(fDocumentHandler);
fDTDValidator.setDocumentSource(fScanner);
fLastComponent = fDTDValidator;
}
}
else {
if (fFeatures.get(NAMESPACES) == Boolean.TRUE) {
fScanner.setDocumentHandler(fNamespaceBinder);
fNamespaceBinder.setDocumentHandler(fDocumentHandler);
fNamespaceBinder.setDocumentSource(fScanner);
fLastComponent = fNamespaceBinder;
}
else {
fScanner.setDocumentHandler(fDocumentHandler);
fLastComponent = fScanner;
}
}
configureDTDPipeline();
|
protected org.apache.xerces.impl.dtd.XMLDTDProcessor | createDTDProcessor()Create a DTD loader .
return new XMLDTDProcessor();
|
protected org.apache.xerces.xni.parser.XMLDTDScanner | createDTDScanner()Create a DTD scanner.
return new XMLDTDScannerImpl();
|
protected org.apache.xerces.impl.dtd.XMLDTDValidator | createDTDValidator()Create a DTD validator.
return new XMLDTDValidator();
|
protected org.apache.xerces.impl.dv.DTDDVFactory | createDatatypeValidatorFactory()Create a datatype validator factory.
return DTDDVFactory.getInstance();
|
protected org.apache.xerces.xni.parser.XMLDocumentScanner | createDocumentScanner()Create a document scanner.
return new XMLDocumentScannerImpl();
|
protected org.apache.xerces.impl.XMLEntityManager | createEntityManager()Creates an entity manager.
return new XMLEntityManager();
|
protected org.apache.xerces.impl.XMLErrorReporter | createErrorReporter()Creates an error reporter.
return new XMLErrorReporter();
|
protected org.apache.xerces.impl.XMLNamespaceBinder | createNamespaceBinder()Create a namespace binder.
return new XMLNamespaceBinder();
|
protected org.apache.xerces.impl.validation.ValidationManager | createValidationManager()
return new ValidationManager();
|
public boolean | parse(boolean complete)Parses the document in a pull parsing fashion.
//
// reset and configure pipeline and set InputSource.
if (fInputSource !=null) {
try {
// resets and sets the pipeline.
reset();
fScanner.setInputSource(fInputSource);
fInputSource = null;
}
catch (XNIException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (IOException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (RuntimeException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (Exception ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw new XNIException(ex);
}
}
try {
return fScanner.scanDocument(complete);
}
catch (XNIException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (IOException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (RuntimeException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (Exception ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw new XNIException(ex);
}
|
public void | parse(org.apache.xerces.xni.parser.XMLInputSource source)Parses the specified input source.
if (fParseInProgress) {
// REVISIT - need to add new error message
throw new XNIException("FWK005 parse may not be called while parsing.");
}
fParseInProgress = true;
try {
setInputSource(source);
parse(true);
}
catch (XNIException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (IOException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (RuntimeException ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw ex;
}
catch (Exception ex) {
if (PRINT_EXCEPTION_STACK_TRACE)
ex.printStackTrace();
throw new XNIException(ex);
}
finally {
fParseInProgress = false;
// close all streams opened by xerces
this.cleanup();
}
|
protected void | reset()Reset all components before parsing.
if (fValidationManager != null)
fValidationManager.reset();
// configure the pipeline and initialize the components
configurePipeline();
super.reset();
|
public void | setInputSource(org.apache.xerces.xni.parser.XMLInputSource inputSource)Sets the input source for the document to parse.
// REVISIT: this method used to reset all the components and
// construct the pipeline. Now reset() is called
// in parse (boolean) just before we parse the document
// Should this method still throw exceptions..?
fInputSource = inputSource;
|
public void | setLocale(java.util.Locale locale)Set the locale to use for messages.
super.setLocale(locale);
fErrorReporter.setLocale(locale);
|