001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * The contents of this file are subject to the terms of the Liferay Enterprise
005     * Subscription License ("License"). You may not use this file except in
006     * compliance with the License. You can obtain a copy of the License by
007     * contacting Liferay, Inc. See the License for the specific language governing
008     * permissions and limitations under the License, including but not limited to
009     * distribution rights of the Software.
010     *
011     *
012     *
013     */
014    
015    package com.liferay.portal.tools;
016    
017    import com.liferay.portal.kernel.util.StringPool;
018    
019    import java.io.FileOutputStream;
020    
021    import javax.xml.transform.Transformer;
022    import javax.xml.transform.TransformerFactory;
023    import javax.xml.transform.stream.StreamResult;
024    import javax.xml.transform.stream.StreamSource;
025    
026    /**
027     * @author Brian Wing Shun Chan
028     */
029    public class XSLTBuilder {
030    
031            public static void main(String[] args) {
032                    if (args.length == 3) {
033                            new XSLTBuilder(args[0], args[1], args[2]);
034                    }
035                    else {
036                            throw new IllegalArgumentException();
037                    }
038            }
039    
040            public XSLTBuilder(String xml, String xsl, String html) {
041                    try {
042                            System.setProperty("line.separator", StringPool.NEW_LINE);
043    
044                            TransformerFactory transformerFactory =
045                                    TransformerFactory.newInstance();
046    
047                            Transformer transformer = transformerFactory.newTransformer(
048                                    new StreamSource(xsl));
049    
050                            transformer.transform(
051                                    new StreamSource(xml),
052                                    new StreamResult(new FileOutputStream(html)));
053                    }
054                    catch (Exception e) {
055                            e.printStackTrace();
056                    }
057            }
058    
059    }