001    /**
002     * Copyright (c) 2000-2010 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 java.io.FileOutputStream;
018    
019    import javax.xml.transform.Transformer;
020    import javax.xml.transform.TransformerFactory;
021    import javax.xml.transform.stream.StreamResult;
022    import javax.xml.transform.stream.StreamSource;
023    
024    /**
025     * @author Brian Wing Shun Chan
026     */
027    public class XSLTBuilder {
028    
029            public static void main(String[] args) {
030                    if (args.length == 3) {
031                            new XSLTBuilder(args[0], args[1], args[2]);
032                    }
033                    else {
034                            throw new IllegalArgumentException();
035                    }
036            }
037    
038            public XSLTBuilder(String xml, String xsl, String html) {
039                    try {
040                            TransformerFactory transformerFactory =
041                                    TransformerFactory.newInstance();
042    
043                            Transformer transformer = transformerFactory.newTransformer(
044                                    new StreamSource(xsl));
045    
046                            transformer.transform(
047                                    new StreamSource(xml),
048                                    new StreamResult(new FileOutputStream(html)));
049                    }
050                    catch (Exception e) {
051                            e.printStackTrace();
052                    }
053            }
054    
055    }