Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4269725

javax.swing.text.html.HTMLDocument.getElement(String) does not work correctly

XMLWordPrintable

    • kestrel
    • sparc
    • solaris_2.6



      Name: mgC56079 Date: 09/08/99



       In JDK 1.3 method HTMLDocument.getElement(String) does not work
      correctly with tag <A>.

      An example:
      --------------------------------------------------------------------------------------------------------------------------

      import javax.swing.text.*;
      import javax.swing.text.html.*;
      import java.io.*;
      import java.util.*;

      public class Test {
          public static void main(String argv[]) {

          String test="<HTML><TITLE>test</TITLE>"
                  +"<BODY><A href=\"www.sun.com\" id=\"magicid\">"
                  +"test</A></BODY></HTML>";

          HTMLEditorKit c = new HTMLEditorKit();
          HTMLDocument doc = null;

          try {
              doc = new HTMLDocument();
              c.read(new StringReader(test),doc,0);
          } catch(Exception e) {
              System.out.println("Unexpected exception " + e);
          }

          Element e = doc.getElement("magicid");

          System.out.println("html: " + test);
          System.out.println("Element: " + e);

          }
      }
      --------------------------------------------------------------------------------------------------------------------------

      Output :
      html: <HTML><TITLE>test</TITLE><BODY><A href="www.sun.com"
      id="magicid">test</A></BODY></HTML>
      Element: null

      ======================================================================

      ###@###.### 1999-11-04
      The JavaDoc states:
      ----
      getElement
      public Element getElement(String id)

           Fetches the element that has the given id attribute. If the element can't
      be found, null is returned. This is not thread-safe.
           Since: 1.3
      ----

      After the fix output of the test example is:

      html: <HTML><TITLE>test</TITLE><BODY><A href="www.sun.com"
      id="magicid">test</A></BODY></HTML>
      Element: content

      this is what it should be according to javadoc:

      html: <HTML><TITLE>test</TITLE><BODY><A href="www.sun.com"
      id="magicid">test</A></BODY></HTML>
      Element: A

      So, the current behavior is not consistent with the
      current javadoc.

            svioletsunw Scott Violet (Inactive)
            gorsunw Gor Gor (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: