ここに驚くべき行動があります。JTextPane を作成し、HTMLEditorKit を使用するように設定して、有効な HTML を入力します。しかし、デフォルトでは、Java の HTMLWriter は無効なHTML を作成します。ほとんどのアイテムは正しくシリアル化されていますが、img タグは終了スラッシュを失っているため、次のようになります。
<img src="https://localhost:9443/ccm/service/com.ibm.team.workitem.common.internal.model.IImageContentService/processattachment/_7rfpIMXdEeGLRroh_7O2yQ/workflow/resolve.gif" alt="Resolved" border="0"/>
は次のように書かれています。
<img src="https://localhost:9443/ccm/service/com.ibm.team.workitem.common.internal.model.IImageContentService/processattachment/_7rfpIMXdEeGLRroh_7O2yQ/workflow/resolve.gif" alt="Resolved" border="0">
すべてにデフォルトを使用しています。なぜうまくいかないのですか、簡単な修正方法はありますか?
コード スニペットを次に示します。
JTextPane editor = new JTextPane();
HTMLEditorKit htmlKit = new HTMLEditorKit();
editor.setContentType("text/html");
editor.setEditorKit(htmlKit);
editor.setText( '*<ADD SOME VALID HTML FROM A FILE>*' );
HTMLDocument d = (HTMLDocument)editor.getDocument();
StringWriter fw = new StringWriter();
HTMLWriter aHTMLWriter = new HTMLWriter(fw,d);
aHTMLWriter.write();
String txt = fw.toString();
// Now txt is not valid HTML ... eek!