001    /**
002     * Copyright (c) 2000-2010 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 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    }