/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* Copyright 2001-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 is the non validating parser configuration. It extends the basic
* configuration with the set of following parser components:
* Document scanner, DTD scanner, namespace binder, document handler.
* <p>
* 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
* @version $Id: NonValidatingConfiguration.java,v 1.7 2010-11-01 04:40:09 joehw Exp $
*/
public class NonValidatingConfiguration
extends BasicParserConfiguration
implements XMLPullParserConfiguration {
//
// Constants
//
// feature identifiers
/** Feature identifier: warn on duplicate attribute definition. */
/** Feature identifier: warn on duplicate entity definition. */
/** Feature identifier: warn on undeclared element definition. */
/** Feature identifier: allow Java encodings. */
/** Feature identifier: continue after fatal error. */
/** Feature identifier: load external DTD. */
/** Feature identifier: notify built-in refereces. */
/** Feature identifier: notify character refereces. */
/** Feature identifier: expose schema normalized value */
/** Feature identifier: send element default value via characters() */
// property identifiers
/** 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. */
/** Property identifier: XML Schema validator. */
/** Property identifier: locale. */
// debugging
/** Set to true and recompile to print exception stack trace. */
private static final boolean PRINT_EXCEPTION_STACK_TRACE = false;
//
// Data
//
// components (non-configurable)
/** Grammar pool. */
/** Datatype validator factory. */
// components (configurable)
/** Error reporter. */
/** Entity manager. */
/** Document scanner. */
/** Input Source */
/** DTD scanner. */
// private data
/** Document scanner that does namespace binding. */
/** Default Xerces implementation of scanner*/
/** 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;
// state
/** Locator */
/**
* True if a parse is in progress. This state is needed because
* some features/properties cannot be set while parsing (e.g.
* validation and namespaces).
*/
protected boolean fParseInProgress = false;
//
// Constructors
//
/** Default constructor. */
public NonValidatingConfiguration() {
} // <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.
*/
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
//LOAD_EXTERNAL_DTD, // from XMLDTDScannerImpl
//NOTIFY_BUILTIN_REFS, // from XMLDocumentFragmentScannerImpl
//NOTIFY_CHAR_REFS, // from XMLDocumentFragmentScannerImpl
//WARN_ON_DUPLICATE_ENTITYDEF // from XMLEntityManager
};
// 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(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 = {
};
if(fGrammarPool != null){
}
// this configuration delays creation of the scanner
// till it is known if namespace processing should be performed
if (fDTDScanner != null) {
if (fDTDScanner instanceof XMLComponent) {
}
}
if (fDatatypeValidatorFactory != null) {
}
if (fValidationManager != null) {
}
// add message formatters
}
fConfigUpdated = false;
// set locale
try {
}
catch (XNIException e) {
// do nothing
// REVISIT: What is the right thing to do? -Ac
}
} // <init>(SymbolTable,XMLGrammarPool)
//
// Public methods
//
throws XMLConfigurationException {
fConfigUpdated = true;
}
throws XMLConfigurationException {
}
return super.getPropertyState(propertyId);
}
throws XMLConfigurationException {
fConfigUpdated = true;
}
}
/**
* 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)
throws XMLConfigurationException {
// make this feature special
}
return super.getFeatureState(featureId);
} // getFeature(String):boolean
//
// XMLPullParserConfiguration methods
//
// parsing
/**
* 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)
/**
* Parses the document in a pull parsing fashion.
*
* @param complete True if the pull parser should parse the
* remaining document completely.
*
* @return True if there is more document to parse.
*
* @exception XNIException Any XNI exception, possibly wrapping
* another exception.
* @exception IOException An IO exception from the parser, possibly
* from a byte stream or character stream
* supplied by the parser.
*
* @see #setInputSource
*/
//
// reset and configure pipeline and set InputSource.
if (fInputSource !=null) {
try {
// resets and sets the pipeline.
reset();
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
/**
* 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() {
}
//
// XMLParserConfiguration methods
//
/**
* 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)
//
// Protected methods
//
/**
* Reset all components before parsing.
*
* @throws XNIException Thrown if an error occurs during initialization.
*/
if (fValidationManager != null)
// configure the pipeline and initialize the components
super.reset();
} // reset()
/** Configures the pipeline. */
protected void configurePipeline() {
// create appropriate scanner
// and register it as one of the components.
if (fNamespaceScanner == null) {
}
}
else {
if (fNonNSScanner == null) {
fNonNSScanner = new XMLDocumentScannerImpl();
}
}
// setup dtd pipeline
if (fDTDScanner != 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.
*/
throws XMLConfigurationException {
//
// 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;
}
}
//
// 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.
*/
throws XMLConfigurationException {
//
// Xerces Properties
//
return PropertyState.RECOGNIZED;
}
}
return PropertyState.RECOGNIZED;
}
}
//
// Not recognized
//
return super.checkProperty(propertyId);
} // checkProperty(String)
// factory methods
/** Creates an entity manager. */
return new XMLEntityManager();
} // createEntityManager():XMLEntityManager
/** Creates an error reporter. */
return new XMLErrorReporter();
} // createErrorReporter():XMLErrorReporter
/** Create a document scanner. */
return null;
} // createDocumentScanner():XMLDocumentScanner
/** Create a DTD scanner. */
return new XMLDTDScannerImpl();
} // createDTDScanner():XMLDTDScanner
/** Create a datatype validator factory. */
return DTDDVFactory.getInstance();
} // createDatatypeValidatorFactory():DatatypeValidatorFactory
return new ValidationManager();
}
} // class NonValidatingConfiguration