digester.setValidating(xmlValidation);
digester.setUseContextClassLoader(true);
- if (xmlValidation || xmlNamespaceAware){
- configureSchema(digester);
- }
-
SchemaResolver schemaResolver = new SchemaResolver(digester);
registerLocalSchema(schemaResolver);
}
}
-
- /**
- * Turn on DTD and/or validation (based on the parser implementation)
- */
- protected static void configureSchema(Digester digester){
- URL url = DigesterFactory.class
- .getResource(Constants.WebSchemaResourcePath_25);
-
- if(url == null) {
- log.error("Could not get url for "
- + Constants.WebSchemaResourcePath_25);
- } else {
- digester.setSchema(url.toString());
- }
- }
}
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
*/
protected Rules rules = null;
- /**
+ /**
* The XML schema language to use for validating an XML instance. By
* default this value is set to <code>W3C_XML_SCHEMA</code>
*/
/**
* Return the SAXParserFactory we will use, creating one if necessary.
+ * @throws ParserConfigurationException
+ * @throws SAXNotSupportedException
+ * @throws SAXNotRecognizedException
*/
- public SAXParserFactory getFactory() {
+ public SAXParserFactory getFactory()
+ throws SAXNotRecognizedException, SAXNotSupportedException,
+ ParserConfigurationException {
if (factory == null) {
factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(namespaceAware);
factory.setValidating(validating);
+ if (validating) {
+ // Enable DTD validation
+ factory.setFeature(
+ "http://xml.org/sax/features/validation",
+ true);
+ // Enable schema validation
+ factory.setFeature(
+ "http://apache.org/xml/features/validation/schema",
+ true);
+ }
}
return (factory);
// Create a new parser
try {
- if (validating) {
- Properties properties = new Properties();
- properties.put("SAXParserFactory", getFactory());
- if (schemaLocation != null) {
- properties.put("schemaLocation", schemaLocation);
- properties.put("schemaLanguage", schemaLanguage);
- }
- parser = ParserFeatureSetterFactory.newSAXParser(properties); } else {
- parser = getFactory().newSAXParser();
- }
+ parser = getFactory().newSAXParser();
} catch (Exception e) {
log.error("Digester.getParser: ", e);
return (null);
entityURL = entityValidator.get(publicId);
}
- // Redirect the schema location to a local destination
- if (schemaLocation != null && entityURL == null && systemId != null){
- entityURL = entityValidator.get(systemId);
- }
-
if (entityURL == null) {
if (systemId == null) {
// cannot resolve