This fixes the issues that I already reported about. It does two things:
- Prevent the htmlAttributeSet to slip into user/application-visible
code
- Don't set the resolving parent (this actually solves my problem)

I decided to not remove the htmlAttributeSet altogether because that
would've caused regressions both in Mauve  and the internal testsuite. I
see no regression with the attached patch applied.

2006-11-06  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/html/HTMLDocument.java
        (HTMLReader.addSpecialElement): Removed comment about
        htmlAttributeSet.
        (HTMLReader.handleComment): Create SimpleAttributeSet instead
        of htmlAttributeSet.
        * javax/swing/text/html/parser/DocumentParser.java
        (gnuParser.handleStartTag): Use SimpleAttributeSet instead
        of htmlAttributeSet.
        * javax/swing/text/html/parser/ParserDelegator.java
        (gnuParser.handleStartTag): Use SimpleAttributeSet instead
        of htmlAttributeSet.
        * gnu/javax/swing/text/html/parser/GnuParserDelegator.java
        (gnuParser.handleStartTag): Use SimpleAttributeSet instead
        of htmlAttributeSet.
        * gnu/javax/swing/text/html/parser/support/Parser.java
        (getAttributes): Return a SimpleAttributeSet.
        (restOfTag): Don't set resolving parent here.

/Roman

Index: javax/swing/text/html/HTMLDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.46
diff -u -1 -5 -r1.46 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java	3 Nov 2006 14:00:42 -0000	1.46
+++ javax/swing/text/html/HTMLDocument.java	6 Nov 2006 20:23:18 -0000
@@ -27,31 +27,30 @@
 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 javax.swing.text.html;
 
 import gnu.classpath.NotImplementedException;
-import gnu.javax.swing.text.html.parser.htmlAttributeSet;
 
 import java.io.IOException;
 import java.io.StringReader;
 import java.net.URL;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.Stack;
 import java.util.Vector;
 
 import javax.swing.DefaultButtonModel;
 import javax.swing.JEditorPane;
 import javax.swing.JToggleButton;
 import javax.swing.text.AbstractDocument;
 import javax.swing.text.AttributeSet;
 import javax.swing.text.BadLocationException;
