1 18 package org.apache.tools.ant.taskdefs; 19 20 import java.io.File ; 21 import java.io.OutputStream ; 22 import java.io.FileOutputStream ; 23 24 import org.apache.tools.ant.Project; 25 import org.apache.tools.ant.BuildException; 26 import org.apache.tools.ant.util.XMLFragment; 27 import org.apache.tools.ant.util.DOMElementWriter; 28 import org.apache.tools.ant.util.FileUtils; 29 30 import org.w3c.dom.Node ; 31 import org.w3c.dom.Element ; 32 33 45 public class EchoXML extends XMLFragment { 46 47 private File file; 48 private boolean append; 49 private static final String ERROR_NO_XML = "No nested XML specified"; 50 51 55 public void setFile(File f) { 56 file = f; 57 } 58 59 63 public void setAppend(boolean b) { 64 append = b; 65 } 66 67 70 public void execute() { 71 DOMElementWriter writer = new DOMElementWriter(!append); 72 OutputStream os = null; 73 try { 74 if (file != null) { 75 os = new FileOutputStream (file.getAbsolutePath(), append); 76 } else { 77 os = new LogOutputStream(this, Project.MSG_INFO); 78 } 79 Node n = getFragment().getFirstChild(); 80 if (n == null) { 81 throw new BuildException(ERROR_NO_XML); 82 } 83 writer.write((Element ) n, os); 84 } catch (BuildException e) { 85 throw e; 86 } catch (Exception e) { 87 throw new BuildException(e); 88 } finally { 89 FileUtils.close(os); 90 } 91 } 92 93 } 94 | Popular Tags |