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.Transformer;
7   import javax.xml.transform.TransformerException;
8   import javax.xml.transform.stream.StreamResult;
9   
10  /***
11   * Saves a DOM Document to File.
12   * 
13   * @author tomp
14   */
15  public class Save extends FileCommand {
16  	/***
17  	 * Saves a DOM Document to File.
18  	 * 
19  	 */
20  	public int execute(Context context) throws Exception {
21  		Transformer empty = context.getEmptyTransformer();
22  
23  		try {
24  			Source source = context.refToSource(var);
25  
26  			//System.out.println("source="+source+" var ["+var+"] file="+f);
27  			empty.transform(source,
28  					new StreamResult(getFile(context, fileName)));
29  			
30  			return done(context, 0);
31  
32  		} catch (TransformerException te) {
33  			//te.printStackTrace();
34  			return done(context, 1);
35  		}
36  	}
37  
38  	/***
39  	 * @return "SAVE " + var + " -> " + fileName;
40  	 */
41  	public String toString() {
42  		return "SAVE " + var + " -> " + fileName;
43  	}
44  }
45  
46  /*
47   * The contents of this file are subject to the Mozilla Public License Version
48   * 1.1 (the "License"); you may not use this file except in compliance with the
49   * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
50   * Software distributed under the License is distributed on an "AS IS" basis,
51   * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
52   * the specific language governing rights and limitations under the License. The
53   * Original Code is: all this file. The Initial Developer of the Original Code
54   * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
55   */