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.Transformer;
8   import javax.xml.transform.TransformerException;
9   import javax.xml.transform.stream.StreamResult;
10  
11  import java.io.PrintStream;
12  
13  /***
14   * DOCUMENT ME!
15   * 
16   * @author tomp
17   */
18  public class Dump extends AbstractCommand {
19      /*** DOCUMENT ME! */
20      protected String var;
21  
22      /*** DOCUMENT ME! */
23      protected boolean deep = false;
24  
25      /*** DOCUMENT ME! */
26      protected boolean all = false;
27  
28      /***
29       * DOCUMENT ME!
30       * 
31       * @param v DOCUMENT ME!
32       */
33      public void setVar(String v) {
34          var = v;
35      }
36  
37      /***
38       * DOCUMENT ME!
39       * 
40       * @param v DOCUMENT ME!
41       */
42      public void setDeep(boolean v) {
43          deep = v;
44      }
45  
46      /***
47       * DOCUMENT ME!
48       * 
49       * @param v DOCUMENT ME!
50       */
51      public void setAll(boolean v) {
52          all = v;
53      }
54  
55      /***
56       * DOCUMENT ME!
57       * 
58       * @param context DOCUMENT ME!
59       * @return DOCUMENT ME!
60       * @throws Exception DOCUMENT ME!
61       */
62      public int execute(Context context) throws Exception {
63          PrintStream out = context.getOut();
64  
65          if (out == null || var == null) {
66              return 0;
67          }
68  
69          if (context.get(var) instanceof String) {
70              out.print("[");
71              out.print(context.get(var));
72              out.print("] OK " + this);
73  
74              return 0;
75          } else {
76              Transformer empty = context.getEmptyTransformer();
77  
78              try {
79                  if (context.get(var) instanceof Templates) {
80                      out.print(context.get(var) + " ");
81                  } else {
82                      Source source = context.refToSource(var);
83                      empty.transform(source, new StreamResult(out));
84                  }
85                  return done(context, 0);
86  
87              } catch (TransformerException te) {
88                  return done(context, 1);
89              }
90          }
91      }
92  
93      /***
94       * DOCUMENT ME!
95       * 
96       * @return DOCUMENT ME!
97       */
98      public String toString() {
99          return "DUMP "
100                 + ((var == null) ? ("CONTEXT " + (deep ? "DEEP" : "")) : var);
101     }
102 }
103 
104 /*
105  * The contents of this file are subject to the Mozilla Public License Version
106  * 1.1 (the "License"); you may not use this file except in compliance with the
107  * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
108  * Software distributed under the License is distributed on an "AS IS" basis,
109  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
110  * the specific language governing rights and limitations under the License. The
111  * Original Code is: all this file. The Initial Developer of the Original Code
112  * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
113  */