1 52 53 package freemarker.testcase; 54 55 import java.util.HashMap ; 56 import java.util.Map ; 57 58 import org.xml.sax.InputSource ; 59 60 import org.w3c.dom.Document ; 61 62 import javax.xml.parsers.DocumentBuilder ; 63 import javax.xml.parsers.DocumentBuilderFactory ; 64 65 import freemarker.ext.beans.BeansWrapper; 66 import freemarker.ext.dom.NodeModel; 67 import freemarker.template.SimpleHash; 68 69 73 public class TestXmlFragment extends AbstractTestCase 74 { 75 public TestXmlFragment(String name) 76 { 77 super(name); 78 } 79 80 83 public void setUp() 84 throws 85 Exception  86 { 87 setUpFiles("test-xmlfragment.txt"); 88 89 DocumentBuilderFactory f = DocumentBuilderFactory.newInstance(); 90 f.setNamespaceAware(true); 91 DocumentBuilder db = f.newDocumentBuilder(); 92 Document doc = db.parse(new InputSource (getClass().getResourceAsStream("test-xmlfragment.xml"))); 93 94 Map map = new HashMap (); 95 map.put("node", NodeModel.wrap(doc.getDocumentElement().getFirstChild().getFirstChild())); 96 root = new SimpleHash(map, BeansWrapper.getDefaultInstance()); 97 } 98 99 102 public static void main( String [] argc ) throws Exception { 103 AbstractTestCase cTest = new TestXmlFragment("test-xmlfragment.txt"); 104 cTest.run(); 105 } 106 } | Popular Tags |