Package org.apache.commons.digester

Examples of org.apache.commons.digester.Digester


        //
        // This test doesn't really belong in this class. If a separate test
        // case class is created for PluginRules, then this method should be
        // moved there.

        Digester digester = new Digester();
        PluginRules rc = new PluginRules();
        digester.setRules(rc);
       
        PluginCreateRule pcr = new PluginCreateRule(Widget.class);
        digester.addRule("/root/widget", pcr);
        digester.addSetNext("/root/widget", "addChild");

        Container root = new Container();
        digester.push(root);
       
        try {
            digester.parse(
                TestAll.getInputStream(this, "test1.xml"));
        }
        catch(Exception e) {
            throw e;
        }
View Full Code Here


                    DIGESTER_DTD_PATH + "\"");
        }
        parser.setDigesterRulesDTD(dtdURL.toString());
        parser.setTarget(digester);

        Digester rulesDigester = new Digester();
        rulesDigester.addRuleSet(parser);
        rulesDigester.push(parser);

        try {
            rulesDigester.parse(xmlRules.openStream());
        } catch (Exception ex) {
            throw new XmlLoadException(ex);
        }
    }
View Full Code Here

     * @param rulesXml URL to the XML file defining the digester rules
     * @return a new Digester initialized with the rules
     */
    public static Digester createDigester(URL rulesXml) {
        RuleSet ruleSet = new FromXmlRuleSet(rulesXml);
        Digester digester = new Digester();
        digester.addRuleSet(ruleSet);
        return digester;
    }
View Full Code Here

     * @return an Object which is the root of the network of Java objects
     * created by digesting fileURL
     */
    public static Object load(URL digesterRules, ClassLoader classLoader,
                              InputStream input) throws IOException, SAXException, DigesterLoadingException {
        Digester digester = createDigester(digesterRules);
        digester.setClassLoader(classLoader);
        try {
            return digester.parse(input);
        } catch (XmlLoadException ex) {
            // This is a runtime exception that can be thrown by
            // FromXmlRuleSet#addRuleInstances, which is called by the Digester
            // before it parses the file.
            throw new DigesterLoadingException(ex.getMessage(), ex);
View Full Code Here

     * created by digesting fileURL
     */
    public static Object load(URL digesterRules, ClassLoader classLoader,
                              InputStream input, Object rootObject) throws IOException, SAXException,
            DigesterLoadingException {
        Digester digester = createDigester(digesterRules);
        digester.setClassLoader(classLoader);
        digester.push(rootObject);
        try {
            return digester.parse(input);
        } catch (XmlLoadException ex) {
            // This is a runtime exception that can be thrown by
            // FromXmlRuleSet#addRuleInstances, which is called by the Digester
            // before it parses the file.
            throw new DigesterLoadingException(ex.getMessage(), ex);
View Full Code Here

            + resourceConfig.toExternalForm());
      }

      InputStream in = URLToStreamHelper.urlToStream(resourceConfig);
      try {
        Digester digester = new Digester();
        digester.setValidating(false);
        digester.setEntityResolver(new EntityResolver() {
          // Dummi resolver - alvays do nothing
          public InputSource resolveEntity(String publicId,
              String systemId) throws SAXException, IOException {
            return new InputSource(new StringReader(""));
          }
        });
        digester.setNamespaceAware(false);
        digester.setUseContextClassLoader(true);
        digester.push(this);
        digester.addObjectCreate("resource-config/resource", "class",
            JarResource.class);
        digester.addObjectCreate("resource-config/resource/renderer",
            "class", HTMLRenderer.class);
        digester.addCallMethod(
            "resource-config/resource/renderer/content-type",
            "setContentType", 0);
        digester.addSetNext("resource-config/resource/renderer",
            "setRenderer", ResourceRenderer.class.getName());
        digester.addCallMethod("resource-config/resource/name",
            "setKey", 0);
        digester.addCallMethod("resource-config/resource/path",
            "setPath", 0);
        digester.addCallMethod("resource-config/resource/cacheable",
            "setCacheable", 0);
        digester.addCallMethod(
            "resource-config/resource/session-aware",
            "setSessionAware", 0);
        digester.addCallMethod("resource-config/resource/property",
            "setProperty", 2);
        digester.addCallParam("resource-config/resource/property/name",
            0);
        digester.addCallParam(
            "resource-config/resource/property/value", 1);
        digester.addCallMethod("resource-config/resource/content-type",
            "setContentType", 0);
        digester.addSetNext("resource-config/resource", "addResource",
            InternetResource.class.getName());
        digester.parse(in);
      } finally {
        in.close();
      }
    } catch (IOException e) {
      throw new FacesException(e);
View Full Code Here

  private static final ExcelSheet BLANK_SHEET = new ExcelSheet();
 
  @SuppressWarnings("unchecked")
  public void setConfig(String... configurations){
    for(String config: configurations){
      Digester digester = DigesterLoader.createDigester(
          new InputSource(Thread.currentThread().getContextClassLoader()
              .getResourceAsStream(RULE_FILE)));
      digester.setValidating(false);
      try {
        List<ExcelSheet> list =
          (List<ExcelSheet>)digester.parse(Thread.currentThread().getContextClassLoader().getResourceAsStream(config));
        for(ExcelSheet es: list)
          sheetDefinitions.put(es.getName(), es);
      } catch (IOException e) {
        e.printStackTrace();
        throw new RuntimeException("Read excel config failed.");
View Full Code Here

            log("Cannot load configuration file " + file.getAbsolutePath());
            return;
        }

        // Load the contents of our configuration file
        Digester digester = new Digester();
        digester.setValidating(false);
        digester.addRuleSet(new MemoryRuleSet());
        try {
            digester.push(this);
            digester.parse(file);
        } catch (Exception e) {
            log("Error processing configuration file " +
                file.getAbsolutePath(), e);
            return;
        } finally {
            digester.push(null);
        }

    }
View Full Code Here

        InputStream stream = null;
        String contextPath = null;
        try {
            URL config = new URL("file", null, configFile.getCanonicalPath());
            stream = config.openStream();
            Digester digester = createDigester();
            digester.clear();
            digester.push(this);
            digester.parse(stream);
            stream.close();
            stream = null;
            if (context !=null) {
              contextPath = context.getPath();
            }
        } catch (Exception e) {
          log( "Parse exception :", e );
          return null;
        } finally {
            if (stream != null) {
                try {
                    stream.close();
                } catch (Throwable t) {
                    ;
                }
            }
          digester.push(null);
            context = null;
        }
        return contextPath;
    }
View Full Code Here

     * context configuration descriptor for an application.
     */
    protected Digester createDigester() {

        if (digester == null) {
            digester = new Digester();
            digester.setValidating(false);
            // Add a substitutor to resolve system properties
            enableDigesterSubstitutor(digester);
            digester.addRuleSet(new ContextRuleSet(""));
            digester.addRuleSet(new NamingRuleSet("Context/"));
View Full Code Here

TOP

Related Classes of org.apache.commons.digester.Digester

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.