• Post Reply Bookmark Topic Watch Topic
  • New Topic

custom JEditorPane to support some HTML Entities  RSS feed

 
s Joshi
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
am using JEditorPane to load an html document from a file. My html file contains character like "& bull;" etc. These characters are not supported in HTML 3.2.

I am overridding html reader such that it doesn't convert "& bull;" to "& amp; bull;". I am also overriding html document writer such that it doesn't convert "& bull; " to "& amp; bull;". If I write my html file to another file it gives me desired result. But if I use jcontentPane.setDocument(doc), it writes "& amp; bull;" to the output. I can't figure out where its doing this conversion.

my code looks like this:

javax.swing.text.html.HTMLEditorKit kit = (javax.swing.text.html.HTMLEditorKit)htmlMailingEditor.getEditorKitForContentType("text/html");

try
{
kit.read(in,doc,0); //overiding html reader
FileWriter writer = new FileWriter(new File("c:\\temp.html"));
doc.write(writer); //overriding html writer
writer.flush();
writer.close();

htmlMailingEditor.setDocument(doc); // html content is changed
}
catch (Exception ex)
{
System.out.println("Exception - " + ex.toString());
javax.swing.JOptionPane.showMessageDialog
(applet, "Error reading Html. " + ex.toString(),
"Html Read error", javax.swing.JOptionPane.ERROR_MESSAGE);
return;
}
 
H Lander
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you can replace the entity names by their numeric equivalents then the JEditorPane will render them correctly. For example, "& bull;" can be replaced by "& 149;".

Good Luck,
Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!