DigesterFactorypublic class DigesterFactory extends Object Wrapper class around the Digester that hide Digester's initialization details |
Fields Summary |
---|
private static String | schemaResourcePrefixThe path prefix for .xsd resources | private static String | dtdResourcePrefixThe path prefix for .dtd resources |
Methods Summary |
---|
public static com.sun.org.apache.commons.digester.Digester | newDigester()Create a Digester parser with no Rule
associated and XML validation turned off.
return newDigester(false, false, null);
| public static com.sun.org.apache.commons.digester.Digester | newDigester(com.sun.org.apache.commons.digester.RuleSet rule)Create a Digester parser with XML validation turned off.
???*
return newDigester(false,false,rule);
| public static com.sun.org.apache.commons.digester.Digester | newDigester(boolean xmlValidation, boolean xmlNamespaceAware, com.sun.org.apache.commons.digester.RuleSet rule)Create a Digester parser.
URL url = null;
Digester digester = new Digester();
digester.setNamespaceAware(xmlNamespaceAware);
digester.setValidating(xmlValidation);
digester.setUseContextClassLoader(true);
String parserName =
digester.getFactory().getClass().getName();
if (parserName.indexOf("xerces")!=-1) {
digester = patchXerces(digester);
}
SchemaResolver schemaResolver = new SchemaResolver(digester);
if (xmlValidation) {
// Xerces 2.3 and up has a special way to turn on validation
// for both DTD and Schema
if (parserName.indexOf("xerces")!=-1) {
turnOnXercesValidation(digester);
} else {
turnOnValidation(digester);
}
}
registerLocalSchema(schemaResolver);
digester.setEntityResolver(schemaResolver);
if ( rule != null )
digester.addRuleSet(rule);
return (digester);
| private static com.sun.org.apache.commons.digester.Digester | patchXerces(com.sun.org.apache.commons.digester.Digester digester)Patch Xerces for backward compatibility.
// This feature is needed for backward compatibility with old DDs
// which used Java encoding names such as ISO8859_1 etc.
// with Crimson (bug 4701993). By default, Xerces does not
// support ISO8859_1.
try{
digester.setFeature(
"http://apache.org/xml/features/allow-java-encodings", true);
} catch(ParserConfigurationException e){
// log("contextConfig.registerLocalSchema", e);
} catch(SAXNotRecognizedException e){
// log("contextConfig.registerLocalSchema", e);
} catch(SAXNotSupportedException e){
// log("contextConfig.registerLocalSchema", e);
}
return digester;
| protected static void | register(org.apache.catalina.util.SchemaResolver schemaResolver, java.lang.String resourceURL, java.lang.String resourcePublicId)Load the resource and add it to the
URL url = DigesterFactory.class.getResource(resourceURL);
schemaResolver.register(resourcePublicId , url.toString() );
| protected static void | registerLocalSchema(org.apache.catalina.util.SchemaResolver schemaResolver)Utilities used to force the parser to use local schema, when available,
instead of the schemaLocation XML element.
if (schemaResourcePrefix != null) {
// Java EE 5
register(
schemaResolver,
schemaResourcePrefix + Constants.JAVA_EE_SCHEMA_PUBLIC_ID_5,
Constants.JAVA_EE_SCHEMA_PUBLIC_ID_5);
// J2EE
register(
schemaResolver,
schemaResourcePrefix + Constants.J2eeSchemaPublicId_14,
Constants.J2eeSchemaPublicId_14);
// W3C
register(
schemaResolver,
schemaResourcePrefix + Constants.W3cSchemaPublicId_10,
Constants.W3cSchemaPublicId_10);
// JSP
register(
schemaResolver,
schemaResourcePrefix + Constants.JspSchemaPublicId_20,
Constants.JspSchemaPublicId_20);
register(
schemaResolver,
schemaResourcePrefix + Constants.JSP_SCHEMA_PUBLIC_ID_21,
Constants.JSP_SCHEMA_PUBLIC_ID_21);
// TLD
register(
schemaResolver,
schemaResourcePrefix + Constants.TldSchemaPublicId_20,
Constants.TldSchemaPublicId_20);
register(
schemaResolver,
schemaResourcePrefix + Constants.TLD_SCHEMA_PUBLIC_ID_21,
Constants.TLD_SCHEMA_PUBLIC_ID_21);
// web.xml
register(
schemaResolver,
schemaResourcePrefix + Constants.WebSchemaPublicId_24,
Constants.WebSchemaPublicId_24);
register(
schemaResolver,
schemaResourcePrefix + Constants.WebSchemaPublicId_25,
Constants.WebSchemaPublicId_25);
// Web Service
register(
schemaResolver,
schemaResourcePrefix + Constants.J2eeWebServiceClientSchemaPublicId_11,
Constants.J2eeWebServiceClientSchemaPublicId_11);
} else {
// Java EE 5
register(schemaResolver,
Constants.JAVA_EE_SCHEMA_RESOURCE_PATH_5,
Constants.JAVA_EE_SCHEMA_PUBLIC_ID_5);
// J2EE
register(schemaResolver,
Constants.J2eeSchemaResourcePath_14,
Constants.J2eeSchemaPublicId_14);
// W3C
register(schemaResolver,
Constants.W3cSchemaResourcePath_10,
Constants.W3cSchemaPublicId_10);
// JSP
register(schemaResolver,
Constants.JspSchemaResourcePath_20,
Constants.JspSchemaPublicId_20);
register(schemaResolver,
Constants.JSP_SCHEMA_RESOURCE_PATH_21,
Constants.JSP_SCHEMA_PUBLIC_ID_21);
// TLD
register(schemaResolver,
Constants.TldSchemaResourcePath_20,
Constants.TldSchemaPublicId_20);
register(schemaResolver,
Constants.TLD_SCHEMA_RESOURCE_PATH_21,
Constants.TLD_SCHEMA_PUBLIC_ID_21);
// web.xml
register(schemaResolver,
Constants.WebSchemaResourcePath_24,
Constants.WebSchemaPublicId_24);
register(schemaResolver,
Constants.WebSchemaResourcePath_25,
Constants.WebSchemaPublicId_25);
// Web Service
register(schemaResolver,
Constants.J2eeWebServiceClientSchemaResourcePath_11,
Constants.J2eeWebServiceClientSchemaPublicId_11);
}
if (dtdResourcePrefix != null) {
// TLD
register(schemaResolver,
dtdResourcePrefix + "web-jsptaglibrary_1_1.dtd",
Constants.TldDtdPublicId_11);
register(schemaResolver,
dtdResourcePrefix + "web-jsptaglibrary_1_2.dtd",
Constants.TldDtdPublicId_12);
// web.xml
register(schemaResolver,
dtdResourcePrefix + "web-app_2_2.dtd",
Constants.WebDtdPublicId_22);
register(schemaResolver,
dtdResourcePrefix + "web-app_2_3.dtd",
Constants.WebDtdPublicId_23);
} else {
// TLD
register(schemaResolver,
Constants.TldDtdResourcePath_11,
Constants.TldDtdPublicId_11);
register(schemaResolver,
Constants.TldDtdResourcePath_12,
Constants.TldDtdPublicId_12);
// web.xml
register(schemaResolver,
Constants.WebDtdResourcePath_22,
Constants.WebDtdPublicId_22);
register(schemaResolver,
Constants.WebDtdResourcePath_23,
Constants.WebDtdPublicId_23);
}
| public static void | setDtdResourcePrefix(java.lang.String prefix)Sets the path prefix for .dtd resources
dtdResourcePrefix = prefix;
| public static void | setSchemaResourcePrefix(java.lang.String prefix)Sets the path prefix for .xsd resources
schemaResourcePrefix = prefix;
| protected static void | turnOnValidation(com.sun.org.apache.commons.digester.Digester digester)Turn on DTD and/or validation (based on the parser implementation)
URL url = DigesterFactory.class
.getResource(Constants.WebSchemaResourcePath_24);
digester.setSchema(url.toString());
| protected static void | turnOnXercesValidation(com.sun.org.apache.commons.digester.Digester digester)Turn on schema AND DTD validation on Xerces parser.
try{
digester.setFeature(
"http://apache.org/xml/features/validation/dynamic",
true);
digester.setFeature(
"http://apache.org/xml/features/validation/schema",
true);
} catch(ParserConfigurationException e){
// log("contextConfig.registerLocalSchema", e);
} catch(SAXNotRecognizedException e){
// log("contextConfig.registerLocalSchema", e);
} catch(SAXNotSupportedException e){
// log("contextConfig.registerLocalSchema", e);
}
|
|