1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.transformation;
17
18 import java.io.IOException;
19
20 import javax.xml.transform.TransformerConfigurationException;
21 import javax.xml.transform.TransformerException;
22 import javax.xml.transform.TransformerFactory;
23 import javax.xml.transform.sax.SAXResult;
24 import javax.xml.transform.sax.SAXSource;
25 import javax.xml.transform.sax.SAXTransformerFactory;
26 import javax.xml.transform.sax.TransformerHandler;
27 import javax.xml.transform.stream.StreamSource;
28
29 import org.apache.xml.serializer.OutputPropertiesFactory;
30 import org.apache.xml.serializer.Serializer;
31 import org.apache.xml.serializer.SerializerFactory;
32 import org.junit.Test;
33 import org.kuali.rice.kew.test.KEWTestCase;
34 import org.xml.sax.InputSource;
35 import org.xml.sax.SAXException;
36 import org.xml.sax.XMLReader;
37 import org.xml.sax.helpers.XMLReaderFactory;
38
39
40
41
42
43
44 public class Pipe extends KEWTestCase
45 {
46 @Test
47 public void testPipe()
48 throws TransformerException, TransformerConfigurationException,
49 SAXException, IOException
50 {
51
52 TransformerFactory tFactory = TransformerFactory.newInstance();
53
54
55 if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE))
56 {
57
58 SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
59
60 TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(Pipe.class.getResourceAsStream("foo1.xsl")));
61 TransformerHandler tHandler2 = saxTFactory.newTransformerHandler(new StreamSource(Pipe.class.getResourceAsStream("foo2.xsl")));
62 TransformerHandler tHandler3 = saxTFactory.newTransformerHandler(new StreamSource(Pipe.class.getResourceAsStream("foo3.xsl")));
63
64
65 XMLReader reader = XMLReaderFactory.createXMLReader();
66 reader.setContentHandler(tHandler1);
67 reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);
68
69 tHandler1.setResult(new SAXResult(tHandler2));
70 tHandler2.setResult(new SAXResult(tHandler3));
71
72
73 java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
74 xmlProps.setProperty("indent", "yes");
75 xmlProps.setProperty("standalone", "no");
76 Serializer serializer = SerializerFactory.getSerializer(xmlProps);
77 serializer.setOutputStream(System.out);
78 tHandler3.setResult(new SAXResult(serializer.asContentHandler()));
79
80
81
82 reader.parse(new InputSource(Pipe.class.getResourceAsStream("foo.xml")));
83 }
84 }
85 }