Package org.apache.commons.digester

Examples of org.apache.commons.digester.Digester


     * @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


                                Reader reader)
                                    throws
                                        IOException,
                                        SAXException,
                                        DigesterLoadingException {
        Digester digester = createDigester(digesterRules);
        digester.setClassLoader(classLoader);
        try {
            return digester.parse(reader);
        } 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

                                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

            "<root>" +
              "<property name='attr' value='prop.value'/>" +
              "<bean alpha='${attr}'/>" +
            "</root>";
        StringReader input = new StringReader(xml);
        Digester digester = createDigesterThatCanDoAnt();

        simpleTestBeans.clear();
        digester.push(this);
        digester.parse(input);

        assertEquals(1, simpleTestBeans.size());
        SimpleTestBean bean = (SimpleTestBean) simpleTestBeans.get(0);
        assertEquals("prop.value", bean.getAlpha());
    }
View Full Code Here

              "<property name='attr1' value='prop.value1'/>" +
              "<property name='attr2' value='substituted-${attr1}'/>" +
              "<bean alpha='${attr2}'/>" +
            "</root>";
        StringReader input = new StringReader(xml);
        Digester digester = createDigesterThatCanDoAnt();

        simpleTestBeans.clear();
        digester.push(this);
        digester.parse(input);

        assertEquals(1, simpleTestBeans.size());
        SimpleTestBean bean = (SimpleTestBean) simpleTestBeans.get(0);
        assertEquals("substituted-prop.value1", bean.getAlpha());
    }
View Full Code Here

    public void testCreateDigester() throws Exception {
        URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/testrules.xml");
        URL input = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/test.xml");
        assertNotNull("The test could not locate testrules.xml", rules);
        assertNotNull("The test could not locate test.xml", input);
        Digester digester = DigesterLoader.createDigester(rules);
        digester.push(new ArrayList());
        Object root = digester.parse(input.openStream());
        assertEquals("[foo1 baz1 foo2, foo3 foo4]",root.toString());
    }
View Full Code Here

     * Validates that circular includes are detected and result in an exception
     */
    public void testCircularInclude1() {
        URL rules = ClassLoader.getSystemResource("org/apache/commons/digester/xmlrules/testCircularRules.xml");
        try {
            Digester digester = DigesterLoader.createDigester(rules);
            assertNotNull(digester); // just to prevent compiler warning on unused var
        } catch (Exception ex) {
            return;
        }
        fail("Creating a digester with circular rules should have thrown CircularIncludeException.");
View Full Code Here

        String xml = "<?xml version='1.0' ?>"
                     + "<root><foo attr='long'><bar>short</bar><foobar><ping>tosh</ping></foobar></foo></root>";
       
        CallParamTestObject testObject = new CallParamTestObject();
       
        Digester digester = DigesterLoader.createDigester(new InputSource(new StringReader(rulesXml)));
        digester.push(testObject);
        digester.parse(new StringReader(xml));       
                                                                       
        assertEquals("Incorrect left value", "long", testObject.getLeft());
        assertEquals("Incorrect middle value", "short", testObject.getMiddle());
        assertEquals("Incorrect right value", "", testObject.getRight());
    }
View Full Code Here

       
        URL rules = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/test-node-create-rules.xml");
        URL input = getClass().getClassLoader().getResource("org/apache/commons/digester/xmlrules/test-node-create-rules-input.xml");
        assertNotNull("The test could not locate test-node-create-rules.xml", rules);
        assertNotNull("The test could not locate test-node-create-rules-input.xml", input);
        Digester digester = DigesterLoader.createDigester(rules);
        digester.push(new ArrayList());
        Object root = digester.parse(input.openStream());

        assertNotNull("root was null", root);       
        assertTrue("no nodes were captured.", (((List)root).size() > 0));
        Object[] nodeArray = (Object[])((List)root).toArray();
        assertNotNull("resulting node array from array list was null", nodeArray);
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.