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

text.html.HTMLDocument.insertAfterStart(Element,String) does not work correctly

XMLWordPrintable

    • kestrel
    • generic, sparc
    • generic, solaris_2.6



      Name: mgC56079 Date: 09/06/99



       In JDK 1.3 method HTMLDocument.insertAfterStart(Element, String) does not work
      correctly.

      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="<!DOCTYPE HTML PUBLIC \"-//w3c//DTD html 3.2//EN\">"
                  +"<HTML><TITLE>test</TITLE>"
                  +"<BODY><P><SELECT>"
                  +"</SELECT></P></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);
          }

          System.out.println("-------------------------------------------");

          try{
              StringWriter sw1 = new StringWriter();
              HTMLWriter w1 = new HTMLWriter(sw1, doc);
              w1.write();
              System.out.println(sw1.toString());
          } catch(Exception e3) {
              System.out.println("Unexpected exception " + e3);
          }

          System.out.println("-------------------------------------------");

          Element el = doc.getDefaultRootElement().getElement(1).getElement(0);

          System.out.println("Element: " + el.getName() + ", " + el.toString());

          try {
              doc.insertAfterStart(el, "<H1>test</H1>");
          } catch(Exception e) {
              System.out.println("Unexpected exception " + e);
          }

          System.out.println("-------------------------------------------");
          try{
              StringWriter sw = new StringWriter();
              HTMLWriter w = new HTMLWriter(sw, doc);
              w.write();
              System.out.println(sw.toString());
          } catch(Exception e3) {
              System.out.println("Unexpected exception " + e3);
          }

          }
      }


      --------------------------------------------------------------------------------------------------------------------------

      Output :
      -------------------------------------------
      <html>
        <head>
          <title>test </title>

        </head>
        <body>
          <p>
            <select>
            </select>

          </p>
        </body>
      </html>

      -------------------------------------------
      Element: p, BranchElement(p) 3,5

      -------------------------------------------
      <html>
        <head>
          <title>test </title>

        </head>
        <body>
          <p>
            <select>
            </select>

          </p>
        </body>
      </html>

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

            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: