[cp-patches] Patch: HTMLDocument addition

2005-12-13 Thread Lillian Angel
Added in the missing methods for HTMLDocument. I was only able to
implement 2 so far. The others are just stubs for now.

2005-12-13  Lillian Angel  <[EMAIL PROTECTED]>

* javax/swing/text/html/HTMLDocument.java
(getElement): Implemented.
(getElement): Implemented.
(setInnerHTML): Added, not fully implemented.
(setOuterHTML): Likewise.
(insertBeforeStart): Likewise.
(insertAfterStart): Likewise.
(insertBeforeEnd): Likewise.
(insertAfterEnd): Likewise.

Index: javax/swing/text/html/HTMLDocument.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.10
diff -u -r1.10 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java	13 Dec 2005 17:14:29 -	1.10
+++ javax/swing/text/html/HTMLDocument.java	13 Dec 2005 19:48:46 -
@@ -39,6 +39,10 @@
 package javax.swing.text.html;
 
 import java.net.URL;
+
+import java.io.IOException;
+import java.io.StringReader;
+
 import java.util.HashMap;
 import java.util.Stack;
 import java.util.Vector;
@@ -1153,4 +1157,170 @@
   {
 return new HTMLReader(pos, popDepth, pushDepth, insertTag);
   }  
+  
+  /**
+   * Gets the child element that contains the attribute with the value or null.
+   * Not thread-safe.
+   * 
+   * @param e - the element to begin search at
+   * @param attribute - the desired attribute
+   * @param value - the desired value
+   * @return the element found with the attribute and value specified or null
+   * if it is not found.
+   */
+  public Element getElement(Element e, Object attribute, Object value)
+  {
+if (e != null)
+  {
+if (e.getAttributes().containsAttribute(attribute, value))
+  return e;
+
+int count = e.getElementCount();
+for (int j = 0; j < count; j++)
+  {
+Element child = e.getElement(j);
+if (child.getAttributes().containsAttribute(attribute, value))
+  return child;
+
+return getElement(child, attribute, value);
+  }
+  }
+return null;
+  }
+  
+  /**
+   * Returns the element that has the given id Attribute. If it is not found, 
+   * null is returned. This method works on an Attribute, not a character tag.
+   * This is not thread-safe.
+   * 
+   * @param attrId - the Attribute id to look for
+   * @return the element that has the given id.
+   */
+  public Element getElement(String attrId)
+  {
+Element root = getDefaultRootElement();
+return getElement(root, HTML.getAttributeKey(attrId) , attrId);
+  }
+  
+  /**
+   * Replaces the children of the given element with the contents of
+   * the string. The document must have an HTMLEditorKit.Parser set.
+   * This will be seen as at least two events, n inserts followed by a remove.
+   * 
+   * @param elem - the brance element whose children will be replaced
+   * @param htmlText - the string to be parsed and assigned to element.
+   * @throws BadLocationException
+   * @throws IOException
+   * @throws IllegalArgumentException - if elem is a leaf 
+   * @throws IllegalStateException - if an HTMLEditorKit.Parser has not been set
+   */
+  public void setInnerHTML(Element elem, String htmlText) 
+throws BadLocationException, IOException
+  {
+if (elem.isLeaf())
+  throw new IllegalArgumentException("Element is a leaf");
+if (parser == null)
+  throw new IllegalStateException("Parser has not been set");
+// FIXME: Not implemented fully, use InsertHTML* in HTMLEditorKit?
+System.out.println("setInnerHTML not implemented");
+  }
+  
+  /**
+   * Replaces the given element in the parent with the string. When replacing
+   * a leaf, this will attempt to make sure there is a newline present if one is
+   * needed. This may result in an additional element being inserted.
+   * This will be seen as at least two events, n inserts followed by a remove.
+   * The HTMLEditorKit.Parser must be set.
+   * 
+   * @param elem - the branch element whose parent will be replaced
+   * @param htmlText - the string to be parsed and assigned to elem
+   * @throws BadLocationException
+   * @throws IOException
+   * @throws IllegalStateException - if parser is not set
+   */
+  public void setOuterHTML(Element elem, String htmlText) 
+throws BadLocationException, IOException
+{
+  if (parser == null)
+throw new IllegalStateException("Parser has not been set");
+  // FIXME: Not implemented fully, use InsertHTML* in HTMLEditorKit?
+  System.out.println("setOuterHTML not implemented");
+}
+  
+  /**
+   * Inserts the string before the start of the given element.
+   * The parser must be set.
+   * 
+   * @param elem - the element to be the root for the new text.
+   * @param htmlText - the string to be parsed and assigned to elem
+   * @throws BadLocationException
+   * @throws IOException
+   * @throws Illega

[cp-patches] Patch: HTMLDocument fix.

2005-12-13 Thread Lillian Angel
Implemented the getReader functions in HTMLDocument according to the
API. They return an instance of HTMLDocument.HTMLReader.

2005-12-13  Lillian Angel  <[EMAIL PROTECTED]>

* javax/swing/text/html/HTMLDocument.java
(getReader): Implemented.
(getReader): Implemented.

Index: javax/swing/text/html/HTMLDocument.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.9
diff -u -r1.9 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java	13 Dec 2005 17:08:46 -	1.9
+++ javax/swing/text/html/HTMLDocument.java	13 Dec 2005 17:13:05 -
@@ -1132,8 +1132,7 @@
*/
   public HTMLEditorKit.ParserCallback getReader(int pos)
   {
-// FIXME: Not implemented.
-return null;
+return new HTMLReader(pos);
   }  
   
   /**
@@ -1152,7 +1151,6 @@
 int pushDepth,
 HTML.Tag insertTag)
   {
-// FIXME: Not Implemented.
-return null;
+return new HTMLReader(pos, popDepth, pushDepth, insertTag);
   }  
 }
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] Patch: HTMLDocument addition

2005-12-13 Thread Lillian Angel
Added and implemented an inner class in HTMLDocument.

2005-12-13  Lillian Angel  <[EMAIL PROTECTED]>

* javax/swing/text/html/HTMLDocument.java
(BlockElement.getName): Should use getAttribute because the API 
says that this function can return null.
(RunElement): New class implemented.
(RunElement.getName): Implemented.
(RunElement.getResolvingParent): Implemented.

Index: javax/swing/text/html/HTMLDocument.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.8
diff -u -r1.8 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java	13 Dec 2005 16:13:08 -	1.8
+++ javax/swing/text/html/HTMLDocument.java	13 Dec 2005 17:04:51 -
@@ -308,10 +308,57 @@
   return null;
 }
 
+/**
+ * Gets the name of the element.
+ * 
+ * @return the name of the element if it exists, null otherwise.
+ */
 public String getName()
 {
-  //FIXME: this is supposed to do something different from the super class
-  return super.getName();
+  return (String) getAttribute(NameAttribute); 
+}
+  }
+  
+  /**
+   * RunElement represents a section of text that has a set of 
+   * HTML character level attributes assigned to it.
+   */
+  public class RunElement extends AbstractDocument.LeafElement
+  {
+
+/**
+ * Constructs an element that has no children. It represents content
+ * within the document.
+ * 
+ * @param parent - parent of this
+ * @param a - elements attributes
+ * @param start - the start offset >= 0
+ * @param end - the end offset 
+ */
+public RunElement(Element parent, AttributeSet a, int start, int end)
+{
+  super(parent, a, start, end);
+}
+
+/**
+ * Gets the name of the element.
+ * 
+ * @return the name of the element if it exists, null otherwise.
+ */
+public String getName()
+{
+  return (String) getAttribute(NameAttribute);  
+}
+
+/**
+ * Gets the resolving parent. HTML attributes do not inherit at the
+ * model level, so this method returns null.
+ * 
+ * @return null
+ */
+public AttributeSet getResolveParent()
+{
+  return null;
 }
   }
   
