FileDocCategorySizeDatePackage
DigesterFactory.javaAPI DocGlassfish v2 API12839Fri May 04 22:32:28 BST 2007org.apache.catalina.startup

DigesterFactory

public class DigesterFactory extends Object
Wrapper class around the Digester that hide Digester's initialization details
author
Jean-Francois Arcand

Fields Summary
private static String
schemaResourcePrefix
The path prefix for .xsd resources
private static String
dtdResourcePrefix
The path prefix for .dtd resources
Constructors Summary
Methods Summary
public static com.sun.org.apache.commons.digester.DigesternewDigester()
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.DigesternewDigester(com.sun.org.apache.commons.digester.RuleSet rule)
Create a Digester parser with XML validation turned off. ???*

param
rule an instance of Rule

        return newDigester(false,false,rule);
    
public static com.sun.org.apache.commons.digester.DigesternewDigester(boolean xmlValidation, boolean xmlNamespaceAware, com.sun.org.apache.commons.digester.RuleSet rule)
Create a Digester parser.

param
xmlValidation turn on/off xml validation
param
xmlNamespaceAware turn on/off namespace validation
param
rule an instance of Rule


        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.DigesterpatchXerces(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 voidregister(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 voidregisterLocalSchema(org.apache.catalina.util.SchemaResolver schemaResolver)
Utilities used to force the parser to use local schema, when available, instead of the schemaLocation XML element.

param
The instance on which properties are set.
return
an instance ready to parse XML schema.


        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 voidsetDtdResourcePrefix(java.lang.String prefix)
Sets the path prefix for .dtd resources

        dtdResourcePrefix = prefix;
    
public static voidsetSchemaResourcePrefix(java.lang.String prefix)
Sets the path prefix for .xsd resources

        schemaResourcePrefix = prefix;
    
protected static voidturnOnValidation(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 voidturnOnXercesValidation(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);
        }