Example usage for org.apache.commons.digester Digester addRuleSet

List of usage examples for org.apache.commons.digester Digester addRuleSet

Introduction

In this page you can find the example usage for org.apache.commons.digester Digester addRuleSet.

Prototype

public void addRuleSet(RuleSet ruleSet) 

Source Link

Document

Register a set of Rule instances defined in a RuleSet.

Usage

From source file:com.threerings.cast.bundle.tools.ComponentBundlerUtil.java

/**
 * Configures <code>ruleSet</code> and hooks it into <code>digester</code>.
 *//*from   w  w  w  .  j av  a 2s. c  o  m*/
protected static void addTileSetRuleSet(Digester digester, TileSetRuleSet ruleSet) {
    ruleSet.setPrefix("actions" + ActionRuleSet.ACTION_PATH);
    digester.addRuleSet(ruleSet);
    digester.addSetNext(ruleSet.getPath(), "addTileSet", TileSet.class.getName());
}

From source file:com.threerings.cast.bundle.tools.MetadataBundlerTask.java

/**
 * Configures <code>ruleSet</code> and hooks it into <code>digester</code>.
 *//*from ww w  .ja v a 2s.  c  o m*/
protected static void addTileSetRuleSet(Digester digester, TileSetRuleSet ruleSet) {
    ruleSet.setPrefix("actions" + ActionRuleSet.ACTION_PATH);
    digester.addRuleSet(ruleSet);
    digester.addSetNext(ruleSet.getPath(), "add", Object.class.getName());
}

From source file:com.sun.faces.generate.GeneratorUtil.java

/**
 * <p>Configure and return a <code>Digester</code> instance suitable for
 * use in the environment specified by our parameter flags.</p>
 *
 * @param design Include rules suitable for design time use in a tool
 * @param generate Include rules suitable for generating component,
 * renderer, and tag classes//from  w  ww.  j a v  a  2s  .  c om
 * @param runtime Include rules suitable for runtime execution
 */
private static Digester createDigester(boolean design, boolean generate, boolean runtime) {

    Digester digester = DigesterFactory.newInstance(true).createDigester();

    // Configure parsing rules
    digester.addRuleSet(new FacesConfigRuleSet(design, generate, runtime));

    // Configure preregistered entities

    return (digester);

}

From source file:com.sun.faces.generate.AbstractGenerator.java

/**
 * <p>Configure and return a <code>Digester</code> instance suitable for
 * use in the environment specified by our parameter flags.</p>
 *
 * @param dtd[] array of absolute pathnames of the DTDs to be registered (if any)
 *  and their corresponding public identifiers
 * @param design Include rules suitable for design time use in a tool
 * @param generate Include rules suitable for generating component,
 *  renderer, and tag classes//from  w  ww  .  j a v a  2  s .c  o m
 * @param runtime Include rules suitable for runtime execution
 *
 * @exception MalformedURLException if a URL cannot be formed correctly
 */
protected static Digester digester(String dtd[], boolean design, boolean generate, boolean runtime)
        throws MalformedURLException {

    Digester digester = new Digester();

    // Configure basic properties
    digester.setNamespaceAware(false);
    digester.setUseContextClassLoader(true);
    digester.setValidating(true);

    // Configure parsing rules
    digester.addRuleSet(new FacesConfigRuleSet(design, generate, runtime));

    // Configure preregistered entities
    int i = 0;
    while (dtd.length > 0) {
        if (dtd[i] != null && dtd[i + 1] != null) {
            digester.register(dtd[i], (new File(dtd[i + 1])).toURL().toString());
        }
        i += 2;
        if (i >= dtd.length) {
            break;
        }
    }
    return (digester);

}

From source file:com.liusoft.sc.startup.DigesterFactory.java

/**
 * 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.
 *//*from ww  w  .  ja va 2s  .  c o m*/
public static Digester newDigester(boolean xmlValidation, boolean xmlNamespaceAware, RuleSet rule) {
    Digester digester = new Digester();
    digester.setNamespaceAware(xmlNamespaceAware);
    digester.setValidating(xmlValidation);
    digester.setUseContextClassLoader(true);

    if (xmlValidation || xmlNamespaceAware) {
        configureSchema(digester);
    }

    schemaResolver = new SchemaResolver(digester);
    registerLocalSchema();

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

    return (digester);
}

From source file:com.marvinformatics.formatter.model.ConfigReader.java

