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  
11  import java.io.PrintStream;
12  
13  /***
14   * DOCUMENT ME!
15   * 
16   * @author tomp
17   */
18  public class TransformerFilterCommand extends FilterCommand {
19      /*** DOCUMENT ME! */
20      protected String styleRef;
21  
22      //    protected Templates templates;
23      public void setStyleRef(String s) {
24          styleRef = s;
25      }
26  
27      /***
28       * DOCUMENT ME!
29       * 
30       * @param context DOCUMENT ME!
31       * @return DOCUMENT ME!
32       * @throws Exception DOCUMENT ME!
33       */
34      public int execute(Context context) throws Exception {
35          PrintStream out = context.getOut();
36          XTFilterFactory factory = context.getXTFilterFactory();
37          int retCode = 0;
38  
39          try {
40              Templates templates = styleRef.startsWith("$") ? context
41                      .refToStyle(styleRef) : null;
42  
43              XMLFilter filter = factory.newTransformerFilter(templates);
44  
45              if (filter instanceof XTFilter) {
46                  retCode = initFilter((XTFilter) filter, context);
47  
48                  // FIXME
49                  listMap(realParams);
50              }
51  
52              context.put(var, filter);
53          } catch (Exception e) {
54              e.printStackTrace();
55              retCode = 1;
56          }
57  
58          if (out != null) {
59              out.print(((retCode <= 0) ? "OK " : "ERR ") + this);
60          }
61  
62          return retCode;
63      }
64  
65      /***
66       * DOCUMENT ME!
67       * 
68       * @return DOCUMENT ME!
69       */
70      public String toString() {
71          return "TRANSFORMER FILTER " + var + "=" + styleRef + "("
72                  + listMap(params) + ")";
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   */