001    package org.apache.fulcrum.xslt;
002    
003    /*
004     * Licensed to the Apache Software Foundation (ASF) under one
005     * or more contributor license agreements.  See the NOTICE file
006     * distributed with this work for additional information
007     * regarding copyright ownership.  The ASF licenses this file
008     * to you under the Apache License, Version 2.0 (the
009     * "License"); you may not use this file except in compliance
010     * with the License.  You may obtain a copy of the License at
011     *
012     *   http://www.apache.org/licenses/LICENSE-2.0
013     *
014     * Unless required by applicable law or agreed to in writing,
015     * software distributed under the License is distributed on an
016     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017     * KIND, either express or implied.  See the License for the
018     * specific language governing permissions and limitations
019     * under the License.
020     */
021    
022    import java.io.Reader;
023    import java.io.Writer;
024    import java.util.Map;
025    
026    import org.w3c.dom.Node;
027    
028    /**
029     * This is a static accesor class for {@link XSLTService}.
030     *
031     * @author <a href="mailto:leon@opticode.co.za">Leon Messerschmidt</a>
032     * @author <a href="mailto:tv@apache.org">Thomas Vandahl</a>
033     */
034    public class XSLTServiceFacade
035    {
036        private static XSLTService xsltService;
037    
038        /**
039         * Utility method for accessing the service implementation
040         *
041         * @return a XSLTService implementation instance
042         */
043        protected static XSLTService getService()
044        {
045            return xsltService;
046        }
047    
048        /**
049         * Static utility method to set the service instance to be used in the
050         * facade
051         *
052         * @param xsltService
053         *            the service instance
054         */
055        protected static void setService(XSLTService xsltService)
056        {
057            XSLTServiceFacade.xsltService = xsltService;
058        }
059    
060        /**
061         * Uses an xsl file to transform xml input from a reader and writes the
062         * output to a writer.
063         *
064         * @param xslName The name of the file that contains the xsl stylesheet.
065         * @param in The reader that passes the xml to be transformed
066         * @param out The writer for the transformed output
067         * @throws Exception the transformation failed
068         */
069        public static void transform(String xslName, Reader in, Writer out)
070                throws Exception
071        {
072            getService().transform(xslName, in, out);
073        }
074    
075        /**
076         * Uses an xsl file to transform xml input from a reader and returns a
077         * string containing the transformed output.
078         *
079         * @param xslName The name of the file that contains the xsl stylesheet.
080         * @param in The reader that passes the xml to be transformed
081         * @return the transformed output
082         * @throws Exception the transformation failed
083         */
084        public static String transform(String xslName, Reader in) throws Exception
085        {
086            return getService().transform(xslName, in);
087        }
088    
089        /**
090         * Uses an xsl file to transform xml input from a DOM note and writes the
091         * output to a writer.
092         *
093         * @param xslName The name of the file that contains the xsl stylesheet.
094         * @param in The DOM Node to be transformed
095         * @param out The writer for the transformed output
096         * @throws Exception the transformation failed
097         */
098        public void transform(String xslName, Node in, Writer out) throws Exception
099        {
100            getService().transform(xslName, in, out);
101        }
102    
103        /**
104         * Uses an xsl file to transform xml input from a DOM note and returns a
105         * string containing the transformed output.
106         *
107         * @param xslName The name of the file that contains the xsl stylesheet.
108         * @param in The DOM Node to be transformed
109         * @return the transformed output
110         * @throws Exception the transformation failed
111         */
112        public String transform(String xslName, Node in) throws Exception
113        {
114            return getService().transform(xslName, in);
115        }
116    
117        /**
118         * Uses an xsl file to transform xml input from a reader and writes the
119         * output to a writer.
120         *
121         * @param xslName The name of the file that contains the xsl stylesheet.
122         * @param in The reader that passes the xml to be transformed
123         * @param out The writer for the transformed output
124         * @param params A set of parameters that will be forwarded to the XSLT
125         * @throws Exception the transformation failed
126         */
127        void transform(String xslName, Reader in, Writer out, Map params) throws Exception
128        {
129            getService().transform(xslName, in, out, params);
130        }
131    
132        /**
133         * Uses an xsl file to transform xml input from a reader and returns a
134         * string containing the transformed output.
135         *
136         * @param xslName The name of the file that contains the xsl stylesheet.
137         * @param in The reader that passes the xml to be transformed
138         * @param params A set of parameters that will be forwarded to the XSLT
139         * @return the transformed output
140         * @throws Exception the transformation failed
141         */
142        String transform(String xslName, Reader in, Map params) throws Exception
143        {
144            return getService().transform(xslName, in, params);
145        }
146    
147        /**
148         * Uses an xsl file to transform xml input from a DOM note and writes the
149         * output to a writer.
150         *
151         * @param xslName The name of the file that contains the xsl stylesheet.
152         * @param in The DOM Node to be transformed
153         * @param out The writer for the transformed output
154         * @param params A set of parameters that will be forwarded to the XSLT
155         * @throws Exception the transformation failed
156         */
157        void transform(String xslName, Node in, Writer out, Map params) throws Exception
158        {
159            getService().transform(xslName, in, out, params);
160        }
161    
162        /**
163         * Uses an xsl file to transform xml input from a DOM note and returns a
164         * string containing the transformed output.
165         *
166         * @param xslName The name of the file that contains the xsl stylesheet.
167         * @param in The DOM Node to be transformed
168         * @param params A set of parameters that will be forwarded to the XSLT
169         * @return the transformed output
170         * @throws Exception the transformation failed
171         */
172        String transform(String xslName, Node in, Map params) throws Exception
173        {
174            return getService().transform(xslName, in, params);
175        }
176    
177        /**
178         * Uses an xsl file without any xml input.
179         *
180         * @param xslName The name of the file that contains the xsl stylesheet.
181         * @param params A set of parameters that will be forwarded to the XSLT
182         * @return the transformed output
183         * @throws Exception the transformation failed
184         */
185        public String transform(String xslName, Map params) throws Exception {
186            return getService().transform(xslName, params);
187        }
188    
189        /**
190         * Uses an xsl file without any xml input.
191         *
192         * @param xslName The name of the file that contains the xsl stylesheet
193         * @param out The writer for the transformed output.
194         * @param params A set of parameters that will be forwarded to the XSLT
195         * @throws Exception the transformation failed
196         */    
197        public void transform(String xslName, Writer out, Map params) throws Exception {
198            getService().transform(xslName, out, params);
199        }
200    }