XMLDTDLoaderpublic class XMLDTDLoader extends XMLDTDProcessor implements org.apache.xerces.xni.grammars.XMLGrammarLoaderThe DTD loader. The loader knows how to build grammars from XMLInputSources.
It extends the DTD processor in order to do this; it's
a separate class because DTD processors don't need to know how
to talk to the outside world in their role as instance-document
helpers.
This component requires the following features and properties. It
know ho to set them if no one else does:from the
- http://xml.org/sax/features/namespaces
- http://apache.org/xml/properties/internal/symbol-table
- http://apache.org/xml/properties/internal/error-reporter
- http://apache.org/xml/properties/internal/grammar-pool
- http://apache.org/xml/properties/internal/datatype-validator-factory
|
Fields Summary |
---|
protected static final String | STANDARD_URI_CONFORMANT_FEATUREFeature identifier: standard uri conformant feature. | protected static final String | BALANCE_SYNTAX_TREESFeature identifier: balance syntax trees. | private static final String[] | LOADER_RECOGNIZED_FEATURES | protected static final String | ERROR_HANDLERProperty identifier: error handler. | public static final String | ENTITY_RESOLVERProperty identifier: entity resolver. | private static final String[] | LOADER_RECOGNIZED_PROPERTIESRecognized properties. | private boolean | fStrictURI | private boolean | fBalanceSyntaxTreesControls whether the DTD grammar produces balanced syntax trees. | protected org.apache.xerces.xni.parser.XMLEntityResolver | fEntityResolverEntity resolver . | protected org.apache.xerces.impl.XMLDTDScannerImpl | fDTDScanner | protected org.apache.xerces.impl.XMLEntityManager | fEntityManager | protected Locale | fLocale |
Constructors Summary |
---|
public XMLDTDLoader()Deny default construction; we need a SymtolTable!
//
// Constructors
//
this(new SymbolTable());
| public XMLDTDLoader(org.apache.xerces.util.SymbolTable symbolTable)
this(symbolTable, null);
| public XMLDTDLoader(org.apache.xerces.util.SymbolTable symbolTable, org.apache.xerces.xni.grammars.XMLGrammarPool grammarPool)
this(symbolTable, grammarPool, null, new XMLEntityManager());
| XMLDTDLoader(org.apache.xerces.util.SymbolTable symbolTable, org.apache.xerces.xni.grammars.XMLGrammarPool grammarPool, org.apache.xerces.impl.XMLErrorReporter errorReporter, org.apache.xerces.xni.parser.XMLEntityResolver entityResolver)
fSymbolTable = symbolTable;
fGrammarPool = grammarPool;
if(errorReporter == null) {
errorReporter = new XMLErrorReporter();
errorReporter.setProperty(ERROR_HANDLER, new DefaultErrorHandler());
}
fErrorReporter = errorReporter;
// Add XML message formatter if there isn't one.
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
XMLMessageFormatter xmft = new XMLMessageFormatter();
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
}
fEntityResolver = entityResolver;
if(fEntityResolver instanceof XMLEntityManager) {
fEntityManager = (XMLEntityManager)fEntityResolver;
} else {
fEntityManager = new XMLEntityManager();
}
fEntityManager.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY, errorReporter);
fDTDScanner = createDTDScanner(fSymbolTable, fErrorReporter, fEntityManager);
fDTDScanner.setDTDHandler(this);
fDTDScanner.setDTDContentModelHandler(this);
reset();
|
Methods Summary |
---|
protected org.apache.xerces.impl.XMLDTDScannerImpl | createDTDScanner(org.apache.xerces.util.SymbolTable symbolTable, org.apache.xerces.impl.XMLErrorReporter errorReporter, org.apache.xerces.impl.XMLEntityManager entityManager)
return new XMLDTDScannerImpl(symbolTable, errorReporter, entityManager);
| public org.apache.xerces.xni.parser.XMLEntityResolver | getEntityResolver()Returns the registered entity resolver.
return fEntityResolver;
| public org.apache.xerces.xni.parser.XMLErrorHandler | getErrorHandler()Returns the registered error handler.
return fErrorReporter.getErrorHandler();
| public boolean | getFeature(java.lang.String featureId)Returns the state of a feature.
if (featureId.equals(VALIDATION)) {
return fValidation;
}
else if (featureId.equals(WARN_ON_DUPLICATE_ATTDEF)) {
return fWarnDuplicateAttdef;
}
else if (featureId.equals(WARN_ON_UNDECLARED_ELEMDEF)) {
return fWarnOnUndeclaredElemdef;
}
else if (featureId.equals(NOTIFY_CHAR_REFS)) {
return fDTDScanner.getFeature(featureId);
}
else if (featureId.equals(STANDARD_URI_CONFORMANT_FEATURE)) {
return fStrictURI;
}
else if (featureId.equals(BALANCE_SYNTAX_TREES)) {
return fBalanceSyntaxTrees;
}
throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);
| public java.util.Locale | getLocale()Return the Locale the XMLGrammarLoader is using.
return fLocale;
| public java.lang.Object | getProperty(java.lang.String propertyId)Returns the state of a property.
if(propertyId.equals( SYMBOL_TABLE)) {
return fSymbolTable;
} else if(propertyId.equals( ERROR_REPORTER)) {
return fErrorReporter;
} else if(propertyId.equals( ERROR_HANDLER)) {
return fErrorReporter.getErrorHandler();
} else if(propertyId.equals( ENTITY_RESOLVER)) {
return fEntityResolver;
} else if(propertyId.equals( GRAMMAR_POOL)) {
return fGrammarPool;
} else if(propertyId.equals( DTD_VALIDATOR)) {
return fValidator;
}
throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, propertyId);
| public java.lang.String[] | getRecognizedFeatures()Returns a list of feature identifiers that are recognized by
this component. This method may return null if no features
are recognized by this component.
return (String[])(LOADER_RECOGNIZED_FEATURES.clone());
| public java.lang.String[] | getRecognizedProperties()Returns a list of property identifiers that are recognized by
this component. This method may return null if no properties
are recognized by this component.
return (String[])(LOADER_RECOGNIZED_PROPERTIES.clone());
| protected short | getScannerVersion()
return Constants.XML_VERSION_1_0;
| public org.apache.xerces.xni.grammars.Grammar | loadGrammar(org.apache.xerces.xni.parser.XMLInputSource source)Returns a Grammar object by parsing the contents of the
entity pointed to by source.
reset();
// First chance checking strict URI
String eid = XMLEntityManager.expandSystemId(source.getSystemId(), source.getBaseSystemId(), fStrictURI);
XMLDTDDescription desc = new XMLDTDDescription(source.getPublicId(), source.getSystemId(), source.getBaseSystemId(), eid, null);
if (!fBalanceSyntaxTrees) {
fDTDGrammar = new DTDGrammar(fSymbolTable, desc);
}
else {
fDTDGrammar = new BalancedDTDGrammar(fSymbolTable, desc);
}
fGrammarBucket = new DTDGrammarBucket();
fGrammarBucket.setStandalone(false);
fGrammarBucket.setActiveGrammar(fDTDGrammar);
// no reason to use grammar bucket's "put" method--we
// know which grammar it is, and we don't know the root name anyway...
// actually start the parsing!
try {
fDTDScanner.setInputSource(source);
fDTDScanner.scanDTDExternalSubset(true);
} catch (EOFException e) {
// expected behaviour...
}
finally {
// Close all streams opened by the parser.
fEntityManager.closeReaders();
}
if(fDTDGrammar != null && fGrammarPool != null) {
fGrammarPool.cacheGrammars(XMLDTDDescription.XML_DTD, new Grammar[] {fDTDGrammar});
}
return fDTDGrammar;
| public void | loadGrammarWithContext(XMLDTDValidator validator, java.lang.String rootName, java.lang.String publicId, java.lang.String systemId, java.lang.String baseSystemId, java.lang.String internalSubset)Parse a DTD internal and/or external subset and insert the content
into the existing DTD grammar owned by the given DTDValidator.
final DTDGrammarBucket grammarBucket = validator.getGrammarBucket();
final DTDGrammar activeGrammar = grammarBucket.getActiveGrammar();
if (activeGrammar != null && !activeGrammar.isImmutable()) {
fGrammarBucket = grammarBucket;
fEntityManager.setScannerVersion(getScannerVersion());
reset();
try {
// process internal subset
if (internalSubset != null) {
// To get the DTD scanner to end at the right place we have to fool
// it into thinking that it reached the end of the internal subset
// in a real document.
StringBuffer buffer = new StringBuffer(internalSubset.length() + 2);
buffer.append(internalSubset).append("]>");
XMLInputSource is = new XMLInputSource(null, baseSystemId,
null, new StringReader(buffer.toString()), null);
fEntityManager.startDocumentEntity(is);
fDTDScanner.scanDTDInternalSubset(true, false, systemId != null);
}
// process external subset
if (systemId != null) {
XMLDTDDescription desc = new XMLDTDDescription(publicId, systemId, baseSystemId, null, rootName);
XMLInputSource source = fEntityManager.resolveEntity(desc);
fDTDScanner.setInputSource(source);
fDTDScanner.scanDTDExternalSubset(true);
}
}
catch (EOFException e) {
// expected behaviour...
}
finally {
// Close all streams opened by the parser.
fEntityManager.closeReaders();
}
}
| protected void | reset()
super.reset();
fDTDScanner.reset();
fEntityManager.reset();
fErrorReporter.setDocumentLocator(fEntityManager.getEntityScanner());
| public void | setEntityResolver(org.apache.xerces.xni.parser.XMLEntityResolver entityResolver)Sets the entity resolver.
fEntityResolver = entityResolver;
fEntityManager.setProperty(ENTITY_RESOLVER, entityResolver);
| public void | setErrorHandler(org.apache.xerces.xni.parser.XMLErrorHandler errorHandler)Sets the error handler.
fErrorReporter.setProperty(ERROR_HANDLER, errorHandler);
| public void | setFeature(java.lang.String featureId, boolean state)Sets the state of a feature. This method is called by the component
manager any time after reset when a feature changes state.
Note: Components should silently ignore features
that do not affect the operation of the component.
if (featureId.equals(VALIDATION)) {
fValidation = state;
}
else if (featureId.equals(WARN_ON_DUPLICATE_ATTDEF)) {
fWarnDuplicateAttdef = state;
}
else if (featureId.equals(WARN_ON_UNDECLARED_ELEMDEF)) {
fWarnOnUndeclaredElemdef = state;
}
else if (featureId.equals(NOTIFY_CHAR_REFS)) {
fDTDScanner.setFeature(featureId, state);
}
else if (featureId.equals(STANDARD_URI_CONFORMANT_FEATURE)) {
fStrictURI = state;
}
else if (featureId.equals(BALANCE_SYNTAX_TREES)) {
fBalanceSyntaxTrees = state;
}
else {
throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, featureId);
}
| public void | setLocale(java.util.Locale locale)Set the locale to use for messages.
fLocale = locale;
| public void | setProperty(java.lang.String propertyId, java.lang.Object value)Sets the value of a property. This method is called by the component
manager any time after reset when a property changes value.
Note: Components should silently ignore properties
that do not affect the operation of the component.
if(propertyId.equals( SYMBOL_TABLE)) {
fSymbolTable = (SymbolTable)value;
fDTDScanner.setProperty(propertyId, value);
fEntityManager.setProperty(propertyId, value);
} else if(propertyId.equals( ERROR_REPORTER)) {
fErrorReporter = (XMLErrorReporter)value;
// Add XML message formatter if there isn't one.
if (fErrorReporter.getMessageFormatter(XMLMessageFormatter.XML_DOMAIN) == null) {
XMLMessageFormatter xmft = new XMLMessageFormatter();
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XML_DOMAIN, xmft);
fErrorReporter.putMessageFormatter(XMLMessageFormatter.XMLNS_DOMAIN, xmft);
}
fDTDScanner.setProperty(propertyId, value);
fEntityManager.setProperty(propertyId, value);
} else if(propertyId.equals( ERROR_HANDLER)) {
fErrorReporter.setProperty(propertyId, value);
} else if(propertyId.equals( ENTITY_RESOLVER)) {
fEntityResolver = (XMLEntityResolver)value;
fEntityManager.setProperty(propertyId, value);
} else if(propertyId.equals( GRAMMAR_POOL)) {
fGrammarPool = (XMLGrammarPool)value;
} else {
throw new XMLConfigurationException(XMLConfigurationException.NOT_RECOGNIZED, propertyId);
}
|
|