List of usage examples for javax.swing.text.rtf RTFEditorKit createDefaultDocument
public Document createDefaultDocument()
From source file:org.alder.fotobuchconvert.scribus.RtfToScribusConverter.java
public void convert(XmlBuilder xml, String input, ScribusWriter scribus) throws IOException, BadLocationException { if (input == null) return;/*from ww w . j a va2 s. c om*/ log.debug("RTF input: " + input); CharArrayReader rd = new CharArrayReader(input.toCharArray()); RTFEditorKit kit = new RTFEditorKit(); DefaultStyledDocument doc = (DefaultStyledDocument) kit.createDefaultDocument(); kit.read(rd, doc, 0); output(xml, doc, scribus); }
From source file:org.nuxeo.ecm.core.convert.plugins.text.extractors.RTF2TextConverter.java
@Override public BlobHolder convert(BlobHolder blobHolder, Map<String, Serializable> parameters) throws ConversionException { File f = null;//from w w w . j av a 2 s .co m try { RTFEditorKit rtfParser = new RTFEditorKit(); Document document = rtfParser.createDefaultDocument(); rtfParser.read(blobHolder.getBlob().getStream(), document, 0); String text = document.getText(0, document.getLength()); f = Framework.createTempFile("swing-rtf2text", ".txt"); FileUtils.writeStringToFile(f, text); Blob blob; try (InputStream in = new FileInputStream(f)) { blob = Blobs.createBlob(in, "text/plain"); } return new SimpleCachableBlobHolder(blob); } catch (IOException | BadLocationException e) { throw new ConversionException("Error during Word2Text conversion", e); } finally { if (f != null) { f.delete(); } } }
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);//from www .j ava 2 s . c om 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 va 2 s. com 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;//from ww w .j av a 2 s . 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);/*from ww w .ja va2s . co m*/ // return plaintext return document.getText(0, document.getLength()); }