Java Code Examples for org.apache.tomcat.util.digester.Digester#addRuleSet()

The following examples show how to use org.apache.tomcat.util.digester.Digester#addRuleSet() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DigesterFactory.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Create a <code>Digester</code> parser.
 * @param xmlValidation turn on/off xml validation
 * @param xmlNamespaceAware turn on/off namespace validation
 * @param rule an instance of <code>RuleSet</code> used for parsing the xml.
 * @param blockExternal turn on/off the blocking of external resources
 */
public static Digester newDigester(boolean xmlValidation,
                                   boolean xmlNamespaceAware,
                                   RuleSet rule,
                                   boolean blockExternal) {
    Digester digester = new Digester();
    digester.setNamespaceAware(xmlNamespaceAware);
    digester.setValidating(xmlValidation);
    digester.setUseContextClassLoader(true);
    EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS,
            SERVLET_API_SYSTEM_IDS, blockExternal);
    digester.setEntityResolver(resolver);
    if (rule != null) {
        digester.addRuleSet(rule);
    }

    return digester;
}
 
Example 2
Source File: ContextConfig.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Create (if necessary) and return a Digester configured to process the
 * context configuration descriptor for an application.
 * @return the digester for context.xml files
 */
protected Digester createContextDigester() {
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.setRulesValidation(true);
    Map<Class<?>, List<String>> fakeAttributes = new HashMap<>();
    List<String> objectAttrs = new ArrayList<>();
    objectAttrs.add("className");
    fakeAttributes.put(Object.class, objectAttrs);
    // Ignore attribute added by Eclipse for its internal tracking
    List<String> contextAttrs = new ArrayList<>();
    contextAttrs.add("source");
    fakeAttributes.put(StandardContext.class, contextAttrs);
    digester.setFakeAttributes(fakeAttributes);
    RuleSet contextRuleSet = new ContextRuleSet("", false);
    digester.addRuleSet(contextRuleSet);
    RuleSet namingRuleSet = new NamingRuleSet("Context/");
    digester.addRuleSet(namingRuleSet);
    return digester;
}
 
Example 3
Source File: DigesterFactory.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Create a <code>Digester</code> parser.
 * @param xmlValidation turn on/off xml validation
 * @param xmlNamespaceAware turn on/off namespace validation
 * @param rule an instance of <code>RuleSet</code> used for parsing the xml.
 */
public static Digester newDigester(boolean xmlValidation,
                                   boolean xmlNamespaceAware,
                                   RuleSet rule) {
    Digester digester = new Digester();
    digester.setNamespaceAware(xmlNamespaceAware);
    digester.setValidating(xmlValidation);
    digester.setUseContextClassLoader(true);

    SchemaResolver schemaResolver = new SchemaResolver(digester);
    registerLocalSchema(schemaResolver);
    
    digester.setEntityResolver(schemaResolver);
    if ( rule != null ) {
        digester.addRuleSet(rule);
    }

    return (digester);
}
 
Example 4
Source File: DigesterFactory.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Create a <code>Digester</code> parser.
 * @param xmlValidation turn on/off xml validation
 * @param xmlNamespaceAware turn on/off namespace validation
 * @param rule an instance of <code>RuleSet</code> used for parsing the xml.
 * @param blockExternal turn on/off the blocking of external resources
 * @return a new digester
 */
public static Digester newDigester(boolean xmlValidation,
                                   boolean xmlNamespaceAware,
                                   RuleSet rule,
                                   boolean blockExternal) {
    Digester digester = new Digester();
    digester.setNamespaceAware(xmlNamespaceAware);
    digester.setValidating(xmlValidation);
    digester.setUseContextClassLoader(true);
    EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS,
            SERVLET_API_SYSTEM_IDS, blockExternal);
    digester.setEntityResolver(resolver);
    if (rule != null) {
        digester.addRuleSet(rule);
    }

    return digester;
}
 
Example 5
Source File: Catalina.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Cluster support is optional. The JARs may have been removed.
 */
