Parsing HTML into DOM using HTMLEditorKit

I am trying to parse an HTML file using javax.swing.text.html.HTMLEditorKit. My limitations are that I cannot install new libraries like jtidy and I must use a .jsp file, not a servlet. I'm able to get the url and parse it using ParserCallBack, but the new handleText method will not write to the page. Further more I cannot pass anything out of this method to use later because it is void. I want to get some data back from this method or at least do something useful within it. Is that possible?

java.net.URL url =new java.net.URL("http://" + request.getServerName() +"/" + urls.get(i));

java.io.InputStream is = url.openStream();

java.io.InputStreamReader isr =new java.io.InputStreamReader(is);

java.io.BufferedReader br =new java.io.BufferedReader(isr);

javax.swing.text.html.HTMLEditorKit.ParserCallback callback =

new javax.swing.text.html.HTMLEditorKit.ParserCallback (){

publicvoid handleText(char[] data,int pos){

out.println(data);

}

};

new javax.swing.text.html.parser.ParserDelegator().parse(br, callback,false);

Attempting to print from within this method gives this error:

Attempt to use a non-final variable out from a different method. From enclosing blocks, only final local variables are available.

Maybe I need to try and write the output xml file all from inside the parserCallback?

[1891 byte] By [Koal_Bradleya] at [2007-11-27 11:16:15]
# 1

Those are rather stupid requirements. Okay, I can see the one about not using external libraries because nobody knows how to deal with the licences. But making you use a JSP instead of a servlet just gets in the way of writing the Java code which you could probably do perfectly well if you didn't have to cram it into a JSP scriptlet. Stupid.

But anyway: the error message says you need a final local variable. So don't just sit there, give it a final local variable. I forget just what type "out" is supposed to be, but something like "final JSPWriter fakeOut = out", followed by using "fakeOut" rather than "out" should work.

DrClapa at 2007-7-29 14:18:00 > top of Java-index,Java Essentials,Java Programming...