View Javadoc

1   package net.sf.tomp.xtcl.command;
2   
3   import javax.xml.transform.Templates;
4   import javax.xml.transform.TransformerConfigurationException;
5   import javax.xml.transform.TransformerFactory;
6   import javax.xml.transform.stream.StreamSource;
7   
8   import net.sf.tomp.xtcl.Context;
9   import net.sf.tomp.xtcl.filter.XTFilterFactory;
10  
11  import org.xml.sax.XMLFilter;
12  
13  /***
14   * Filter based on XSLT transformation.
15   * 
16   * @author tomp
17   */
18  public class XSLTFilterCommand extends StyleFilterCommand {
19  
20  	/***
21  	 * Gets the necesssary factories and creates the transformation 
22  	 * filter based on the XSLT style.
23  	 * 
24  	 * @see net.sf.tomp.xtcl.command.StyleFilterCommand#makeFilter(net.sf.tomp.xtcl.Context, java.lang.String)
25  	 */
26  	protected XMLFilter makeFilter(Context context, String styleRef)
27  			throws TransformerConfigurationException {
28  
29  		TransformerFactory tf = context.getTransformerFactory();
30  		XTFilterFactory factory = context.getXTFilterFactory();
31  
32  		Templates templates = styleRef.startsWith("$") ? context
33  				.refToStyle(styleRef) : tf.newTemplates(new StreamSource(
34  				context.getFile(styleRef)));
35  
36  		return factory.newTransformerFilter(templates);
37  	}
38  
39  	/***
40  	 * 
41  	 * @return "XSLT FILTER " + super.toString();
42  	 */
43  	public String toString() {
44  		return "XSLT FILTER " + super.toString();
45  	}
46  }
47  
48  /*
49   * The contents of this file are subject to the Mozilla Public License Version
50   * 1.1 (the "License"); you may not use this file except in compliance with the
51   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
52   * Software distributed under the License is distributed on an "AS IS" basis,
53   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
54   * the specific language governing rights and limitations under the License. The
55   * Original Code is: all this file. The Initial Developer of the Original Code
56   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
57   */