Browse Source

specify encoding for XmlLogger, handle TEXT Elements properly in

DOMElementWriter.

Submitted by:	Stephane Bailliez <sbailliez@imediation.com>


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@268982 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 24 years ago
parent
commit
e7bcfc18b7
2 changed files with 18 additions and 4 deletions
  1. +6
    -2
      src/main/org/apache/tools/ant/XmlLogger.java
  2. +12
    -2
      src/main/org/apache/tools/ant/util/DOMElementWriter.java

+ 6
- 2
src/main/org/apache/tools/ant/XmlLogger.java View File

@@ -132,8 +132,12 @@ public class XmlLogger implements BuildListener {
if (outFilename == null) {
outFilename = "log.xml";
}

Writer out = new FileWriter(outFilename);
// specify output in UTF8 otherwise accented characters will blow
// up everything
Writer out =
new OutputStreamWriter(new FileOutputStream(outFilename),
"UTF8");
out.write("<?xml:stylesheet type=\"text/xsl\" href=\"log.xsl\"?>\n\n");
(new DOMElementWriter()).write(buildElement, out, 0, "\t");
out.flush();


+ 12
- 2
src/main/org/apache/tools/ant/util/DOMElementWriter.java View File

@@ -67,7 +67,7 @@ import org.w3c.dom.*;
*
* @author The original author of XmlLogger
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a>
* @author <a href="mailto:bailliez@noos.fr">Stephane Bailliez</tt>
* @author <a href="mailto:sbailliez@imediation.com">Stephane Bailliez</tt>
*/
public class DOMElementWriter {

@@ -131,6 +131,9 @@ public class DOMElementWriter {
break;
case Node.TEXT_NODE:
out.write(encode(child.getNodeValue()));
break;
case Node.CDATA_SECTION_NODE:
out.write("<![CDATA[");
out.write(((Text)child).getData());
@@ -170,10 +173,11 @@ public class DOMElementWriter {
out.write(element.getTagName());
out.write(">");
out.write(lSep);
out.flush();
}

/**
* Escape &lt;, &amp; and &quot; as their entities.
* Escape &lt;, &gt; &amp; &apos; and &quot; as their entities.
*/
public String encode(String value) {
sb.setLength(0);
@@ -183,6 +187,12 @@ public class DOMElementWriter {
case '<':
sb.append("&lt;");
break;
case '>':
sb.append("&gt;");
break;
case '\'':
sb.append("&apos;");
break;
case '\"':
sb.append("&quot;");
break;


Loading…
Cancel
Save