You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/03/26 19:44:20 UTC

svn commit: r641472 - /myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/io/XmlWriter.java

Author: skitching
Date: Wed Mar 26 11:44:17 2008
New Revision: 641472

URL: http://svn.apache.org/viewvc?rev=641472&view=rev
Log:
Minor code tidyup, add comments etc. No functional changes.

Modified:
    myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/io/XmlWriter.java

Modified: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/io/XmlWriter.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/io/XmlWriter.java?rev=641472&r1=641471&r2=641472&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/io/XmlWriter.java (original)
+++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/io/XmlWriter.java Wed Mar 26 11:44:17 2008
@@ -21,12 +21,21 @@
 import java.io.PrintWriter;
 import java.util.Stack;
 
+/**
+ * Simple utility to help write out data structures in xml format, with pretty
+ * indenting.
+ */
 public class XmlWriter
 {
-    PrintWriter out;
-    Stack contexts = new Stack();
-    int indent = 0;
-    boolean openElement = false;
+    private static final String XML_CHARS = "<>&";
+
+    private PrintWriter out;
+    private Stack contexts = new Stack();
+    private int indent = 0;
+
+    // Is the current xml element still "open" for adding attributes,
+    // ie needs a ">" before adding nested text or child elements.
+    private boolean openElement = false;
 
     private static class Context
     {
@@ -65,8 +74,6 @@
         indent();
     }
 
-    private static final String XML_CHARS = "<>&";
-
     private boolean containsXmlChars(String text)
     {
         for (int i = 0; i < XML_CHARS.length(); ++i)
@@ -97,11 +104,13 @@
 
         if (containsXmlChars(body))
         {
+            // The text contains chars that need to be escaped. Rather than
+            // escape them one-by-one, just write the body in a CDATA section.
+
             if (body.indexOf("\n") > 0)
             {
                 // multi-line body, so it is most readable when the CDATA
-                // markers
-                // are against the left-hand margin
+                // markers are against the left-hand margin
                 out.write("\n<![CDATA[\n");
                 out.write(body);
                 out.write("\n]]>");