View Javadoc

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   * The contents of this file are subject to the Mozilla Public License Version
45   * 1.1 (the "License"); you may not use this file except in compliance with the
46   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
47   * Software distributed under the License is distributed on an "AS IS" basis,
48   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
49   * the specific language governing rights and limitations under the License. The
50   * Original Code is: all this file. The Initial Developer of the Original Code
51   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
52   */