In my last patch I added support for HTML <input> tags. However, I came
upon a problem with the attributes there. Strangely, all input tags
showed up as <input type="text">. It turned out that this is the DTD
default for that tag. After some debugging I found that somehow the HTML
parser or some part of the javax.swing.text package got confused with
the htmlAttributSet class and its handling of the resolveParent.

AFAICS, the only purpose of that class is to support upper and lowercase
attributes. I think that this is not correct. The HTML parser should
emit attributes as HTML.Attribute objects and not as strings. I fixed
that in the html parser. IMO we should not use the htmlAttributeSet
class anymore, and instead rely on the classes in javax.swing.text for
attribute handling. The StyleContext class provides methods and pooling
for AttributeSets which should be quite efficient.

I propose to remove htmlAttributeSet and SmallAttributeSet and use the
SimpleAttributeSet and StyleContext instead. This also solves my initial
problem with the input tag. However, I would like to hear feedback from
Audrius, he wrote these bits and might have some more insight.

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

        * javax/swing/text/html/parser/DocumentParser.java
        (gnuParser.handleStartTag): Use SimpleAttributeSet rather than
        htmlAttributeSet.
        * javax/swing/text/html/parser/ParserDelegator.java
        (gnuParser.handleStartTag): Use SimpleAttributeSet rather than
        htmlAttributeSet.
        * javax/swing/text/html/HTMLDocument.java
        (HTMLReader.handleComment): Use new SimpleAttributeSet, rather
        than htmlAttributeSet.
        * gnu/javax/swing/text/html/GnuParserDelegator.java
        (gnuParser.handleStartTag): Use SimpleAttributeSet rather than
        htmlAttributeSet.
        * gnu/javax/swing/text/html/htmlValidator.java
        (openTag): Changed signature to work with plain AttributeSet.
        (validateAttribute): Changed signature to work with plain
        AttributeSet.
        (validateTag): Changed signature to work with plain
        AttributeSet.
        (validateParameters): Changed signature to work with plain
        AttributeSet. Don't check for htmlAttributeSet.
        (validateAttribute): Changed signature to work with plain
        AttributeSet.
        * gnu/javax/swing/text/html/parser/support/Parser.java
        (attributes): Changed to type AttributeSet.
        (Parser): Use SimpleAttributeSet.EMPTY for initializing the
        attributes.
        (_handleText): Use SimpleAttributeSet.EMPTY for initializing the
        attributes.
        (getAttributes): Changed to return a SimpleAttributeSet. Maybe
        convert the attributes to a SimpleAttributeSet before.
        (noValueAttribute): Add attibute via StyleContext.
        (readAttributes): Use SimpleAttributeSet.EMPTY and StyleContext
        for managing attributes. Convert attibute key strings to
        the corresponding HTML.Attribute.
        (restOfTag): Use StyleContext for managing attributes.
        Convert attibute key strings to the corresponding HTML.Attribute.
        * gnu/javax/swing/text/html/parser/support/parameterDefaulter.java
        (getDefaultParameters): Changed to return a plain AttributeSet.
        Use SimpleAttributeSet.EMPTY and StyleContext for managing
        attributes.
        * gnu/javax/swing/text/html/parser/htmlAttributeSet.java:
        Removed.
        * gnu/javax/swing/text/html/parser/SmallHTMLAttributeSet.java:
        Removed.

/Roman

Index: javax/swing/text/html/HTMLDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.43
diff -u -1 -5 -r1.43 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java	2 Nov 2006 21:36:29 -0000	1.43
+++ javax/swing/text/html/HTMLDocument.java	2 Nov 2006 22:05:42 -0000
@@ -1282,31 +1282,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);
+                           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())
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	2 Nov 2006 22:05:42 -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.MutableAttributeSet;
 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,35 +81,35 @@
                               );
     }
 
     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();
-
+      MutableAttributeSet attributes = gnu.getAttributes();
       if (tag.fictional())
