View Javadoc

1   package net.sf.tomp.xtcl.command;
2   
3   import javax.xml.transform.TransformerConfigurationException;
4   import net.sf.tomp.xtcl.Context;
5   import net.sf.tomp.xtcl.filter.XTFilter;
6   import org.xml.sax.XMLFilter;
7   
8   /***
9    * Abstract ancestor for all style-based TransformerFilters
10   * 
11   * @author tomp
12   */
13  public abstract class StyleFilterCommand extends FilterCommand {
14  
15  	/*** Reference to a style (XSLT or STX) */
16  	protected String styleRef;
17  
18  	/***
19  	 * set Reference to a style
20  	 * 
21  	 * @param s
22  	 *            Reference to a style
23  	 */
24  	public void setStyleRef(String s) {
25  		styleRef = s;
26  	}
27  
28  	/***
29  	 * Sets the properties from prop. references to parameters,
30  	 * creates the style-based filter,
31  	 * initializes it, puts into Context as variable
32  	 * 
33  	 * @param context
34  	 *            to put the filter in
35  	 * @return 0 if OK
36  	 * @throws Exception
37  	 *         if anything fails
38  	 */
39  	public int execute(Context context) throws Exception {
40  
41  		int retCode = 0;
42  		// transfer props to params
43  		propertiesToParameters(context);
44  
45  		try {
46  			XMLFilter filter = makeFilter(context, styleRef);
47  
48  			if (filter instanceof XTFilter) {
49  				retCode = initFilter((XTFilter) filter, context);
50  
51  				// FIXME
52  				listMap(realParams);
53  			}
54  
55  			context.put(var, filter);
56  		} catch (Exception e) {
57  			e.printStackTrace();
58  			retCode = 1;
59  		}
60  
61  		return done(context, retCode);
62  	}
63  
64  	/***
65  	 * make style-based (XSLT or STX) filter
66  	 * 
67  	 * @param context the Context for getting factories
68  	 * @param styleRef String ref to XSLT or STX style
69  	 * @return the filter
70  	 * @throws TransformerConfigurationException if cannot be created
71  	 */
72  	protected abstract XMLFilter makeFilter(Context context, String styleRef)
73  			throws TransformerConfigurationException;
74  
75  	/***
76  	 * Base for toString() in Joost and XSTL filters
77  	 * 
78  	 */
79  	public String toString() {
80  		return var + "=" + styleRef + "(" + listMap(params)
81  				+ ")";
82  	}
83  }
84  
85  /*
86   * The contents of this file are subject to the Mozilla Public License Version
87   * 1.1 (the "License"); you may not use this file except in compliance with the
88   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
89   * Software distributed under the License is distributed on an "AS IS" basis,
90   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
91   * the specific language governing rights and limitations under the License. The
92   * Original Code is: all this file. The Initial Developer of the Original Code
93   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
94   */