Name: aaC67449 Date: 08/24/99
The javax.swing.text.html.HTMLEditorKit class adds whitespaces to the original
text after parsing. The javadoc should say about number and position of added
whitespaces.
Different versions of jdk add different number of whitespaces. See example.
------------- example --------------
import javax.swing.*;
import javax.swing.text.*;
import javax.swing.text.html.*;
import java.io.*;
import java.util.*;
import javax.accessibility.*;
public class Test extends JApplet{
public static void main(String argv[]) {
(new Test()).init();
}
public void init() {
String test1="<!DOCTYPE HTML PUBLIC \"-//w3c//DTD html 3.2//EN\"><HTML><HEAD><TITLE>test</TITLE></HEAD></head><body><P><A Href=\"index.html\">Test1</A></P></body></html>";
String test2="<!DOCTYPE HTML PUBLIC \"-//w3c//DTD html 3.2//EN\"><HTML><HEAD><TITLE>test</TITLE></HEAD></head><body><P>Test2</P></body></html>";
JEditorPane o = new JEditorPane("text/html",test1);
AccessibleHyperlink c=(AccessibleHyperlink)((AccessibleHypertext)o.getAccessibleContext().getAccessibleText()).getLink(0);
System.out.println("HTMLLink.getStartIndex="+c.getStartIndex());
HTMLEditorKit kit = new HTMLEditorKit();
HTMLDocument doc=(HTMLDocument)kit.createDefaultDocument();
try {
kit.read(new StringReader(test2),doc,0);
System.out.println("HTMLDocument.getText(3,5)="+doc.getText(3,5));
} catch (Exception e){}
}
}
------------- jdk1.2.2 output ---------------
HTMLLink.getStartIndex=5
HTMLDocument.getText(3,5)=
Tes
------------- jdk1.2.2 output ---------------
HTMLLink.getStartIndex=3
HTMLDocument.getText(3,5)=Test2
======================================================================