javax.swing.text.rtf.RTFEditorKit源码实例Demo

类javax.swing.text.rtf.RTFEditorKit源码实例Demo

下面列出了javax.swing.text.rtf.RTFEditorKit 类实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: Quelea   文件: SundayPlusParser.java
private String getLyrics(String raw) {
    try {
        RTFEditorKit rtfParser = new RTFEditorKit();
        Document document = rtfParser.createDefaultDocument();
        rtfParser.read(new ByteArrayInputStream(raw.getBytes()), document, 0);
        String text = document.getText(0, document.getLength());
        StringBuilder textBuilder = new StringBuilder();
        for (String line : text.split("\n")) {
            textBuilder.append(line.trim()).append("\n");
        }
        return textBuilder.toString().replaceAll("[\n]{2,}", "\n\n").replace("^", "'").trim();
    } catch (Exception ex) {
        LOGGER.log(Level.WARNING, "Invalid RTF string, trying old method");
        return getLyricsOld(raw);
    }
}
 
源代码2 项目: openjdk-jdk9   文件: RTFWriteParagraphAlignTest.java
public static void main(String[] args) throws Exception{
    rtfEditorKit = new RTFEditorKit();
    robot = new Robot();

    SwingUtilities.invokeAndWait(() -> {
        frame = new JFrame();
        frame.setUndecorated(true);
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.setSize(600, 200);
        jTextPane = new JTextPane();
        frame.getContentPane().add(jTextPane);
        frame.setVisible(true);
    });

    test(StyleConstants.ALIGN_LEFT);
    test(StyleConstants.ALIGN_CENTER);
    test(StyleConstants.ALIGN_RIGHT);
    test(StyleConstants.ALIGN_JUSTIFIED);

    SwingUtilities.invokeAndWait(()->frame.dispose());

    System.out.println("ok");
}
 
/**
 * {@inheritDoc}
 */
public String extractText(InputStream stream, String type, String encoding) throws IOException {

	try {
		RTFEditorKit rek = new RTFEditorKit();
		DefaultStyledDocument doc = new DefaultStyledDocument();
		rek.read(stream, doc, 0);
		String text = doc.getText(0, doc.getLength());
		return text;
	} catch (Throwable e) {
		logger.warn("Failed to extract RTF text content", e);
		throw new IOException(e.getMessage(), e);
	} finally {
		stream.close();
	}
}
 
源代码4 项目: Ic2ExpReactorPlanner   文件: HtmlSelection.java
private static String convertToRTF(final String htmlStr) {

        OutputStream os = new ByteArrayOutputStream();
        HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
        RTFEditorKit rtfEditorKit = new RTFEditorKit();
        String rtfStr = null;

        String tempStr = htmlStr.replace("</font>", "#END_FONT#").replace("<br>", "#NEW_LINE#");
        InputStream is = new ByteArrayInputStream(tempStr.getBytes());
        try {
            Document doc = htmlEditorKit.createDefaultDocument();
            htmlEditorKit.read(is, doc, 0);
            rtfEditorKit.write(os, doc, 0, doc.getLength());
            rtfStr = os.toString();
            rtfStr = rtfStr.replace("#NEW_LINE#", "\\line ");
            rtfStr = rtfStr.replace("#END_FONT#", "\\cf0 ");
        } catch (IOException | BadLocationException e) {
            e.printStackTrace();
        }
        return rtfStr;
    }
 
private String convert(InputStream rtfDocumentInputStream) throws IOException {
  RTFEditorKit aRtfEditorkit = new RTFEditorKit();

  StyledDocument styledDoc = new DefaultStyledDocument();

  String textDocument;

  try {
    aRtfEditorkit.read(rtfDocumentInputStream, styledDoc, 0);

    textDocument = styledDoc.getText(0, styledDoc.getLength());
  } catch (BadLocationException e) {
    throw new IOException("Error during parsing");
  }

  return textDocument;
}
 