-        attributes.addAttribute(ParserCallback.IMPLIED, Boolean.TRUE);
-
+        {
+          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()
     {
       // Accessing the inherited gnu.javax.swing.text.html.parser.support.Parser
       // field. super. is a workaround, required to support JDK1.3's javac.
       return super.dtd;
Index: gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java
===================================================================
RCS file: gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java
diff -N gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java
--- gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java	9 Jun 2006 12:51:24 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,261 +0,0 @@
-/* SmallHtmlAttributeSet.java -- Small fixed HTML attribute set
-   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 java.io.Serializable;
-import java.util.Enumeration;
-import java.util.NoSuchElementException;
-
-import javax.swing.text.AttributeSet;
-import javax.swing.text.html.HTML.Attribute;
-import javax.swing.text.html.HTML.Tag;
-
-/**
- * Small fixed HTML attribute set. The most of the HTML elements contain only
- * several attributes. With four attributes, the number of operations in more
- * complex algorithms is not larger than using the naive algorithm.
- * 
- * Same as HtmlAttributeSet, this set allows both strings and non-string as
- * keys. The strings are case insensitive, the non strings are compared with
- * .equals.
- * 
- * @author Audrius Meskauskas ([EMAIL PROTECTED]) 
- */
-public class SmallHtmlAttributeSet
-    implements AttributeSet, Cloneable, Serializable
-{
-  private static final long serialVersionUID = 1;
-  
-  /**
-   * The keys, stored in this attribute set.
-   */
-  final Object[] keys;
-
-  /**
-   * The values, stored in this attribute set.
-   */
-  final Object[] values;
-
-  /**
-   * The parent, used for resolving the values, not found in this set.
-   */
-  final AttributeSet parent;
-
-  /**
-   * Create a new small fixed attribute set that contains the unchangeable copy
-   * of the passed attribute set and inherits its parent.
-   * 
-   * @param copyFrom the attribute set, containing the attribute values to copy.
-   */
-  public SmallHtmlAttributeSet(AttributeSet copyFrom)
-  {
-    int n = copyFrom.getAttributeCount();
-
-    keys = new Object[n];
-    values = new Object[n];
-    parent = copyFrom.getResolveParent();
-
-    Enumeration en = copyFrom.getAttributeNames();
-    Object key;
-    Object value;
-
-    for (int i = 0; i < n; i++)
-      {
-        key = en.nextElement();
-        keys[i] = key;
-        value = copyFrom.getAttribute(key);
-        values[i] = value;
-      }
-  }
-
-  public boolean containsAttribute(Object name, Object value)
-  {
-    Object contains = getAttribute(name);
-    if (value == null)
-      return value == contains;
-    else
-      return value.equals(contains);
-  }
-
-  public boolean containsAttributes(AttributeSet attributes)
-  {
-    if (attributes == this)
-      return true;
-    Object v;
-    for (int i = 0; i < keys.length; i++)
-      {
-        v = attributes.getAttribute(keys[i]);
-        if (v != values[i])
-          {
-            if (values[i] == null)
-              return false;
-            else if (! values[i].equals(v))
-              return false;
-          }
-      }
-    return true;
-  }
-
-  /**
-   * THIS can be safely returned as the set is not mutable.
-   */
-  public AttributeSet copyAttributes()
-  {
-    return this;
-  }
-
-  /**
-   * Get the attribute value, matching this key. If not found in this set, the
-   * call is delegated to parent.
-   * 
-   * @return the value, matching key (or null if none).
-   */
-  public Object getAttribute(Object key)
-  {
-    // Null and HTML attributes or tags can be searched by direct comparison.
-    if (key == null || key instanceof Attribute || key instanceof Tag)
-      {
-        for (int i = 0; i < keys.length; i++)
-          {
-            if (keys[i] == key)
-              return values[i];
-          }
-      }
-
-    // Strings are case insensitive. Only string can be match the string.
-    else if (key instanceof String)
-      {
-        String ks = (String) key;
-        for (int i = 0; i < keys.length; i++)
-          {
-            if (keys[i] instanceof String)
-              if (ks.equalsIgnoreCase((String) keys[i]))
-                return values[i];
-          }
-      }
-
-    // Otherwise, defaults to .equals
-    else
-      {
-        for (int i = 0; i < keys.length; i++)
-          {
-            if (key.equals(keys[i]))
-              return values[i];
-          }
-      }
-
-    if (parent != null)
-      return parent.getAttribute(key);
-    else
-      return null;
-  }
-
-  /**
-   * Get the number of the stored attributes.
-   */
-  public int getAttributeCount()
-  {
-    return keys.length;
-  }
-
-  /**
-   * Get enumeration, containing the attribute names. No guard agains the
-   * concurent modification is required as the set is not mutable.
-   */
-  public Enumeration getAttributeNames()
-  {
-    return new Enumeration()
-    {
-      int p = 0;
-
-      public boolean hasMoreElements()
-      {
-        return p < keys.length;
-      }
-
-      public Object nextElement()
-      {
-        if (p < keys.length)
-          return keys[p++];
-        else
-          throw new NoSuchElementException();
-      }
-    };
-  }
-  
-  /**
-   * Get the parent that this set uses to resolve the not found attributes.
-   */
-  public AttributeSet getResolveParent()
-  {
-    return parent;
-  }
-  
-  /**
-   * Check if the given attribute is defined in this set (not in the parent).
-   */
-  public boolean isDefined(Object attrName)
-  {
-    if (attrName instanceof String)
-      attrName = ((String) attrName).toLowerCase();
-
-    for (int i = 0; i < keys.length; i++)
-      {
-        if (attrName.equals(keys[i]))
-          return true;
-      }
-    return false;
-  }
-  
-  /**
-   * Check this set and another set for equality by content.
-   */
-  public boolean isEqual(AttributeSet attr)
-  {
-    return keys.length == attr.getAttributeCount() && containsAttributes(attr);
-  }
-
-  /**
-   * It is safe to return THIS on cloning, if one happens.
-   */
-  protected Object clone()
-  {
-    return this;
-  }
-}
Index: gnu/javax/swing/text/html/parser/htmlAttributeSet.java
===================================================================
RCS file: gnu/javax/swing/text/html/parser/htmlAttributeSet.java
diff -N gnu/javax/swing/text/html/parser/htmlAttributeSet.java
--- gnu/javax/swing/text/html/parser/htmlAttributeSet.java	6 Jun 2006 13:51:35 -0000	1.5
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,183 +0,0 @@
-/* htmlAttributeSet.java -- A set to store HTML attributes
-   Copyright (C) 2005 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 java.util.Enumeration;
-
-import javax.swing.text.AttributeSet;
-import javax.swing.text.SimpleAttributeSet;
-import javax.swing.text.html.HTML;
-
-/**
- * A set, adapted to store HTML attributes.
- * 
- * @author Audrius Meskauskas, Lithuania ([EMAIL PROTECTED])
- */
-public class htmlAttributeSet
-  extends SimpleAttributeSet
-{
-  public static final htmlAttributeSet EMPTY_HTML_ATTRIBUTE_SET =
-    new htmlAttributeSet();
-  
-  AttributeSet parent;
-
-  /**
-   * Looks in this set and, if not found, later looks in the parent set. Calls
-   * toString(), allowing to pass as HTML.Attribute, as String to this method.
-   * 
-   * @param _key A key to search for a value.
-   * @return The value, if one is defined.
-   */
-  public Object getAttribute(Object _key)
-  {
-    Object v = super.getAttribute(_key);
-    if (v != null || _key == null)
-      return v;
-
-    Object key = _key.toString().toLowerCase();
-
-    v = super.getAttribute(key);
-    if (v != null)
-      return v;
-
-    key = HTML.getAttributeKey((String) key);
-    v = super.getAttribute(key);
-    if (v != null)
-      return v;
-
-    if (parent != null)
-      return parent.getAttribute(key);
-    else
-      return null;
-  }
-
-  /**
-   * The name set must return HTML.Attribute and not a string,
-   * where applicable.
-   */
-  public Enumeration getAttributeNames()
-  {
-    // Replace the string keys by HTML.attribute, where applicable
-    final Enumeration enumeration = super.getAttributeNames();
-
-    return new Enumeration()
-    {
-      public boolean hasMoreElements()
-      {
-        return enumeration.hasMoreElements();
-      }
-
-      public Object nextElement()
-      {
-        Object key = enumeration.nextElement();
-        if (key instanceof String)
-          {
-            HTML.Attribute hKey = HTML.getAttributeKey((String) key);
-            if (hKey != null)
-              return hKey;
-          }
-        return key;
-      }
-    };
-  }
-
-  /**
-   * Set the parent set, containing the default values.
-   * 
-   * @param a_parent
-   */
-  public void setResolveParent(AttributeSet a_parent)
-  {
-    parent = a_parent;
-  }
-
-  /**
-   * Get the parent set, containing the default values.
-   * 
-   * @return the parent, used to resolve the attributes.
-   */
-  public AttributeSet getResolveParent()
-  {
-    return parent;
-  }
-
-  /**
-   * Add the attribute to this attribute set.
-   * 
-   * @param key Attribute key (if string, it will be case insensitive)
-   * @param value Attribute value
-   */
-  public void addAttribute(Object key, Object value)
-  {
-    if (key instanceof String)
-      super.addAttribute(((String) key).toLowerCase(), value);
-    else
-      super.addAttribute(key, value);
-  }
-
-  /**
-   * Copy attributes. The returned copy does not longer contains the extended
-   * features, needed to participate in the HTML parsing. The returned set may
-   * not be mutable.
-   */
-  public AttributeSet copyAttributes()
-  {
-    if (getAttributeCount() <= 8)
-      // For the small size, typical in HTML tags, the direct iteration is
-      // faster than more complex algorithms.
-      return new SmallHtmlAttributeSet(this);
-    else
-      return (AttributeSet) clone();
-  }   
-  
-  /**
-   * Returns a clone of the attribute set.
-   * 
-   * @return A clone of the attribute set.
-   */
-  public Object clone()
-  {
-    htmlAttributeSet set = new htmlAttributeSet();
-    set.addAttributes(this);
-    AttributeSet parent = getResolveParent();
-    if (parent != null)
-      set.setResolveParent(parent);
-    return set;
-  }  
-}
Index: gnu/javax/swing/text/html/parser/htmlValidator.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/swing/text/html/parser/htmlValidator.java,v
retrieving revision 1.5
diff -u -1 -5 -r1.5 htmlValidator.java
--- gnu/javax/swing/text/html/parser/htmlValidator.java	16 Jul 2006 18:25:53 -0000	1.5
+++ gnu/javax/swing/text/html/parser/htmlValidator.java	2 Nov 2006 22:05:43 -0000
@@ -34,30 +34,31 @@
 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 gnu.javax.swing.text.html.parser.models.node;
 import gnu.javax.swing.text.html.parser.models.transformer;
 
 import java.util.BitSet;
 import java.util.Enumeration;
 import java.util.LinkedList;
 import java.util.ListIterator;
 
+import javax.swing.text.AttributeSet;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.html.HTML;
 import javax.swing.text.html.parser.*;
 
 /**
  * <p>The HTML content validator, is responsible for opening and
  * closing elements with optional start/end tags, detecting
  * the wrongly placed html tags and reporting errors. The working instance
  * is the inner class inside the [EMAIL PROTECTED] javax.swing.text.html.parser.Parser }
  * </p>
  * <p>This class could potentially
  * provide basis for automated closing and insertion of the html tags,
  * correcting the found html errors.
  * @author Audrius Meskauskas, Lithuania ([EMAIL PROTECTED])
  */
@@ -192,31 +193,31 @@
 
                 stack.remove(x);
                 return;
               }
           }
       }
     s_error("Closing unopened <" + tag + ">");
   }
 
   /**
    * Add the given HTML tag to the stack of the opened tags. Forcibly closes
    * all tags in the stack that does not allow this tag in they content (error
    * is reported).
    * @param element
    */