private void addClusterRuleSet(Digester digester, String prefix) {
    Class<?> clazz = null;
    Constructor<?> constructor = null;
    try {
        clazz = Class.forName("org.apache.catalina.ha.ClusterRuleSet");
        constructor = clazz.getConstructor(String.class);
        RuleSet ruleSet = (RuleSet) constructor.newInstance(prefix);
        digester.addRuleSet(ruleSet);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("catalina.noCluster",
                    e.getClass().getName() + ": " +  e.getMessage()), e);
        } else if (log.isInfoEnabled()) {
            log.info(sm.getString("catalina.noCluster",
                    e.getClass().getName() + ": " +  e.getMessage()));
        }
    }
}
 
Example 6
Source File: ContextConfig.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Create (if necessary) and return a Digester configured to process the
 * context configuration descriptor for an application.
 */
protected Digester createContextDigester() {
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.setRulesValidation(true);
    HashMap<Class<?>, List<String>> fakeAttributes =
        new HashMap<Class<?>, List<String>>();
    ArrayList<String> attrs = new ArrayList<String>();
    attrs.add("className");
    fakeAttributes.put(Object.class, attrs);
    digester.setFakeAttributes(fakeAttributes);
    RuleSet contextRuleSet = new ContextRuleSet("", false);
    digester.addRuleSet(contextRuleSet);
    RuleSet namingRuleSet = new NamingRuleSet("Context/");
    digester.addRuleSet(namingRuleSet);
    return digester;
}
 
Example 7
Source File: Catalina.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Cluster support is optional. The JARs may have been removed.
 */
private void addClusterRuleSet(Digester digester, String prefix) {
    Class<?> clazz = null;
    Constructor<?> constructor = null;
    try {
        clazz = Class.forName("org.apache.catalina.ha.ClusterRuleSet");
        constructor = clazz.getConstructor(String.class);
        RuleSet ruleSet = (RuleSet) constructor.newInstance(prefix);
        digester.addRuleSet(ruleSet);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("catalina.noCluster",
                    e.getClass().getName() + ": " +  e.getMessage()), e);
        } else if (log.isInfoEnabled()) {
            log.info(sm.getString("catalina.noCluster",
                    e.getClass().getName() + ": " +  e.getMessage()));
        }
    }
}
 
Example 8
Source File: DigesterFactory.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Create a <code>Digester</code> parser.
 * @param xmlValidation turn on/off xml validation
 * @param xmlNamespaceAware turn on/off namespace validation
 * @param rule an instance of <code>RuleSet</code> used for parsing the xml.
 */
public static Digester newDigester(boolean xmlValidation,
                                   boolean xmlNamespaceAware,
                                   RuleSet rule) {
    Digester digester = new Digester();
    digester.setNamespaceAware(xmlNamespaceAware);
    digester.setValidating(xmlValidation);
    digester.setUseContextClassLoader(true);

    SchemaResolver schemaResolver = new SchemaResolver(digester);
    registerLocalSchema(schemaResolver);
    
    digester.setEntityResolver(schemaResolver);
    if ( rule != null ) {
        digester.addRuleSet(rule);
    }

    return (digester);
}
 
Example 9
Source File: DigesterFactory.java    From Tomcat7.0.67 with Apache License 2.0 6 votes vote down vote up
/**
 * Create a <code>Digester</code> parser.
 * @param xmlValidation turn on/off xml validation
 * @param xmlNamespaceAware turn on/off namespace validation
 * @param rule an instance of <code>RuleSet</code> used for parsing the xml.
 * @param blockExternal turn on/off the blocking of external resources
 */
public static Digester newDigester(boolean xmlValidation,
                                   boolean xmlNamespaceAware,
                                   RuleSet rule,
                                   boolean blockExternal) {
    Digester digester = new Digester();
    digester.setNamespaceAware(xmlNamespaceAware);
    digester.setValidating(xmlValidation);
    digester.setUseContextClassLoader(true);
    EntityResolver2 resolver = new LocalResolver(SERVLET_API_PUBLIC_IDS,
            SERVLET_API_SYSTEM_IDS, blockExternal);
    digester.setEntityResolver(resolver);
    if (rule != null) {
        digester.addRuleSet(rule);
    }

    return digester;
}
 
Example 10
Source File: Catalina.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Cluster support is optional. The JARs may have been removed.
 */
