1 17 18 package org.apache.commons.digester.xmlrules; 19 20 import java.util.ArrayList ; 21 import java.io.StringReader ; 22 import org.xml.sax.InputSource ; 23 24 import junit.framework.TestCase; 25 26 import org.apache.commons.digester.Digester; 27 import org.apache.commons.digester.Rule; 28 29 32 public class IncludeTest extends TestCase { 33 34 public static class TestDigesterRuleSource implements DigesterRulesSource { 35 public void getRules(Digester digester) { 36 digester.addRule("bar", 37 new Rule() { 38 public void body(String namespace, String name, String text) { 39 ((ArrayList ) this.digester.peek()).add(text); 40 } 41 }); 42 } 43 } 44 45 public IncludeTest(String testName) { 46 super(testName); 47 } 48 49 public void testBasicInclude() throws Exception { 50 String rulesXml = "<?xml version='1.0'?>" 51 + "<digester-rules>" 52 + " <pattern value='root/foo'>" 53 + " <include class='org.apache.commons.digester.xmlrules.IncludeTest$TestDigesterRuleSource'/>" 54 + " </pattern>" 55 + "</digester-rules>"; 56 57 String xml = "<?xml version='1.0' ?><root><foo><bar>short</bar></foo></root>"; 58 59 ArrayList list = new ArrayList (); 60 Digester digester = DigesterLoader.createDigester(new InputSource (new StringReader (rulesXml))); 61 digester.push(list); 62 digester.parse(new StringReader (xml)); 63 64 assertEquals("Number of entries", 1, list.size()); 65 assertEquals("Entry value", "short", list.get(0)); 66 } 67 } 68 | Popular Tags |