-  public void openTag(TagElement tElement, htmlAttributeSet parameters)
+  public void openTag(TagElement tElement, AttributeSet parameters)
   {
     // If this is a fictional call, the message from the parser
     // has recursively returned - ignore.
     if (tElement.fictional())
       return;
 
     validateParameters(tElement, parameters);
 
     // If the stack is empty, start from HTML
     if (stack.isEmpty() && tElement.getHTMLTag() != HTML.Tag.HTML)
       {
         Element html = dtd.getElement(HTML.Tag.HTML.toString());
         openFictionalTag(html);
       }
 
@@ -350,31 +351,31 @@
             Element P = dtd.getElement(HTML_401F.P);
             if (inclusions.get(P.index))
               return P;
             else
               return Boolean.FALSE;
           }
       }
     return Boolean.TRUE;
   }
 
   /**
    * Validate tag without storing in into the tag stack. This is called
    * for the empty tags and results the subsequent calls to the openTag
    * and closeTag.
    */
-  public void validateTag(TagElement tElement, htmlAttributeSet parameters)
+  public void validateTag(TagElement tElement, AttributeSet parameters)
   {
     openTag(tElement, parameters);
     closeTag(tElement);
   }
 
   /**
    * Check for mandatory elements, subsequent to the last tag:
    * @param tElement The element that will be inserted next.
    */
   protected void checkContentModel(TagElement tElement, boolean first)
   {
     if (stack.isEmpty())
       return;
 
     hTag last = (hTag) stack.getLast();
@@ -420,34 +421,33 @@
   /**
    * Handles the error message. This method must be overridden to pass
    * the message where required.
    * @param msg The message text.
    */
   protected abstract void s_error(String msg);
 
   /**
    * Validate the parameters, report the error if the given parameter is
    * not in the parameter set, valid for the given attribute. The information
    * about the valid parameter set is taken from the Element, enclosed
    * inside the tag. The method does not validate the default parameters.
    * @param tag The tag
    * @param parameters The parameters of this tag.
    */
-  protected void validateParameters(TagElement tag, htmlAttributeSet parameters)
+  protected void validateParameters(TagElement tag, AttributeSet parameters)
   {
     if (parameters == null ||
-        parameters == htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET ||
         parameters == SimpleAttributeSet.EMPTY
        )
       return;
 
     Enumeration enumeration = parameters.getAttributeNames();
 
     while (enumeration.hasMoreElements())
       {
         validateAttribute(tag, parameters, enumeration);
       }
 
     // Check for missing required values.
     AttributeList a = tag.getElement().getAttributes();
 
     while (a != null)
@@ -476,31 +476,31 @@
 
   private void closeLast()
   {
     handleSupposedEndTag(((hTag) stack.getLast()).element);
     stack.removeLast();
   }
 
   private void openFictionalTag(Element e)
   {
     handleSupposedStartTag(e);
     stack.add(new hTag(new TagElement(e, true)));
     if (!e.omitStart())
       s_error("<" + e + "> is expected (supposing it)");
   }
 
-  private void validateAttribute(TagElement tag, htmlAttributeSet parameters,
+  private void validateAttribute(TagElement tag, AttributeSet parameters,
                                  Enumeration enumeration
                                 )
   {
     Object foundAttribute;
     AttributeList dtdAttribute;
     foundAttribute = enumeration.nextElement();
     dtdAttribute = tag.getElement().getAttribute(foundAttribute.toString());
     if (dtdAttribute == null)
       {
         StringBuffer valid =
           new StringBuffer("The tag <" + tag.getHTMLTag() +
                            "> cannot contain the attribute '" + foundAttribute +
                            "'. The valid attributes for this tag are: "
                           );
 
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	2 Nov 2006 22:05:43 -0000
@@ -26,48 +26,53 @@
 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.support;
 
-import gnu.javax.swing.text.html.parser.htmlAttributeSet;
 import gnu.javax.swing.text.html.parser.htmlValidator;
 import gnu.javax.swing.text.html.parser.support.low.Constants;
 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.lang.reflect.Field;
 
 import java.util.Comparator;
+import java.util.HashMap;
 import java.util.Set;
 import java.util.TreeSet;
 import java.util.Vector;
 
+import javax.swing.text.AttributeSet;
 import javax.swing.text.ChangedCharSetException;
+import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleContext;
 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
@@ -79,30 +84,31 @@
  * will invoke exactly the handling methods exactly in the same order
  * (and with the same parameters) as if parsing the document: <br>
  * <em>&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;&lt;table&gt;&lt;
  * tbody&gt;</em>&lt;tr&gt;&lt;td&gt;a<em>&lt;/td&gt;</em>&lt;td&gt;b<em>
  * &lt;/td&gt;</em>&lt;td&gt;c<em>&lt;/td&gt;&lt;/tr&gt;</em>&lt;
  * <em>/tbody&gt;&lt;/table&gt;&lt;/body&gt;&lt;/html&gt;</em></p>
  * (supposed tags are given in italics). The parser also supports
  * obsolete elements of HTML syntax.<p>
  * </p>
  * @author Audrius Meskauskas, Lithuania ([EMAIL PROTECTED])
  */
 public class Parser
   extends ReaderTokenizer
   implements DTDConstants
 {
+
   /**
    * The current html tag.
    */
   public Token hTag = new Token();
 
   /**
    * The document template description that will be used to parse the documents.
    */
   protected DTD dtd;
 
   /**
    * The value of this field determines whether or not the Parser will be
    * strict in enforcing SGML compatibility. The default value is false,
    * stating that the parser should do everything to parse and get at least
    * some information even from the incorrectly written HTML input.
@@ -147,32 +153,31 @@
    * True means that the 'title' tag of this document has
    * already been handled.
    */
   private boolean titleHandled;
 
   /**
    * True means that the 'title' tag is currently open and all
    * text is also added to the title buffer.
    */
   private boolean titleOpen;
 
   /**
    * The attributes of the current HTML element.
    * Package-private to avoid an accessor method.
    */
-  htmlAttributeSet attributes =
-    htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET;
+  AttributeSet attributes = SimpleAttributeSet.EMPTY;
 
   /**
    * The validator, controlling the forcible closing of the tags that
    * (in accordance to dtd) are not allowed in the current context.
    */
   private htmlValidator validator;
 
   /**
    * Provides the default values for parameters in the case when these
    * values are defined in the DTD.
    */
   private parameterDefaulter defaulter;
 
   /**
    * The text pre-processor for handling line ends and tabs.
@@ -226,45 +231,50 @@
             _handleEndTag_remaining(tag);
           }
 
           /**
            * The method is called when the the tag validator decides to open
            * the new tag on its own initiative. The tags, opened in this
            * way, are HTML, HEAD and BODY. The attribute set is temporary
            * assigned to the empty one, the previous value is
            * restored before return.
            *
            * @param element The tag being fictionally (forcibly) closed.
            */
           protected void handleSupposedStartTag(Element tElement)
           {
             TagElement tag = makeTag(tElement, true);
-            htmlAttributeSet were = attributes;
-            attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET;
+            AttributeSet were = attributes;
+            attributes = SimpleAttributeSet.EMPTY;
             _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;
+    SimpleAttributeSet mAtts;
+    if (attributes instanceof SimpleAttributeSet)
+      mAtts = (SimpleAttributeSet) attributes;
+    else
+      mAtts = new SimpleAttributeSet(attributes);
+    return mAtts;
   }
 
   /**
    * 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,
@@ -649,31 +659,31 @@
    * by the single one and the result is  moved into array,
    * passing it  to handleText().
    */
   protected void _handleText()
   {
     char[] text;
 
     if (preformatted > 0)
       text = textProcessor.preprocessPreformatted(buffer);
     else
       text = textProcessor.preprocess(buffer);
 
     if (text != null && text.length > 0)
       {
         TagElement pcdata = new TagElement(dtd.getElement("#pcdata"));
-        attributes = htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET;
+        attributes = SimpleAttributeSet.EMPTY;
         _handleEmptyTag(pcdata);
 
         handleText(text);
         if (titleOpen)
           title.append(text);
       }
   }
 
   /**
    * Add the image of this token to the buffer.
    * @param t A token to append.
    */
   protected final void append(Token t)
   {
     if (t.kind != EOF)
@@ -858,31 +868,33 @@
   protected void noValueAttribute(String element, String attribute)
   {
     Object value = HTML.NULL_ATTRIBUTE_VALUE;
 
     Element e = (Element) dtd.elementHash.get(element.toLowerCase());
     if (e != null)
       {
         AttributeList attr = e.getAttribute(attribute);
         if (attr != null)
           {
             Vector values = attr.values;
             if (values != null && values.size() == 1)
               value = values.get(0);
           }
       }
-    attributes.addAttribute(attribute, value);
+    StyleContext ctx = StyleContext.getDefaultStyleContext();
+    HTML.Attribute att = HTML.getAttributeKey(attribute);
+    attributes = ctx.addAttribute(attributes, att, value);
   }
 
   /**
    * Consume the optional token, if present.
    * @param kind The kind of token to consume.
    */
   protected Token optional(int kind)
   {
     if (getTokenAhead().kind == kind)
       return getNextToken();
     else
       return null;
   }
 
   /** Parse the html document. */
@@ -917,34 +929,36 @@
       }
   }
 
   /**
    * Read the element attributes, adding them into attribute set.
    * @param element The element name (needed to access attribute
    * information in dtd).
    */
   protected void readAttributes(String element)
   {
     Token name;
     Token value;
     Token next;
     String attrValue;
 
-    attributes = new htmlAttributeSet();
+    attributes = SimpleAttributeSet.EMPTY;
 
     optional(WS);
 
+    StyleContext ctx = StyleContext.getDefaultStyleContext();
+
     attributeReading: 
       while (getTokenAhead().kind == NUMTOKEN)
       {
         name = getNextToken();
         optional(WS);
 
         next = getTokenAhead();
         if (next.kind == EQ)
           {
             mustBe(EQ);
             optional(WS);
 
             next = getNextToken();
 
             switch (next.kind)
@@ -1016,31 +1030,32 @@
                   {
                     StringBuffer image = new StringBuffer(value.getImage());
                     while (next.kind == NUMTOKEN || next.kind == SLASH)
                       {
                         image.append(getNextToken().getImage());
                         next = getTokenAhead();
                       }
                     attrValue = image.toString();
                   }
                 else
                   attrValue = value.getImage();
                 break;
               default:
                 break attributeReading;
               }
-            attributes.addAttribute(name.getImage(), attrValue);
+            HTML.Attribute att = HTML.getAttributeKey(name.getImage());
+            attributes = ctx.addAttribute(attributes, att, attrValue);
             optional(WS);
           }
         else
           // The '=' is missing: attribute without value.
           {
             noValueAttribute(element, name.getImage());
           }
       }
   }
 
   /**
    * Return string, corresponding the given named entity. The name is passed
    * with the preceeding &, but without the ending semicolon.
    */
   protected String resolveNamedEntity(final String a_tag)
@@ -1406,31 +1421,33 @@
     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()));
+    SimpleAttributeSet sAtts = new SimpleAttributeSet(attributes);
+    sAtts.setResolveParent(defaulter.getDefaultParameters(name.getImage()));
+    attributes = sAtts;
 
     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);
@@ -1471,16 +1488,17 @@
   {
     try
       {
         startTag(tag);
       }
     catch (ChangedCharSetException cax)
       {
         error("Invalid change of charset");
       }
   }
 
   private void ws_error()
   {
     error("Whitespace here is not permitted");
   }
+
 }