private void addClusterRuleSet(Digester digester, String prefix) {
    Class<?> clazz = null;
    Constructor<?> constructor = null;
    try {
        clazz = Class.forName("org.apache.catalina.ha.ClusterRuleSet");
        constructor = clazz.getConstructor(String.class);
        RuleSet ruleSet = (RuleSet) constructor.newInstance(prefix);
        digester.addRuleSet(ruleSet);
    } catch (Exception e) {
        if (log.isDebugEnabled()) {
            log.debug(sm.getString("catalina.noCluster",
                    e.getClass().getName() + ": " +  e.getMessage()), e);
        } else if (log.isInfoEnabled()) {
            log.info(sm.getString("catalina.noCluster",
                    e.getClass().getName() + ": " +  e.getMessage()));
        }
    }
}
 
Example 11
Source File: ContextConfig.java    From tomcatsrc with Apache License 2.0 6 votes vote down vote up
/**
 * Create (if necessary) and return a Digester configured to process the
 * context configuration descriptor for an application.
 */
protected Digester createContextDigester() {
    Digester digester = new Digester();
    digester.setValidating(false);
    digester.setRulesValidation(true);
    HashMap<Class<?>, List<String>> fakeAttributes =
        new HashMap<Class<?>, List<String>>();
    ArrayList<String> attrs = new ArrayList<String>();
    attrs.add("className");
    fakeAttributes.put(Object.class, attrs);
    digester.setFakeAttributes(fakeAttributes);
    RuleSet contextRuleSet = new ContextRuleSet("", false);
    digester.addRuleSet(contextRuleSet);
    RuleSet namingRuleSet = new NamingRuleSet("Context/");
    digester.addRuleSet(namingRuleSet);
    return digester;
}
 
Example 12
Source File: RealmRuleSet.java    From Tomcat8-Source-Read with MIT License 5 votes vote down vote up
private void addRuleInstances(Digester digester, String pattern, String methodName) {
    digester.addObjectCreate(pattern, null /* MUST be specified in the element */,
            "className");
    digester.addSetProperties(pattern);
    digester.addSetNext(pattern, methodName, "org.apache.catalina.Realm");
    digester.addRuleSet(new CredentialHandlerRuleSet(pattern + "/"));
}
 
Example 13
Source File: EngineRuleSet.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Add the set of Rule instances defined in this RuleSet to the
 * specified <code>Digester</code> instance, associating them with
 * our namespace URI (if any).  This method should only be called
 * by a Digester instance.</p>
 *
 * @param digester Digester instance to which the new Rule instances
 *  should be added.
 */
