1 package net.sf.tomp.xtcl.command;
2
3 import net.sf.tomp.xtcl.Context;
4
5 import org.w3c.dom.Document;
6
7 import javax.xml.parsers.DocumentBuilder;
8
9 /***
10 * Creates an empty DOM tree and stores it as variable into the Context.
11 *
12 * @author tomp
13 */
14 public class Doc extends VarCommand {
15 /***
16 * Creates an empty DOM tree and stores it as variable
17 * into the Context.
18 *
19 * @param context
20 *
21 * @return 0 (OK)
22 * @throws Exception if DOM Document could not be created.
23 */
24 public int execute(Context context) throws Exception {
25 DocumentBuilder db = context.getDocumentBuilder();
26 Document doc = db.newDocument();
27
28 context.put(var, doc);
29
30 return done(context, 0);
31 }
32
33 /***
34 * String representation.
35 *
36 * @return "DOCUMENT " + varname
37 */
38 public String toString() {
39 return "DOCUMENT " + var;
40 }
41 }
42
43
44
45
46
47
48
49
50
51
52