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.FileOutputStream;
19
20 import javax.xml.transform.TransformerFactory;
21 import javax.xml.transform.URIResolver;
22 import javax.xml.transform.sax.SAXResult;
23 import javax.xml.transform.sax.SAXSource;
24 import javax.xml.transform.sax.SAXTransformerFactory;
25 import javax.xml.transform.sax.TransformerHandler;
26 import javax.xml.transform.stream.StreamSource;
27
28 import org.apache.xml.serializer.OutputPropertiesFactory;
29 import org.apache.xml.serializer.Serializer;
30 import org.apache.xml.serializer.SerializerFactory;
31 import org.junit.Test;
32 import org.kuali.rice.kew.test.KEWTestCase;
33 import org.xml.sax.InputSource;
34 import org.xml.sax.XMLReader;
35 import org.xml.sax.helpers.XMLReaderFactory;
36
37 public class PipeTransformationTest extends KEWTestCase {
38
39 @Test public void testPipeUsingTemplate(){
40 try{
41
42 TransformerFactory tFactory = TransformerFactory.newInstance();
43
44
45 if (tFactory.getFeature(SAXSource.FEATURE) && tFactory.getFeature(SAXResult.FEATURE)){
46
47 SAXTransformerFactory saxTFactory = ((SAXTransformerFactory) tFactory);
48
49 URIResolver resolver = new WidgetURITestResolver();
50 saxTFactory.setURIResolver(resolver);
51
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 TransformerHandler tHandler1 = saxTFactory.newTransformerHandler(new StreamSource(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop_Style_pipeTest.xml")));
77
78
79
80
81 XMLReader reader = XMLReaderFactory.createXMLReader();
82 reader.setContentHandler(tHandler1);
83 reader.setProperty("http://xml.org/sax/properties/lexical-handler", tHandler1);
84
85
86
87
88
89 java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
90 xmlProps.setProperty("indent", "yes");
91 xmlProps.setProperty("standalone", "no");
92 Serializer serializer = SerializerFactory.getSerializer(xmlProps);
93 FileOutputStream transformedXML=new FileOutputStream("c://file.xml");
94 serializer.setOutputStream(transformedXML);
95 tHandler1.setResult(new SAXResult(serializer.asContentHandler()));
96
97
98
99 reader.parse(new InputSource(PipeTransformationTest.class.getResourceAsStream("StudentInitiatedDrop.xml")));
100 }
101
102 }catch(Exception ex){
103 ex.printStackTrace();
104 }
105 }
106
107
108 }