@Override
public void addRuleInstances(Digester digester) {
    
    digester.addObjectCreate(prefix + "Engine",
                             "org.apache.catalina.core.StandardEngine",
                             "className");
    digester.addSetProperties(prefix + "Engine");
    digester.addRule(prefix + "Engine",
                     new LifecycleListenerRule
                     ("org.apache.catalina.startup.EngineConfig",
                      "engineConfigClass"));
    digester.addSetNext(prefix + "Engine",
                        "setContainer",
                        "org.apache.catalina.Container");

    //Cluster configuration start
    digester.addObjectCreate(prefix + "Engine/Cluster",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Cluster");
    digester.addSetNext(prefix + "Engine/Cluster",
                        "setCluster",
                        "org.apache.catalina.Cluster");
    //Cluster configuration end

    digester.addObjectCreate(prefix + "Engine/Listener",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Listener");
    digester.addSetNext(prefix + "Engine/Listener",
                        "addLifecycleListener",
                        "org.apache.catalina.LifecycleListener");


    digester.addRuleSet(new RealmRuleSet(prefix + "Engine/"));

    digester.addObjectCreate(prefix + "Engine/Valve",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Valve");
    digester.addSetNext(prefix + "Engine/Valve",
                        "addValve",
                        "org.apache.catalina.Valve");

}
 
Example 14
Source File: EngineRuleSet.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Add the set of Rule instances defined in this RuleSet to the
 * specified <code>Digester</code> instance, associating them with
 * our namespace URI (if any).  This method should only be called
 * by a Digester instance.</p>
 *
 * @param digester Digester instance to which the new Rule instances
 *  should be added.
 */
@Override
public void addRuleInstances(Digester digester) {
    
    digester.addObjectCreate(prefix + "Engine",
                             "org.apache.catalina.core.StandardEngine",
                             "className");
    digester.addSetProperties(prefix + "Engine");
    digester.addRule(prefix + "Engine",
                     new LifecycleListenerRule
                     ("org.apache.catalina.startup.EngineConfig",
                      "engineConfigClass"));
    digester.addSetNext(prefix + "Engine",
                        "setContainer",
                        "org.apache.catalina.Container");

    //Cluster configuration start
    digester.addObjectCreate(prefix + "Engine/Cluster",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Cluster");
    digester.addSetNext(prefix + "Engine/Cluster",
                        "setCluster",
                        "org.apache.catalina.Cluster");
    //Cluster configuration end

    digester.addObjectCreate(prefix + "Engine/Listener",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Listener");
    digester.addSetNext(prefix + "Engine/Listener",
                        "addLifecycleListener",
                        "org.apache.catalina.LifecycleListener");


    digester.addRuleSet(new RealmRuleSet(prefix + "Engine/"));

    digester.addObjectCreate(prefix + "Engine/Valve",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Valve");
    digester.addSetNext(prefix + "Engine/Valve",
                        "addValve",
                        "org.apache.catalina.Valve");

}
 
Example 15
Source File: HostRuleSet.java    From tomcatsrc with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Add the set of Rule instances defined in this RuleSet to the
 * specified <code>Digester</code> instance, associating them with
 * our namespace URI (if any).  This method should only be called
 * by a Digester instance.</p>
 *
 * @param digester Digester instance to which the new Rule instances
 *  should be added.
 */
@Override
public void addRuleInstances(Digester digester) {

    digester.addObjectCreate(prefix + "Host",
                             "org.apache.catalina.core.StandardHost",
                             "className");
    digester.addSetProperties(prefix + "Host");
    digester.addRule(prefix + "Host",
                     new CopyParentClassLoaderRule());
    digester.addRule(prefix + "Host",
                     new LifecycleListenerRule
                     ("org.apache.catalina.startup.HostConfig",
                      "hostConfigClass"));
    digester.addSetNext(prefix + "Host",
                        "addChild",
                        "org.apache.catalina.Container");

    digester.addCallMethod(prefix + "Host/Alias",
                           "addAlias", 0);

    //Cluster configuration start
    digester.addObjectCreate(prefix + "Host/Cluster",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Cluster");
    digester.addSetNext(prefix + "Host/Cluster",
                        "setCluster",
                        "org.apache.catalina.Cluster");
    //Cluster configuration end

    digester.addObjectCreate(prefix + "Host/Listener",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Listener");
    digester.addSetNext(prefix + "Host/Listener",
                        "addLifecycleListener",
                        "org.apache.catalina.LifecycleListener");

    digester.addRuleSet(new RealmRuleSet(prefix + "Host/"));

    digester.addObjectCreate(prefix + "Host/Valve",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Valve");
    digester.addSetNext(prefix + "Host/Valve",
                        "addValve",
                        "org.apache.catalina.Valve");

}
 
Example 16
Source File: HostRuleSet.java    From Tomcat7.0.67 with Apache License 2.0 4 votes vote down vote up
/**
 * <p>Add the set of Rule instances defined in this RuleSet to the
 * specified <code>Digester</code> instance, associating them with
 * our namespace URI (if any).  This method should only be called
 * by a Digester instance.</p>
 *
 * @param digester Digester instance to which the new Rule instances
 *  should be added.
 */
@Override
public void addRuleInstances(Digester digester) {

    digester.addObjectCreate(prefix + "Host",
                             "org.apache.catalina.core.StandardHost",
                             "className");
    digester.addSetProperties(prefix + "Host");
    digester.addRule(prefix + "Host",
                     new CopyParentClassLoaderRule());
    digester.addRule(prefix + "Host",
                     new LifecycleListenerRule
                     ("org.apache.catalina.startup.HostConfig",
                      "hostConfigClass"));
    digester.addSetNext(prefix + "Host",
                        "addChild",
                        "org.apache.catalina.Container");

    digester.addCallMethod(prefix + "Host/Alias",
                           "addAlias", 0);

    //Cluster configuration start
    digester.addObjectCreate(prefix + "Host/Cluster",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Cluster");
    digester.addSetNext(prefix + "Host/Cluster",
                        "setCluster",
                        "org.apache.catalina.Cluster");
    //Cluster configuration end

    digester.addObjectCreate(prefix + "Host/Listener",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Listener");
    digester.addSetNext(prefix + "Host/Listener",
                        "addLifecycleListener",
                        "org.apache.catalina.LifecycleListener");

    digester.addRuleSet(new RealmRuleSet(prefix + "Host/"));

    digester.addObjectCreate(prefix + "Host/Valve",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Valve");
    digester.addSetNext(prefix + "Host/Valve",
                        "addValve",
                        "org.apache.catalina.Valve");

}
 
Example 17
Source File: EngineRuleSet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * <p>Add the set of Rule instances defined in this RuleSet to the
 * specified <code>Digester</code> instance, associating them with
 * our namespace URI (if any).  This method should only be called
 * by a Digester instance.</p>
 *
 * @param digester Digester instance to which the new Rule instances
 *  should be added.
 */
@Override
public void addRuleInstances(Digester digester) {

    digester.addObjectCreate(prefix + "Engine",
                             "org.apache.catalina.core.StandardEngine",
                             "className");
    digester.addSetProperties(prefix + "Engine");
    digester.addRule(prefix + "Engine",
                     new LifecycleListenerRule
                     ("org.apache.catalina.startup.EngineConfig",
                      "engineConfigClass"));
    digester.addSetNext(prefix + "Engine",
                        "setContainer",
                        "org.apache.catalina.Engine");

    //Cluster configuration start
    digester.addObjectCreate(prefix + "Engine/Cluster",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Cluster");
    digester.addSetNext(prefix + "Engine/Cluster",
                        "setCluster",
                        "org.apache.catalina.Cluster");
    //Cluster configuration end

    digester.addObjectCreate(prefix + "Engine/Listener",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Listener");
    digester.addSetNext(prefix + "Engine/Listener",
                        "addLifecycleListener",
                        "org.apache.catalina.LifecycleListener");


    digester.addRuleSet(new RealmRuleSet(prefix + "Engine/"));

    digester.addObjectCreate(prefix + "Engine/Valve",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Engine/Valve");
    digester.addSetNext(prefix + "Engine/Valve",
                        "addValve",
                        "org.apache.catalina.Valve");

}
 
Example 18
Source File: HostRuleSet.java    From Tomcat8-Source-Read with MIT License 4 votes vote down vote up
/**
 * <p>Add the set of Rule instances defined in this RuleSet to the
 * specified <code>Digester</code> instance, associating them with
 * our namespace URI (if any).  This method should only be called
 * by a Digester instance.</p>
 *
 * @param digester Digester instance to which the new Rule instances
 *  should be added.
 */
@Override
public void addRuleInstances(Digester digester) {

    digester.addObjectCreate(prefix + "Host",
                             "org.apache.catalina.core.StandardHost",
                             "className");
    digester.addSetProperties(prefix + "Host");
    digester.addRule(prefix + "Host",
                     new CopyParentClassLoaderRule());
    digester.addRule(prefix + "Host",
                     new LifecycleListenerRule
                     ("org.apache.catalina.startup.HostConfig",
                      "hostConfigClass"));
    digester.addSetNext(prefix + "Host",
                        "addChild",
                        "org.apache.catalina.Container");

    digester.addCallMethod(prefix + "Host/Alias",
                           "addAlias", 0);

    //Cluster configuration start
    digester.addObjectCreate(prefix + "Host/Cluster",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Cluster");
    digester.addSetNext(prefix + "Host/Cluster",
                        "setCluster",
                        "org.apache.catalina.Cluster");
    //Cluster configuration end

    digester.addObjectCreate(prefix + "Host/Listener",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Listener");
    digester.addSetNext(prefix + "Host/Listener",
                        "addLifecycleListener",
                        "org.apache.catalina.LifecycleListener");

    digester.addRuleSet(new RealmRuleSet(prefix + "Host/"));

    digester.addObjectCreate(prefix + "Host/Valve",
                             null, // MUST be specified in the element
                             "className");
    digester.addSetProperties(prefix + "Host/Valve");
    digester.addSetNext(prefix + "Host/Valve",
                        "addValve",
                        "org.apache.catalina.Valve");

}