| XSLTBuilder.java |
1 /**
2 * Copyright (c) 2000-2010 Liferay, Inc. All rights reserved.
3 *
4 * This library is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU Lesser General Public License as published by the Free
6 * Software Foundation; either version 2.1 of the License, or (at your option)
7 * any later version.
8 *
9 * This library is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12 * details.
13 */
14
15 package com.liferay.portal.tools;
16
17 import java.io.FileOutputStream;
18
19 import javax.xml.transform.Transformer;
20 import javax.xml.transform.TransformerFactory;
21 import javax.xml.transform.stream.StreamResult;
22 import javax.xml.transform.stream.StreamSource;
23
24 /**
25 * <a href="XSLTBuilder.java.html"><b><i>View Source</i></b></a>
26 *
27 * @author Brian Wing Shun Chan
28 */
29 public class XSLTBuilder {
30
31 public static void main(String[] args) {
32 if (args.length == 3) {
33 new XSLTBuilder(args[0], args[1], args[2]);
34 }
35 else {
36 throw new IllegalArgumentException();
37 }
38 }
39
40 public XSLTBuilder(String xml, String xsl, String html) {
41 try {
42 TransformerFactory transformerFactory =
43 TransformerFactory.newInstance();
44
45 Transformer transformer = transformerFactory.newTransformer(
46 new StreamSource(xsl));
47
48 transformer.transform(
49 new StreamSource(xml),
50 new StreamResult(new FileOutputStream(html)));
51 }
52 catch (Exception e) {
53 e.printStackTrace();
54 }
55 }
56
57 }