001    /**
002     * Copyright (c) 2000-2013 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
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    }