View Javadoc

1   package net.sf.tomp.xtcl.command;
2   
3   import net.sf.tomp.xtcl.Context;
4   import net.sf.tomp.xtcl.filter.XTFilter;
5   import net.sf.tomp.xtcl.filter.XTFilterFactory;
6   
7   import org.xml.sax.XMLFilter;
8   
9   import javax.xml.transform.Templates;
10  import javax.xml.transform.TransformerFactory;
11  import javax.xml.transform.stream.StreamSource;
12  
13  import java.io.PrintStream;
14  
15  /***
16   * DOCUMENT ME!
17   * 
18   * @author tomp
19   */
20  public class JoostFilterCommand extends FilterCommand {
21      /*** DOCUMENT ME! */
22      protected String styleRef;
23  
24      //    protected Templates templates;
25      public void setStyleRef(String s) {
26          styleRef = s;
27      }
28  
29      /***
30       * DOCUMENT ME!
31       * 
32       * @param context DOCUMENT ME!
33       * @return DOCUMENT ME!
34       * @throws Exception DOCUMENT ME!
35       */
36      public int execute(Context context) throws Exception {
37          PrintStream out = context.getOut();
38          XTFilterFactory factory = context.getXTFilterFactory();
39          TransformerFactory jtf = context.getJoostTransformerFactory();
40          int retCode = 0;
41  
42          try {
43              Templates templates = styleRef.startsWith("$") ? context
44                      .refToJoostStyle(styleRef) : jtf
45                      .newTemplates(new StreamSource(context.getFile(styleRef)));
46  
47              XMLFilter filter = factory.newJoostFilter(templates);
48  
49              if (filter instanceof XTFilter) {
50                  retCode = initFilter((XTFilter) filter, context);
51  
52                  // FIXME
53                  listMap(realParams);
54              }
55  
56              context.put(var, filter);
57          } catch (Exception e) {
58              e.printStackTrace();
59              retCode = 1;
60          }
61  
62          return done(context, retCode);
63      }
64  
65      /***
66       * DOCUMENT ME!
67       * 
68       * @return DOCUMENT ME!
69       */
70      public String toString() {
71          return "JOOST FILTER " + var + "=" + styleRef + "(" + listMap(params)
72                  + ")";
73      }
74  }
75  
76  /*
77   * The contents of this file are subject to the Mozilla Public License Version
78   * 1.1 (the "License"); you may not use this file except in compliance with the
79   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
80   * Software distributed under the License is distributed on an "AS IS" basis,
81   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
82   * the specific language governing rights and limitations under the License. The
83   * Original Code is: all this file. The Initial Developer of the Original Code
84   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
85   */