/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* This class is the non vlaidating parser configuration
* used to parse XML 1.0 and XML 1.1 documents.
*
* Xerces parser that uses this configuration is <strong>not</strong> <a href="http://www.w3.org/TR/REC-xml#sec-conformance">conformant</a>
* non-validating XML processor, since conformant non-validating processor is required
* to process "all the declarations they read in the internal DTD subset ... must use the information in those declarations to normalize attribute values,
* include the replacement text of internal entities, and supply default attribute values".
* @author Elena Litani, IBM
* @author John Kim, IBM
* @author Michael Glavassevich, IBM
*
* @version $Id: XML11NonValidatingConfiguration.java,v 1.5 2010-11-01 04:40:10 joehw Exp $
*/
implements XMLPullParserConfiguration, XML11Configurable {
//
// Constants
//
"com.sun.org.apache.xerces.internal.impl.dv.dtd.XML11DTDDVFactoryImpl";
// feature identifiers
/** Feature identifier: validation. */
/** Feature identifier: namespaces. */
/** Feature identifier: external general entities. */
/** Feature identifier: external parameter entities. */
/** Feature identifier: continue after fatal error. */
// property identifiers
/** Property identifier: xml string. */
/** Property identifier: symbol table. */
/** Property identifier: error handler. */
/** Property identifier: entity resolver. */
/** Property identifier: error reporter. */
/** Property identifier: entity manager. */
/** Property identifier document scanner: */
/** Property identifier: DTD scanner. */
/** Property identifier: grammar pool. */
/** Property identifier: DTD validator. */
/** Property identifier: namespace binder. */
/** Property identifier: datatype validator factory. */
// debugging
/** Set to true and recompile to print exception stack trace. */
protected static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
//
// Data
//
/** XML 1.0 Components. */
/** XML 1.1. Components. */
/** Common components: XMLEntityManager, XMLErrorReporter */
/** The document handler. */
/** The DTD handler. */
/** The DTD content model handler. */
/** Last component in the document pipeline */
/**
* True if a parse is in progress. This state is needed because
* some features/properties cannot be set while parsing (e.g.
* namespaces).
*/
protected boolean fParseInProgress = false;
/** fConfigUpdated is set to true if there has been any change to the configuration settings,
* i.e a feature or a property was changed.
*/
protected boolean fConfigUpdated = false;
//
// XML 1.0 components
//
/** The XML 1.0 Datatype validator factory. */
/** The XML 1.0 Document scanner that does namespace binding. */
/** The XML 1.0 Non-namespace implementation of scanner */
/** The XML 1.0 DTD scanner. */
//
// XML 1.1 components
//
/** The XML 1.1 datatype factory. **/
/** The XML 1.1 document scanner that does namespace binding. **/
/** The XML 1.1 document scanner that does not do namespace binding. **/
/** The XML 1.1 DTD scanner. **/
//
// Common components
//
/** Grammar pool. */
/** Error reporter. */
/** Entity manager. */
/** Current scanner */
/** Current Datatype validator factory. */
/** Current DTD scanner. */
/** Flag indiciating whether XML11 components have been initialized. */
private boolean f11Initialized = false;
//
// Constructors
//
/** Default constructor. */
public XML11NonValidatingConfiguration() {
} // <init>()
/**
* Constructs a parser configuration using the specified symbol table.
*
* @param symbolTable The symbol table to use.
*/
} // <init>(SymbolTable)
/**
* Constructs a parser configuration using the specified symbol table and
* grammar pool.
* <p>
* <strong>REVISIT:</strong>
* Grammar pool will be updated when the new validation engine is
* implemented.
*
* @param symbolTable The symbol table to use.
* @param grammarPool The grammar pool to use.
*/
} // <init>(SymbolTable,XMLGrammarPool)
/**
* Constructs a parser configuration using the specified symbol table,
* grammar pool, and parent settings.
* <p>
* <strong>REVISIT:</strong>
* Grammar pool will be updated when the new validation engine is
* implemented.
*
* @param symbolTable The symbol table to use.
* @param grammarPool The grammar pool to use.
* @param parentSettings The parent settings.
*/
public XML11NonValidatingConfiguration(
super(parentSettings);
// create a vector to hold all the components in use
// XML 1.0 specialized components
fComponents = new ArrayList();
// XML 1.1 specialized components
fXML11Components = new ArrayList();
// Common components for XML 1.1. and XML 1.0
fCommonComponents = new ArrayList();
// create table for features and properties
fProperties = new HashMap();
// add default recognized features
final String[] recognizedFeatures =
{
CONTINUE_AFTER_FATAL_ERROR, // from XMLDTDScannerImpl
};
// set state for default features
// add default recognized properties
final String[] recognizedProperties =
{
XMLGRAMMAR_POOL, };
if (symbolTable == null) {
symbolTable = new SymbolTable();
}
if (fGrammarPool != null) {
}
fEntityManager = new XMLEntityManager();
fErrorReporter = new XMLErrorReporter();
fDTDScanner = new XMLDTDScannerImpl();
fValidationManager = new ValidationManager();
fVersionDetector = new XMLVersionDetector();
// add message formatters
}
// set locale
try {
} catch (XNIException e) {
// do nothing
// REVISIT: What is the right thing to do? -Ac
}
fConfigUpdated = false;
} // <init>(SymbolTable,XMLGrammarPool)
/**
* Sets the input source for the document to parse.
*
* @param inputSource The document's input source.
*
* @exception XMLConfigurationException Thrown if there is a
* configuration error when initializing the
* parser.
* @exception IOException Thrown on I/O error.
*
* @see #parse(boolean)
*/
throws XMLConfigurationException, IOException {
// 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..?
} // setInputSource(XMLInputSource)
/**
* Set the locale to use for messages.
*
* @param locale The locale object to use for localization of messages.
*
* @exception XNIException Thrown if the parser does not support the
* specified locale.
*/
} // setLocale(Locale)
/**
* Sets the document handler on the last component in the pipeline
* to receive information about the document.
*
* @param documentHandler The document handler.
*/
if (fLastComponent != null) {
if (fDocumentHandler !=null){
}
}
} // setDocumentHandler(XMLDocumentHandler)
/** Returns the registered document handler. */
return fDocumentHandler;
} // getDocumentHandler():XMLDocumentHandler
/**
* Sets the DTD handler.
*
* @param dtdHandler The DTD handler.
*/
} // setDTDHandler(XMLDTDHandler)
/** Returns the registered DTD handler. */
return fDTDHandler;
} // getDTDHandler():XMLDTDHandler
/**
* Sets the DTD content model handler.
*
* @param handler The DTD content model handler.
*/
} // setDTDContentModelHandler(XMLDTDContentModelHandler)
/** Returns the registered DTD content model handler. */
return fDTDContentModelHandler;
} // getDTDContentModelHandler():XMLDTDContentModelHandler
/**
* Sets the resolver used to resolve external entities. The EntityResolver
* interface supports resolution of public and system identifiers.
*
* @param resolver The new entity resolver. Passing a null value will
* uninstall the currently installed resolver.
*/
} // setEntityResolver(XMLEntityResolver)
/**
* Return the current entity resolver.
*
* @return The current entity resolver, or null if none
* has been registered.
* @see #setEntityResolver
*/
} // getEntityResolver():XMLEntityResolver
/**
* Allow an application to register an error event handler.
*
* <p>If the application does not register an error handler, all
* error events reported by the SAX parser will be silently
* ignored; however, normal processing may not continue. It is
* highly recommended that all SAX applications implement an
* error handler to avoid unexpected bugs.</p>
*
* <p>Applications may register a new or different handler in the
* middle of a parse, and the SAX parser must begin using the new
* handler immediately.</p>
*
* @param errorHandler The error handler.
* @exception java.lang.NullPointerException If the handler
* argument is null.
* @see #getErrorHandler
*/
} // setErrorHandler(XMLErrorHandler)
/**
* Return the current error handler.
*
* @return The current error handler, or null if none
* has been registered.
* @see #setErrorHandler
*/
// REVISIT: Should this be a property?
} // getErrorHandler():XMLErrorHandler
/**
* 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.
*/
public void cleanup() {
}
/**
* Parses the specified input source.
*
* @param source The input source.
*
* @exception XNIException Throws exception on XNI error.
* @exception java.io.IOException Throws exception on i/o error.
*/
if (fParseInProgress) {
// REVISIT - need to add new error message
throw new XNIException("FWK005 parse may not be called while parsing.");
}
fParseInProgress = true;
try {
parse(true);
} catch (XNIException ex) {
throw ex;
} catch (IOException ex) {
throw ex;
} catch (RuntimeException ex) {
throw ex;
throw new XNIException(ex);
} finally {
fParseInProgress = false;
// close all streams opened by xerces
this.cleanup();
}
} // parse(InputSource)
//
// reset and configure pipeline and set InputSource.
if (fInputSource != null) {
try {
fVersionDetector.reset(this);
resetCommon();
resetXML11();
} else {
reset();
}
// mark configuration as fixed
fConfigUpdated = false;
// resets and sets the pipeline.
fInputSource = null;
} catch (XNIException ex) {
throw ex;
} catch (IOException ex) {
throw ex;
} catch (RuntimeException ex) {
throw ex;
throw new XNIException(ex);
}
}
try {
} catch (XNIException ex) {
throw ex;
} catch (IOException ex) {
throw ex;
} catch (RuntimeException ex) {
throw ex;
throw new XNIException(ex);
}
} // parse(boolean):boolean
/**
* Returns the state of a feature.
*
* @param featureId The feature identifier.
* @return true if the feature is supported
*
* @throws XMLConfigurationException Thrown for configuration error.
* In general, components should
* only throw this exception if
* it is <strong>really</strong>
* a critical error.
*/
throws XMLConfigurationException {
// make this feature special
}
return super.getFeatureState(featureId);
} // getFeature(String):boolean
/**
* Set the state of a feature.
*
* Set the state of any feature in a SAX2 parser. The parser
* might not recognize the feature, and if it does recognize
* it, it might not be able to fulfill the request.
*
* @param featureId The unique identifier (URI) of the feature.
* @param state The requested state of the feature (true or false).
*
* @exception com.sun.org.apache.xerces.internal.xni.parser.XMLConfigurationException If the
* requested feature is not known.
*/
throws XMLConfigurationException {
fConfigUpdated = true;
// forward to every XML 1.0 component
for (int i = 0; i < count; i++) {
}
// forward it to common components
for (int i = 0; i < count; i++) {
}
// forward to every XML 1.1 component
for (int i = 0; i < count; i++) {
try{
}
catch (Exception e){
// no op
}
}
// save state if noone "objects"
} // setFeature(String,boolean)
/**
* setProperty
*
* @param propertyId
* @param value
*/
throws XMLConfigurationException {
fConfigUpdated = true;
// forward to every XML 1.0 component
for (int i = 0; i < count; i++) {
}
// forward it to every common Component
for (int i = 0; i < count; i++) {
}
// forward it to every XML 1.1 component
for (int i = 0; i < count; i++) {
try{
}
catch (Exception e){
// ignore it
}
}
// store value if noone "objects"
} // setProperty(String,Object)
/** Returns the locale. */
return fLocale;
} // getLocale():Locale
/**
* reset all XML 1.0 components before parsing and namespace context
*/
for (int i = 0; i < count; i++) {
c.reset(this);
}
} // reset()
/**
* reset all common components before parsing
*/
// reset common components
for (int i = 0; i < count; i++) {
c.reset(this);
}
} // resetCommon()
/**
* reset all components before parsing and namespace context
*/
// reset every component
for (int i = 0; i < count; i++) {
c.reset(this);
}
} // resetXML11()
/**
* Configures the XML 1.1 pipeline.
* Note: this method also resets the new XML11 components.
*/
protected void configureXML11Pipeline() {
if (fCurrentDVFactory != fXML11DatatypeFactory) {
}
// setup DTD pipeline
if (fCurrentDTDScanner != fXML11DTDScanner) {
}
// setup XML 1.1 document pipeline
if (fCurrentScanner != fXML11NSDocScanner) {
}
if (fDocumentHandler != null) {
}
} else {
// create components
if (fXML11DocScanner == null) {
// non namespace document pipeline
fXML11DocScanner = new XML11DocumentScannerImpl();
}
if (fCurrentScanner != fXML11DocScanner) {
}
if (fDocumentHandler != null) {
}
}
} // configureXML11Pipeline()
/** Configures the pipeline. */
protected void configurePipeline() {
if (fCurrentDVFactory != fDatatypeValidatorFactory) {
// use XML 1.0 datatype library
}
// setup DTD pipeline
if (fCurrentDTDScanner != fDTDScanner) {
}
// setup document pipeline
if (fCurrentScanner != fNamespaceScanner) {
}
if (fDocumentHandler != null) {
}
} else {
// create components
if (fNonNSScanner == null) {
fNonNSScanner = new XMLDocumentScannerImpl();
// add components
}
if (fCurrentScanner != fNonNSScanner) {
}
if (fDocumentHandler != null) {
}
}
} // configurePipeline()
// features and properties
/**
* Check a feature. If feature is know and supported, this method simply
* returns. Otherwise, the appropriate exception is thrown.
*
* @param featureId The unique identifier (URI) of the feature.
*
* @throws XMLConfigurationException Thrown for configuration error.
* In general, components should
* only throw this exception if
* it is <strong>really</strong>
* a critical error.
*/
//
// Xerces Features
//
//
// Allows the parser to validate a document only when it
// on each document instance, automatically.
//
return FeatureState.RECOGNIZED;
}
//
//
// REVISIT
return FeatureState.NOT_SUPPORTED;
}
//
//
// REVISIT
return FeatureState.NOT_SUPPORTED;
}
//
//
return FeatureState.RECOGNIZED;
}
//
//
return FeatureState.RECOGNIZED;
}
//
//
return FeatureState.NOT_SUPPORTED;
}
// special performance feature: only component manager is allowed to set it.
return FeatureState.NOT_SUPPORTED;
}
}
//
// Not recognized
//
return super.checkFeature(featureId);
} // checkFeature(String)
/**
* Check a property. If the property is know and supported, this method
* simply returns. Otherwise, the appropriate exception is thrown.
*
* @param propertyId The unique identifier (URI) of the property
* being set.
*
* @throws XMLConfigurationException Thrown for configuration error.
* In general, components should
* only throw this exception if
* it is <strong>really</strong>
* a critical error.
*/
//
// Xerces Properties
//
return PropertyState.RECOGNIZED;
}
}
return PropertyState.RECOGNIZED;
}
}
// special cases
//
// Value type: String
// Access: read-only
// Get the literal string of characters associated with the
// current event. If the parser recognises and supports this
// property but is not currently parsing text, it should return
// null (this is a good way to check for availability before the
// parse begins).
//
// REVISIT - we should probably ask xml-dev for a precise
// definition of what this is actually supposed to return, and
// in exactly which circumstances.
return PropertyState.NOT_SUPPORTED;
}
}
//
// Not recognized
//
return super.checkProperty(propertyId);
} // checkProperty(String)
/**
* Adds a component to the parser configuration. This method will
* also add all of the component's recognized features and properties
* to the list of default recognized features and properties.
*
* @param component The component to add.
*/
// don't add a component more than once
return;
}
} // addComponent(XMLComponent)
/**
* Adds common component to the parser configuration. This method will
* also add all of the component's recognized features and properties
* to the list of default recognized features and properties.
*
* @param component The component to add.
*/
// don't add a component more than once
return;
}
} // addCommonComponent(XMLComponent)
/**
* Adds an XML 1.1 component to the parser configuration. This method will
* also add all of the component's recognized features and properties
* to the list of default recognized features and properties.
*
* @param component The component to add.
*/
// don't add a component more than once
return;
}
} // addXML11Component(XMLComponent)
/**
* Adds all of the component's recognized features and properties
* to the list of default recognized features and properties, and
* sets default values on the configuration for features and
* properties which were previously absent from the configuration.
*
* @param component The component whose recognized features
* and properties will be added to the configuration
*/
// register component's recognized features
// register component's recognized properties
// set default values
if (recognizedFeatures != null) {
// Do not overwrite values already set on the configuration.
// For newly added components who recognize this feature
// but did not offer a default value, we need to make
// sure these components will get an opportunity to read
// the value before parsing begins.
fConfigUpdated = true;
}
}
}
}
if (recognizedProperties != null) {
// Do not overwrite values already set on the configuration.
// For newly added components who recognize this property
// but did not offer a default value, we need to make
// sure these components will get an opportunity to read
// the value before parsing begins.
fConfigUpdated = true;
}
}
}
}
}
private void initXML11Components() {
if (!f11Initialized) {
// create datatype factory
// setup XML 1.1 DTD pipeline
fXML11DTDScanner = new XML11DTDScannerImpl();
// setup XML 1.1. document pipeline - namespace aware
f11Initialized = true;
}
}
} // class XML11NonValidatingConfiguration