源代码6 项目: Quelea   文件: MissionPraiseParser.java
/**
 * Parse the file to get the songs.
 * <p>
 * @param file the RTF file.
 * @param statusPanel the status panel to update.
 * @return a list of the songs found in the Songs.MB file.
 * @throws IOException if something went wrong with the import.
 */
@Override
public List<SongDisplayable> getSongs(File file, StatusPanel statusPanel) throws IOException {
    List<SongDisplayable> ret = new ArrayList<>();
    String text = Utils.getTextFromFile(file.getAbsolutePath(), "", "CP1250");
    text = text.replace("’", "'");
    try {
        if (!text.isEmpty()) {
            RTFEditorKit rtfParser = new RTFEditorKit();
            Document document = rtfParser.createDefaultDocument();
            rtfParser.read(new ByteArrayInputStream(text.getBytes("CP1250")), document, 0);
            String plainText = document.getText(0, document.getLength());
            String title = getTitle(plainText);
            String lyrics = getLyrics(plainText);
            String author = getAuthor(plainText);
            String copyright = getCopyright(plainText);
            
            SongDisplayable song = new SongDisplayable(title, author);
            song.setLyrics(lyrics);
            song.setCopyright(copyright);
            ret.add(song);
        }
    } catch (IOException | BadLocationException ex) {
        LOGGER.log(Level.WARNING, "Error importing mission praise", ex);
    }
    return ret;
}
 
源代码7 项目: Quelea   文件: ProPresenterParser.java
private String stripRtfTags(String text) {
	RTFEditorKit rtfParser = new RTFEditorKit();
	javax.swing.text.Document document = rtfParser.createDefaultDocument();
	try {
		rtfParser.read(new ByteArrayInputStream(text.getBytes("UTF-8")), document, 0);
		return document.getText(0, document.getLength());
	} catch (IOException | BadLocationException ex) {
		LOGGER.log(Level.SEVERE, "Error stripping RTF tags", ex);
		return text;
	}
}
 
源代码8 项目: document-management-software   文件: RTFParser.java
protected String extractText(InputStream input) throws IOException, BadLocationException {
	RTFEditorKit rek = new RTFEditorKit();
	DefaultStyledDocument doc = new DefaultStyledDocument();
	rek.read(input, doc, 0);
	String text = doc.getText(0, doc.getLength());
	return text;
}
 
源代码9 项目: netbeans   文件: EditorSanityTest.java
public void testTextRtfEditorKits() {
    JEditorPane pane = new JEditorPane();
    setContentTypeInAwt(pane, "text/rtf");
    
    // Test JDK kit
    EditorKit kitFromJdk = pane.getEditorKit();
    assertNotNull("Can't find JDK kit for text/rtf", kitFromJdk);
    assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit);
}
 
源代码10 项目: netbeans   文件: EditorSanityTest.java
public void testApplicationRtfEditorKits() {
    JEditorPane pane = new JEditorPane();
    setContentTypeInAwt(pane, "application/rtf");
    
    // Test JDK kit
    EditorKit kitFromJdk = pane.getEditorKit();
    assertNotNull("Can't find JDK kit for application/rtf", kitFromJdk);
    assertTrue("Wrong JDK kit for application/rtf", kitFromJdk instanceof RTFEditorKit);
}
 
源代码11 项目: birt   文件: RTFParser.java
public static void parse( String rtfString, RTFDocumentHandler handler )
		throws IOException, BadLocationException
{
	RTFEditorKit rtfeditorkit = new RTFEditorKit( );
	DefaultStyledDocument document = new DefaultStyledDocument( );
	ByteArrayInputStream bytearrayinputstream = new ByteArrayInputStream( rtfString.getBytes( ) );
	rtfeditorkit.read( bytearrayinputstream, document, 0 );
	Element element = document.getDefaultRootElement( );
	parseElement( document, element, handler, true );
}
 
源代码12 项目: pentaho-reporting   文件: RtfRichTextConverter.java
public RtfRichTextConverter() {
  editorKit = new RTFEditorKit();
}
 
如果文章对您有帮助,请点击页面广告。以鼓励作者做出的努力。
 类所在包
 类方法
 同包方法