File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Swing / AWT / SWT and the fly likes HTMLEditorKit & Performance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "HTMLEditorKit & Performance" Watch "HTMLEditorKit & Performance" New topic
Author

HTMLEditorKit & Performance

emmanuel soyeux
Greenhorn

Joined: Aug 09, 2001
Posts: 4
I develop a java reporting tool which generates outputs in several formats(HTML,TXT,RTF...)
This component is accessible either a Client/Server Application written with Swing library , either a web-application.
When we use the swing application, a JEditorPane is used to retrieve the reports, associated with a correspondant EditorKit.
Even if the report is small (20 Ko), it takes time to display it in HTML..... and if you relaunch it many times, the application hangs up (memory leak ?)
With TXT, it is good and with the web-application too.
I suppose (and i'm sure with JBuilder !) that the problem is due to the read method called with HTMLEditorLit.read(inputstream,doc,pos)....
Thanks for your help.
clio katz
Ranch Hand

Joined: Apr 30, 2004
Posts: 101
Originally posted by emmanuel soyeux:
it takes time to display it in HTML..... and if you relaunch it many times, the application hangs up (memory leak ?)


hmmm. relaunch it many times? not in a hurry i hope:-)


just fishin' in the dark but have you tried apache's httpclient?

they have a nice sample that will write output to a JEditorPane, so you could do a litmus test:

http://cvs.apache.org/viewcvs.cgi/jakarta-commons/httpclient/src/examples/ClientApp.java?rev=1.11&only_with_tag=HTTPCLIENT_2_0_BRANCH&view=markup


i mention this because i've seen prev complaints about hangs because java doesn't support setting http connection timeout. this may or may not be related to your issue, but it might be interesting to see if this helps to isolate the problem (in the editor kit or otherwise)

good luck - let us know how it comes out!
emmanuel soyeux
Greenhorn

Joined: Aug 09, 2001
Posts: 4
The previous code from Apache is quite similar to my own one.
To be short,the problem occurs in these lines
JeditorPane editorPane; // already defined
InputStreamReader reader; // already defined
HTMLDocument doc = new HTMLDocument();
editorPane.read(reader, doc); => problem !!!

This takes a long time and the VM increases strongly!!
Same behaviour with using HTMLEditorKit, ......

What's wrong ?
clio katz
Ranch Hand

Joined: Apr 30, 2004
Posts: 101
i gave this a quick try and ... it wasn't so quick. however, performance was not horrible - especially for smaller or less complex documents.

just some ideas from a 10k ft view:

possible places to look(?) -

(1) Format of the HTML report(s) you're reading

JEditorpane - from what i can see - has about 15 html handling bugs being fixed in 1.5, including an important-looking META tag support bug.

API gives current HTML support at 3.2 (if in doubt, report
compliance could be verified w tool like jtidy also see last item below)


(2) issues related to _read (vs. using constructor or _setPage)

(a) *non* asynch vs asynch performance; (b) existence of
relative path refs (determination of basedir), (c) content type, etc.

(3) content itself
can be set/checked before/after instantiation.
any possibility of charset issues? is doc editable?


finally, there's a jeditorpane-based simple browser (platespiller ) out there that you could use as a baseline - to see if these reports display ok using that browser, and to check the rendering integrity and performance deltas


hth - good luck!
emmanuel soyeux
Greenhorn

Joined: Aug 09, 2001
Posts: 4
For all projects regarding a java browser for HTML Document, they always use JeditorPane with read or setPage method......

My own code concerning the HTML viewver of the application seems to the following lines :

JEditorPane editorPane= new JEditorPane();
editorPane.setEditable(false);
editorPane.setContentType("text/html; charset=ISO-8859-1");
HTMLEditorKit htmlKit = new HTMLEditorKit();
editorPane.setEditorKit(htmlKit);
Document doc = htmlKit.createDefaultDocument();
//To have the focus on this dialogBox...
JWindow wnd = new JWindow();
wnd.setContentPane(editorPane);
wnd.pack();
wnd.setVisible(true);
wnd.toFront();
editorPane.validate();

//Loading data...
try {
editorPane.read(in,doc);

} catch (Exception e) {
System.out.println(e); // => The second run fails !
}

JScrollPane editorScrollPane = new JScrollPane(editorPane);
editorScrollPane.setPreferredSize(new Dimension(500, 500));
editorScrollPane.setMinimumSize(new Dimension(100, 100));
editorScrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
editorScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);

setLayout(new GridBagLayout()); //The general panel which embedds the editorPane
addToGridBag....


The problem is awalys in the read method......
I have the feeling that some static objects associated to the editorkit, htmldocument...... are not properly cleaned
but when i close the window, all the objects are reset to null (and as they are locally, java can remove them from memory thanks to garbage collector..... but we can help this process.....)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: HTMLEditorKit & Performance