Constructor: |
protected BasicParserConfiguration() {
//
// Constructors
//
this(null, null);
}
|
protected BasicParserConfiguration(SymbolTable symbolTable) {
this(symbolTable, null);
}
Constructs a parser configuration using the specified symbol table. Parameters:
symbolTable - The symbol table to use.
|
protected BasicParserConfiguration(SymbolTable symbolTable,
XMLComponentManager parentSettings) {
super(parentSettings);
// create a vector to hold all the components in use
fComponents = new ArrayList();
// create storage for recognized features and properties
fRecognizedFeatures = new ArrayList();
fRecognizedProperties = new ArrayList();
// create table for features and properties
fFeatures = new HashMap();
fProperties = new HashMap();
// add default recognized features
final String[] recognizedFeatures = {
PARSER_SETTINGS,
VALIDATION,
NAMESPACES,
EXTERNAL_GENERAL_ENTITIES,
EXTERNAL_PARAMETER_ENTITIES,
};
addRecognizedFeatures(recognizedFeatures);
fFeatures.put(PARSER_SETTINGS, Boolean.TRUE);
// set state for default features
fFeatures.put(VALIDATION, Boolean.FALSE);
fFeatures.put(NAMESPACES, Boolean.TRUE);
fFeatures.put(EXTERNAL_GENERAL_ENTITIES, Boolean.TRUE);
fFeatures.put(EXTERNAL_PARAMETER_ENTITIES, Boolean.TRUE);
// add default recognized properties
final String[] recognizedProperties = {
XML_STRING,
SYMBOL_TABLE,
ERROR_HANDLER,
ENTITY_RESOLVER,
};
addRecognizedProperties(recognizedProperties);
if (symbolTable == null) {
symbolTable = new SymbolTable();
}
fSymbolTable = symbolTable;
fProperties.put(SYMBOL_TABLE, fSymbolTable);
}
Constructs a parser configuration using the specified symbol table
and parent settings. Parameters:
symbolTable - The symbol table to use.
parentSettings - The parent settings.
|
Method from org.apache.xerces.parsers.BasicParserConfiguration Detail: |
protected void addComponent(XMLComponent component) {
// don't add a component more than once
if (fComponents.contains(component)) {
return;
}
fComponents.add(component);
// register component's recognized features
String[] recognizedFeatures = component.getRecognizedFeatures();
addRecognizedFeatures(recognizedFeatures);
// register component's recognized properties
String[] recognizedProperties = component.getRecognizedProperties();
addRecognizedProperties(recognizedProperties);
// set default values
if (recognizedFeatures != null) {
for (int i = 0; i < recognizedFeatures.length; i++) {
String featureId = recognizedFeatures[i];
Boolean state = component.getFeatureDefault(featureId);
if (state != null) {
super.setFeature(featureId, state.booleanValue());
}
}
}
if (recognizedProperties != null) {
for (int i = 0; i < recognizedProperties.length; i++) {
String propertyId = recognizedProperties[i];
Object value = component.getPropertyDefault(propertyId);
if (value != null) {
super.setProperty(propertyId, value);
}
}
}
}
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. |
protected void checkFeature(String featureId) throws XMLConfigurationException {
//
// Xerces Features
//
if (featureId.startsWith(Constants.XERCES_FEATURE_PREFIX)) {
final int suffixLength = featureId.length() - Constants.XERCES_FEATURE_PREFIX.length();
//
// special performance feature: no one by component manager is allowed to set it
//
if (suffixLength == Constants.PARSER_SETTINGS.length() &&
featureId.endsWith(Constants.PARSER_SETTINGS)) {
short type = XMLConfigurationException.NOT_SUPPORTED;
throw new XMLConfigurationException(type, featureId);
}
}
super.checkFeature(featureId);
}
Check a feature. If feature is know and supported, this method simply
returns. Otherwise, the appropriate exception is thrown. |
protected void checkProperty(String propertyId) throws XMLConfigurationException {
// special cases
if (propertyId.startsWith(Constants.SAX_PROPERTY_PREFIX)) {
final int suffixLength = propertyId.length() - Constants.SAX_PROPERTY_PREFIX.length();
//
// http://xml.org/sax/properties/xml-string
// 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).
//
if (suffixLength == Constants.XML_STRING_PROPERTY.length() &&
propertyId.endsWith(Constants.XML_STRING_PROPERTY)) {
// REVISIT - we should probably ask xml-dev for a precise
// definition of what this is actually supposed to return, and
// in exactly which circumstances.
short type = XMLConfigurationException.NOT_SUPPORTED;
throw new XMLConfigurationException(type, propertyId);
}
}
// check property
super.checkProperty(propertyId);
}
Check a property. If the property is known and supported, this method
simply returns. Otherwise, the appropriate exception is thrown. |
public XMLDTDContentModelHandler getDTDContentModelHandler() {
return fDTDContentModelHandler;
}
Returns the registered DTD content model handler. |
public XMLDTDHandler getDTDHandler() {
return fDTDHandler;
}
Returns the registered DTD handler. |
public XMLDocumentHandler getDocumentHandler() {
return fDocumentHandler;
}
Returns the registered document handler. |
public XMLEntityResolver getEntityResolver() {
// REVISIT: Should this be a property?
return (XMLEntityResolver)fProperties.get(ENTITY_RESOLVER);
}
Return the current entity resolver. |
public XMLErrorHandler getErrorHandler() {
// REVISIT: Should this be a property?
return (XMLErrorHandler)fProperties.get(ERROR_HANDLER);
}
Return the current error handler. |
public Locale getLocale() {
return fLocale;
}
|
abstract public void parse(XMLInputSource inputSource) throws IOException, XNIException
Parse an XML document.
The parser can use this method to instruct this configuration
to begin parsing an XML document from any valid input source
(a character stream, a byte stream, or a URI).
Parsers may not invoke this method while a parse is in progress.
Once a parse is complete, the parser may then parse another XML
document.
This method is synchronous: it will not return until parsing
has ended. If a client application wants to terminate
parsing early, it should throw an exception. |
protected void reset() throws XNIException {
// reset every component
int count = fComponents.size();
for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fComponents.get(i);
c.reset(this);
}
}
reset all components before parsing and namespace context |
public void setDTDContentModelHandler(XMLDTDContentModelHandler handler) {
fDTDContentModelHandler = handler;
}
Sets the DTD content model handler. |
public void setDTDHandler(XMLDTDHandler dtdHandler) {
fDTDHandler = dtdHandler;
}
|
public void setDocumentHandler(XMLDocumentHandler documentHandler) {
fDocumentHandler = documentHandler;
if (fLastComponent != null) {
fLastComponent.setDocumentHandler(fDocumentHandler);
if (fDocumentHandler !=null){
fDocumentHandler.setDocumentSource(fLastComponent);
}
}
}
Sets the document handler on the last component in the pipeline
to receive information about the document. |
public void setEntityResolver(XMLEntityResolver resolver) {
// REVISIT: Should this be a property?
fProperties.put(ENTITY_RESOLVER, resolver);
}
Sets the resolver used to resolve external entities. The EntityResolver
interface supports resolution of public and system identifiers. |
public void setErrorHandler(XMLErrorHandler errorHandler) {
// REVISIT: Should this be a property?
fProperties.put(ERROR_HANDLER, errorHandler);
}
Allow an application to register an error event handler.
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.
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. |
public void setFeature(String featureId,
boolean state) throws XMLConfigurationException {
// forward to every component
int count = fComponents.size();
for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fComponents.get(i);
c.setFeature(featureId, state);
}
// save state if noone "objects"
super.setFeature(featureId, state);
}
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. |
public void setLocale(Locale locale) throws XNIException {
fLocale = locale;
}
Set the locale to use for messages. |
public void setProperty(String propertyId,
Object value) throws XMLConfigurationException {
// forward to every component
int count = fComponents.size();
for (int i = 0; i < count; i++) {
XMLComponent c = (XMLComponent) fComponents.get(i);
c.setProperty(propertyId, value);
}
// store value if noone "objects"
super.setProperty(propertyId, value);
}
|