Index: gnu/javax/swing/text/html/parser/support/parameterDefaulter.java
===================================================================
RCS file: /cvsroot/classpath/classpath/gnu/javax/swing/text/html/parser/support/parameterDefaulter.java,v
retrieving revision 1.2
diff -u -1 -5 -r1.2 parameterDefaulter.java
--- gnu/javax/swing/text/html/parser/support/parameterDefaulter.java	2 Jul 2005 20:32:15 -0000	1.2
+++ gnu/javax/swing/text/html/parser/support/parameterDefaulter.java	2 Nov 2006 22:05:43 -0000
@@ -26,81 +26,85 @@
 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.support;
 
-import gnu.javax.swing.text.html.parser.htmlAttributeSet;
-
 import java.util.Hashtable;
 
+import javax.swing.text.AttributeSet;
+import javax.swing.text.SimpleAttributeSet;
+import javax.swing.text.StyleContext;
 import javax.swing.text.html.parser.AttributeList;
 import javax.swing.text.html.parser.DTD;
 import javax.swing.text.html.parser.Element;
 
 /**
  * Returns an attribute set, containing default
  * parameters for the given element. Caches sets of default
  * parameters.
  * @author Audrius Meskauskas, Lithuania ([EMAIL PROTECTED])
  */
 public class parameterDefaulter
 {
   public final DTD dtd;
   Hashtable sets = new Hashtable();
 
   /**
    * Create a parameterDefaulter that looks for the default attribute
    * values in the given DTD.
    * @param a_dtd
    */
   public parameterDefaulter(DTD a_dtd)
   {
     dtd = a_dtd;
   }
 
   /**
    * Get the default parameter set for the given element.
    * @param element The element name (case insensitive).
    * @return the default attrbute set.
    */
-  public htmlAttributeSet getDefaultParameters(String element)
+  public AttributeSet getDefaultParameters(String element)
   {
     String key = element.toLowerCase();
-    htmlAttributeSet atts = (htmlAttributeSet) sets.get(key);
+    AttributeSet atts = (AttributeSet) sets.get(key);
 
     if (atts == null)
       {
-        htmlAttributeSet set = new htmlAttributeSet();
+        AttributeSet set = SimpleAttributeSet.EMPTY;
         Element e = (Element) dtd.elementHash.get(element.toLowerCase());
 
         if (e != null)
           {
             AttributeList a = e.getAttributes();
 
             while (a != null)
               {
                 if (a.value != null)
-                  set.addAttribute(a.name, a.value);
+                  {
+                    StyleContext ctx = StyleContext.getDefaultStyleContext();
+                    set = ctx.addAttribute(set, a.name, a.value);
+                  }
                 a = a.next;
               }
           }
 
         if (set.getAttributeCount() > 0)
           sets.put(key, set);
         else
-          sets.put(key, htmlAttributeSet.EMPTY_HTML_ATTRIBUTE_SET);
+          sets.put(key, SimpleAttributeSet.EMPTY);
 
         atts = set;
       }
     return atts;
   }
 }
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	2 Nov 2006 22:05:43 -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	2 Nov 2006 22:05:43 -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()

Reply via email to