View Javadoc

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   * The contents of this file are subject to the Mozilla Public License Version
83   * 1.1 (the "License"); you may not use this file except in compliance with the
84   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
85   * Software distributed under the License is distributed on an "AS IS" basis,
86   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
87   * the specific language governing rights and limitations under the License. The
88   * Original Code is: all this file. The Initial Developer of the Original Code
89   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
90   */