@@ -1339,32 +1338,31 @@
     }
     
     /**
      * This method called by parser to handle a comment block.
      * 
      * @param data the comment
      * @param pos the position at which the comment was encountered
      */
     public void handleComment(char[] data, int pos)
     {
       if (shouldInsert())
         {
           TagAction action = (TagAction) tagToAction.get(HTML.Tag.COMMENT);
           if (action != null)
             {
-              action.start(HTML.Tag.COMMENT, 
-                           htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET);
+              action.start(HTML.Tag.COMMENT, new SimpleAttributeSet());
               action.end(HTML.Tag.COMMENT);
             }
         }
     }
     
     /**
      * This method is called by the parser and should route the call to the
      * proper handler for the tag.
      * 
      * @param t the HTML.Tag
      * @param pos the position at which the tag was encountered
      */
     public void handleEndTag(HTML.Tag t, int pos)
     {
       if (shouldInsert())
@@ -1582,39 +1580,35 @@
               // TODO: what to do here?
             }
         }
     }
     
     /**
      * Adds content that is specified in the attribute set.
      * 
      * @param t the HTML.Tag
      * @param a the attribute set specifying the special content
      */
     protected void addSpecialElement(HTML.Tag t, MutableAttributeSet a)
     {
       a.addAttribute(StyleConstants.NameAttribute, t);
       
-      // Migrate from the rather htmlAttributeSet to the faster, lighter and 
-      // unchangeable alternative implementation.
-      AttributeSet copy = a.copyAttributes();
-
       // The two spaces are required because some special elements like HR
       // must be broken. At least two characters are needed to break into the
       // two parts.
       DefaultStyledDocument.ElementSpec spec =
-        new DefaultStyledDocument.ElementSpec(copy,
+        new DefaultStyledDocument.ElementSpec(a.copyAttributes(),
 	  DefaultStyledDocument.ElementSpec.ContentType, 
           new char[] {' ', ' '}, 0, 2 );
       parseBuffer.add(spec);
     }
     
     void printBuffer()
     {      
       print ("\n*********BUFFER**********");
       for (int i = 0; i < parseBuffer.size(); i ++)
         print ("  "+parseBuffer.get(i));
       print ("***************************");
     }
   }
   
   /**
Index: javax/swing/text/html/parser/DocumentParser.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/parser/DocumentParser.java,v
retrieving revision 1.9
diff -u -1 -5 -r1.9 DocumentParser.java
--- javax/swing/text/html/parser/DocumentParser.java	19 Oct 2005 14:57:33 -0000	1.9
+++ javax/swing/text/html/parser/DocumentParser.java	6 Nov 2006 20:23:18 -0000
@@ -26,37 +26,37 @@
 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 javax.swing.text.html.parser;
 
-import gnu.javax.swing.text.html.parser.htmlAttributeSet;
 import javax.swing.text.html.parser.Parser;
 
 import java.io.IOException;
 import java.io.Reader;
 
 import javax.swing.text.BadLocationException;
+import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.html.HTMLEditorKit;
 
 /**
  * <p>A simple error-tolerant HTML parser that uses a DTD document
  * to access data on the possible tokens, arguments and syntax.</p>
  * <p> The parser reads an HTML content from a Reader and calls various
  * notifying methods (which should be overridden in a subclass)
  * when tags or data are encountered.</p>
  * <p>Some HTML elements need no opening or closing tags. The
  * task of this parser is to invoke the tag handling methods also when
  * the tags are not explicitly specified and must be supposed using
  * information, stored in the DTD.
  * For  example, parsing the document
  * <p>&lt;table&gt;&lt;tr&gt;&lt;td&gt;a&lt;td&gt;b&lt;td&gt;c&lt;/tr&gt; <br>
  * will invoke exactly the handling methods exactly in the same order
@@ -105,31 +105,31 @@
     protected final void handleEndTag(TagElement tag)
     {
       parser.handleEndTag(tag);
       callBack.handleEndTag(tag.getHTMLTag(), hTag.where.startPosition);
     }
 
     protected final void handleError(int line, String message)
     {
       parser.handleError(line, message);
       callBack.handleError(message, hTag.where.startPosition);
     }
 
     protected final void handleStartTag(TagElement tag)
     {
       parser.handleStartTag(tag);
-      htmlAttributeSet attributes = gnu.getAttributes();
+      SimpleAttributeSet attributes = gnu.getAttributes();
 
       if (tag.fictional())
         attributes.addAttribute(HTMLEditorKit.ParserCallback.IMPLIED,
                                 Boolean.TRUE
                                );
 
       callBack.handleStartTag(tag.getHTMLTag(), attributes,
                               hTag.where.startPosition
                              );
     }
 
     protected final void handleText(char[] text)
     {
       parser.handleText(text);
       callBack.handleText(text, hTag.where.startPosition);
Index: javax/swing/text/html/parser/ParserDelegator.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/parser/ParserDelegator.java,v
retrieving revision 1.9
diff -u -1 -5 -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	6 Nov 2006 20:23:18 -0000
@@ -26,37 +26,37 @@
 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 javax.swing.text.html.parser;
 
 import gnu.javax.swing.text.html.parser.HTML_401F;
-import gnu.javax.swing.text.html.parser.htmlAttributeSet;
 
 import java.io.IOException;
 import java.io.Reader;
 import java.io.Serializable;
 
 import javax.swing.text.BadLocationException;
+import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.html.HTMLEditorKit;
 import javax.swing.text.html.HTMLEditorKit.ParserCallback;
 
 /**
  * This class instantiates and starts the working instance of
  * html parser, being responsible for providing the default DTD.
  *
  * @author Audrius Meskauskas ([EMAIL PROTECTED])
  */
 public class ParserDelegator
   extends javax.swing.text.html.HTMLEditorKit.Parser
   implements Serializable
 {
   private class gnuParser
     extends gnu.javax.swing.text.html.parser.support.Parser
@@ -81,31 +81,31 @@
                               );
     }
 
     protected final void handleEndTag(TagElement tag)
     {
       callBack.handleEndTag(tag.getHTMLTag(), hTag.where.startPosition);
     }
 
     protected final void handleError(int line, String message)
     {
       callBack.handleError(message, hTag.where.startPosition);
     }
 
     protected final void handleStartTag(TagElement tag)
     {
-      htmlAttributeSet attributes = gnu.getAttributes();
+      SimpleAttributeSet attributes = gnu.getAttributes();
 
       if (tag.fictional())
         attributes.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE);
 
       callBack.handleStartTag(tag.getHTMLTag(), attributes,
                               hTag.where.startPosition
                              );
     }
 
     protected final void handleText(char[] text)
     {
       callBack.handleText(text, hTag.where.startPosition);
     }
 
     DTD getDTD()
Index: gnu/javax/swing/text/html/parser/GnuParserDelegator.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/swing/text/html/parser/GnuParserDelegator.java,v
retrieving revision 1.1
diff -u -1 -5 -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	6 Nov 2006 20:23:18 -0000
@@ -31,30 +31,31 @@
 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 java.io.IOException;
 import java.io.Reader;
 import java.io.Serializable;
 
 import javax.swing.text.BadLocationException;
