classpath-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [cp-patches] RFC: Decouple DOM HTML parser from Swing


From: Meskauskas Audrius
Subject: Re: [cp-patches] RFC: Decouple DOM HTML parser from Swing
Date: Thu, 25 Aug 2005 20:53:18 +0200
User-agent: Mozilla Thunderbird 1.0.2 (Windows/20050317)

Hi,

This change may not be necessary. Unless somebody changed this, DomHTMLImpl is not coupled with swing. The coupled class is gnu.xml.dom.html2.DomHTMLParser. If you do not plan to parse HTML with your system, just do not include it into your derived work.

Audrius.

Roman Kennke wrote:

Hi,

I notice that the HTML parser in gnu.xml.dom.html2 depends on
gnu.javax.swing and javax.swing packages. That is because it basically
extends the Swing HTML parser. The problem that I have is that we (==
Aicas) also would like to build with GUI-less configurations, that means
without AWT and Swing. The situation now is that ripping out AWT and
Swing also means ripping out the whole DOM stuff because of this
dependency.

Ideally I would like to have an independent DOM HTML parser, and let the
Swing HTML parser extend that, instead of doing it the other way round.
I already contacted Audrius in private for suggestions on solving this
dependency problem. My solution for now is to decouple the dependency by
detecting and loading the DomHTMLImpl dynamically. Is this ok to check
in?

2005-08-25  Roman Kennke  <address@hidden>

       * gnu/xml/dom/DomImpl.java
       (hasFeature): Dynamically detect if there actually is a HTML
        parser implementation present.
       (getFeature): Dynamically load the DomHTMLImpl. This decouples
       the XML/HTML packages from the Swing packages.

/Roman

------------------------------------------------------------------------

Index: gnu/xml/dom/DomImpl.java
===================================================================
RCS file: /CVSROOT/Jamaica/src/classpath/gnu/xml/dom/DomImpl.java,v
retrieving revision 1.1
diff -u -r1.1 DomImpl.java
--- gnu/xml/dom/DomImpl.java    24 Aug 2005 11:01:51 -0000      1.1
+++ gnu/xml/dom/DomImpl.java    25 Aug 2005 10:25:45 -0000
@@ -47,7 +47,7 @@
import org.w3c.dom.ls.LSOutput;
import org.w3c.dom.ls.LSParser;
import org.w3c.dom.ls.LSSerializer;
-import gnu.xml.dom.html2.DomHTMLImpl;
+//import gnu.xml.dom.html2.DomHTMLImpl;
import gnu.xml.dom.ls.DomLSInput;
import gnu.xml.dom.ls.DomLSOutput;
import gnu.xml.dom.ls.DomLSParser;
@@ -153,9 +153,19 @@
      }
    else if ("html".equals(name) || "xhtml".equals(name))
      {
-        return (version == null ||
-                "".equals(version) ||
-                "2.0".equals(version));
+        boolean hasHtmlParser = true;
+        try
+          {
+            Class.forName("gnu.xml.dom.html2.DomHTMLImpl");
+          }
+        catch (ClassNotFoundException ex)
+          {
+            hasHtmlParser = false;
+          }
+        return (hasHtmlParser
+                && (version == null ||
+                    "".equals(version) ||
+                    "2.0".equals(version)));
      }

    // views
@@ -244,7 +254,29 @@
        if ("html".equalsIgnoreCase(feature) ||
            "xhtml".equalsIgnoreCase(feature))
          {
-            return new DomHTMLImpl();
+            // FIXME: This decouples dependency on HTML parser. This is
+            // necessary because the HTML parser depends on the Swing HTML
+            // parser stuff and this would disable XML/HTML parser for
+            // GUI-less configurations.
+            Object res = null;
+            try
+              {
+                Class domHtmlImplClass = 
Class.forName("gnu.xml.dom.html2.DomHTMLImpl");
+                res = domHtmlImplClass.newInstance();
+              }
+            catch (ClassNotFoundException ex)
+              {
+                // Return null if HTML parser cannot be found.
+              }
+            catch (IllegalAccessException ex)
+              {
+                // Return null if HTML parser cannot be found.
+              }
+            catch (InstantiationException ex)
+              {
+                // Return null if HTML parser cannot be found.
+              }
+            return res;
          }
        return this;
      }
------------------------------------------------------------------------

_______________________________________________
Classpath-patches mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/classpath-patches





reply via email to

[Prev in Thread] Current Thread [Next in Thread]