Revision: 18070
          http://sourceforge.net/p/gate/code/18070
Author:   ian_roberts
Date:     2014-06-11 11:22:39 +0000 (Wed, 11 Jun 2014)
Log Message:
-----------
For some reason the flying saucer default parser chokes on divs that have an id
attribute when Xerces is on the classpath!  Changed the metadata viewer to
parse the description HTML using the NekoHTML parser instead of the default one
- as well as working around this bug it means we can use HTML in the long
descriptions that is not strictly XHTML compliant.

Modified Paths:
--------------
    gate/trunk/src/main/gate/gui/ControllerMetadataViewer.java

Modified: gate/trunk/src/main/gate/gui/ControllerMetadataViewer.java
===================================================================
--- gate/trunk/src/main/gate/gui/ControllerMetadataViewer.java  2014-06-11 
01:19:20 UTC (rev 18069)
+++ gate/trunk/src/main/gate/gui/ControllerMetadataViewer.java  2014-06-11 
11:22:39 UTC (rev 18070)
@@ -25,7 +25,7 @@
 
 import java.awt.BorderLayout;
 import java.awt.Font;
-import java.io.ByteArrayInputStream;
+import java.io.StringReader;
 import java.net.URL;
 import java.util.Iterator;
 import java.util.List;
@@ -36,6 +36,9 @@
 import javax.xml.parsers.ParserConfigurationException;
 
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.xerces.parsers.DOMParser;
+import org.cyberneko.html.HTMLConfiguration;
 import org.w3c.dom.Document;
 import org.w3c.dom.Node;
 import org.xhtmlrenderer.simple.XHTMLPanel;
@@ -43,6 +46,7 @@
 import org.xhtmlrenderer.swing.FSMouseListener;
 import org.xhtmlrenderer.swing.LinkListener;
 import org.xhtmlrenderer.util.Configuration;
+import org.xml.sax.InputSource;
 
 /**
  * This viewer displays metadata associated with a GATE Controller. The 
location
@@ -129,8 +133,7 @@
           Gate.getUserConfig().getFont(GateConstants.TEXT_COMPONENTS_FONT);
 
       StringBuilder page = new StringBuilder();
-      page.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
-      page.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" 
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>");
+      page.append("<!DOCTYPE html>");
       page.append("<html>");
       page.append("<head>");
       page.append("<style type='text/css'>body { font-family: ")
@@ -139,12 +142,19 @@
       page.append("</head>");
       page.append("<body>");
       page.append("<h1><img style='vertical-align: middle;' src='")
-          .append(iconDesc.toString()).append("'/> ")
-          .append(text.getTextContent()).append("</h1>");
+          
.append(StringEscapeUtils.escapeHtml(iconDesc.toString())).append("'/> ")
+          
.append(StringEscapeUtils.escapeHtml(text.getTextContent())).append("</h1>");
       page.append(IOUtils.toString(longDesc, "UTF-8"));
       page.append("</body></html>");
 
-      display.setDocument(new ByteArrayInputStream(page.toString().getBytes()),
+      // parse using NekoHTML
+      HTMLConfiguration config = new HTMLConfiguration();
+      // Force element names to lower case to match XHTML requirements
+      // as that is what Flying Saucer expects
+      config.setProperty("http://cyberneko.org/html/properties/names/elems";, 
"lower");
+      DOMParser htmlParser = new DOMParser(config);
+      htmlParser.parse(new InputSource(new StringReader(page.toString())));
+      display.setDocument(htmlParser.getDocument(),
           longDesc.toString());
 
     } catch(Exception e) {

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
HPCC Systems Open Source Big Data Platform from LexisNexis Risk Solutions
Find What Matters Most in Your Big Data with HPCC Systems
Open Source. Fast. Scalable. Simple. Ideal for Dirty Data.
Leverages Graph Analysis for Fast Processing & Easy Data Exploration
http://p.sf.net/sfu/hpccsystems
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to