1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package org.dbforms.devgui;
25
26 import org.dbforms.util.Util;
27
28 import java.io.File;
29 import java.io.FileNotFoundException;
30
31
32 import java.io.FileOutputStream;
33 import java.io.IOException;
34
35 import javax.xml.transform.OutputKeys;
36 import javax.xml.transform.Transformer;
37 import javax.xml.transform.TransformerConfigurationException;
38 import javax.xml.transform.TransformerException;
39
40
41 import javax.xml.transform.TransformerFactory;
42 import javax.xml.transform.stream.StreamResult;
43 import javax.xml.transform.stream.StreamSource;
44
45
46
47 /***
48 * Simple sample code to show how to run the XSL processor from the API.
49 */
50 public class XSLTransformer {
51 /***
52 * DOCUMENT ME!
53 *
54 * @param xmlFile DOCUMENT ME!
55 * @param xslFile DOCUMENT ME!
56 * @param destinationFile DOCUMENT ME!
57 * @param useJsCalendar DOCUMENT ME!
58 * @param xsltEncoding DOCUMENT ME!
59 *
60 * @throws TransformerException DOCUMENT ME!
61 * @throws TransformerConfigurationException DOCUMENT ME!
62 * @throws FileNotFoundException DOCUMENT ME!
63 * @throws IOException DOCUMENT ME!
64 */
65 public static void transform(File xmlFile,
66 File xslFile,
67 File destinationFile,
68 boolean useJsCalendar,
69 String xsltEncoding)
70 throws TransformerException,
71 TransformerConfigurationException,
72 FileNotFoundException, IOException {
73
74
75
76
77 TransformerFactory tFactory = TransformerFactory.newInstance();
78
79
80
81
82 Transformer transformer = tFactory.newTransformer(new StreamSource(xslFile));
83
84
85 if (!Util.isNull(xsltEncoding)) {
86 transformer.setOutputProperty(OutputKeys.ENCODING, xsltEncoding);
87 }
88
89
90
91 if (useJsCalendar) {
92 transformer.setParameter("useCalendar", "true");
93 }
94
95
96
97 transformer.transform(new StreamSource(xmlFile),
98 new StreamResult(new FileOutputStream(destinationFile)));
99 }
100 }