1 package net.sf.tomp.xtcl.command;
2
3 import net.sf.tomp.xtcl.Context;
4
5 import javax.xml.transform.Source;
6 import javax.xml.transform.Templates;
7 import javax.xml.transform.TransformerException;
8 import javax.xml.transform.stream.StreamSource;
9
10 import java.io.PrintStream;
11
12 /***
13 * DOCUMENT ME!
14 *
15 * @author tomp
16 */
17 public class JoostStyle extends VarCommand {
18 /*** DOCUMENT ME! */
19 protected String styleRef;
20
21 /*** DOCUMENT ME! */
22 protected Templates templates;
23
24 /***
25 * DOCUMENT ME!
26 *
27 * @param s DOCUMENT ME!
28 */
29 public void setStyleRef(String s) {
30 styleRef = s;
31 }
32
33 /***
34 * DOCUMENT ME!
35 *
36 * @param context DOCUMENT ME!
37 * @return DOCUMENT ME!
38 * @throws Exception DOCUMENT ME!
39 */
40 public int execute(Context context) throws Exception {
41 PrintStream out = context.getOut();
42
43 if ((styleRef == null) || (styleRef.length() == 0)) {
44 return 1;
45 }
46
47 try {
48 Source templatesSource = styleRef.startsWith("$") ? context
49 .refToSource(styleRef) : new StreamSource(context
50 .getFile(styleRef));
51
52 templates = context.getJoostTransformerFactory().newTemplates(
53 templatesSource);
54
55 context.put(var, templates);
56
57 if (out != null) {
58 out.print("OK " + this);
59 }
60
61 return 0;
62 } catch (TransformerException te) {
63 if (out != null) {
64 out.print("ERR " + this + ": " + te);
65 }
66
67 return 1;
68 }
69 }
70
71 /***
72 * DOCUMENT ME!
73 *
74 * @return DOCUMENT ME!
75 */
76 public String toString() {
77 return "JOOST STYLE " + var + " <- " + styleRef;
78 }
79 }
80
81
82
83
84
85
86
87
88
89
90