KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > soto > state > xml > TransformStateTest


1 package org.sapia.soto.state.xml;
2
3 import java.io.File JavaDoc;
4 import java.io.FileInputStream JavaDoc;
5
6 import org.sapia.soto.SotoContainer;
7 import org.sapia.soto.state.StateMachine;
8 import org.xml.sax.InputSource JavaDoc;
9 import org.apache.xml.serialize.OutputFormat;
10 import org.apache.xml.serialize.Serializer;
11 import org.apache.xml.serialize.SerializerFactory;
12
13
14 import junit.framework.TestCase;
15
16 /**
17  * @author Yanick Duchesne
18  *
19  * <dl>
20  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
21  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
22  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
23  * </dl>
24  */

25 public class TransformStateTest extends TestCase{
26     
27     public TransformStateTest(String JavaDoc name){
28         super(name);
29     }
30     
31     public void testNoStylesheet() throws Exception JavaDoc{
32         SotoContainer cont = new SotoContainer();
33         StateMachine stm = new StateMachine();
34         TransformState st = new TransformState();
35         st.setEnv(cont.toEnv());
36     st.setId("txform");
37         stm.addState(st);
38         stm.init();
39         XMLContext ctx = new XMLContextImpl();
40
41         OutputFormat format = new OutputFormat("xml", "UTF-8", true);
42         Serializer ser = SerializerFactory.getSerializerFactory("xml")
43                                                                                 .makeSerializer(System.out, format);
44         ctx.setContentHandler(ser.asContentHandler());
45         ctx.push(new InputSource JavaDoc(new FileInputStream JavaDoc(new File JavaDoc("etc/stm/dog.xml"))));
46         stm.execute("txform", ctx);
47     }
48     
49     public void testSingleStylesheet() throws Exception JavaDoc{
50         SotoContainer cont = new SotoContainer();
51         StateMachine stm = new StateMachine();
52         TransformState st = new TransformState();
53         st.setEnv(cont.toEnv());
54         st.setId("txform");
55         stm.addState(st);
56         StyleStep step = new StyleStep();
57         step.setEnv(cont.toEnv());
58         step.setSrc("etc/stm/dogToCat.xsl");
59         st.addExecutable(step);
60         stm.init();
61         XMLContext ctx = new XMLContextImpl();
62         OutputFormat format = new OutputFormat("xml", "UTF-8", true);
63         Serializer ser = SerializerFactory.getSerializerFactory("xml")
64                                                                                 .makeSerializer(System.out, format);
65         ctx.setContentHandler(ser.asContentHandler());
66         ctx.push(new InputSource JavaDoc(new FileInputStream JavaDoc(new File JavaDoc("etc/stm/dog.xml"))));
67         stm.execute("txform", ctx);
68     }
69     
70     public void testMultiStylesheets() throws Exception JavaDoc{
71         SotoContainer cont = new SotoContainer();
72         StateMachine stm = new StateMachine();
73         TransformState st = new TransformState();
74         st.setEnv(cont.toEnv());
75         st.setId("txform");
76         stm.addState(st);
77         StyleStep step1 = new StyleStep();
78         step1.setEnv(cont.toEnv());
79         step1.setSrc("etc/stm/dogToCat.xsl");
80         st.addExecutable(step1);
81         StyleStep step2 = new StyleStep();
82         step2.setEnv(cont.toEnv());
83         step2.setSrc("etc/stm/catToDog.xsl");
84         st.addExecutable(step2);
85         stm.init();
86         XMLContext ctx = new XMLContextImpl();
87         OutputFormat format = new OutputFormat("xml", "UTF-8", true);
88         Serializer ser = SerializerFactory.getSerializerFactory("xml")
89                                                                                 .makeSerializer(System.out, format);
90         ctx.setContentHandler(ser.asContentHandler());
91         ctx.push(new InputSource JavaDoc(new FileInputStream JavaDoc(new File JavaDoc("etc/stm/dog.xml"))));
92         stm.execute("txform", ctx);
93     }
94
95 }
96
Popular Tags