I'm using JTextPane as simple html editor.
jtp=new JTextPane();
jtp.setContentType("text/html;charset=UTF-8");
jtp.setEditorKit(new HTMLEditorKit());
When I call jtp.getText() I get nice html code with all special chars escaped. But I don't want escape national characters (polish) but only special html chars like &, <, > When I enter in editor
<foo>ą ś &
I get
<foo>ą ś &
but I would like get
<foo>ą ś &
How it is possile?
It is not possible, all characters above code 127 are translated to a numeric entity & # number ;. The HTML-entities are translated into named entities & lt ; , and so on. So you may easily resubstitute them. (This is done in HTMLWriter.output, and there seems to be no provision for character sets whatsoever.)
That's not possible, unfortunately.
There's a flaw inside javax.swing.text.html.HTMLWriter -- it is hardcoded to convert any symbol that is not ASCII to its numeric representation:
This logic cannot be controlled in any way.
BUT If you really really need that functionality you could do the crazy stuff:
HTMLWriterHack
(in the same packagejavax.swing.text.html
and renaming all strings inside)output
lines with something likeoutput(String.valueOf(chars[counter]));
HTMLDocumentHack
(in the same packagejavax.swing.text.html
, renaming all strings inside, making it extendHTMLDocument
and removing clashing methods)Although the steps above work (I tested it), I certainly wouldn't recommend doing that.