/**
   * 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);
  }
Exemple #2
0
 /** 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()));
     }
   }
 }
Exemple #3
0
  /** Create and configure the Digester we will be using for startup. */
  protected Digester createStartDigester() {
    long t1 = System.currentTimeMillis();
    // Initialize the digester
    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);
    digester.setUseContextClassLoader(true);

    // Configure the actions we will be using
    digester.addObjectCreate("Server", "org.apache.catalina.core.StandardServer", "className");
    digester.addSetProperties("Server");
    digester.addSetNext("Server", "setServer", "org.apache.catalina.Server");

    digester.addObjectCreate(
        "Server/GlobalNamingResources", "org.apache.catalina.deploy.NamingResources");
    digester.addSetProperties("Server/GlobalNamingResources");
    digester.addSetNext(
        "Server/GlobalNamingResources",
        "setGlobalNamingResources",
        "org.apache.catalina.deploy.NamingResources");

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

    digester.addObjectCreate(
        "Server/Service", "org.apache.catalina.core.StandardService", "className");
    digester.addSetProperties("Server/Service");
    digester.addSetNext("Server/Service", "addService", "org.apache.catalina.Service");

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

    // Executor
    digester.addObjectCreate(
        "Server/Service/Executor", "org.apache.catalina.core.StandardThreadExecutor", "className");
    digester.addSetProperties("Server/Service/Executor");

    digester.addSetNext("Server/Service/Executor", "addExecutor", "org.apache.catalina.Executor");

    digester.addRule("Server/Service/Connector", new ConnectorCreateRule());
    digester.addRule(
        "Server/Service/Connector", new SetAllPropertiesRule(new String[] {"executor"}));
    digester.addSetNext(
        "Server/Service/Connector", "addConnector", "org.apache.catalina.connector.Connector");

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

    // Add RuleSets for nested elements
    digester.addRuleSet(new NamingRuleSet("Server/GlobalNamingResources/"));
    digester.addRuleSet(new EngineRuleSet("Server/Service/"));
    digester.addRuleSet(new HostRuleSet("Server/Service/Engine/"));
    digester.addRuleSet(new ContextRuleSet("Server/Service/Engine/Host/"));
    addClusterRuleSet(digester, "Server/Service/Engine/Host/Cluster/");
    digester.addRuleSet(new NamingRuleSet("Server/Service/Engine/Host/Context/"));

    // When the 'engine' is found, set the parentClassLoader.
    digester.addRule("Server/Service/Engine", new SetParentClassLoaderRule(parentClassLoader));
    addClusterRuleSet(digester, "Server/Service/Engine/Cluster/");

    long t2 = System.currentTimeMillis();
    if (log.isDebugEnabled()) {
      log.debug("Digester for server.xml created " + (t2 - t1));
    }
    return (digester);
  }