/**
 * Read from the <code>input</code> and return it's configuration settings
 * as a {@link Map}.//w w w  . j a v a  2 s  .  co m
 * 
 * @param input
 * @return return {@link Map} with all the configurations read from the
 *         config file, or throws an exception if there's a problem reading
 *         the input, e.g.: invalid XML.
 * @throws SAXException
 * @throws IOException
 * @throws ConfigReadException
 */
public Map<String, String> read(InputStream input) throws IOException, SAXException, ConfigReadException {
    Digester digester = new Digester();
    digester.addRuleSet(new RuleSet());

    Object result = digester.parse(input);
    if (result == null && !(result instanceof Profiles)) {
        throw new ConfigReadException("No profiles found in config file");
    }

    Profiles profiles = (Profiles) result;
    List<Map<String, String>> list = profiles.getProfiles();
    if (list.size() == 0) {
        throw new ConfigReadException("No profile in config file of kind: " + Profiles.PROFILE_KIND);
    }

    return (Map<String, String>) list.get(0);
}

From source file:com.discursive.jccook.xml.bean.NamespaceDigest.java

public void testDigest() throws IOException, SAXException {

    Pages pages = new Pages();

    Digester digester = new Digester();
    digester.setNamespaceAware(true);/*from w w  w.ja v  a  2s . c o m*/
    digester.addRuleSet(new PageRuleSet());
    digester.addRuleSet(new PersonRuleSet());

    digester.push(pages);

    InputStream input = getClass().getResourceAsStream("./content.xml");
    digester.parse(input);

    Page page = (Page) pages.getPages().get(0);
    System.out.println(page);
}

From source file:com.relativitas.maven.plugins.formatter.XmlConfigReader.java

/**
 * Read from the <code>input</code> and return it's configuration settings
 * as a {@link Map}.//ww w . jav  a  2 s .  co m
 * 
 * @param input
 * @return return {@link Map} with all the configurations read from the
 *         config file, or throws an exception if there's a problem reading
 *         the input, e.g.: invalid XML.
 * @throws SAXException
 * @throws IOException
 * @throws ConfigReadException
 */
public Map<String, String> read(InputStream input) throws IOException, ConfigReadException {
    Digester digester = new Digester();
    digester.addRuleSet(new RuleSet());

    Object result;
    try {
        result = digester.parse(input);
    } catch (SAXException e) {
        throw new ConfigReadException("Unable to parse XML", e);
    }
    if (result == null && !(result instanceof Profiles)) {
        throw new ConfigReadException("No profiles found in config file");
    }

    Profiles profiles = (Profiles) result;
    List<Map<String, String>> list = profiles.getProfiles();
    if (list.size() == 0) {
        throw new ConfigReadException("No profile in config file of kind: " + Profiles.CODE_FORMATTER_PROFILE);
    }

    return list.get(0);
}

From source file:com.discursive.jccook.xml.bean.XMLNamespaceDigest.java

public void testDigest() throws IOException, SAXException {

    Pages pages = new Pages();

    Digester digester = new Digester();
    digester.setNamespaceAware(true);//from w w w .jav a2 s .co m

    digester.setRuleNamespaceURI("http://discursive.com/page");
    URL pageRules = getClass().getResource("./page-rules.xml");
    digester.addRuleSet(new FromXmlRuleSet(pageRules));

    digester.setRuleNamespaceURI("http://discursive.com/person");
    URL personRules = getClass().getResource("./person-rules.xml");
    digester.addRuleSet(new FromXmlRuleSet(personRules));

    digester.push(pages);

    InputStream input = getClass().getResourceAsStream("./content.xml");
    digester.parse(input);

    Page page = (Page) pages.getPages().get(0);
    System.out.println(page);
}

From source file:net.jakubholy.jeeutils.jsfelcheck.beanfinder.jsf11.Jsf11FacesConfigXmlBeanFinder.java

protected Digester digester(boolean validateXml) {
    Digester digester = new Digester();

    digester.setNamespaceAware(false);//from  w ww. j a  v  a  2  s  .  co  m
    digester.setUseContextClassLoader(true);
    digester.setValidating(validateXml);

    digester.addRuleSet(new FacesConfigRuleSet(false, false, true));

    for (int i = 0; i < DTD_INFO.length; i++) {
        URL url = getClass().getResource(DTD_INFO[i][0]);
        if (url != null) {
            digester.register(DTD_INFO[i][1], url.toString());
        } else {
            throw new RuntimeException("NO_DTD_FOUND_ERROR: " + DTD_INFO[i][1] + "," + DTD_INFO[i][0]);
        }

    }

    digester.push(new FacesConfigBean());

    return digester;
}