Go Back   Velocity Reviews > Newsgroups > Java
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

Java - HTMLEditorKit is throwing exception

 
Thread Tools Search this Thread
Old 04-20-2004, 05:37 PM   #1
Default HTMLEditorKit is throwing exception


Hi!

What is wrong with this code:

HTMLDocument html = new HTMLDocument();
try {
HTMLEditorKit kit = new HTMLEditorKit();
URL url = new URL("http://www.google.com/");
kit.read(new BufferedReader(new
InputStreamReader(url.openStream())), html, 0);
}
catch (Exception e) {
System.err.println("Error");
}

Exception is thrown every time. (Yes, I am connected to the Internet
and I can read from reader - I have tryed reading from new
BufferedReader(new InputStreamReader(url.openStream())) Reader and it
works.)


Mike


Mike Mimic
  Reply With Quote
Old 04-20-2004, 06:14 PM   #2
Bryce (Work)
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
On Tue, 20 Apr 2004 18:37:49 +0200, Mike Mimic <>
wrote:

>Hi!
>
>What is wrong with this code:
>
>HTMLDocument html = new HTMLDocument();
>try {
> HTMLEditorKit kit = new HTMLEditorKit();
> URL url = new URL("http://www.google.com/");
> kit.read(new BufferedReader(new
> InputStreamReader(url.openStream())), html, 0);
>}
>catch (Exception e) {
> System.err.println("Error");
>}
>
>Exception is thrown every time. (Yes, I am connected to the Internet
>and I can read from reader - I have tryed reading from new
>BufferedReader(new InputStreamReader(url.openStream())) Reader and it
>works.)


What's the Exception? Just printing "error" doesn't tell you much. Try
e.printStackTrace();

--
now with more cowbell


Bryce (Work)
  Reply With Quote
Old 04-20-2004, 06:19 PM   #3
Mike Mimic
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
Hi!

Bryce (Work) wrote:
> What's the Exception? Just printing "error" doesn't tell you much. Try
> e.printStackTrace();


Good idea.

I have been reading message but it was null.

Here it is:

javax.swing.text.ChangedCharSetException
at javax.swing.text.html.parser.DocumentParser.handle EmptyTag(Unknown
Source)
at javax.swing.text.html.parser.Parser.startTag(Unkno wn Source)
at javax.swing.text.html.parser.Parser.parseTag(Unkno wn Source)
at javax.swing.text.html.parser.Parser.parseContent(U nknown Source)
at javax.swing.text.html.parser.Parser.parse(Unknown Source)
at javax.swing.text.html.parser.DocumentParser.parse( Unknown Source)
at javax.swing.text.html.parser.ParserDelegator.parse (Unknown Source)
at javax.swing.text.html.HTMLEditorKit.read(Unknown Source)
at test.main(test.java:1

Does not tell me much. Empty tag?


Mike


Mike Mimic
  Reply With Quote
Old 04-20-2004, 07:17 PM   #4
Chris Smith
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
Mike Mimic wrote:
> Here it is:
>
> javax.swing.text.ChangedCharSetException


Mike,

When you provide a Reader to HTMLEditorKit to retrieve an HTML page,
you're giving it a character stream that isn't encoded at all. If it
encounters a meta tag in the HTML source that tries to change the
encoding, it will therefore throw an exception, because it has no way to
honor that request.

You can set a property on the document to tell it to ignore this. The
code looks like this:

doc.putProperty("IgnoreCharsetDirective", new Boolean(true));

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Chris Smith
  Reply With Quote
Old 04-20-2004, 07:37 PM   #5
Mike Mimic
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
Hi!

Chris Smith wrote:
> When you provide a Reader to HTMLEditorKit to retrieve an HTML page,
> you're giving it a character stream that isn't encoded at all.


Encoded to what?

How can I then encode stream so that HTMLEditorKit will be able to
change the encoding?


Mike


Mike Mimic
  Reply With Quote
Old 04-20-2004, 08:19 PM   #6
Chris Smith
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
Mike Mimic wrote:
> Encoded to what?
>
> How can I then encode stream so that HTMLEditorKit will be able to
> change the encoding?


Though I haven't tried it, I believe you may have better luck if you
used InputStream instead of Reader. Alternatively, just set that
property.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Chris Smith
  Reply With Quote
Old 04-20-2004, 11:33 PM   #7
Mike Mimic
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
Hi!

Chris Smith wrote:
> Though I haven't tried it, I believe you may have better luck if you
> used InputStream instead of Reader. Alternatively, just set that
> property.


I had only BufferStream (chained to InputStream) but it was the same.


Mike


Mike Mimic
  Reply With Quote
Old 04-21-2004, 02:01 AM   #8
Chris Smith
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
Mike Mimic wrote:
> Chris Smith wrote:
> > Though I haven't tried it, I believe you may have better luck if you
> > used InputStream instead of Reader. Alternatively, just set that
> > property.

>
> I had only BufferStream (chained to InputStream) but it was the same.


Yep, after looking into it, turns out that the default parser just gives
up anyway, rather than switching encodings. Set that property and avoid
the whole mess.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation


Chris Smith
  Reply With Quote
Old 04-21-2004, 11:14 AM   #9
Mike Mimic
 
Posts: n/a
Default Re: HTMLEditorKit is throwing exception
Hi!

Chris Smith wrote:
> Yep, after looking into it, turns out that the default parser just gives
> up anyway, rather than switching encodings. Set that property and avoid
> the whole mess.


I have. It works now. Thanks.


Mike


Mike Mimic
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
java.net.SocketException: Broken pipe exception at HttpServletRequest sadasivar Software 0 03-11-2008 04:40 AM
exception unknown software exception error - Excel.exe mfinamore Software 0 11-15-2007 04:54 PM
Exception in thread "main" java.lang.NoClassDefFoundError: prakash.nmsp@gmail.com Software 0 06-29-2007 10:03 AM
Help on PrincipalPermission Demand Throwing Exception Abba Biya MCTS 1 02-07-2007 10:05 PM
how to overcome the nullpointer exception arputharaj Software 0 11-11-2006 07:05 AM




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46