changeset 80:0f2fddf76a78

consistently parse whitespace characters in text 2010-12-13 Omair Majid <omajid@redhat.com> * netx/net/sourceforge/jnlp/Parser.java (getInformationDesc): Fix whitespace in title, vendor and description elements. (getRelatedContent): Fix whitespace in title and description elements. (getSpanText(Node)): Delegate to ... (getSpanText(Node,boolean)): New method. Return the text in an element, optionally fixing whitespace.
author Omair Majid <omajid@redhat.com>
date Mon, 13 Dec 2010 16:12:06 -0500
parents e9150d5accf6
children adef5d4159ee
files ChangeLog netx/net/sourceforge/jnlp/Parser.java
diffstat 2 files changed, 40 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Fri Dec 10 10:07:13 2010 -0500
+++ b/ChangeLog	Mon Dec 13 16:12:06 2010 -0500
@@ -1,3 +1,13 @@
+2010-12-13  Omair Majid  <omajid@redhat.com>
+
+	* netx/net/sourceforge/jnlp/Parser.java
+	(getInformationDesc): Fix whitespace in title, vendor and description
+	elements.
+	(getRelatedContent): Fix whitespace in title and description elements.
+	(getSpanText(Node)): Delegate to ...
+	(getSpanText(Node,boolean)): New method.  Return the text in an element,
+	optionally fixing whitespace.
+
 2010-12-10  Omair Majid  <omajid@redhat.com>
 
 	* netx/net/sourceforge/jnlp/tools/JarSigner.java: Remove unused variables
--- a/netx/net/sourceforge/jnlp/Parser.java	Fri Dec 10 10:07:13 2010 -0500
+++ b/netx/net/sourceforge/jnlp/Parser.java	Mon Dec 13 16:12:06 2010 -0500
@@ -446,9 +446,9 @@
             String name = child.getNodeName();
 
             if ("title".equals(name))
-                addInfo(info, child, null, getSpanText(child));
+                addInfo(info, child, null, getSpanText(child, false));
             if ("vendor".equals(name))
-                addInfo(info, child, null, getSpanText(child));
+                addInfo(info, child, null, getSpanText(child, false));
             if ("description".equals(name)) {
                 String kind = getAttribute(child, "kind", "default");
                 if (descriptionsUsed.contains(kind))
@@ -456,7 +456,7 @@
                         throw new ParseException(R("PTwoDescriptions", kind));
 
                 descriptionsUsed.add(kind);
-                addInfo(info, child, kind, getSpanText(child));
+                addInfo(info, child, kind, getSpanText(child, false));
             }
             if ("homepage".equals(name))
                 addInfo(info, child, null, getRequiredURL(child, "href", base));
@@ -774,12 +774,12 @@
                 if (title != null && strict) {
                     throw new ParseException(R("PTwoTitles"));
                 }
-                title = getSpanText(child);
+                title = getSpanText(child, false);
             } else if ("description".equals(name)) {
                 if (description != null && strict) {
                     throw new ParseException(R("PTwoDescriptions"));
                 }
-                description = getSpanText(child);
+                description = getSpanText(child, false);
             } else if ("icon".equals(name)) {
                 if (icon != null && strict) {
                     throw new ParseException(R("PTwoIcons"));
@@ -876,7 +876,6 @@
     }
 
     // XML junk
-
     /**
      * Returns the implied text under a node, for example "text" in
      * "<description>text</description>".
@@ -885,11 +884,35 @@
      * @throws ParseException if the JNLP file is invalid
      */
     public String getSpanText(Node node) throws ParseException {
+        return getSpanText(node, true);
+    }
+
+    /**
+     * Returns the implied text under a node, for example "text" in
+     * "<description>text</description>". If preserveSpacing is false,
+     * sequences of whitespace characters are turned into a single
+     * space character.
+     *
+     * @param node the node with text under it
+     * @param preserveSpacing if true, preserve whitespace
+     * @throws ParseException if the JNLP file is invalid
+     */
+    public String getSpanText(Node node, boolean preserveSpacing)
+            throws ParseException {
         if (node == null)
             return null;
 
         // NANO
-        return node.getNodeValue();
+        String val = node.getNodeValue();
+        if (preserveSpacing) {
+            return val;
+        } else {
+            if (val == null) {
+                return null;
+            } else {
+                return val.replaceAll("\\s+", " ");
+            }
+        }
 
         /* TINY
         Node child = node.getFirstChild();