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 Style 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 done(context, 1);
45          }
46  
47          try {
48              // FIXME URI reference to style should be possible!
49              Source templatesSource = styleRef.startsWith("$") ? context
50                      .refToSource(styleRef) : new StreamSource(context
51                      .getFile(styleRef));
52  
53              templates = context.getTransformerFactory().newTemplates(
54                      templatesSource);
55  
56              context.put(var, templates);
57  
58              return done(context, 0);
59          } catch (TransformerException te) {
60              return done(context, 1);
61          }
62      }
63  
64      /***
65       * DOCUMENT ME!
66       * 
67       * @return DOCUMENT ME!
68       */
69      public String toString() {
70          return "STYLE " + var + " <- " + styleRef;
71      }
72  }
73  
74  /*
75   * The contents of this file are subject to the Mozilla Public License Version
76   * 1.1 (the "License"); you may not use this file except in compliance with the
77   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
78   * Software distributed under the License is distributed on an "AS IS" basis,
79   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
80   * the specific language governing rights and limitations under the License. The
81   * Original Code is: all this file. The Initial Developer of the Original Code
82   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
83   */