/*
* reserved comment block
* DO NOT REMOVE OR ALTER!
*/
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999-2003 The Apache Software Foundation.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xerces" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 1999, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
*/
/**
* The 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.
* <p>
* This component requires the following features and properties. It
* know ho to set them if no one else does:from the
* <ul>
* <li>http://xml.org/sax/features/namespaces</li>
* </ul>
*
* @xerces.internal
*
* @author Neil Graham, IBM
* @author Michael Glavassevich, IBM
*
* @version $Id: XMLDTDLoader.java,v 1.6 2010-11-01 04:39:42 joehw Exp $
*/
public class XMLDTDLoader
extends XMLDTDProcessor
implements XMLGrammarLoader {
//
// Constants
//
// feature identifiers
/** Feature identifier: standard uri conformant feature. */
/** Feature identifier: balance syntax trees. */
// recognized features:
};
// property identifiers
/** Property identifier: error handler. */
/** Property identifier: entity resolver. */
/** Property identifier: locale. */
/** Recognized properties. */
};
// enforcing strict uri?
private boolean fStrictURI = false;
/** Controls whether the DTD grammar produces balanced syntax trees. */
private boolean fBalanceSyntaxTrees = false;
/** Entity resolver . */
// the scanner we use to actually read the DTD
// the entity manager the scanner needs.
// what's our Locale?
//
// Constructors
//
/** Deny default construction; we need a SymtolTable! */
public XMLDTDLoader() {
this(new SymbolTable());
} // <init>()
this(symbolTable, null);
} // init(SymbolTable)
} // init(SymbolTable, XMLGrammarPool)
if(errorReporter == null) {
errorReporter = new XMLErrorReporter();
}
// Add XML message formatter if there isn't one.
}
if(fEntityResolver instanceof XMLEntityManager) {
} else {
fEntityManager = new XMLEntityManager();
}
fEntityManager.setProperty(Constants.XERCES_PROPERTY_PREFIX + Constants.ERROR_REPORTER_PROPERTY, errorReporter);
fDTDScanner.setDTDHandler(this);
reset();
} // init(SymbolTable, XMLGrammarPool, XMLErrorReporter, XMLEntityResolver)
// XMLGrammarLoader methods
/**
* 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.
*/
} // getRecognizedFeatures():String[]
/**
* Sets the state of a feature. This method is called by the component
* manager any time after reset when a feature changes state.
* <p>
* <strong>Note:</strong> Components should silently ignore features
* that do not affect the operation of the component.
*
* @param featureId The feature identifier.
* @param state The state of the feature.
*
* @throws SAXNotRecognizedException The component should not throw
* this exception.
* @throws SAXNotSupportedException The component should not throw
* this exception.
*/
throws XMLConfigurationException {
fValidation = state;
}
}
}
}
fStrictURI = state;
}
}
else {
}
} // setFeature(String,boolean)
/**
* 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.
*/
} // getRecognizedProperties():String[]
/**
* Returns the state of a property.
*
* @param propertyId The property identifier.
*
* @throws XMLConfigurationException Thrown on configuration error.
*/
throws XMLConfigurationException {
return fSymbolTable;
}
return fErrorReporter;
}
return fErrorReporter.getErrorHandler();
}
return fEntityResolver;
}
return getLocale();
}
return fGrammarPool;
}
return fValidator;
}
} // getProperty(String): Object
/**
* Sets the value of a property. This method is called by the component
* manager any time after reset when a property changes value.
* <p>
* <strong>Note:</strong> Components should silently ignore properties
* that do not affect the operation of the component.
*
* @param propertyId The property identifier.
* @param value The value of the property.
*
* @throws SAXNotRecognizedException The component should not throw
* this exception.
* @throws SAXNotSupportedException The component should not throw
* this exception.
*/
throws XMLConfigurationException {
}
// Add XML message formatter if there isn't one.
}
}
}
}
}
}
else {
}
} // setProperty(String,Object)
/**
* Returns the state of a feature.
*
* @param featureId The feature identifier.
*
* @throws XMLConfigurationException Thrown on configuration error.
*/
throws XMLConfigurationException {
return fValidation;
}
return fWarnDuplicateAttdef;
}
return fWarnOnUndeclaredElemdef;
}
}
return fStrictURI;
}
return fBalanceSyntaxTrees;
}
} //getFeature(String): boolean
/**
* 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)
/** Return the Locale the XMLGrammarLoader is using. */
return fLocale;
} // getLocale(): Locale
/**
* Sets the error handler.
*
* @param errorHandler The error handler.
*/
} // setErrorHandler(XMLErrorHandler)
/** Returns the registered error handler. */
return fErrorReporter.getErrorHandler();
} // getErrorHandler(): XMLErrorHandler
/**
* Sets the entity resolver.
*
* @param entityResolver The new entity resolver.
*/
} // setEntityResolver(XMLEntityResolver)
/** Returns the registered entity resolver. */
return fEntityResolver;
} // getEntityResolver(): XMLEntityResolver
/**
* Returns a Grammar object by parsing the contents of the
* entity pointed to by source.
*
* @param source the location of the entity which forms
* the starting point of the grammar to be constructed.
* @throws IOException When a problem is encountered reading the entity
* XNIException When a condition arises (such as a FatalError) that requires parsing
* of the entity be terminated.
*/
throws IOException, XNIException {
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) {
}
else {
}
fGrammarBucket = new DTDGrammarBucket();
fGrammarBucket.setStandalone(false);
// 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.scanDTDExternalSubset(true);
} catch (EOFException e) {
// expected behaviour...
}
finally {
// Close all streams opened by the parser.
}
}
return fDTDGrammar;
} // loadGrammar(XMLInputSource): Grammar
/**
* into the existing DTD grammar owned by the given DTDValidator.
*/
throws IOException, XNIException {
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.
}
// process external subset
fDTDScanner.scanDTDExternalSubset(true);
}
}
catch (EOFException e) {
// expected behaviour...
}
finally {
// Close all streams opened by the parser.
}
}
} // loadGrammarWithContext(XMLDTDValidator, String, String, String, String, String)
// reset all the components that we rely upon
protected void reset() {
super.reset();
fDTDScanner.reset();
}
} // createDTDScanner(SymbolTable, XMLErrorReporter, XMLEntityManager) : XMLDTDScannerImpl
protected short getScannerVersion() {
return Constants.XML_VERSION_1_0;
} // getScannerVersion() : short
} // class XMLDTDLoader