+import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.html.HTMLEditorKit;
 import javax.swing.text.html.HTMLEditorKit.ParserCallback;
 import javax.swing.text.html.parser.DTD;
 import javax.swing.text.html.parser.ParserDelegator;
 import javax.swing.text.html.parser.TagElement;
 
 /**
  * This parser delegator uses the different DTD ([EMAIL PROTECTED] HTML_401Swing}).
  * It is derived from the ParserDelegator for the compatibility reasons.
  * 
  * @author Audrius Meskauskas ([EMAIL PROTECTED]) 
  */
 public class GnuParserDelegator extends ParserDelegator implements Serializable
 {
   class gnuParser
@@ -80,31 +81,31 @@
                               );
     }
 
     protected final void handleEndTag(TagElement tag)
     {
       callBack.handleEndTag(tag.getHTMLTag(), hTag.where.startPosition);
     }
 
     protected final void handleError(int line, String message)
     {
       callBack.handleError(message, hTag.where.startPosition);
     }
 
     protected final void handleStartTag(TagElement tag)
     {
-      htmlAttributeSet attributes = gnu.getAttributes();
+      SimpleAttributeSet attributes = gnu.getAttributes();
 
       if (tag.fictional())
         attributes.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE);
 
       callBack.handleStartTag(tag.getHTMLTag(), attributes,
                               hTag.where.startPosition
                              );
     }
 
     protected final void handleText(char[] text)
     {
       callBack.handleText(text, hTag.where.startPosition);
     }
 
     DTD getDTD()
Index: gnu/javax/swing/text/html/parser/support/Parser.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/swing/text/html/parser/support/Parser.java,v
retrieving revision 1.7
diff -u -1 -5 -r1.7 Parser.java
--- gnu/javax/swing/text/html/parser/support/Parser.java	2 May 2006 15:50:50 -0000	1.7
+++ gnu/javax/swing/text/html/parser/support/Parser.java	6 Nov 2006 20:23:19 -0000
@@ -44,30 +44,31 @@
 import gnu.javax.swing.text.html.parser.support.low.ParseException;
 import gnu.javax.swing.text.html.parser.support.low.ReaderTokenizer;
 import gnu.javax.swing.text.html.parser.support.low.Token;
 import gnu.javax.swing.text.html.parser.support.low.node;
 import gnu.javax.swing.text.html.parser.support.low.pattern;
 
 import java.io.IOException;
 import java.io.Reader;
 
 import java.util.Comparator;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.Vector;
 
 import javax.swing.text.ChangedCharSetException;
+import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.html.HTML;
 import javax.swing.text.html.parser.AttributeList;
 import javax.swing.text.html.parser.DTD;
 import javax.swing.text.html.parser.DTDConstants;
 import javax.swing.text.html.parser.Element;
 import javax.swing.text.html.parser.Entity;
 import javax.swing.text.html.parser.TagElement;
 
 /**
  * <p>A simple error-tolerant HTML parser that uses a DTD document
  * to access data on the possible tokens, arguments and syntax.</p>
  * <p> The parser reads an HTML content from a Reader and calls various
  * notifying methods (which should be overridden in a subclass)
  * when tags or data are encountered.</p>
  * <p>Some HTML elements need no opening or closing tags. The
@@ -238,33 +239,33 @@
           protected void handleSupposedStartTag(Element tElement)
           {
             TagElement tag = makeTag(tElement, true);
             htmlAttributeSet were = attributes;
             attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET;
             _handleStartTag(tag);
             attributes = were;
           }
         };
   }
 
   /**
    * Get the attributes of the current tag.
    * @return The attribute set, representing the attributes of the current tag.
    */
-  public htmlAttributeSet getAttributes()
+  public SimpleAttributeSet getAttributes()
   {
-    return attributes;
+    return new SimpleAttributeSet(attributes);
   }
 
   /**
    * Invokes the error handler. The default method in this implementation
    * delegates the call to handleError, also providing the current line.
    */
   public void error(String msg)
   {
     error(msg, getTokenAhead());
   }
 
   public void error(String msg, Token atToken)
   {
     if (atToken != null)
       handleError(atToken.where.beginLine,
@@ -1406,32 +1407,30 @@
     optional(WS);
 
     readAttributes(name.getImage());
 
     optional(WS);
 
     next = getTokenAhead();
     if (next.kind == END)
       {
         mustBe(END);
         end = true;
       }
 
     hTag = new Token(start, next);
 
-    attributes.setResolveParent(defaulter.getDefaultParameters(name.getImage()));
-
     if (!end)
       {
         // The tag body contains errors. If additionally the tag
         // name is not valid, this construction is treated as text.
         if (dtd.elementHash.get(name.getImage().toLowerCase()) == null &&
             backupMode
            )
           {
             error("Errors in tag body and unknown tag name. " +
                   "Treating the tag as a text."
                  );
             reset();
 
             hTag = mustBe(BEGIN);
             buffer.setLength(0);

Reply via email to