Author: stevel
Date: Mon Oct 10 14:17:56 2005
New Revision: 312750
URL: http://svn.apache.org/viewcvs?rev=312750&view=rev
Log:
echoXML does property expansion, does not print the XML header when appending.
There is some defect here wherein some tailing spaces get into every printed
node, so <e>value</e> goes to <e>value </e>
; I havent tracked it down yet.
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
ant/core/trunk/src/main/org/apache/tools/ant/util/XMLFragment.java
Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
URL:
http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java?rev=312750&r1=312749&r2=312750&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/EchoXML.java Mon Oct
10 14:17:56 2005
@@ -34,10 +34,10 @@
*/
public class EchoXML extends XMLFragment {
- private static final DOMElementWriter writer = new DOMElementWriter();
private File file;
private boolean append;
+ public static final String ERROR_NO_XML = "No nested XML specified";
/**
* Set the output file.
@@ -59,6 +59,7 @@
* Execute the task.
*/
public void execute() {
+ DOMElementWriter writer = new DOMElementWriter(!append);
try {
OutputStream os = null;
if (file != null) {
@@ -68,7 +69,7 @@
}
Node n = getFragment().getFirstChild();
if (n == null) {
- throw new BuildException("No nested XML specified");
+ throw new BuildException(ERROR_NO_XML);
}
writer.write((Element) n, os);
} catch (Exception e) {
Modified:
ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
URL:
http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java?rev=312750&r1=312749&r2=312750&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/DOMElementWriter.java Mon
Oct 10 14:17:56 2005
@@ -30,7 +30,7 @@
/**
* Writes a DOM tree to a given Writer.
- *
+ * warning: this utility currently does not declare XML Namespaces.
* <p>Utility class used by [EMAIL PROTECTED] org.apache.tools.ant.XmlLogger
* XmlLogger} and
* org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter
@@ -39,6 +39,26 @@
*/
public class DOMElementWriter {
+ /** xml declaration is on by default */
+ private boolean xmlDeclaration=true;
+
+ /**
+ * Create an element writer.
+ * The ?xml? declaration will be included.
+ */
+ public DOMElementWriter() {
+ }
+
+ /**
+ * Create an element writer
+ * @param xmlDeclaration flag to indicate whether the ?xml? declaration
+ * should be included.
+ * @since Ant1.7
+ */
+ public DOMElementWriter(boolean xmlDeclaration) {
+ this.xmlDeclaration = xmlDeclaration;
+ }
+
private static String lSep = System.getProperty("line.separator");
/**
@@ -50,7 +70,8 @@
/**
* Writes a DOM tree to a stream in UTF8 encoding. Note that
- * it prepends the <?xml version='1.0' encoding='UTF-8'?>.
+ * it prepends the <?xml version='1.0' encoding='UTF-8'?> if
+ * the xmlDeclaration field is true.
* The indent number is set to 0 and a 2-space indent.
* @param root the root element of the DOM tree.
* @param out the outputstream to write to.
@@ -58,7 +79,9 @@
*/
public void write(Element root, OutputStream out) throws IOException {
Writer wri = new OutputStreamWriter(out, "UTF8");
- wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ if(xmlDeclaration) {
+ wri.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
+ }
write(root, wri, 0, " ");
wri.flush();
}
Modified: ant/core/trunk/src/main/org/apache/tools/ant/util/XMLFragment.java
URL:
http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/util/XMLFragment.java?rev=312750&r1=312749&r2=312750&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/util/XMLFragment.java
(original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/util/XMLFragment.java Mon Oct
10 14:17:56 2005
@@ -60,7 +60,7 @@
}
/**
- * Add nested text.
+ * Add nested text, expanding properties as we go
* @param s the text to add
*/
public void addText(String s) {
@@ -80,9 +80,16 @@
return new Child(e);
}
+ /**
+ * Add text to a node.
+ * @param n node
+ * @param s value
+ */
private void addText(Node n, String s) {
+ s = getProject().replaceProperties(s);
+ //only text nodes that are non null after property expansion are added
if (s != null && !s.trim().equals("")) {
- Text t = doc.createTextNode(s);
+ Text t = doc.createTextNode(s.trim());
n.appendChild(t);
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]