@@ -319,7 +366,6 @@
* A reader to load an HTMLDocument with HTML structure.
* 
* @author Anthony Balkissoon abalkiss at redhat dot com
-   *
*/
   public class HTMLReader extends HTMLEditorKit.ParserCallback
   {
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] Patch: HTMLDocument fix

2005-12-09 Thread Lillian Angel
I committed this just so the mauve test compiles. It is not implemented
yet.

2005-12-09  Lillian Angel  <[EMAIL PROTECTED]>

* javax/swing/text/html/HTMLDocument.java
(getReader): Added function. Not implemented. It was
added so a certain mauve test committed compiles with
classpath fine.

Index: javax/swing/text/html/HTMLDocument.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/text/html/HTMLDocument.java,v
retrieving revision 1.6
diff -u -r1.6 HTMLDocument.java
--- javax/swing/text/html/HTMLDocument.java	19 Oct 2005 14:37:56 -	1.6
+++ javax/swing/text/html/HTMLDocument.java	9 Dec 2005 17:50:37 -
@@ -265,4 +265,16 @@
   return super.getName();
 }
   }
+  
+  /**
+   * Gets the reader for the parser to use when loading the document with HTML. 
+   * 
+   * @param pos - the starting position
+   * @return - the reader
+   */
+  public HTMLEditorKit.ParserCallback getReader(int pos)
+  {
+// FIXME: Not implemented.
+return null;
+  }
 }
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] [Patch] HTMLDocument

2005-04-12 Thread Michael Koch
Hi list,


I just commited the attached patch to add a new file written by Audrius.


Michael


2005-04-12  Audrius Meskauskas, Lithuania  <[EMAIL PROTECTED]>

* javax/swing/text/html/HTMLDocument.java: New file.

Index: javax/swing/text/html/HTMLDocument.java
===
RCS file: javax/swing/text/html/HTMLDocument.java
diff -N javax/swing/text/html/HTMLDocument.java
--- /dev/null   1 Jan 1970 00:00:00 -
+++ javax/swing/text/html/HTMLDocument.java 12 Apr 2005 17:02:42 -
@@ -0,0 +1,53 @@
+/* HTMLDocument.java --
+   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., 59 Temple Place, Suite 330, Boston, MA
+02111-1307 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 javax.swing.text.html;
+
+import javax.swing.text.DefaultStyledDocument;
+
+/**
+ * TODO: This class is not yet completetely implemented.
+ *
+ * @author Audrius Meskauskas, Lithuania ([EMAIL PROTECTED])
+ */
+public class HTMLDocument extends DefaultStyledDocument
+{
+  public void processHTMLFrameHyperlinkEvent(HTMLFrameHyperlinkEvent event)
+  {
+  }
+}
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches