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
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
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
87
88
89
90
91
92
93
94