You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@turbine.apache.org by pa...@apache.org on 2019/05/21 03:47:20 UTC

svn commit: r1045257 [7/22] - in /websites/production/turbine/content/fulcrum/fulcrum-xslt: ./ announcements/ apidocs/ apidocs/org/apache/fulcrum/xslt/ apidocs/org/apache/fulcrum/xslt/class-use/ apidocs/resources/ apidocs/src-html/org/apache/fulcrum/xs...

Modified: websites/production/turbine/content/fulcrum/fulcrum-xslt/apidocs/src-html/org/apache/fulcrum/xslt/DefaultXSLTService.html
==============================================================================
--- websites/production/turbine/content/fulcrum/fulcrum-xslt/apidocs/src-html/org/apache/fulcrum/xslt/DefaultXSLTService.html (original)
+++ websites/production/turbine/content/fulcrum/fulcrum-xslt/apidocs/src-html/org/apache/fulcrum/xslt/DefaultXSLTService.html Tue May 21 03:47:18 2019
@@ -1,491 +1,525 @@
-<HTML>
-<BODY BGCOLOR="white">
-<PRE>
-<FONT color="green">001</FONT>    package org.apache.fulcrum.xslt;<a name="line.1"></a>
-<FONT color="green">002</FONT>    <a name="line.2"></a>
-<FONT color="green">003</FONT>    /*<a name="line.3"></a>
-<FONT color="green">004</FONT>     * Licensed to the Apache Software Foundation (ASF) under one<a name="line.4"></a>
-<FONT color="green">005</FONT>     * or more contributor license agreements.  See the NOTICE file<a name="line.5"></a>
-<FONT color="green">006</FONT>     * distributed with this work for additional information<a name="line.6"></a>
-<FONT color="green">007</FONT>     * regarding copyright ownership.  The ASF licenses this file<a name="line.7"></a>
-<FONT color="green">008</FONT>     * to you under the Apache License, Version 2.0 (the<a name="line.8"></a>
-<FONT color="green">009</FONT>     * "License"); you may not use this file except in compliance<a name="line.9"></a>
-<FONT color="green">010</FONT>     * with the License.  You may obtain a copy of the License at<a name="line.10"></a>
-<FONT color="green">011</FONT>     *<a name="line.11"></a>
-<FONT color="green">012</FONT>     *   http://www.apache.org/licenses/LICENSE-2.0<a name="line.12"></a>
-<FONT color="green">013</FONT>     *<a name="line.13"></a>
-<FONT color="green">014</FONT>     * Unless required by applicable law or agreed to in writing,<a name="line.14"></a>
-<FONT color="green">015</FONT>     * software distributed under the License is distributed on an<a name="line.15"></a>
-<FONT color="green">016</FONT>     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY<a name="line.16"></a>
-<FONT color="green">017</FONT>     * KIND, either express or implied.  See the License for the<a name="line.17"></a>
-<FONT color="green">018</FONT>     * specific language governing permissions and limitations<a name="line.18"></a>
-<FONT color="green">019</FONT>     * under the License.<a name="line.19"></a>
-<FONT color="green">020</FONT>     */<a name="line.20"></a>
-<FONT color="green">021</FONT>    <a name="line.21"></a>
-<FONT color="green">022</FONT>    import java.io.Reader;<a name="line.22"></a>
-<FONT color="green">023</FONT>    import java.io.StringWriter;<a name="line.23"></a>
-<FONT color="green">024</FONT>    import java.io.Writer;<a name="line.24"></a>
-<FONT color="green">025</FONT>    import java.net.MalformedURLException;<a name="line.25"></a>
-<FONT color="green">026</FONT>    import java.net.URL;<a name="line.26"></a>
-<FONT color="green">027</FONT>    import java.util.Hashtable;<a name="line.27"></a>
-<FONT color="green">028</FONT>    import java.util.Iterator;<a name="line.28"></a>
-<FONT color="green">029</FONT>    import java.util.Map;<a name="line.29"></a>
-<FONT color="green">030</FONT>    <a name="line.30"></a>
-<FONT color="green">031</FONT>    import javax.xml.transform.Result;<a name="line.31"></a>
-<FONT color="green">032</FONT>    import javax.xml.transform.Source;<a name="line.32"></a>
-<FONT color="green">033</FONT>    import javax.xml.transform.Templates;<a name="line.33"></a>
-<FONT color="green">034</FONT>    import javax.xml.transform.Transformer;<a name="line.34"></a>
-<FONT color="green">035</FONT>    import javax.xml.transform.TransformerFactory;<a name="line.35"></a>
-<FONT color="green">036</FONT>    import javax.xml.transform.dom.DOMSource;<a name="line.36"></a>
-<FONT color="green">037</FONT>    import javax.xml.transform.stream.StreamResult;<a name="line.37"></a>
-<FONT color="green">038</FONT>    import javax.xml.transform.stream.StreamSource;<a name="line.38"></a>
-<FONT color="green">039</FONT>    import javax.xml.parsers.DocumentBuilder;<a name="line.39"></a>
-<FONT color="green">040</FONT>    import javax.xml.parsers.DocumentBuilderFactory;<a name="line.40"></a>
-<FONT color="green">041</FONT>    <a name="line.41"></a>
-<FONT color="green">042</FONT>    import org.apache.avalon.framework.activity.Initializable;<a name="line.42"></a>
-<FONT color="green">043</FONT>    import org.apache.avalon.framework.configuration.Configurable;<a name="line.43"></a>
-<FONT color="green">044</FONT>    import org.apache.avalon.framework.configuration.Configuration;<a name="line.44"></a>
-<FONT color="green">045</FONT>    import org.apache.avalon.framework.configuration.ConfigurationException;<a name="line.45"></a>
-<FONT color="green">046</FONT>    import org.apache.avalon.framework.context.Context;<a name="line.46"></a>
-<FONT color="green">047</FONT>    import org.apache.avalon.framework.context.ContextException;<a name="line.47"></a>
-<FONT color="green">048</FONT>    import org.apache.avalon.framework.context.Contextualizable;<a name="line.48"></a>
-<FONT color="green">049</FONT>    import org.apache.avalon.framework.logger.AbstractLogEnabled;<a name="line.49"></a>
-<FONT color="green">050</FONT>    import org.apache.avalon.framework.service.ServiceManager;<a name="line.50"></a>
-<FONT color="green">051</FONT>    import org.apache.avalon.framework.service.Serviceable;<a name="line.51"></a>
-<FONT color="green">052</FONT>    import org.w3c.dom.Node;<a name="line.52"></a>
-<FONT color="green">053</FONT>    import org.w3c.dom.Document;<a name="line.53"></a>
-<FONT color="green">054</FONT>    <a name="line.54"></a>
-<FONT color="green">055</FONT>    /**<a name="line.55"></a>
-<FONT color="green">056</FONT>     * Implementation of the Turbine XSLT Service. It transforms xml with a given<a name="line.56"></a>
-<FONT color="green">057</FONT>     * xsl file. XSL stylesheets are compiled and cached (if the service property is<a name="line.57"></a>
-<FONT color="green">058</FONT>     * set) to improve speeds.<a name="line.58"></a>
-<FONT color="green">059</FONT>     *<a name="line.59"></a>
-<FONT color="green">060</FONT>     * @author &lt;a href="mailto:leon@opticode.co.za"&gt;Leon Messerschmidt&lt;/a&gt;<a name="line.60"></a>
-<FONT color="green">061</FONT>     * @author &lt;a href="mailto:rubys@us.ibm.com"&gt;Sam Ruby&lt;/a&gt;<a name="line.61"></a>
-<FONT color="green">062</FONT>     * @author &lt;a href="mailto:epugh@opensourceconnections.com"&gt;Eric Pugh&lt;/a&gt;<a name="line.62"></a>
-<FONT color="green">063</FONT>     * @author &lt;a href="mailto:tv@apache.org"&gt;Thomas Vandahl&lt;/a&gt;<a name="line.63"></a>
-<FONT color="green">064</FONT>     */<a name="line.64"></a>
-<FONT color="green">065</FONT>    public class DefaultXSLTService extends AbstractLogEnabled implements<a name="line.65"></a>
-<FONT color="green">066</FONT>            XSLTService, Initializable, Configurable, Contextualizable, Serviceable<a name="line.66"></a>
-<FONT color="green">067</FONT>    {<a name="line.67"></a>
-<FONT color="green">068</FONT>        /**<a name="line.68"></a>
-<FONT color="green">069</FONT>         * The application root<a name="line.69"></a>
-<FONT color="green">070</FONT>         */<a name="line.70"></a>
-<FONT color="green">071</FONT>        private String applicationRoot;<a name="line.71"></a>
-<FONT color="green">072</FONT>    <a name="line.72"></a>
-<FONT color="green">073</FONT>        /**<a name="line.73"></a>
-<FONT color="green">074</FONT>         * Property to control the caching of Templates.<a name="line.74"></a>
-<FONT color="green">075</FONT>         */<a name="line.75"></a>
-<FONT color="green">076</FONT>        protected boolean caching = false;<a name="line.76"></a>
-<FONT color="green">077</FONT>    <a name="line.77"></a>
-<FONT color="green">078</FONT>        /**<a name="line.78"></a>
-<FONT color="green">079</FONT>         * Path to style sheets used for tranforming well-formed XML documents. The<a name="line.79"></a>
-<FONT color="green">080</FONT>         * path is relative to the webapp context.<a name="line.80"></a>
-<FONT color="green">081</FONT>         */<a name="line.81"></a>
-<FONT color="green">082</FONT>        protected String path;<a name="line.82"></a>
-<FONT color="green">083</FONT>    <a name="line.83"></a>
-<FONT color="green">084</FONT>        /**<a name="line.84"></a>
-<FONT color="green">085</FONT>         * Cache of compiled Templates.<a name="line.85"></a>
-<FONT color="green">086</FONT>         */<a name="line.86"></a>
-<FONT color="green">087</FONT>        protected Hashtable cache = new Hashtable();<a name="line.87"></a>
-<FONT color="green">088</FONT>    <a name="line.88"></a>
-<FONT color="green">089</FONT>        protected final static String STYLESHEET_PATH = "path";<a name="line.89"></a>
-<FONT color="green">090</FONT>    <a name="line.90"></a>
-<FONT color="green">091</FONT>        protected final static String STYLESHEET_CACHING = "cache";<a name="line.91"></a>
-<FONT color="green">092</FONT>    <a name="line.92"></a>
-<FONT color="green">093</FONT>        /**<a name="line.93"></a>
-<FONT color="green">094</FONT>         * Factory for producing templates and null transformers<a name="line.94"></a>
-<FONT color="green">095</FONT>         */<a name="line.95"></a>
-<FONT color="green">096</FONT>        private static TransformerFactory tfactory;<a name="line.96"></a>
-<FONT color="green">097</FONT>    <a name="line.97"></a>
-<FONT color="green">098</FONT>        /**<a name="line.98"></a>
-<FONT color="green">099</FONT>         * Try to create a valid url object from the style parameter.<a name="line.99"></a>
-<FONT color="green">100</FONT>         *<a name="line.100"></a>
-<FONT color="green">101</FONT>         * @param style<a name="line.101"></a>
-<FONT color="green">102</FONT>         *            the xsl-Style<a name="line.102"></a>
-<FONT color="green">103</FONT>         * @return a &lt;code&gt;URL&lt;/code&gt; object or null if the style sheet could not<a name="line.103"></a>
-<FONT color="green">104</FONT>         *         be found<a name="line.104"></a>
-<FONT color="green">105</FONT>         */<a name="line.105"></a>
-<FONT color="green">106</FONT>        private URL getStyleURL(String style)<a name="line.106"></a>
-<FONT color="green">107</FONT>        {<a name="line.107"></a>
-<FONT color="green">108</FONT>            StringBuffer sb = new StringBuffer();<a name="line.108"></a>
-<FONT color="green">109</FONT>    <a name="line.109"></a>
-<FONT color="green">110</FONT>            sb.append(path);<a name="line.110"></a>
-<FONT color="green">111</FONT>    <a name="line.111"></a>
-<FONT color="green">112</FONT>            // we chop off the existing extension<a name="line.112"></a>
-<FONT color="green">113</FONT>            int colon = style.lastIndexOf(".");<a name="line.113"></a>
-<FONT color="green">114</FONT>    <a name="line.114"></a>
-<FONT color="green">115</FONT>            if (colon &gt; 0)<a name="line.115"></a>
-<FONT color="green">116</FONT>            {<a name="line.116"></a>
-<FONT color="green">117</FONT>                sb.append(style.substring(0, colon));<a name="line.117"></a>
-<FONT color="green">118</FONT>            }<a name="line.118"></a>
-<FONT color="green">119</FONT>            else<a name="line.119"></a>
-<FONT color="green">120</FONT>            {<a name="line.120"></a>
-<FONT color="green">121</FONT>                sb.append(style);<a name="line.121"></a>
-<FONT color="green">122</FONT>            }<a name="line.122"></a>
-<FONT color="green">123</FONT>    <a name="line.123"></a>
-<FONT color="green">124</FONT>            sb.append(".xslt");<a name="line.124"></a>
-<FONT color="green">125</FONT>    <a name="line.125"></a>
-<FONT color="green">126</FONT>            URL url = null;<a name="line.126"></a>
-<FONT color="green">127</FONT>    <a name="line.127"></a>
-<FONT color="green">128</FONT>            try<a name="line.128"></a>
-<FONT color="green">129</FONT>            {<a name="line.129"></a>
-<FONT color="green">130</FONT>                url = new URL(sb.toString());<a name="line.130"></a>
-<FONT color="green">131</FONT>            }<a name="line.131"></a>
-<FONT color="green">132</FONT>            catch (MalformedURLException e)<a name="line.132"></a>
-<FONT color="green">133</FONT>            {<a name="line.133"></a>
-<FONT color="green">134</FONT>                getLogger().error("Malformed URL: " + sb, e);<a name="line.134"></a>
-<FONT color="green">135</FONT>            }<a name="line.135"></a>
-<FONT color="green">136</FONT>    <a name="line.136"></a>
-<FONT color="green">137</FONT>            return url;<a name="line.137"></a>
-<FONT color="green">138</FONT>        }<a name="line.138"></a>
-<FONT color="green">139</FONT>    <a name="line.139"></a>
-<FONT color="green">140</FONT>        /**<a name="line.140"></a>
-<FONT color="green">141</FONT>         * Compile Templates from an input file.<a name="line.141"></a>
-<FONT color="green">142</FONT>         *<a name="line.142"></a>
-<FONT color="green">143</FONT>         * @param source the source URL<a name="line.143"></a>
-<FONT color="green">144</FONT>         * @return the compiled template<a name="line.144"></a>
-<FONT color="green">145</FONT>         * @throws Exception the compilation failed<a name="line.145"></a>
-<FONT color="green">146</FONT>         */<a name="line.146"></a>
-<FONT color="green">147</FONT>        protected Templates compileTemplates(URL source) throws Exception<a name="line.147"></a>
-<FONT color="green">148</FONT>        {<a name="line.148"></a>
-<FONT color="green">149</FONT>            StreamSource xslin = new StreamSource(source.openStream());<a name="line.149"></a>
-<FONT color="green">150</FONT>            return tfactory.newTemplates(xslin);<a name="line.150"></a>
-<FONT color="green">151</FONT>        }<a name="line.151"></a>
-<FONT color="green">152</FONT>    <a name="line.152"></a>
-<FONT color="green">153</FONT>        /**<a name="line.153"></a>
-<FONT color="green">154</FONT>         * Retrieves Templates. If caching is switched on the first attempt is to<a name="line.154"></a>
-<FONT color="green">155</FONT>         * load Templates from the cache. If caching is switched of or if the<a name="line.155"></a>
-<FONT color="green">156</FONT>         * Stylesheet is not found in the cache new Templates are compiled from an<a name="line.156"></a>
-<FONT color="green">157</FONT>         * input file.<a name="line.157"></a>
-<FONT color="green">158</FONT>         * &lt;p&gt;<a name="line.158"></a>
-<FONT color="green">159</FONT>         * This method is synchronized on the xsl cache so that a thread does not<a name="line.159"></a>
-<FONT color="green">160</FONT>         * attempt to load Templates from the cache while it is still being<a name="line.160"></a>
-<FONT color="green">161</FONT>         * compiled.<a name="line.161"></a>
-<FONT color="green">162</FONT>         *<a name="line.162"></a>
-<FONT color="green">163</FONT>         * @param xslName the name of the XSL file<a name="line.163"></a>
-<FONT color="green">164</FONT>         * @return the correspondint template or null if the XSL was not found<a name="line.164"></a>
-<FONT color="green">165</FONT>         * @throws Exception getting the template failed<a name="line.165"></a>
-<FONT color="green">166</FONT>         */<a name="line.166"></a>
-<FONT color="green">167</FONT>        protected Templates getTemplates(String xslName) throws Exception<a name="line.167"></a>
-<FONT color="green">168</FONT>        {<a name="line.168"></a>
-<FONT color="green">169</FONT>            synchronized (cache)<a name="line.169"></a>
-<FONT color="green">170</FONT>            {<a name="line.170"></a>
-<FONT color="green">171</FONT>                URL fn = getStyleURL(xslName);<a name="line.171"></a>
-<FONT color="green">172</FONT>                if (fn == null)<a name="line.172"></a>
-<FONT color="green">173</FONT>                    return null;<a name="line.173"></a>
-<FONT color="green">174</FONT>    <a name="line.174"></a>
-<FONT color="green">175</FONT>                if (caching &amp;&amp; cache.containsKey(fn))<a name="line.175"></a>
-<FONT color="green">176</FONT>                {<a name="line.176"></a>
-<FONT color="green">177</FONT>                    return (Templates) cache.get(fn);<a name="line.177"></a>
-<FONT color="green">178</FONT>                }<a name="line.178"></a>
-<FONT color="green">179</FONT>    <a name="line.179"></a>
-<FONT color="green">180</FONT>                Templates sr = compileTemplates(fn);<a name="line.180"></a>
-<FONT color="green">181</FONT>    <a name="line.181"></a>
-<FONT color="green">182</FONT>                if (caching)<a name="line.182"></a>
-<FONT color="green">183</FONT>                {<a name="line.183"></a>
-<FONT color="green">184</FONT>                    cache.put(fn, sr);<a name="line.184"></a>
-<FONT color="green">185</FONT>                }<a name="line.185"></a>
-<FONT color="green">186</FONT>    <a name="line.186"></a>
-<FONT color="green">187</FONT>                return sr;<a name="line.187"></a>
-<FONT color="green">188</FONT>            }<a name="line.188"></a>
-<FONT color="green">189</FONT>        }<a name="line.189"></a>
-<FONT color="green">190</FONT>    <a name="line.190"></a>
-<FONT color="green">191</FONT>        protected void transform(String xslName, Source xmlin, Result xmlout, Map params)<a name="line.191"></a>
-<FONT color="green">192</FONT>                throws Exception<a name="line.192"></a>
-<FONT color="green">193</FONT>        {<a name="line.193"></a>
-<FONT color="green">194</FONT>            try<a name="line.194"></a>
-<FONT color="green">195</FONT>            {<a name="line.195"></a>
-<FONT color="green">196</FONT>                long startTime = System.currentTimeMillis();<a name="line.196"></a>
-<FONT color="green">197</FONT>                Transformer transformer = getTransformer(xslName);<a name="line.197"></a>
-<FONT color="green">198</FONT>    <a name="line.198"></a>
-<FONT color="green">199</FONT>                if (params != null)<a name="line.199"></a>
-<FONT color="green">200</FONT>                {<a name="line.200"></a>
-<FONT color="green">201</FONT>                    for (Iterator it = params.entrySet().iterator(); it.hasNext(); )<a name="line.201"></a>
-<FONT color="green">202</FONT>                    {<a name="line.202"></a>
-<FONT color="green">203</FONT>                        Map.Entry entry = (Map.Entry) it.next();<a name="line.203"></a>
-<FONT color="green">204</FONT>                        transformer.setParameter(String.valueOf(entry.getKey()), entry.getValue());<a name="line.204"></a>
-<FONT color="green">205</FONT>                    }<a name="line.205"></a>
-<FONT color="green">206</FONT>                }<a name="line.206"></a>
-<FONT color="green">207</FONT>    <a name="line.207"></a>
-<FONT color="green">208</FONT>                transformer.transform(xmlin, xmlout);<a name="line.208"></a>
-<FONT color="green">209</FONT>    <a name="line.209"></a>
-<FONT color="green">210</FONT>                if(getLogger().isDebugEnabled())<a name="line.210"></a>
-<FONT color="green">211</FONT>                {<a name="line.211"></a>
-<FONT color="green">212</FONT>                    long duration = System.currentTimeMillis() - startTime;<a name="line.212"></a>
-<FONT color="green">213</FONT>                    getLogger().debug("The transforamtion '" + xslName + "' took " + duration + " ms");<a name="line.213"></a>
-<FONT color="green">214</FONT>                }<a name="line.214"></a>
-<FONT color="green">215</FONT>            }<a name="line.215"></a>
-<FONT color="green">216</FONT>            catch(Exception e)<a name="line.216"></a>
-<FONT color="green">217</FONT>            {<a name="line.217"></a>
-<FONT color="green">218</FONT>                getLogger().debug("The transformation '" + xslName + "' failed due to : " + e.getMessage());<a name="line.218"></a>
-<FONT color="green">219</FONT>                throw e;<a name="line.219"></a>
-<FONT color="green">220</FONT>            }<a name="line.220"></a>
-<FONT color="green">221</FONT>        }<a name="line.221"></a>
-<FONT color="green">222</FONT>    <a name="line.222"></a>
-<FONT color="green">223</FONT>        /**<a name="line.223"></a>
-<FONT color="green">224</FONT>         * Uses an xsl file to transform xml input from a reader and writes the<a name="line.224"></a>
-<FONT color="green">225</FONT>         * output to a writer.<a name="line.225"></a>
-<FONT color="green">226</FONT>         *<a name="line.226"></a>
-<FONT color="green">227</FONT>         * @param xslName<a name="line.227"></a>
-<FONT color="green">228</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.228"></a>
-<FONT color="green">229</FONT>         * @param in<a name="line.229"></a>
-<FONT color="green">230</FONT>         *            The reader that passes the xml to be transformed<a name="line.230"></a>
-<FONT color="green">231</FONT>         * @param out<a name="line.231"></a>
-<FONT color="green">232</FONT>         *            The writer for the transformed output<a name="line.232"></a>
-<FONT color="green">233</FONT>         */<a name="line.233"></a>
-<FONT color="green">234</FONT>        public void transform(String xslName, Reader in, Writer out)<a name="line.234"></a>
-<FONT color="green">235</FONT>                throws Exception<a name="line.235"></a>
-<FONT color="green">236</FONT>        {<a name="line.236"></a>
-<FONT color="green">237</FONT>            Source xmlin = new StreamSource(in);<a name="line.237"></a>
-<FONT color="green">238</FONT>            Result xmlout = new StreamResult(out);<a name="line.238"></a>
-<FONT color="green">239</FONT>            transform(xslName, xmlin, xmlout, null);<a name="line.239"></a>
-<FONT color="green">240</FONT>        }<a name="line.240"></a>
-<FONT color="green">241</FONT>    <a name="line.241"></a>
-<FONT color="green">242</FONT>        /**<a name="line.242"></a>
-<FONT color="green">243</FONT>         * Uses an xsl file to transform xml input from a reader and returns a<a name="line.243"></a>
-<FONT color="green">244</FONT>         * string containing the transformed output.<a name="line.244"></a>
-<FONT color="green">245</FONT>         *<a name="line.245"></a>
-<FONT color="green">246</FONT>         * @param xslName<a name="line.246"></a>
-<FONT color="green">247</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.247"></a>
-<FONT color="green">248</FONT>         * @param in<a name="line.248"></a>
-<FONT color="green">249</FONT>         *            The reader that passes the xml to be transformed<a name="line.249"></a>
-<FONT color="green">250</FONT>         */<a name="line.250"></a>
-<FONT color="green">251</FONT>        public String transform(String xslName, Reader in) throws Exception<a name="line.251"></a>
-<FONT color="green">252</FONT>        {<a name="line.252"></a>
-<FONT color="green">253</FONT>            StringWriter sw = new StringWriter();<a name="line.253"></a>
-<FONT color="green">254</FONT>            transform(xslName, in, sw, null);<a name="line.254"></a>
-<FONT color="green">255</FONT>            return sw.toString();<a name="line.255"></a>
-<FONT color="green">256</FONT>        }<a name="line.256"></a>
-<FONT color="green">257</FONT>    <a name="line.257"></a>
-<FONT color="green">258</FONT>        /**<a name="line.258"></a>
-<FONT color="green">259</FONT>         * Uses an xsl file to transform xml input from a DOM note and writes the<a name="line.259"></a>
-<FONT color="green">260</FONT>         * output to a writer.<a name="line.260"></a>
-<FONT color="green">261</FONT>         *<a name="line.261"></a>
-<FONT color="green">262</FONT>         * @param xslName<a name="line.262"></a>
-<FONT color="green">263</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.263"></a>
-<FONT color="green">264</FONT>         * @param in<a name="line.264"></a>
-<FONT color="green">265</FONT>         *            The DOM Node to be transformed<a name="line.265"></a>
-<FONT color="green">266</FONT>         * @param out<a name="line.266"></a>
-<FONT color="green">267</FONT>         *            The writer for the transformed output<a name="line.267"></a>
-<FONT color="green">268</FONT>         */<a name="line.268"></a>
-<FONT color="green">269</FONT>        public void transform(String xslName, org.w3c.dom.Node in, Writer out)<a name="line.269"></a>
-<FONT color="green">270</FONT>                throws Exception<a name="line.270"></a>
-<FONT color="green">271</FONT>        {<a name="line.271"></a>
-<FONT color="green">272</FONT>            Source xmlin = new DOMSource(in);<a name="line.272"></a>
-<FONT color="green">273</FONT>            Result xmlout = new StreamResult(out);<a name="line.273"></a>
-<FONT color="green">274</FONT>            transform(xslName, xmlin, xmlout, null);<a name="line.274"></a>
-<FONT color="green">275</FONT>        }<a name="line.275"></a>
-<FONT color="green">276</FONT>    <a name="line.276"></a>
-<FONT color="green">277</FONT>        /**<a name="line.277"></a>
-<FONT color="green">278</FONT>         * Uses an xsl file to transform xml input from a DOM note and returns a<a name="line.278"></a>
-<FONT color="green">279</FONT>         * string containing the transformed output.<a name="line.279"></a>
-<FONT color="green">280</FONT>         *<a name="line.280"></a>
-<FONT color="green">281</FONT>         * @param xslName<a name="line.281"></a>
-<FONT color="green">282</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.282"></a>
-<FONT color="green">283</FONT>         * @param in<a name="line.283"></a>
-<FONT color="green">284</FONT>         *            The DOM Node to be transformed<a name="line.284"></a>
-<FONT color="green">285</FONT>         */<a name="line.285"></a>
-<FONT color="green">286</FONT>        public String transform(String xslName, org.w3c.dom.Node in)<a name="line.286"></a>
-<FONT color="green">287</FONT>                throws Exception<a name="line.287"></a>
-<FONT color="green">288</FONT>        {<a name="line.288"></a>
-<FONT color="green">289</FONT>            StringWriter sw = new StringWriter();<a name="line.289"></a>
-<FONT color="green">290</FONT>            transform(xslName, in, sw);<a name="line.290"></a>
-<FONT color="green">291</FONT>            return sw.toString();<a name="line.291"></a>
-<FONT color="green">292</FONT>        }<a name="line.292"></a>
-<FONT color="green">293</FONT>    <a name="line.293"></a>
-<FONT color="green">294</FONT>        /**<a name="line.294"></a>
-<FONT color="green">295</FONT>         * Uses an xsl file to transform xml input from a reader and writes the<a name="line.295"></a>
-<FONT color="green">296</FONT>         * output to a writer.<a name="line.296"></a>
-<FONT color="green">297</FONT>         *<a name="line.297"></a>
-<FONT color="green">298</FONT>         * @param xslName<a name="line.298"></a>
-<FONT color="green">299</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.299"></a>
-<FONT color="green">300</FONT>         * @param in<a name="line.300"></a>
-<FONT color="green">301</FONT>         *            The reader that passes the xml to be transformed<a name="line.301"></a>
-<FONT color="green">302</FONT>         * @param out<a name="line.302"></a>
-<FONT color="green">303</FONT>         *            The writer for the transformed output<a name="line.303"></a>
-<FONT color="green">304</FONT>         * @param params<a name="line.304"></a>
-<FONT color="green">305</FONT>         *            A set of parameters that will be forwarded to the XSLT<a name="line.305"></a>
-<FONT color="green">306</FONT>         */<a name="line.306"></a>
-<FONT color="green">307</FONT>        public void transform(String xslName, Reader in, Writer out, Map params)<a name="line.307"></a>
-<FONT color="green">308</FONT>                throws Exception<a name="line.308"></a>
-<FONT color="green">309</FONT>        {<a name="line.309"></a>
-<FONT color="green">310</FONT>            Source xmlin = new StreamSource(in);<a name="line.310"></a>
-<FONT color="green">311</FONT>            Result xmlout = new StreamResult(out);<a name="line.311"></a>
-<FONT color="green">312</FONT>            transform(xslName, xmlin, xmlout, params);<a name="line.312"></a>
-<FONT color="green">313</FONT>        }<a name="line.313"></a>
-<FONT color="green">314</FONT>    <a name="line.314"></a>
-<FONT color="green">315</FONT>        /**<a name="line.315"></a>
-<FONT color="green">316</FONT>         * Uses an xsl file to transform xml input from a reader and returns a<a name="line.316"></a>
-<FONT color="green">317</FONT>         * string containing the transformed output.<a name="line.317"></a>
-<FONT color="green">318</FONT>         *<a name="line.318"></a>
-<FONT color="green">319</FONT>         * @param xslName<a name="line.319"></a>
-<FONT color="green">320</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.320"></a>
-<FONT color="green">321</FONT>         * @param in<a name="line.321"></a>
-<FONT color="green">322</FONT>         *            The reader that passes the xml to be transformed<a name="line.322"></a>
-<FONT color="green">323</FONT>         * @param params<a name="line.323"></a>
-<FONT color="green">324</FONT>         *            A set of parameters that will be forwarded to the XSLT<a name="line.324"></a>
-<FONT color="green">325</FONT>         */<a name="line.325"></a>
-<FONT color="green">326</FONT>        public String transform(String xslName, Reader in, Map params)<a name="line.326"></a>
-<FONT color="green">327</FONT>                throws Exception<a name="line.327"></a>
-<FONT color="green">328</FONT>        {<a name="line.328"></a>
-<FONT color="green">329</FONT>            StringWriter sw = new StringWriter();<a name="line.329"></a>
-<FONT color="green">330</FONT>            transform(xslName, in, sw, params);<a name="line.330"></a>
-<FONT color="green">331</FONT>            return sw.toString();<a name="line.331"></a>
-<FONT color="green">332</FONT>        }<a name="line.332"></a>
-<FONT color="green">333</FONT>    <a name="line.333"></a>
-<FONT color="green">334</FONT>        /**<a name="line.334"></a>
-<FONT color="green">335</FONT>         * Uses an xsl file to transform xml input from a DOM note and writes the<a name="line.335"></a>
-<FONT color="green">336</FONT>         * output to a writer.<a name="line.336"></a>
-<FONT color="green">337</FONT>         *<a name="line.337"></a>
-<FONT color="green">338</FONT>         * @param xslName<a name="line.338"></a>
-<FONT color="green">339</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.339"></a>
-<FONT color="green">340</FONT>         * @param in<a name="line.340"></a>
-<FONT color="green">341</FONT>         *            The DOM Node to be transformed<a name="line.341"></a>
-<FONT color="green">342</FONT>         * @param out<a name="line.342"></a>
-<FONT color="green">343</FONT>         *            The writer for the transformed output<a name="line.343"></a>
-<FONT color="green">344</FONT>         * @param params<a name="line.344"></a>
-<FONT color="green">345</FONT>         *            A set of parameters that will be forwarded to the XSLT<a name="line.345"></a>
-<FONT color="green">346</FONT>         */<a name="line.346"></a>
-<FONT color="green">347</FONT>        public void transform(String xslName, Node in, Writer out, Map params)<a name="line.347"></a>
-<FONT color="green">348</FONT>                throws Exception<a name="line.348"></a>
-<FONT color="green">349</FONT>        {<a name="line.349"></a>
-<FONT color="green">350</FONT>            Source xmlin = new DOMSource(in);<a name="line.350"></a>
-<FONT color="green">351</FONT>            Result xmlout = new StreamResult(out);<a name="line.351"></a>
-<FONT color="green">352</FONT>            transform(xslName, xmlin, xmlout, params);<a name="line.352"></a>
-<FONT color="green">353</FONT>        }<a name="line.353"></a>
-<FONT color="green">354</FONT>    <a name="line.354"></a>
-<FONT color="green">355</FONT>        /**<a name="line.355"></a>
-<FONT color="green">356</FONT>         * Uses an xsl file to transform xml input from a DOM note and returns a<a name="line.356"></a>
-<FONT color="green">357</FONT>         * string containing the transformed output.<a name="line.357"></a>
-<FONT color="green">358</FONT>         *<a name="line.358"></a>
-<FONT color="green">359</FONT>         * @param xslName<a name="line.359"></a>
-<FONT color="green">360</FONT>         *            The name of the file that contains the xsl stylesheet.<a name="line.360"></a>
-<FONT color="green">361</FONT>         * @param in<a name="line.361"></a>
-<FONT color="green">362</FONT>         *            The DOM Node to be transformed<a name="line.362"></a>
-<FONT color="green">363</FONT>         * @param params<a name="line.363"></a>
-<FONT color="green">364</FONT>         *            A set of parameters that will be forwarded to the XSLT<a name="line.364"></a>
-<FONT color="green">365</FONT>         */<a name="line.365"></a>
-<FONT color="green">366</FONT>        public String transform(String xslName, Node in, Map params)<a name="line.366"></a>
-<FONT color="green">367</FONT>                throws Exception<a name="line.367"></a>
-<FONT color="green">368</FONT>        {<a name="line.368"></a>
-<FONT color="green">369</FONT>            StringWriter sw = new StringWriter();<a name="line.369"></a>
-<FONT color="green">370</FONT>            transform(xslName, in, sw, params);<a name="line.370"></a>
-<FONT color="green">371</FONT>            return sw.toString();<a name="line.371"></a>
-<FONT color="green">372</FONT>        }<a name="line.372"></a>
-<FONT color="green">373</FONT>    <a name="line.373"></a>
-<FONT color="green">374</FONT>        /**<a name="line.374"></a>
-<FONT color="green">375</FONT>         * Uses an xsl file without any input.<a name="line.375"></a>
-<FONT color="green">376</FONT>         *<a name="line.376"></a>
-<FONT color="green">377</FONT>         * @param xslName The name of the file that contains the xsl stylesheet.<a name="line.377"></a>
-<FONT color="green">378</FONT>         * @param params A set of parameters that will be forwarded to the XSLT<a name="line.378"></a>
-<FONT color="green">379</FONT>         * @return the transformed output<a name="line.379"></a>
-<FONT color="green">380</FONT>         * @throws Exception the transformation failed<a name="line.380"></a>
-<FONT color="green">381</FONT>         */<a name="line.381"></a>
-<FONT color="green">382</FONT>        public String transform(String xslName, Map params) throws Exception {<a name="line.382"></a>
-<FONT color="green">383</FONT>    <a name="line.383"></a>
-<FONT color="green">384</FONT>            StringWriter sw = new StringWriter();<a name="line.384"></a>
-<FONT color="green">385</FONT>            transform(xslName, sw, params);<a name="line.385"></a>
-<FONT color="green">386</FONT>            return sw.toString();<a name="line.386"></a>
-<FONT color="green">387</FONT>        }<a name="line.387"></a>
-<FONT color="green">388</FONT>    <a name="line.388"></a>
-<FONT color="green">389</FONT>        /**<a name="line.389"></a>
-<FONT color="green">390</FONT>         * Uses an xsl file without any xml input (simplified stylesheet)<a name="line.390"></a>
-<FONT color="green">391</FONT>         *<a name="line.391"></a>
-<FONT color="green">392</FONT>         * @param xslName The name of the file that contains the xsl stylesheet<a name="line.392"></a>
-<FONT color="green">393</FONT>         * @param out The writer for the transformed output.<a name="line.393"></a>
-<FONT color="green">394</FONT>         * @param params A set of parameters that will be forwarded to the XSLT<a name="line.394"></a>
-<FONT color="green">395</FONT>         * @throws Exception the transformation failed<a name="line.395"></a>
-<FONT color="green">396</FONT>         */<a name="line.396"></a>
-<FONT color="green">397</FONT>        public void transform(String xslName, Writer out, Map params) throws Exception {<a name="line.397"></a>
-<FONT color="green">398</FONT>    <a name="line.398"></a>
-<FONT color="green">399</FONT>            DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();<a name="line.399"></a>
-<FONT color="green">400</FONT>            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();<a name="line.400"></a>
-<FONT color="green">401</FONT>            Document document = documentBuilder.newDocument();<a name="line.401"></a>
-<FONT color="green">402</FONT>    <a name="line.402"></a>
-<FONT color="green">403</FONT>            transform(xslName, document.getDocumentElement(), out, params);<a name="line.403"></a>
-<FONT color="green">404</FONT>        }<a name="line.404"></a>
-<FONT color="green">405</FONT>    <a name="line.405"></a>
-<FONT color="green">406</FONT>        /**<a name="line.406"></a>
-<FONT color="green">407</FONT>         * Retrieve a transformer for the given stylesheet name. If no stylesheet is<a name="line.407"></a>
-<FONT color="green">408</FONT>         * available for the provided name, an identity transformer will be<a name="line.408"></a>
-<FONT color="green">409</FONT>         * returned. This allows clients of this service to perform more complex<a name="line.409"></a>
-<FONT color="green">410</FONT>         * transformations (for example, where parameters must be set). When<a name="line.410"></a>
-<FONT color="green">411</FONT>         * possible prefer using one of the forms of {@link #transform}.<a name="line.411"></a>
-<FONT color="green">412</FONT>         *<a name="line.412"></a>
-<FONT color="green">413</FONT>         * @param xslName<a name="line.413"></a>
-<FONT color="green">414</FONT>         *            Identifies stylesheet to get transformer for<a name="line.414"></a>
-<FONT color="green">415</FONT>         * @return A transformer for that stylesheet<a name="line.415"></a>
-<FONT color="green">416</FONT>         * @throws Exception retrieving the transformer failed<a name="line.416"></a>
-<FONT color="green">417</FONT>         */<a name="line.417"></a>
-<FONT color="green">418</FONT>        public Transformer getTransformer(String xslName) throws Exception<a name="line.418"></a>
-<FONT color="green">419</FONT>        {<a name="line.419"></a>
-<FONT color="green">420</FONT>            Templates sr = getTemplates(xslName);<a name="line.420"></a>
-<FONT color="green">421</FONT>    <a name="line.421"></a>
-<FONT color="green">422</FONT>            if (sr == null)<a name="line.422"></a>
-<FONT color="green">423</FONT>            {<a name="line.423"></a>
-<FONT color="green">424</FONT>                return tfactory.newTransformer();<a name="line.424"></a>
-<FONT color="green">425</FONT>            }<a name="line.425"></a>
-<FONT color="green">426</FONT>            else<a name="line.426"></a>
-<FONT color="green">427</FONT>            {<a name="line.427"></a>
-<FONT color="green">428</FONT>                return sr.newTransformer();<a name="line.428"></a>
-<FONT color="green">429</FONT>            }<a name="line.429"></a>
-<FONT color="green">430</FONT>        }<a name="line.430"></a>
-<FONT color="green">431</FONT>    <a name="line.431"></a>
-<FONT color="green">432</FONT>        // ---------------- Avalon Lifecycle Methods ---------------------<a name="line.432"></a>
-<FONT color="green">433</FONT>        /**<a name="line.433"></a>
-<FONT color="green">434</FONT>         * Avalon component lifecycle method<a name="line.434"></a>
-<FONT color="green">435</FONT>         *<a name="line.435"></a>
-<FONT color="green">436</FONT>         * This method processes the repository path, to make it relative to the web<a name="line.436"></a>
-<FONT color="green">437</FONT>         * application root, if neccessary. It supports URL-style repositories.<a name="line.437"></a>
-<FONT color="green">438</FONT>         */<a name="line.438"></a>
-<FONT color="green">439</FONT>        public void configure(Configuration conf) throws ConfigurationException<a name="line.439"></a>
-<FONT color="green">440</FONT>        {<a name="line.440"></a>
-<FONT color="green">441</FONT>            StringBuffer sb = new StringBuffer(conf.getAttribute(STYLESHEET_PATH,<a name="line.441"></a>
-<FONT color="green">442</FONT>                    "/"));<a name="line.442"></a>
-<FONT color="green">443</FONT>    <a name="line.443"></a>
-<FONT color="green">444</FONT>            // is URL?<a name="line.444"></a>
-<FONT color="green">445</FONT>            if (!sb.toString().matches("[a-zA-Z]{3,}://.*"))<a name="line.445"></a>
-<FONT color="green">446</FONT>            {<a name="line.446"></a>
-<FONT color="green">447</FONT>                // No<a name="line.447"></a>
-<FONT color="green">448</FONT>                if (sb.charAt(0) != '/')<a name="line.448"></a>
-<FONT color="green">449</FONT>                {<a name="line.449"></a>
-<FONT color="green">450</FONT>                    sb.insert(0, '/');<a name="line.450"></a>
-<FONT color="green">451</FONT>                }<a name="line.451"></a>
-<FONT color="green">452</FONT>                sb.insert(0, applicationRoot);<a name="line.452"></a>
-<FONT color="green">453</FONT>                sb.insert(0, "file:");<a name="line.453"></a>
-<FONT color="green">454</FONT>            }<a name="line.454"></a>
-<FONT color="green">455</FONT>    <a name="line.455"></a>
-<FONT color="green">456</FONT>            if (sb.charAt(sb.length() - 1) != '/')<a name="line.456"></a>
-<FONT color="green">457</FONT>            {<a name="line.457"></a>
-<FONT color="green">458</FONT>                sb.append('/');<a name="line.458"></a>
-<FONT color="green">459</FONT>            }<a name="line.459"></a>
-<FONT color="green">460</FONT>    <a name="line.460"></a>
-<FONT color="green">461</FONT>            path = sb.toString();<a name="line.461"></a>
-<FONT color="green">462</FONT>            caching = conf.getAttributeAsBoolean(STYLESHEET_CACHING, false);<a name="line.462"></a>
-<FONT color="green">463</FONT>        }<a name="line.463"></a>
-<FONT color="green">464</FONT>    <a name="line.464"></a>
-<FONT color="green">465</FONT>        /**<a name="line.465"></a>
-<FONT color="green">466</FONT>         * Initializes the service.<a name="line.466"></a>
-<FONT color="green">467</FONT>         */<a name="line.467"></a>
-<FONT color="green">468</FONT>        public void initialize() throws Exception<a name="line.468"></a>
-<FONT color="green">469</FONT>        {<a name="line.469"></a>
-<FONT color="green">470</FONT>            tfactory = TransformerFactory.newInstance();<a name="line.470"></a>
-<FONT color="green">471</FONT>        }<a name="line.471"></a>
-<FONT color="green">472</FONT>    <a name="line.472"></a>
-<FONT color="green">473</FONT>        public void contextualize(Context context) throws ContextException<a name="line.473"></a>
-<FONT color="green">474</FONT>        {<a name="line.474"></a>
-<FONT color="green">475</FONT>            this.applicationRoot = context.get("urn:avalon:home").toString();<a name="line.475"></a>
-<FONT color="green">476</FONT>        }<a name="line.476"></a>
-<FONT color="green">477</FONT>    <a name="line.477"></a>
-<FONT color="green">478</FONT>        /**<a name="line.478"></a>
-<FONT color="green">479</FONT>         * Avalon component lifecycle method<a name="line.479"></a>
-<FONT color="green">480</FONT>         */<a name="line.480"></a>
-<FONT color="green">481</FONT>        public void service(ServiceManager manager)<a name="line.481"></a>
-<FONT color="green">482</FONT>        {<a name="line.482"></a>
-<FONT color="green">483</FONT>            XSLTServiceFacade.setService(this);<a name="line.483"></a>
-<FONT color="green">484</FONT>        }<a name="line.484"></a>
-<FONT color="green">485</FONT>    }<a name="line.485"></a>
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html lang="en">
+<head>
+<title>Source code</title>
+<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">
+</head>
+<body>
+<div class="sourceContainer">
+<pre><span class="sourceLineNo">001</span>package org.apache.fulcrum.xslt;<a name="line.1"></a>
+<span class="sourceLineNo">002</span><a name="line.2"></a>
+<span class="sourceLineNo">003</span>/*<a name="line.3"></a>
+<span class="sourceLineNo">004</span> * Licensed to the Apache Software Foundation (ASF) under one<a name="line.4"></a>
+<span class="sourceLineNo">005</span> * or more contributor license agreements.  See the NOTICE file<a name="line.5"></a>
+<span class="sourceLineNo">006</span> * distributed with this work for additional information<a name="line.6"></a>
+<span class="sourceLineNo">007</span> * regarding copyright ownership.  The ASF licenses this file<a name="line.7"></a>
+<span class="sourceLineNo">008</span> * to you under the Apache License, Version 2.0 (the<a name="line.8"></a>
+<span class="sourceLineNo">009</span> * "License"); you may not use this file except in compliance<a name="line.9"></a>
+<span class="sourceLineNo">010</span> * with the License.  You may obtain a copy of the License at<a name="line.10"></a>
+<span class="sourceLineNo">011</span> *<a name="line.11"></a>
+<span class="sourceLineNo">012</span> *   http://www.apache.org/licenses/LICENSE-2.0<a name="line.12"></a>
+<span class="sourceLineNo">013</span> *<a name="line.13"></a>
+<span class="sourceLineNo">014</span> * Unless required by applicable law or agreed to in writing,<a name="line.14"></a>
+<span class="sourceLineNo">015</span> * software distributed under the License is distributed on an<a name="line.15"></a>
+<span class="sourceLineNo">016</span> * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY<a name="line.16"></a>
+<span class="sourceLineNo">017</span> * KIND, either express or implied.  See the License for the<a name="line.17"></a>
+<span class="sourceLineNo">018</span> * specific language governing permissions and limitations<a name="line.18"></a>
+<span class="sourceLineNo">019</span> * under the License.<a name="line.19"></a>
+<span class="sourceLineNo">020</span> */<a name="line.20"></a>
+<span class="sourceLineNo">021</span><a name="line.21"></a>
+<span class="sourceLineNo">022</span>import java.io.Reader;<a name="line.22"></a>
+<span class="sourceLineNo">023</span>import java.io.StringWriter;<a name="line.23"></a>
+<span class="sourceLineNo">024</span>import java.io.Writer;<a name="line.24"></a>
+<span class="sourceLineNo">025</span>import java.net.MalformedURLException;<a name="line.25"></a>
+<span class="sourceLineNo">026</span>import java.net.URL;<a name="line.26"></a>
+<span class="sourceLineNo">027</span>import java.util.Hashtable;<a name="line.27"></a>
+<span class="sourceLineNo">028</span>import java.util.Map;<a name="line.28"></a>
+<span class="sourceLineNo">029</span>import java.util.Map.Entry;<a name="line.29"></a>
+<span class="sourceLineNo">030</span><a name="line.30"></a>
+<span class="sourceLineNo">031</span>import javax.xml.parsers.DocumentBuilder;<a name="line.31"></a>
+<span class="sourceLineNo">032</span>import javax.xml.parsers.DocumentBuilderFactory;<a name="line.32"></a>
+<span class="sourceLineNo">033</span>import javax.xml.transform.Result;<a name="line.33"></a>
+<span class="sourceLineNo">034</span>import javax.xml.transform.Source;<a name="line.34"></a>
+<span class="sourceLineNo">035</span>import javax.xml.transform.Templates;<a name="line.35"></a>
+<span class="sourceLineNo">036</span>import javax.xml.transform.Transformer;<a name="line.36"></a>
+<span class="sourceLineNo">037</span>import javax.xml.transform.TransformerFactory;<a name="line.37"></a>
+<span class="sourceLineNo">038</span>import javax.xml.transform.dom.DOMSource;<a name="line.38"></a>
+<span class="sourceLineNo">039</span>import javax.xml.transform.stream.StreamResult;<a name="line.39"></a>
+<span class="sourceLineNo">040</span>import javax.xml.transform.stream.StreamSource;<a name="line.40"></a>
+<span class="sourceLineNo">041</span><a name="line.41"></a>
+<span class="sourceLineNo">042</span>import org.apache.avalon.framework.activity.Initializable;<a name="line.42"></a>
+<span class="sourceLineNo">043</span>import org.apache.avalon.framework.configuration.Configurable;<a name="line.43"></a>
+<span class="sourceLineNo">044</span>import org.apache.avalon.framework.configuration.Configuration;<a name="line.44"></a>
+<span class="sourceLineNo">045</span>import org.apache.avalon.framework.configuration.ConfigurationException;<a name="line.45"></a>
+<span class="sourceLineNo">046</span>import org.apache.avalon.framework.context.Context;<a name="line.46"></a>
+<span class="sourceLineNo">047</span>import org.apache.avalon.framework.context.ContextException;<a name="line.47"></a>
+<span class="sourceLineNo">048</span>import org.apache.avalon.framework.context.Contextualizable;<a name="line.48"></a>
+<span class="sourceLineNo">049</span>import org.apache.avalon.framework.logger.AbstractLogEnabled;<a name="line.49"></a>
+<span class="sourceLineNo">050</span>import org.apache.avalon.framework.service.ServiceManager;<a name="line.50"></a>
+<span class="sourceLineNo">051</span>import org.apache.avalon.framework.service.Serviceable;<a name="line.51"></a>
+<span class="sourceLineNo">052</span>import org.w3c.dom.Document;<a name="line.52"></a>
+<span class="sourceLineNo">053</span>import org.w3c.dom.Node;<a name="line.53"></a>
+<span class="sourceLineNo">054</span><a name="line.54"></a>
+<span class="sourceLineNo">055</span>/**<a name="line.55"></a>
+<span class="sourceLineNo">056</span> * Implementation of the Turbine XSLT Service. It transforms xml with a given<a name="line.56"></a>
+<span class="sourceLineNo">057</span> * xsl file. XSL stylesheets are compiled and cached (if the service property is<a name="line.57"></a>
+<span class="sourceLineNo">058</span> * set) to improve speeds.<a name="line.58"></a>
+<span class="sourceLineNo">059</span> *<a name="line.59"></a>
+<span class="sourceLineNo">060</span> * @author &lt;a href="mailto:leon@opticode.co.za"&gt;Leon Messerschmidt&lt;/a&gt;<a name="line.60"></a>
+<span class="sourceLineNo">061</span> * @author &lt;a href="mailto:rubys@us.ibm.com"&gt;Sam Ruby&lt;/a&gt;<a name="line.61"></a>
+<span class="sourceLineNo">062</span> * @author &lt;a href="mailto:epugh@opensourceconnections.com"&gt;Eric Pugh&lt;/a&gt;<a name="line.62"></a>
+<span class="sourceLineNo">063</span> * @author &lt;a href="mailto:tv@apache.org"&gt;Thomas Vandahl&lt;/a&gt;<a name="line.63"></a>
+<span class="sourceLineNo">064</span> */<a name="line.64"></a>
+<span class="sourceLineNo">065</span>public class DefaultXSLTService extends AbstractLogEnabled implements<a name="line.65"></a>
+<span class="sourceLineNo">066</span>        XSLTService, Initializable, Configurable, Contextualizable, Serviceable<a name="line.66"></a>
+<span class="sourceLineNo">067</span>{<a name="line.67"></a>
+<span class="sourceLineNo">068</span>    /**<a name="line.68"></a>
+<span class="sourceLineNo">069</span>     * The application root<a name="line.69"></a>
+<span class="sourceLineNo">070</span>     */<a name="line.70"></a>
+<span class="sourceLineNo">071</span>    private String applicationRoot;<a name="line.71"></a>
+<span class="sourceLineNo">072</span><a name="line.72"></a>
+<span class="sourceLineNo">073</span>    /**<a name="line.73"></a>
+<span class="sourceLineNo">074</span>     * Property to control the caching of Templates.<a name="line.74"></a>
+<span class="sourceLineNo">075</span>     */<a name="line.75"></a>
+<span class="sourceLineNo">076</span>    protected boolean caching = false;<a name="line.76"></a>
+<span class="sourceLineNo">077</span><a name="line.77"></a>
+<span class="sourceLineNo">078</span>    /**<a name="line.78"></a>
+<span class="sourceLineNo">079</span>     * Path to style sheets used for transforming well-formed XML documents. The<a name="line.79"></a>
+<span class="sourceLineNo">080</span>     * path is relative to the webapp context.<a name="line.80"></a>
+<span class="sourceLineNo">081</span>     */<a name="line.81"></a>
+<span class="sourceLineNo">082</span>    protected String path;<a name="line.82"></a>
+<span class="sourceLineNo">083</span><a name="line.83"></a>
+<span class="sourceLineNo">084</span>    /**<a name="line.84"></a>
+<span class="sourceLineNo">085</span>     * Cache of compiled Templates.<a name="line.85"></a>
+<span class="sourceLineNo">086</span>     */<a name="line.86"></a>
+<span class="sourceLineNo">087</span>    protected Hashtable&lt;URL, Templates&gt; cache = new Hashtable&lt;URL, Templates&gt;();<a name="line.87"></a>
+<span class="sourceLineNo">088</span><a name="line.88"></a>
+<span class="sourceLineNo">089</span>    protected final static String STYLESHEET_PATH = "path";<a name="line.89"></a>
+<span class="sourceLineNo">090</span><a name="line.90"></a>
+<span class="sourceLineNo">091</span>    protected final static String STYLESHEET_CACHING = "cache";<a name="line.91"></a>
+<span class="sourceLineNo">092</span><a name="line.92"></a>
+<span class="sourceLineNo">093</span>    /**<a name="line.93"></a>
+<span class="sourceLineNo">094</span>     * Factory for producing templates and null transformers<a name="line.94"></a>
+<span class="sourceLineNo">095</span>     */<a name="line.95"></a>
+<span class="sourceLineNo">096</span>    private static TransformerFactory tfactory;<a name="line.96"></a>
+<span class="sourceLineNo">097</span><a name="line.97"></a>
+<span class="sourceLineNo">098</span>    /**<a name="line.98"></a>
+<span class="sourceLineNo">099</span>     * Try to create a valid url object from the style parameter.<a name="line.99"></a>
+<span class="sourceLineNo">100</span>     *<a name="line.100"></a>
+<span class="sourceLineNo">101</span>     * @param style<a name="line.101"></a>
+<span class="sourceLineNo">102</span>     *            the xsl-Style<a name="line.102"></a>
+<span class="sourceLineNo">103</span>     * @return a &lt;code&gt;URL&lt;/code&gt; object or null if the style sheet could not<a name="line.103"></a>
+<span class="sourceLineNo">104</span>     *         be found<a name="line.104"></a>
+<span class="sourceLineNo">105</span>     */<a name="line.105"></a>
+<span class="sourceLineNo">106</span>    private URL getStyleURL(String style)<a name="line.106"></a>
+<span class="sourceLineNo">107</span>    {<a name="line.107"></a>
+<span class="sourceLineNo">108</span>        StringBuilder sb = new StringBuilder();<a name="line.108"></a>
+<span class="sourceLineNo">109</span><a name="line.109"></a>
+<span class="sourceLineNo">110</span>        sb.append(path);<a name="line.110"></a>
+<span class="sourceLineNo">111</span><a name="line.111"></a>
+<span class="sourceLineNo">112</span>        // we chop off the existing extension<a name="line.112"></a>
+<span class="sourceLineNo">113</span>        int colon = style.lastIndexOf(".");<a name="line.113"></a>
+<span class="sourceLineNo">114</span><a name="line.114"></a>
+<span class="sourceLineNo">115</span>        if (colon &gt; 0)<a name="line.115"></a>
+<span class="sourceLineNo">116</span>        {<a name="line.116"></a>
+<span class="sourceLineNo">117</span>            sb.append(style.substring(0, colon));<a name="line.117"></a>
+<span class="sourceLineNo">118</span>        }<a name="line.118"></a>
+<span class="sourceLineNo">119</span>        else<a name="line.119"></a>
+<span class="sourceLineNo">120</span>        {<a name="line.120"></a>
+<span class="sourceLineNo">121</span>            sb.append(style);<a name="line.121"></a>
+<span class="sourceLineNo">122</span>        }<a name="line.122"></a>
+<span class="sourceLineNo">123</span><a name="line.123"></a>
+<span class="sourceLineNo">124</span>        sb.append(".xslt");<a name="line.124"></a>
+<span class="sourceLineNo">125</span><a name="line.125"></a>
+<span class="sourceLineNo">126</span>        URL url = null;<a name="line.126"></a>
+<span class="sourceLineNo">127</span><a name="line.127"></a>
+<span class="sourceLineNo">128</span>        try<a name="line.128"></a>
+<span class="sourceLineNo">129</span>        {<a name="line.129"></a>
+<span class="sourceLineNo">130</span>            url = new URL(sb.toString());<a name="line.130"></a>
+<span class="sourceLineNo">131</span>        }<a name="line.131"></a>
+<span class="sourceLineNo">132</span>        catch (MalformedURLException e)<a name="line.132"></a>
+<span class="sourceLineNo">133</span>        {<a name="line.133"></a>
+<span class="sourceLineNo">134</span>            getLogger().error("Malformed URL: " + sb, e);<a name="line.134"></a>
+<span class="sourceLineNo">135</span>        }<a name="line.135"></a>
+<span class="sourceLineNo">136</span><a name="line.136"></a>
+<span class="sourceLineNo">137</span>        return url;<a name="line.137"></a>
+<span class="sourceLineNo">138</span>    }<a name="line.138"></a>
+<span class="sourceLineNo">139</span><a name="line.139"></a>
+<span class="sourceLineNo">140</span>    /**<a name="line.140"></a>
+<span class="sourceLineNo">141</span>     * Compile Templates from an input file.<a name="line.141"></a>
+<span class="sourceLineNo">142</span>     *<a name="line.142"></a>
+<span class="sourceLineNo">143</span>     * @param source the source URL<a name="line.143"></a>
+<span class="sourceLineNo">144</span>     * @return the compiled template<a name="line.144"></a>
+<span class="sourceLineNo">145</span>     * @throws Exception the compilation failed<a name="line.145"></a>
+<span class="sourceLineNo">146</span>     */<a name="line.146"></a>
+<span class="sourceLineNo">147</span>    protected Templates compileTemplates(URL source) throws Exception<a name="line.147"></a>
+<span class="sourceLineNo">148</span>    {<a name="line.148"></a>
+<span class="sourceLineNo">149</span>        StreamSource xslin = new StreamSource(source.openStream());<a name="line.149"></a>
+<span class="sourceLineNo">150</span>        return tfactory.newTemplates(xslin);<a name="line.150"></a>
+<span class="sourceLineNo">151</span>    }<a name="line.151"></a>
+<span class="sourceLineNo">152</span><a name="line.152"></a>
+<span class="sourceLineNo">153</span>    /**<a name="line.153"></a>
+<span class="sourceLineNo">154</span>     * Retrieves Templates. If caching is switched on the first attempt is to<a name="line.154"></a>
+<span class="sourceLineNo">155</span>     * load Templates from the cache. If caching is switched of or if the<a name="line.155"></a>
+<span class="sourceLineNo">156</span>     * Stylesheet is not found in the cache new Templates are compiled from an<a name="line.156"></a>
+<span class="sourceLineNo">157</span>     * input file.<a name="line.157"></a>
+<span class="sourceLineNo">158</span>     * &lt;p&gt;<a name="line.158"></a>
+<span class="sourceLineNo">159</span>     * This method is synchronized on the xsl cache so that a thread does not<a name="line.159"></a>
+<span class="sourceLineNo">160</span>     * attempt to load Templates from the cache while it is still being<a name="line.160"></a>
+<span class="sourceLineNo">161</span>     * compiled.<a name="line.161"></a>
+<span class="sourceLineNo">162</span>     *<a name="line.162"></a>
+<span class="sourceLineNo">163</span>     * @param xslName the name of the XSL file<a name="line.163"></a>
+<span class="sourceLineNo">164</span>     * @return the correspondint template or null if the XSL was not found<a name="line.164"></a>
+<span class="sourceLineNo">165</span>     * @throws Exception getting the template failed<a name="line.165"></a>
+<span class="sourceLineNo">166</span>     */<a name="line.166"></a>
+<span class="sourceLineNo">167</span>    protected Templates getTemplates(String xslName) throws Exception<a name="line.167"></a>
+<span class="sourceLineNo">168</span>    {<a name="line.168"></a>
+<span class="sourceLineNo">169</span>        synchronized (cache)<a name="line.169"></a>
+<span class="sourceLineNo">170</span>        {<a name="line.170"></a>
+<span class="sourceLineNo">171</span>            URL fn = getStyleURL(xslName);<a name="line.171"></a>
+<span class="sourceLineNo">172</span>            if (fn == null)<a name="line.172"></a>
+<span class="sourceLineNo">173</span>                return null;<a name="line.173"></a>
+<span class="sourceLineNo">174</span><a name="line.174"></a>
+<span class="sourceLineNo">175</span>            if (caching &amp;&amp; cache.containsKey(fn))<a name="line.175"></a>
+<span class="sourceLineNo">176</span>            {<a name="line.176"></a>
+<span class="sourceLineNo">177</span>                return (Templates) cache.get(fn);<a name="line.177"></a>
+<span class="sourceLineNo">178</span>            }<a name="line.178"></a>
+<span class="sourceLineNo">179</span><a name="line.179"></a>
+<span class="sourceLineNo">180</span>            Templates sr = compileTemplates(fn);<a name="line.180"></a>
+<span class="sourceLineNo">181</span><a name="line.181"></a>
+<span class="sourceLineNo">182</span>            if (caching)<a name="line.182"></a>
+<span class="sourceLineNo">183</span>            {<a name="line.183"></a>
+<span class="sourceLineNo">184</span>                cache.put(fn, sr);<a name="line.184"></a>
+<span class="sourceLineNo">185</span>            }<a name="line.185"></a>
+<span class="sourceLineNo">186</span><a name="line.186"></a>
+<span class="sourceLineNo">187</span>            return sr;<a name="line.187"></a>
+<span class="sourceLineNo">188</span>        }<a name="line.188"></a>
+<span class="sourceLineNo">189</span>    }<a name="line.189"></a>
+<span class="sourceLineNo">190</span><a name="line.190"></a>
+<span class="sourceLineNo">191</span>    /**<a name="line.191"></a>
+<span class="sourceLineNo">192</span>     * Transform the XML file<a name="line.192"></a>
+<span class="sourceLineNo">193</span>     * <a name="line.193"></a>
+<span class="sourceLineNo">194</span>     * @param xslName the name of the XSL file<a name="line.194"></a>
+<span class="sourceLineNo">195</span>     * @param xmlin source xml<a name="line.195"></a>
+<span class="sourceLineNo">196</span>     * @param xmlout resulting xml<a name="line.196"></a>
+<span class="sourceLineNo">197</span>     * @param params A set of parameters that will be forwarded to the XSLT<a name="line.197"></a>
+<span class="sourceLineNo">198</span>     * @throws Exception if the transform fails<a name="line.198"></a>
+<span class="sourceLineNo">199</span>     */<a name="line.199"></a>
+<span class="sourceLineNo">200</span>    protected void transform(String xslName, Source xmlin, Result xmlout, Map&lt;?, ?&gt; params)<a name="line.200"></a>
+<span class="sourceLineNo">201</span>            throws Exception<a name="line.201"></a>
+<span class="sourceLineNo">202</span>    {<a name="line.202"></a>
+<span class="sourceLineNo">203</span>        try<a name="line.203"></a>
+<span class="sourceLineNo">204</span>        {<a name="line.204"></a>
+<span class="sourceLineNo">205</span>            long startTime = System.currentTimeMillis();<a name="line.205"></a>
+<span class="sourceLineNo">206</span>            Transformer transformer = getTransformer(xslName);<a name="line.206"></a>
+<span class="sourceLineNo">207</span><a name="line.207"></a>
+<span class="sourceLineNo">208</span>            if (params != null)<a name="line.208"></a>
+<span class="sourceLineNo">209</span>            {<a name="line.209"></a>
+<span class="sourceLineNo">210</span>                for ( Entry&lt;?, ?&gt; entry : params.entrySet() )<a name="line.210"></a>
+<span class="sourceLineNo">211</span>                {<a name="line.211"></a>
+<span class="sourceLineNo">212</span>                    transformer.setParameter(String.valueOf(entry.getKey()), entry.getValue());<a name="line.212"></a>
+<span class="sourceLineNo">213</span>                }<a name="line.213"></a>
+<span class="sourceLineNo">214</span>            }<a name="line.214"></a>
+<span class="sourceLineNo">215</span><a name="line.215"></a>
+<span class="sourceLineNo">216</span>            transformer.transform(xmlin, xmlout);<a name="line.216"></a>
+<span class="sourceLineNo">217</span><a name="line.217"></a>
+<span class="sourceLineNo">218</span>            if(getLogger().isDebugEnabled())<a name="line.218"></a>
+<span class="sourceLineNo">219</span>            {<a name="line.219"></a>
+<span class="sourceLineNo">220</span>                long duration = System.currentTimeMillis() - startTime;<a name="line.220"></a>
+<span class="sourceLineNo">221</span>                getLogger().debug("The transforamtion '" + xslName + "' took " + duration + " ms");<a name="line.221"></a>
+<span class="sourceLineNo">222</span>            }<a name="line.222"></a>
+<span class="sourceLineNo">223</span>        }<a name="line.223"></a>
+<span class="sourceLineNo">224</span>        catch(Exception e)<a name="line.224"></a>
+<span class="sourceLineNo">225</span>        {<a name="line.225"></a>
+<span class="sourceLineNo">226</span>            getLogger().debug("The transformation '" + xslName + "' failed due to : " + e.getMessage());<a name="line.226"></a>
+<span class="sourceLineNo">227</span>            throw e;<a name="line.227"></a>
+<span class="sourceLineNo">228</span>        }<a name="line.228"></a>
+<span class="sourceLineNo">229</span>    }<a name="line.229"></a>
+<span class="sourceLineNo">230</span><a name="line.230"></a>
+<span class="sourceLineNo">231</span>    /**<a name="line.231"></a>
+<span class="sourceLineNo">232</span>     * Uses an xsl file to transform xml input from a reader and writes the<a name="line.232"></a>
+<span class="sourceLineNo">233</span>     * output to a writer.<a name="line.233"></a>
+<span class="sourceLineNo">234</span>     *<a name="line.234"></a>
+<span class="sourceLineNo">235</span>     * @param xslName<a name="line.235"></a>
+<span class="sourceLineNo">236</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.236"></a>
+<span class="sourceLineNo">237</span>     * @param in<a name="line.237"></a>
+<span class="sourceLineNo">238</span>     *            The reader that passes the xml to be transformed<a name="line.238"></a>
+<span class="sourceLineNo">239</span>     * @param out<a name="line.239"></a>
+<span class="sourceLineNo">240</span>     *            The writer for the transformed output<a name="line.240"></a>
+<span class="sourceLineNo">241</span>     *            <a name="line.241"></a>
+<span class="sourceLineNo">242</span>     * @throws Exception if the transform fails            <a name="line.242"></a>
+<span class="sourceLineNo">243</span>     */<a name="line.243"></a>
+<span class="sourceLineNo">244</span>    public void transform(String xslName, Reader in, Writer out)<a name="line.244"></a>
+<span class="sourceLineNo">245</span>            throws Exception<a name="line.245"></a>
+<span class="sourceLineNo">246</span>    {<a name="line.246"></a>
+<span class="sourceLineNo">247</span>        Source xmlin = new StreamSource(in);<a name="line.247"></a>
+<span class="sourceLineNo">248</span>        Result xmlout = new StreamResult(out);<a name="line.248"></a>
+<span class="sourceLineNo">249</span>        transform(xslName, xmlin, xmlout, null);<a name="line.249"></a>
+<span class="sourceLineNo">250</span>    }<a name="line.250"></a>
+<span class="sourceLineNo">251</span><a name="line.251"></a>
+<span class="sourceLineNo">252</span>    /**<a name="line.252"></a>
+<span class="sourceLineNo">253</span>     * Uses an xsl file to transform xml input from a reader and returns a<a name="line.253"></a>
+<span class="sourceLineNo">254</span>     * string containing the transformed output.<a name="line.254"></a>
+<span class="sourceLineNo">255</span>     *<a name="line.255"></a>
+<span class="sourceLineNo">256</span>     * @param xslName<a name="line.256"></a>
+<span class="sourceLineNo">257</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.257"></a>
+<span class="sourceLineNo">258</span>     * @param in<a name="line.258"></a>
+<span class="sourceLineNo">259</span>     *            The reader that passes the xml to be transformed<a name="line.259"></a>
+<span class="sourceLineNo">260</span>     *            <a name="line.260"></a>
+<span class="sourceLineNo">261</span>     * @throws Exception if the transform fails            <a name="line.261"></a>
+<span class="sourceLineNo">262</span>     */<a name="line.262"></a>
+<span class="sourceLineNo">263</span>    public String transform(String xslName, Reader in) throws Exception<a name="line.263"></a>
+<span class="sourceLineNo">264</span>    {<a name="line.264"></a>
+<span class="sourceLineNo">265</span>        StringWriter sw = new StringWriter();<a name="line.265"></a>
+<span class="sourceLineNo">266</span>        transform(xslName, in, sw, null);<a name="line.266"></a>
+<span class="sourceLineNo">267</span>        return sw.toString();<a name="line.267"></a>
+<span class="sourceLineNo">268</span>    }<a name="line.268"></a>
+<span class="sourceLineNo">269</span><a name="line.269"></a>
+<span class="sourceLineNo">270</span>    /**<a name="line.270"></a>
+<span class="sourceLineNo">271</span>     * Uses an xsl file to transform xml input from a DOM note and writes the<a name="line.271"></a>
+<span class="sourceLineNo">272</span>     * output to a writer.<a name="line.272"></a>
+<span class="sourceLineNo">273</span>     *<a name="line.273"></a>
+<span class="sourceLineNo">274</span>     * @see org.apache.fulcrum.xslt.XSLTService#transform(java.lang.String, org.w3c.dom.Node, java.io.Writer)<a name="line.274"></a>
+<span class="sourceLineNo">275</span>     *<a name="line.275"></a>
+<span class="sourceLineNo">276</span>     * @param xslName<a name="line.276"></a>
+<span class="sourceLineNo">277</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.277"></a>
+<span class="sourceLineNo">278</span>     * @param in<a name="line.278"></a>
+<span class="sourceLineNo">279</span>     *            The DOM Node to be transformed<a name="line.279"></a>
+<span class="sourceLineNo">280</span>     * @param out<a name="line.280"></a>
+<span class="sourceLineNo">281</span>     *            The writer for the transformed output<a name="line.281"></a>
+<span class="sourceLineNo">282</span>     *            <a name="line.282"></a>
+<span class="sourceLineNo">283</span>     * @throws Exception if the transform fails            <a name="line.283"></a>
+<span class="sourceLineNo">284</span>     */<a name="line.284"></a>
+<span class="sourceLineNo">285</span>    public void transform(String xslName, Node in, Writer out)<a name="line.285"></a>
+<span class="sourceLineNo">286</span>            throws Exception<a name="line.286"></a>
+<span class="sourceLineNo">287</span>    {<a name="line.287"></a>
+<span class="sourceLineNo">288</span>        Source xmlin = new DOMSource(in);<a name="line.288"></a>
+<span class="sourceLineNo">289</span>        Result xmlout = new StreamResult(out);<a name="line.289"></a>
+<span class="sourceLineNo">290</span>        transform(xslName, xmlin, xmlout, null);<a name="line.290"></a>
+<span class="sourceLineNo">291</span>    }<a name="line.291"></a>
+<span class="sourceLineNo">292</span><a name="line.292"></a>
+<span class="sourceLineNo">293</span>    /**<a name="line.293"></a>
+<span class="sourceLineNo">294</span>     * Uses an xsl file to transform xml input from a DOM note and returns a<a name="line.294"></a>
+<span class="sourceLineNo">295</span>     * string containing the transformed output.<a name="line.295"></a>
+<span class="sourceLineNo">296</span>     *<a name="line.296"></a>
+<span class="sourceLineNo">297</span>     * @param xslName<a name="line.297"></a>
+<span class="sourceLineNo">298</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.298"></a>
+<span class="sourceLineNo">299</span>     * @param in<a name="line.299"></a>
+<span class="sourceLineNo">300</span>     *            The DOM Node to be transformed<a name="line.300"></a>
+<span class="sourceLineNo">301</span>     *            <a name="line.301"></a>
+<span class="sourceLineNo">302</span>     * @throws Exception if the transform fails            <a name="line.302"></a>
+<span class="sourceLineNo">303</span>     */<a name="line.303"></a>
+<span class="sourceLineNo">304</span>    public String transform(String xslName, Node in)<a name="line.304"></a>
+<span class="sourceLineNo">305</span>            throws Exception<a name="line.305"></a>
+<span class="sourceLineNo">306</span>    {<a name="line.306"></a>
+<span class="sourceLineNo">307</span>        StringWriter sw = new StringWriter();<a name="line.307"></a>
+<span class="sourceLineNo">308</span>        transform(xslName, in, sw);<a name="line.308"></a>
+<span class="sourceLineNo">309</span>        return sw.toString();<a name="line.309"></a>
+<span class="sourceLineNo">310</span>    }<a name="line.310"></a>
+<span class="sourceLineNo">311</span><a name="line.311"></a>
+<span class="sourceLineNo">312</span>    /**<a name="line.312"></a>
+<span class="sourceLineNo">313</span>     * Uses an xsl file to transform xml input from a reader and writes the<a name="line.313"></a>
+<span class="sourceLineNo">314</span>     * output to a writer.<a name="line.314"></a>
+<span class="sourceLineNo">315</span>     *<a name="line.315"></a>
+<span class="sourceLineNo">316</span>     * @param xslName<a name="line.316"></a>
+<span class="sourceLineNo">317</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.317"></a>
+<span class="sourceLineNo">318</span>     * @param in<a name="line.318"></a>
+<span class="sourceLineNo">319</span>     *            The reader that passes the xml to be transformed<a name="line.319"></a>
+<span class="sourceLineNo">320</span>     * @param out<a name="line.320"></a>
+<span class="sourceLineNo">321</span>     *            The writer for the transformed output<a name="line.321"></a>
+<span class="sourceLineNo">322</span>     * @param params<a name="line.322"></a>
+<span class="sourceLineNo">323</span>     *            A set of parameters that will be forwarded to the XSLT<a name="line.323"></a>
+<span class="sourceLineNo">324</span>     *            <a name="line.324"></a>
+<span class="sourceLineNo">325</span>     * @throws Exception if the transform fails            <a name="line.325"></a>
+<span class="sourceLineNo">326</span>     */<a name="line.326"></a>
+<span class="sourceLineNo">327</span>    public void transform(String xslName, Reader in, Writer out, Map&lt;?, ?&gt; params)<a name="line.327"></a>
+<span class="sourceLineNo">328</span>            throws Exception<a name="line.328"></a>
+<span class="sourceLineNo">329</span>    {<a name="line.329"></a>
+<span class="sourceLineNo">330</span>        Source xmlin = new StreamSource(in);<a name="line.330"></a>
+<span class="sourceLineNo">331</span>        Result xmlout = new StreamResult(out);<a name="line.331"></a>
+<span class="sourceLineNo">332</span>        transform(xslName, xmlin, xmlout, params);<a name="line.332"></a>
+<span class="sourceLineNo">333</span>    }<a name="line.333"></a>
+<span class="sourceLineNo">334</span><a name="line.334"></a>
+<span class="sourceLineNo">335</span>    /**<a name="line.335"></a>
+<span class="sourceLineNo">336</span>     * Uses an xsl file to transform xml input from a reader and returns a<a name="line.336"></a>
+<span class="sourceLineNo">337</span>     * string containing the transformed output.<a name="line.337"></a>
+<span class="sourceLineNo">338</span>     *<a name="line.338"></a>
+<span class="sourceLineNo">339</span>     * @param xslName<a name="line.339"></a>
+<span class="sourceLineNo">340</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.340"></a>
+<span class="sourceLineNo">341</span>     * @param in<a name="line.341"></a>
+<span class="sourceLineNo">342</span>     *            The reader that passes the xml to be transformed<a name="line.342"></a>
+<span class="sourceLineNo">343</span>     * @param params<a name="line.343"></a>
+<span class="sourceLineNo">344</span>     *            A set of parameters that will be forwarded to the XSLT<a name="line.344"></a>
+<span class="sourceLineNo">345</span>     *            <a name="line.345"></a>
+<span class="sourceLineNo">346</span>     * @throws Exception if the transform fails            <a name="line.346"></a>
+<span class="sourceLineNo">347</span>     */<a name="line.347"></a>
+<span class="sourceLineNo">348</span>    public String transform(String xslName, Reader in, Map&lt;?, ?&gt; params)<a name="line.348"></a>
+<span class="sourceLineNo">349</span>            throws Exception<a name="line.349"></a>
+<span class="sourceLineNo">350</span>    {<a name="line.350"></a>
+<span class="sourceLineNo">351</span>        StringWriter sw = new StringWriter();<a name="line.351"></a>
+<span class="sourceLineNo">352</span>        transform(xslName, in, sw, params);<a name="line.352"></a>
+<span class="sourceLineNo">353</span>        return sw.toString();<a name="line.353"></a>
+<span class="sourceLineNo">354</span>    }<a name="line.354"></a>
+<span class="sourceLineNo">355</span><a name="line.355"></a>
+<span class="sourceLineNo">356</span>    /**<a name="line.356"></a>
+<span class="sourceLineNo">357</span>     * Uses an xsl file to transform xml input from a DOM note and writes the<a name="line.357"></a>
+<span class="sourceLineNo">358</span>     * output to a writer.<a name="line.358"></a>
+<span class="sourceLineNo">359</span>     *<a name="line.359"></a>
+<span class="sourceLineNo">360</span>     * @param xslName<a name="line.360"></a>
+<span class="sourceLineNo">361</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.361"></a>
+<span class="sourceLineNo">362</span>     * @param in<a name="line.362"></a>
+<span class="sourceLineNo">363</span>     *            The DOM Node to be transformed<a name="line.363"></a>
+<span class="sourceLineNo">364</span>     * @param out<a name="line.364"></a>
+<span class="sourceLineNo">365</span>     *            The writer for the transformed output<a name="line.365"></a>
+<span class="sourceLineNo">366</span>     * @param params<a name="line.366"></a>
+<span class="sourceLineNo">367</span>     *            A set of parameters that will be forwarded to the XSLT<a name="line.367"></a>
+<span class="sourceLineNo">368</span>     *            <a name="line.368"></a>
+<span class="sourceLineNo">369</span>     * @throws Exception if the transform fails            <a name="line.369"></a>
+<span class="sourceLineNo">370</span>     */<a name="line.370"></a>
+<span class="sourceLineNo">371</span>    public void transform(String xslName, Node in, Writer out, Map&lt;?, ?&gt; params)<a name="line.371"></a>
+<span class="sourceLineNo">372</span>            throws Exception<a name="line.372"></a>
+<span class="sourceLineNo">373</span>    {<a name="line.373"></a>
+<span class="sourceLineNo">374</span>        Source xmlin = new DOMSource(in);<a name="line.374"></a>
+<span class="sourceLineNo">375</span>        Result xmlout = new StreamResult(out);<a name="line.375"></a>
+<span class="sourceLineNo">376</span>        transform(xslName, xmlin, xmlout, params);<a name="line.376"></a>
+<span class="sourceLineNo">377</span>    }<a name="line.377"></a>
+<span class="sourceLineNo">378</span><a name="line.378"></a>
+<span class="sourceLineNo">379</span>    /**<a name="line.379"></a>
+<span class="sourceLineNo">380</span>     * Uses an xsl file to transform xml input from a DOM note and returns a<a name="line.380"></a>
+<span class="sourceLineNo">381</span>     * string containing the transformed output.<a name="line.381"></a>
+<span class="sourceLineNo">382</span>     *<a name="line.382"></a>
+<span class="sourceLineNo">383</span>     * @param xslName<a name="line.383"></a>
+<span class="sourceLineNo">384</span>     *            The name of the file that contains the xsl stylesheet.<a name="line.384"></a>
+<span class="sourceLineNo">385</span>     * @param in<a name="line.385"></a>
+<span class="sourceLineNo">386</span>     *            The DOM Node to be transformed<a name="line.386"></a>
+<span class="sourceLineNo">387</span>     * @param params<a name="line.387"></a>
+<span class="sourceLineNo">388</span>     *            A set of parameters that will be forwarded to the XSLT<a name="line.388"></a>
+<span class="sourceLineNo">389</span>     *            <a name="line.389"></a>
+<span class="sourceLineNo">390</span>     * @throws Exception if the transform fails<a name="line.390"></a>
+<span class="sourceLineNo">391</span>     */<a name="line.391"></a>
+<span class="sourceLineNo">392</span>    public String transform(String xslName, Node in, Map&lt;?, ?&gt; params)<a name="line.392"></a>
+<span class="sourceLineNo">393</span>            throws Exception<a name="line.393"></a>
+<span class="sourceLineNo">394</span>    {<a name="line.394"></a>
+<span class="sourceLineNo">395</span>        StringWriter sw = new StringWriter();<a name="line.395"></a>
+<span class="sourceLineNo">396</span>        transform(xslName, in, sw, params);<a name="line.396"></a>
+<span class="sourceLineNo">397</span>        return sw.toString();<a name="line.397"></a>
+<span class="sourceLineNo">398</span>    }<a name="line.398"></a>
+<span class="sourceLineNo">399</span><a name="line.399"></a>
+<span class="sourceLineNo">400</span>    /**<a name="line.400"></a>
+<span class="sourceLineNo">401</span>     * Uses an xsl file without any input.<a name="line.401"></a>
+<span class="sourceLineNo">402</span>     *<a name="line.402"></a>
+<span class="sourceLineNo">403</span>     * @param xslName The name of the file that contains the xsl stylesheet.<a name="line.403"></a>
+<span class="sourceLineNo">404</span>     * @param params A set of parameters that will be forwarded to the XSLT<a name="line.404"></a>
+<span class="sourceLineNo">405</span>     * @return the transformed output<a name="line.405"></a>
+<span class="sourceLineNo">406</span>     * <a name="line.406"></a>
+<span class="sourceLineNo">407</span>     * @throws Exception if the transform fails<a name="line.407"></a>
+<span class="sourceLineNo">408</span>     */<a name="line.408"></a>
+<span class="sourceLineNo">409</span>    public String transform(String xslName, Map&lt;?, ?&gt; params) throws Exception <a name="line.409"></a>
+<span class="sourceLineNo">410</span>    {<a name="line.410"></a>
+<span class="sourceLineNo">411</span>        StringWriter sw = new StringWriter();<a name="line.411"></a>
+<span class="sourceLineNo">412</span>        transform(xslName, sw, params);<a name="line.412"></a>
+<span class="sourceLineNo">413</span>        return sw.toString();<a name="line.413"></a>
+<span class="sourceLineNo">414</span>    }<a name="line.414"></a>
+<span class="sourceLineNo">415</span><a name="line.415"></a>
+<span class="sourceLineNo">416</span>    /**<a name="line.416"></a>
+<span class="sourceLineNo">417</span>     * Uses an xsl file without any xml input (simplified stylesheet)<a name="line.417"></a>
+<span class="sourceLineNo">418</span>     *<a name="line.418"></a>
+<span class="sourceLineNo">419</span>     * @param xslName The name of the file that contains the xsl stylesheet<a name="line.419"></a>
+<span class="sourceLineNo">420</span>     * @param out The writer for the transformed output.<a name="line.420"></a>
+<span class="sourceLineNo">421</span>     * @param params A set of parameters that will be forwarded to the XSLT<a name="line.421"></a>
+<span class="sourceLineNo">422</span>     * @throws Exception the transformation failed<a name="line.422"></a>
+<span class="sourceLineNo">423</span>     */<a name="line.423"></a>
+<span class="sourceLineNo">424</span>    public void transform(String xslName, Writer out, Map&lt;?, ?&gt; params) throws Exception <a name="line.424"></a>
+<span class="sourceLineNo">425</span>    {<a name="line.425"></a>
+<span class="sourceLineNo">426</span>        DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();<a name="line.426"></a>
+<span class="sourceLineNo">427</span>        DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();<a name="line.427"></a>
+<span class="sourceLineNo">428</span>        Document document = documentBuilder.newDocument();<a name="line.428"></a>
+<span class="sourceLineNo">429</span><a name="line.429"></a>
+<span class="sourceLineNo">430</span>        transform(xslName, document.getDocumentElement(), out, params);<a name="line.430"></a>
+<span class="sourceLineNo">431</span>    }<a name="line.431"></a>
+<span class="sourceLineNo">432</span><a name="line.432"></a>
+<span class="sourceLineNo">433</span>    /**<a name="line.433"></a>
+<span class="sourceLineNo">434</span>     * Retrieve a transformer for the given stylesheet name. If no stylesheet is<a name="line.434"></a>
+<span class="sourceLineNo">435</span>     * available for the provided name, an identity transformer will be<a name="line.435"></a>
+<span class="sourceLineNo">436</span>     * returned. This allows clients of this service to perform more complex<a name="line.436"></a>
+<span class="sourceLineNo">437</span>     * transformations (for example, where parameters must be set). When<a name="line.437"></a>
+<span class="sourceLineNo">438</span>     * possible prefer using one of the forms of {@link #transform}.<a name="line.438"></a>
+<span class="sourceLineNo">439</span>     *<a name="line.439"></a>
+<span class="sourceLineNo">440</span>     * @param xslName<a name="line.440"></a>
+<span class="sourceLineNo">441</span>     *            Identifies stylesheet to get transformer for<a name="line.441"></a>
+<span class="sourceLineNo">442</span>     * @return A transformer for that stylesheet<a name="line.442"></a>
+<span class="sourceLineNo">443</span>     * @throws Exception retrieving the transformer failed<a name="line.443"></a>
+<span class="sourceLineNo">444</span>     */<a name="line.444"></a>
+<span class="sourceLineNo">445</span>    public Transformer getTransformer(String xslName) throws Exception<a name="line.445"></a>
+<span class="sourceLineNo">446</span>    {<a name="line.446"></a>
+<span class="sourceLineNo">447</span>        Templates sr = getTemplates(xslName);<a name="line.447"></a>
+<span class="sourceLineNo">448</span><a name="line.448"></a>
+<span class="sourceLineNo">449</span>        if (sr == null)<a name="line.449"></a>
+<span class="sourceLineNo">450</span>        {<a name="line.450"></a>
+<span class="sourceLineNo">451</span>            return tfactory.newTransformer();<a name="line.451"></a>
+<span class="sourceLineNo">452</span>        }<a name="line.452"></a>
+<span class="sourceLineNo">453</span>        else<a name="line.453"></a>
+<span class="sourceLineNo">454</span>        {<a name="line.454"></a>
+<span class="sourceLineNo">455</span>            return sr.newTransformer();<a name="line.455"></a>
+<span class="sourceLineNo">456</span>        }<a name="line.456"></a>
+<span class="sourceLineNo">457</span>    }<a name="line.457"></a>
+<span class="sourceLineNo">458</span><a name="line.458"></a>
+<span class="sourceLineNo">459</span>    // ---------------- Avalon Lifecycle Methods ---------------------<a name="line.459"></a>
+<span class="sourceLineNo">460</span>    /**<a name="line.460"></a>
+<span class="sourceLineNo">461</span>     * Avalon component lifecycle method<a name="line.461"></a>
+<span class="sourceLineNo">462</span>     *<a name="line.462"></a>
+<span class="sourceLineNo">463</span>     * This method processes the repository path, to make it relative to the web<a name="line.463"></a>
+<span class="sourceLineNo">464</span>     * application root, if neccessary. It supports URL-style repositories.<a name="line.464"></a>
+<span class="sourceLineNo">465</span>     */<a name="line.465"></a>
+<span class="sourceLineNo">466</span>    public void configure(Configuration conf) throws ConfigurationException<a name="line.466"></a>
+<span class="sourceLineNo">467</span>    {<a name="line.467"></a>
+<span class="sourceLineNo">468</span>        StringBuilder sb = new StringBuilder(conf.getAttribute(STYLESHEET_PATH, "/"));<a name="line.468"></a>
+<span class="sourceLineNo">469</span><a name="line.469"></a>
+<span class="sourceLineNo">470</span>        // is URL?<a name="line.470"></a>
+<span class="sourceLineNo">471</span>        if (!sb.toString().matches("[a-zA-Z]{3,}://.*"))<a name="line.471"></a>
+<span class="sourceLineNo">472</span>        {<a name="line.472"></a>
+<span class="sourceLineNo">473</span>            // No<a name="line.473"></a>
+<span class="sourceLineNo">474</span>            if (sb.charAt(0) != '/')<a name="line.474"></a>
+<span class="sourceLineNo">475</span>            {<a name="line.475"></a>
+<span class="sourceLineNo">476</span>                sb.insert(0, '/');<a name="line.476"></a>
+<span class="sourceLineNo">477</span>            }<a name="line.477"></a>
+<span class="sourceLineNo">478</span>            sb.insert(0, applicationRoot);<a name="line.478"></a>
+<span class="sourceLineNo">479</span>            sb.insert(0, "file:");<a name="line.479"></a>
+<span class="sourceLineNo">480</span>        }<a name="line.480"></a>
+<span class="sourceLineNo">481</span><a name="line.481"></a>
+<span class="sourceLineNo">482</span>        if (sb.charAt(sb.length() - 1) != '/')<a name="line.482"></a>

[... 48 lines stripped ...]