Example usage for javax.swing.text.rtf RTFEditorKit read

List of usage examples for javax.swing.text.rtf RTFEditorKit read

Introduction

In this page you can find the example usage for javax.swing.text.rtf RTFEditorKit read.

Prototype

public void read(Reader in, Document doc, int pos) throws IOException, BadLocationException 

Source Link

Document

Insert content from the given stream, which will be treated as plain text.

Usage

From source file:org.obm.push.tnefconverter.RTFUtils.java

private static String extractRtfText(InputStream stream) throws IOException, BadLocationException {
    RTFEditorKit kit = new RTFEditorKit();
    Document doc = kit.createDefaultDocument();
    kit.read(stream, doc, 0);

    return doc.getText(0, doc.getLength());
}

From source file:org.silverpeas.core.index.indexing.parser.rtfParser.RtfParser.java

public void outPutContent(Writer out, String path, String encoding) throws IOException {

    FileInputStream in = null;/*w w  w.  j  a v  a2s. c  o  m*/
    try {
        in = new FileInputStream(path);
        byte[] buffer = new byte[in.available()];
        in.read(buffer, 0, in.available());

        // RTF always uses ASCII, so we don't need to care about the encoding
        String input = new String(buffer);

        String result = null;
        try {
            // use build in RTF parser from Swing API
            RTFEditorKit rtfEditor = new RTFEditorKit();
            Document doc = rtfEditor.createDefaultDocument();
            rtfEditor.read(new StringReader(input), doc, 0);

            result = doc.getText(0, doc.getLength());
        } catch (Exception e) {
            SilverTrace.warn("indexing", "RtfParser.outPutContent()", "", e);
        }
        out.write(result);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:org.silverpeas.search.indexEngine.parser.rtfParser.RtfParser.java

public void outPutContent(Writer out, String path, String encoding) throws IOException {

    FileInputStream in = null;// www.  j a  va2s.  co m
    try {
        in = new FileInputStream(path);
        byte[] buffer = new byte[in.available()];
        in.read(buffer, 0, in.available());

        // RTF always uses ASCII, so we don't need to care about the encoding
        String input = new String(buffer);

        // workaround to remove RTF keywords that cause a NPE in Java 1.4
        // this is a known bug in Java 1.4 that was fixed in 1.5
        // please see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5042109 for
        // the official bug report
        // input = TS_REMOVE_PATTERN.matcher(input).replaceAll("");

        String result = null;
        try {
            // use build in RTF parser from Swing API
            RTFEditorKit rtfEditor = new RTFEditorKit();
            Document doc = rtfEditor.createDefaultDocument();
            rtfEditor.read(new StringReader(input), doc, 0);

            result = doc.getText(0, doc.getLength());
        } catch (Exception e) {
            SilverTrace.warn("indexEngine", "RtfParser.outPutContent()", "", e);
        }

        SilverTrace.debug("indexEngine", "RtfParser.outPutContent", "root.MSG_GEN_EXIT_METHOD", result);

        out.write(result);
    } finally {
        IOUtils.closeQuietly(in);
    }
}

From source file:sernet.gs.ui.rcp.gsimport.TransferData.java

public static String convertRtf(String notizText) throws IOException, BadLocationException {
    StringReader reader = new StringReader(notizText);
    RTFEditorKit kit = new RTFEditorKit();
    Document document = kit.createDefaultDocument();
    kit.read(reader, document, 0);
    // return plaintext
    return document.getText(0, document.getLength());
}