1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.kuali.rice.kew.transformation;
18
19 import java.io.FileOutputStream;
20
21 import javax.xml.transform.TransformerFactory;
22 import javax.xml.transform.URIResolver;
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.XMLReader;
36 import org.xml.sax.helpers.XMLReaderFactory;
37
38 public class PipeTransformationTest extends KEWTestCase {
39
40 @Test public void testPipeUsingTemplate(){
41 try{
42
43 TransformerFactory tFactory = TransformerFactory.newInstance();
44
45
46 if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)){
47
48 SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
49
50 URIResolver resolver = new WidgetURITestResolver();
51 saxTFactory.setURIResolver(resolver);
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop_Style_pipeTest.xml")));
78
79
80
81
82 XMLReader reader = XMLReaderFactory.createXMLReader();
83 reader.setContentHandler(tHandler1);
84 reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);
85
86
87
88
89
90 java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
91 xmlProps.setProperty("indent", "yes");
92 xmlProps.setProperty("standalone", "no");
93 Serializer serializer = SerializerFactory.getSerializer(xmlProps);
94 FileOutputStream transformedXML=new FileOutputStream("c://file.xml");
95 serializer.setOutputStream(transformedXML);
96 tHandler1.setResult(new SAXResult(serializer.asContentHandler()));
97
98
99
100 reader.parse(new InputSource(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop.xml")));
101 }
102
103 }catch(Exception ex){
104 ex.printStackTrace();
105 }
106 }
107
108
109 }