On Mon, 2006-07-17 at 12:59 +0200, Sven de Marothy wrote:
This patch breaks the build. For me, at least. I tried from a fresh tree
and that didn't work. It did compile minus this patch.
/Sven
The build with Jikes is broken because Jikes does not allow to extends
the non-final class javax.swing.text.html.ParserDelegator. Why it does
not allow, remains a mystery to me. Ecj allows to do this and compiles
without any problems.
The ParserDelegate methods to change the DTD are protected by the API. I
cannot call them unless from a derived class. Hence if I cannot extend
it, I cannot change the DTD.
The possible workaround (introduced by this patch) is to use the
ThreadLocal to pass the value of the currently active DTD to the
ParserDelegator constructor. Howerver without knownig a reason, why this
is done, the code looks really strange and unnecessarily complex. I am
not sure if it is sensible to apply it at all: maybe the bug will be
fixed or we can migrate to ecj. Generics are comming. Probably people
who need to work with Jikes now and today can apply it locally.
2006-07-17 Audrius Meskauskas <[EMAIL PROTECTED]>
* gnu/javax/swing/text/html/parser/GnuParserDelegator.java:
Added explaining comment.
* javax/swing/text/html/HTMLEditorKit.java (getParser)
Use static DTDSwitch methods to change the active DTD.
* javax/swing/text/html/parser/ParserDelegator.java (constructor):
Assign the currently active DTD as this parser DTD.
* gnu/javax/swing/text/html/parser/DTDSwitch.java: New file.
### Eclipse Workspace Patch 1.0
#P classpath
Index: gnu/javax/swing/text/html/parser/GnuParserDelegator.java
===================================================================
RCS file: /sources/classpath/classpath/gnu/javax/swing/text/html/parser/GnuParserDelegator.java,v
retrieving revision 1.1
diff -u -r1.1 GnuParserDelegator.java
--- gnu/javax/swing/text/html/parser/GnuParserDelegator.java 16 Jul 2006 15:03:08 -0000 1.1
+++ gnu/javax/swing/text/html/parser/GnuParserDelegator.java 17 Jul 2006 16:12:23 -0000
@@ -53,6 +53,11 @@
* This parser delegator uses the different DTD ([EMAIL PROTECTED] HTML_401Swing}).
* It is derived from the ParserDelegator for the compatibility reasons.
*
+ * TODO: As of 17 Jul 2006, the class is not in use due Jikes 1.22 compiler bug.
+ * However it provides useful functionality just specify arbitrary DTD
+ * when needed and should be used in HTMLEditorKit, dropping the cryptic
+ * and strangely looking workaround with the DTDSwitch.
+ *
* @author Audrius Meskauskas ([EMAIL PROTECTED])
*/
public class GnuParserDelegator extends ParserDelegator implements Serializable
Index: javax/swing/text/html/HTMLEditorKit.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/html/HTMLEditorKit.java,v
retrieving revision 1.31
diff -u -r1.31 HTMLEditorKit.java
--- javax/swing/text/html/HTMLEditorKit.java 16 Jul 2006 15:03:08 -0000 1.31
+++ javax/swing/text/html/HTMLEditorKit.java 17 Jul 2006 16:12:34 -0000
@@ -40,7 +40,7 @@
import gnu.classpath.NotImplementedException;
-import gnu.javax.swing.text.html.parser.GnuParserDelegator;
+import gnu.javax.swing.text.html.parser.DTDSwitch;
import gnu.javax.swing.text.html.parser.HTML_401Swing;
import java.awt.event.ActionEvent;
@@ -889,7 +889,9 @@
{
if (parser == null)
{
- parser = new GnuParserDelegator(HTML_401Swing.getInstance());
+ DTDSwitch.setActiveDTD(HTML_401Swing.getInstance());
+ parser = new ParserDelegator();
+ DTDSwitch.setActiveDTD(null);
}
return parser;
}
Index: javax/swing/text/html/parser/ParserDelegator.java
===================================================================
RCS file: /sources/classpath/classpath/javax/swing/text/html/parser/ParserDelegator.java,v
retrieving revision 1.9
diff -u -r1.9 ParserDelegator.java
--- javax/swing/text/html/parser/ParserDelegator.java 16 Jul 2006 15:03:08 -0000 1.9
+++ javax/swing/text/html/parser/ParserDelegator.java 17 Jul 2006 16:12:34 -0000
@@ -37,6 +37,7 @@
package javax.swing.text.html.parser;
+import gnu.javax.swing.text.html.parser.DTDSwitch;
import gnu.javax.swing.text.html.parser.HTML_401F;
import gnu.javax.swing.text.html.parser.htmlAttributeSet;
@@ -136,28 +137,31 @@
*/
gnuParser gnu;
+ public ParserDelegator()
+ {
+ DTD active = DTDSwitch.getActiveDTD();
+ if (active != null)
+ gnu = new gnuParser(active);
+ else
+ gnu = new gnuParser(dtd);
+ }
+
/**
- * Parses the HTML document, calling methods of the provided
- * callback. This method must be multithread - safe.
+ * Parses the HTML document, calling methods of the provided callback. This
+ * method must be multithread - safe.
+ *
* @param reader The reader to read the HTML document from
- * @param a_callback The callback that is notifyed about the presence
- * of HTML elements in the document.
- * @param ignoreCharSet If thrue, any charset changes during parsing
- * are ignored.
+ * @param a_callback The callback that is notifyed about the presence of HTML
+ * elements in the document.
+ * @param ignoreCharSet If thrue, any charset changes during parsing are
+ * ignored.
* @throws java.io.IOException
*/
public void parse(Reader reader, HTMLEditorKit.ParserCallback a_callback,
- boolean ignoreCharSet
- )
- throws IOException
+ boolean ignoreCharSet) throws IOException
{
callBack = a_callback;
- if (gnu == null || !dtd.equals(gnu.getDTD()))
- {
- gnu = new gnuParser(dtd);
- }
-
gnu.parse(reader);
callBack.handleEndOfLineString(gnu.getEndOfLineSequence());
@@ -173,9 +177,8 @@
}
/**
- * Calling this method instructs that, if not specified directly,
- * the documents will be parsed using the default
- * DTD of the implementation.
+ * Calling this method instructs that, if not specified directly, the
+ * documents will be parsed using the default DTD of the implementation.
*/
protected static void setDefaultDTD()
{
Index: gnu/javax/swing/text/html/parser/DTDSwitch.java
===================================================================
RCS file: gnu/javax/swing/text/html/parser/DTDSwitch.java
diff -N gnu/javax/swing/text/html/parser/DTDSwitch.java
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ gnu/javax/swing/text/html/parser/DTDSwitch.java 1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,67 @@
+/* DTDSwitch.java -- Workaround to switch the DTD's quickly.
+ Copyright (C) 2006 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package gnu.javax.swing.text.html.parser;
+
+import javax.swing.text.html.parser.DTD;
+
+/**
+ * This class allows to switch the ative DTD's easier than overriding the
+ * ParserDelegator. The active DTD can be set for the current thread to
+ * the required type. All subsequent ParserDelegator instances will grab
+ * that DTD. Set to null to return to the default behavior.
+ *
+ * TODO: This class is a temporary workaround against the Jikes 1.22 bug in
+ * 17 Jul 2006. When the bug will be fixed or other compiler preferred,
+ * this cryptic coding should be dropped, returning to the straightforward
+ * use of the GnuParserDelegator.
+ */
+public class DTDSwitch
+{
+ public static ThreadLocal activeDtd = new ThreadLocal();
+
+ public static DTD getActiveDTD()
+ {
+ return (DTD) activeDtd.get();
+ }
+
+ public static void setActiveDTD(DTD dtd)
+ {
+ activeDtd.set(dtd);
+ }
+}