Example usage for org.apache.commons.digester3 Digester getRoot

List of usage examples for org.apache.commons.digester3 Digester getRoot

Introduction

In this page you can find the example usage for org.apache.commons.digester3 Digester getRoot.

Prototype

public <T> T getRoot() 

Source Link

Document

Returns the root element of the tree of objects created as a result of applying the rule objects to the input XML.

Usage

From source file:com.w20e.socrates.factories.OptionsFactory.java

/**
 * Create a new expression based on the input string, or null if no
 * input string./*  w w  w . j a v a2 s .  c  o m*/
 * @param expr String to parse
 * @return the expression created.
 * @throws Exception in case the compiler can't parse.
 */
public final OptionList createObject(final Attributes attrs) throws Exception {

    Digester dig = this.getDigester();

    RenderConfig rConfig = dig.getRoot();

    return rConfig.getOptionList(attrs.getValue("ref"));
}

From source file:org.apache.commons.digester3.examples.api.catalog.Main.java

/**
 * Main method : entry point for running this example program.
 * <p>/*w  w  w. jav  a  2s  . c om*/
 * Usage: java CatalogDigester example.xml
 */
public static void main(String[] args) {
    if (args.length != 1) {
        usage();
        System.exit(-1);
    }

    String filename = args[0];

    // Create a Digester instance
    Digester d = new Digester();

    // Add rules to the digester that will be triggered while
    // parsing occurs.
    addRules(d);

    // Process the input file.
    try {
        java.io.Reader reader = getInputData(filename);
        d.parse(reader);
    } catch (java.io.IOException ioe) {
        System.out.println("Error reading input file:" + ioe.getMessage());
        System.exit(-1);
    } catch (org.xml.sax.SAXException se) {
        System.out.println("Error parsing input file:" + se.getMessage());
        System.exit(-1);
    }

    // Get the first object created by the digester's rules
    // (the "root" object). Note that this is exactly the same object
    // returned by the Digester.parse method; either approach works.
    Catalog catalog = (Catalog) d.getRoot();

    // Print out all the contents of the catalog, as loaded from
    // the input file.
    catalog.print();
}