From bc761e95c6063aaf68e02f7346ad1e10953788da Mon Sep 17 00:00:00 2001
From: Omair Majid <omajid@redhat.com>
Date: Mon, 13 Dec 2010 16:12:06 -0500
Subject: 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.
---
 netx/net/sourceforge/jnlp/Parser.java | 37 ++++++++++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 7 deletions(-)

(limited to 'netx/net')

diff --git a/netx/net/sourceforge/jnlp/Parser.java b/netx/net/sourceforge/jnlp/Parser.java
index f2cfae2..d69c786 100644
--- a/netx/net/sourceforge/jnlp/Parser.java
+++ b/netx/net/sourceforge/jnlp/Parser.java
@@ -446,9 +446,9 @@ class Parser {
             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 @@ class Parser {
                         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 @@ class Parser {
                 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 @@ class Parser {
     }
 
     // XML junk
-
     /**
      * Returns the implied text under a node, for example "text" in
      * "<description>text</description>".
@@ -885,11 +884,35 @@ class Parser {
      * @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();
-- 
cgit v1.2.3