本文整理汇总了Java中javax.swing.text.rtf.RTFEditorKit.createDefaultDocument方法的典型用法代码示例。如果您正苦于以下问题:Java RTFEditorKit.createDefaultDocument方法的具体用法?Java RTFEditorKit.createDefaultDocument怎么用?Java RTFEditorKit.createDefaultDocument使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.swing.text.rtf.RTFEditorKit
的用法示例。
在下文中一共展示了RTFEditorKit.createDefaultDocument方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RTF2TXT
import javax.swing.text.rtf.RTFEditorKit; //导入方法依赖的package包/类
public static final String RTF2TXT(String Str)
throws IOException, BadLocationException
{
if (Str != null && Str.startsWith("{\\rtf1") == true)
{
// There is a "questionable" bug in the RTF-to-Text routine in the Java library. With tables, text in
// adjacent cells are concatenated without any
// spacing. So, for example, a table with a cell containing "abc" followed by another call containing "123",
// after conversion, you'll get "abc123".
// With this hack, we capture the RTF cell delimiter "\cell$" and replace it with ". \cell$". This will
// separate text in cells from other text and will
// allow text processing to give better results.
Str = RTF_CELL_PATTERN.matcher(Str).replaceAll(". $0");
RTFEditorKit RTF = new RTFEditorKit();
Document doc = RTF.createDefaultDocument();
RTF.read(new StringReader(Str), doc, 0);
Str = doc.getText(0, doc.getLength());
}
return Str;
}
示例2: installWidgetsFromRTF
import javax.swing.text.rtf.RTFEditorKit; //导入方法依赖的package包/类
/**
* @param db The {@link Dragboard} containing the dragged data.
* @param selection_tracker Used to get the grid steps from its model to be
* used in offsetting multiple widgets.
* @param widgets The container of the created widgets.
*/
private static void installWidgetsFromRTF (
final DragEvent event,
final SelectedWidgetUITracker selection_tracker,
final List<Widget> widgets
) {
final Dragboard db = event.getDragboard();
final String rtf = db.getRtf();
final RTFEditorKit rtfParser = new RTFEditorKit();
final Document document = rtfParser.createDefaultDocument();
try {
rtfParser.read(new ByteArrayInputStream(rtf.getBytes()), document, 0);
installWidgetsFromString(event, document.getText(0, document.getLength()), selection_tracker, widgets);
} catch ( Exception ex ) {
logger.log(Level.WARNING, "Invalid RTF string", ex);
}
}
示例3: parseContent
import javax.swing.text.rtf.RTFEditorKit; //导入方法依赖的package包/类
@Override
protected void parseContent(StreamLimiter streamLimiter, LanguageEnum lang)
throws IOException {
RTFEditorKit rtf = new RTFEditorKit();
Document doc = rtf.createDefaultDocument();
try {
ParserResultItem result = getNewParserResultItem();
rtf.read(streamLimiter.getNewInputStream(), doc, 0);
result.addField(ParserFieldEnum.content,
doc.getText(0, doc.getLength()).trim());
} catch (BadLocationException e) {
throw new IOException(e);
}
}
示例4: readFile
import javax.swing.text.rtf.RTFEditorKit; //导入方法依赖的package包/类
public static String readFile(String url) {
try {
byte[] array = new byte[4096];
RTFEditorKit rtfParser = new RTFEditorKit();
Document document = rtfParser.createDefaultDocument();
rtfParser.read(new URL(url).openStream(), document, 0);
return document.getText(0, document.getLength());
} catch (Exception e) {
}
return null;
}