[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: HTML parser fixes

Kaffe CVS cvs-commits at kaffe.org
Mon Mar 14 18:46:23 PST 2005


PatchSet 5570 
Date: 2005/03/15 02:40:56
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: HTML parser fixes

2005-03-14  Dalibor Topic  <robilad at kaffe.org>

Resynced with GNU Classpath.

2005-03-14  Audrius Meskauskas  <audriusa at bluewin.ch>

* javax/swing/text/html/parser/Parser.java,
javax/swing/text/html/parser/Entity.java:
Inheriting from DTDConstants.
* javax/swing/text/html/parser/AttributeList.java
(getValues): Changed return type.
* javax/swing/text/html/parser/DocumentParser
(parse): Adding the callback parameter that receives
the parsing events.

Members: 
	ChangeLog:1.3744->1.3745 
	libraries/javalib/javax/swing/text/html/parser/AttributeList.java:1.1->1.2 
	libraries/javalib/javax/swing/text/html/parser/DocumentParser.java:1.1->1.2 
	libraries/javalib/javax/swing/text/html/parser/Entity.java:1.1->1.2 
	libraries/javalib/javax/swing/text/html/parser/Parser.java:1.1->1.2 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3744 kaffe/ChangeLog:1.3745
--- kaffe/ChangeLog:1.3744	Tue Mar 15 02:36:06 2005
+++ kaffe/ChangeLog	Tue Mar 15 02:40:56 2005
@@ -1,3 +1,18 @@
+2005-03-14  Dalibor Topic  <robilad at kaffe.org>
+
+	Resynced with GNU Classpath.
+	
+	2005-03-14  Audrius Meskauskas  <audriusa at bluewin.ch>
+
+	* javax/swing/text/html/parser/Parser.java,
+	javax/swing/text/html/parser/Entity.java:
+	Inheriting from DTDConstants.
+	* javax/swing/text/html/parser/AttributeList.java
+	(getValues): Changed return type.
+	* javax/swing/text/html/parser/DocumentParser
+	(parse): Adding the callback parameter that receives
+	the parsing events.
+	
 2005-03-13  Dalibor Topic  <robilad at kaffe.org>
 
 	Resynced with GNU Classpath.
Index: kaffe/libraries/javalib/javax/swing/text/html/parser/AttributeList.java
diff -u kaffe/libraries/javalib/javax/swing/text/html/parser/AttributeList.java:1.1 kaffe/libraries/javalib/javax/swing/text/html/parser/AttributeList.java:1.2
--- kaffe/libraries/javalib/javax/swing/text/html/parser/AttributeList.java:1.1	Fri Mar 11 20:04:54 2005
+++ kaffe/libraries/javalib/javax/swing/text/html/parser/AttributeList.java	Tue Mar 15 02:41:00 2005
@@ -43,6 +43,7 @@
 import java.io.Serializable;
 
 import java.util.Vector;
+import java.util.Enumeration;
 
 /**
  * <p>
@@ -250,9 +251,9 @@
   /**
    * Get the allowed values of this attribute.
    */
-  public Vector getValues()
+  public Enumeration getValues()
   {
-    return values;
+    return values.elements();
   }
 
   /**
Index: kaffe/libraries/javalib/javax/swing/text/html/parser/DocumentParser.java
diff -u kaffe/libraries/javalib/javax/swing/text/html/parser/DocumentParser.java:1.1 kaffe/libraries/javalib/javax/swing/text/html/parser/DocumentParser.java:1.2
--- kaffe/libraries/javalib/javax/swing/text/html/parser/DocumentParser.java:1.1	Fri Mar 11 20:04:54 2005
+++ kaffe/libraries/javalib/javax/swing/text/html/parser/DocumentParser.java	Tue Mar 15 02:41:00 2005
@@ -38,9 +38,15 @@
 
 package javax.swing.text.html.parser;
 
+import gnu.javax.swing.text.html.parser.htmlAttributeSet;
+import gnu.javax.swing.text.html.parser.support.Parser;
+
 import java.io.IOException;
 import java.io.Reader;
 
+import javax.swing.text.BadLocationException;
+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>
@@ -71,34 +77,135 @@
   implements DTDConstants
 {
   /**
+   * The enclosed working parser class.
+   */
+  private class gnuParser
+    extends gnu.javax.swing.text.html.parser.support.Parser
+  {
+    private gnuParser(DTD d)
+    {
+      super(d);
+    }
+
+    protected final void handleComment(char[] comment)
+    {
+      parser.handleComment(comment);
+      callBack.handleComment(comment, hTag.where.startPosition);
+    }
+
+    protected final void handleEmptyTag(TagElement tag)
+      throws javax.swing.text.ChangedCharSetException
+    {
+      parser.handleEmptyTag(tag);
+      callBack.handleSimpleTag(tag.getHTMLTag(), getAttributes(),
+                               hTag.where.startPosition
+                              );
+    }
+
+    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();
+
+      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);
+    }
+
+    DTD getDTD()
+    {
+      return dtd;
+    }
+  }
+
+  /**
+   * This field is used to access the identically named
+   * methods of the outer class.
+   */
+  private DocumentParser parser = this;
+
+  /**
+   * The callback.
+   */
+  private HTMLEditorKit.ParserCallback callBack;
+
+  /**
+   * The reference to the working class of HTML parser that is
+   * actually used to parse the document.
+   */
+  private gnuParser gnu;
+
+  /**
    * Creates a new parser that uses the given DTD to access data on the
    * possible tokens, arguments and syntax. There is no single - step way
    * to get a default DTD; you must either refer to the implementation -
    * specific packages, write your own DTD or obtain the working instance
    * of parser in other way, for example, by calling
    * {@link javax.swing.text.html.HTMLEditorKit#getParser() }.
-   * @param a_dtd A DTD to use.
+   * @param a_dtd a DTD to use.
    */
   public DocumentParser(DTD a_dtd)
   {
     super(a_dtd);
+    gnu = new gnuParser(a_dtd);
   }
 
   /**
-   * Parse the HTML text, calling various methods in response to the
-   * occurence of the corresponding HTML constructions.
-   * @param reader The reader to read the source HTML from.
-   * @throws IOException If the reader throws one.
-   */
-  public synchronized void parse(Reader reader)
-                          throws IOException
-  {
-    super.parse(reader);
+   * 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 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
+  {
+    callBack = a_callback;
+    gnu.parse(reader);
+
+    callBack.handleEndOfLineString(gnu.getEndOfLineSequence());
+    try
+      {
+        callBack.flush();
+      }
+    catch (BadLocationException ex)
+      {
+        // Convert this into the supported type of exception.
+        throw new IOException(ex.getMessage());
+      }
   }
 
   /**
    * Handle HTML comment. The default method returns without action.
-   * @param comment The comment being handled
+   * @param comment the comment being handled
    */
   protected void handleComment(char[] comment)
   {
@@ -108,7 +215,7 @@
    * Handle the tag with no content, like &lt;br&gt;. The method is
    * called for the elements that, in accordance with the current DTD,
    * has an empty content.
-   * @param tag The tag being handled.
+   * @param tag the tag being handled.
    * @throws javax.swing.text.ChangedCharSetException
    */
   protected void handleEmptyTag(TagElement tag)
@@ -143,7 +250,7 @@
 
   /**
    * Handle the text section.
-   * @param text A section text.
+   * @param text a section text.
    */
   protected void handleText(char[] text)
   {
Index: kaffe/libraries/javalib/javax/swing/text/html/parser/Entity.java
diff -u kaffe/libraries/javalib/javax/swing/text/html/parser/Entity.java:1.1 kaffe/libraries/javalib/javax/swing/text/html/parser/Entity.java:1.2
--- kaffe/libraries/javalib/javax/swing/text/html/parser/Entity.java:1.1	Fri Mar 11 20:04:54 2005
+++ kaffe/libraries/javalib/javax/swing/text/html/parser/Entity.java	Tue Mar 15 02:41:00 2005
@@ -54,7 +54,7 @@
  * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
  */
 public final class Entity
-  implements Serializable
+  implements DTDConstants, Serializable
 {
   /**
    * Package level mapper between type names and they string values.
Index: kaffe/libraries/javalib/javax/swing/text/html/parser/Parser.java
diff -u kaffe/libraries/javalib/javax/swing/text/html/parser/Parser.java:1.1 kaffe/libraries/javalib/javax/swing/text/html/parser/Parser.java:1.2
--- kaffe/libraries/javalib/javax/swing/text/html/parser/Parser.java:1.1	Fri Mar 11 20:04:54 2005
+++ kaffe/libraries/javalib/javax/swing/text/html/parser/Parser.java	Tue Mar 15 02:41:00 2005
@@ -72,7 +72,8 @@
  * </p>
  * @author Audrius Meskauskas, Lithuania (AudriusA at Bioinformatics.org)
  */
-public class Parser
+public class Parser 
+  implements DTDConstants
 {
   /**
    * The document template description that will be used to parse the documents.




More information about the kaffe mailing list