开发者

Does GWT have richtextbox which show RTF type data?

I'm using GWT Richtextbox, But this widget shows values which are simple text or HTML formatted. Is there any way to show RTF data in a GWT-Richtext or GWT-htmlEditor widg开发者_运维知识库et? Or is there a widget in other GWT libraries which will do this?


I don't think so. About year ago we wanted to develop rtf browser on client side and we failed. There is no GWT-Rtf libraries. You could try to find something written in javascript and then wrap it with JSNI, but I haven't seen such library as well. Someone told me that it might be possible with Activex, but we haven't even tried this method.


What are you trying to achieve? If you want to share documents with an RTF editor like, say, Microsoft Word, you should check to see if that editor can also work with HTML. I know that MS Word can edit HTML.

Alternatively, you might consider transposing RTF into HTML and back again on the server side. There are several Java libraries out there for doing that, and I believe that Flying Saucer is one of them.


You could use RTFEditorKit in combination with HTMLEditorKit to convert between the two server-side or in an applet. This way you can use GWT's rich text editor and output or input RTF.

public static String getHtmlFromRtf(InputStream fi){
    Writer sOut = new StringWriter();
    DefaultStyledDocument doc = new DefaultStyledDocument();                  
    HTMLEditorKit htmlKit = new HTMLEditorKit();                  
    RTFEditorKit rtf = new RTFEditorKit();

    try
    {
        rtf.read( fi, doc, 0 );
        htmlKit.write(sOut, doc, 0, doc.getLength());
    }
    catch (IOException e)
    {
        e.printStackTrace();
    }
    catch (BadLocationException e)
    {
        e.printStackTrace();
    }
    return sOut.toString();
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