当前位置: 首页>>代码示例>>Java>>正文


Java DefaultStyledDocument.getText方法代码示例

本文整理汇总了Java中javax.swing.text.DefaultStyledDocument.getText方法的典型用法代码示例。如果您正苦于以下问题:Java DefaultStyledDocument.getText方法的具体用法?Java DefaultStyledDocument.getText怎么用?Java DefaultStyledDocument.getText使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.swing.text.DefaultStyledDocument的用法示例。


在下文中一共展示了DefaultStyledDocument.getText方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: extractText

import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
 * {@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();
	}
}
 
开发者ID:openkm,项目名称:document-management-system,代码行数:19,代码来源:RTFTextExtractor.java

示例2: getFormatedDocument

import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
public StyledDocument getFormatedDocument(String content){
	StyleContext context = new StyleContext();
	DefaultStyledDocument document = new DefaultStyledDocument(context);
	try{
		String tagedText= translateLine(content, false);
		int pointer=0;
		int tagIndex=0;
		while(tagedText.indexOf(BalloonTemplateHandler.START_TAG,pointer)!=-1){
			tagIndex=tagedText.indexOf(BalloonTemplateHandler.START_TAG,pointer);
			// Is there any character before the strat tag which is not parsed yet?
			if (tagIndex!=pointer){
				document.insertString(document.getLength(), tagedText.substring(pointer, tagIndex), NewCSVColumnDialog.getDefaultStyle());
				pointer = tagIndex;
			}
			pointer+=BalloonTemplateHandler.START_TAG.length();
			tagIndex=tagedText.indexOf(BalloonTemplateHandler.END_TAG,pointer);
			document.insertString(document.getLength(), tagedText.substring(pointer, tagIndex), NewCSVColumnDialog.getLabelStyle());
			pointer=tagIndex+BalloonTemplateHandler.END_TAG.length();
		}
		if (pointer!=tagedText.length()-1){
			document.insertString(document.getLength(), tagedText.substring(pointer,tagedText.length()), NewCSVColumnDialog.getDefaultStyle());
		}
		// check for [EOL]
		pointer=0;
		tagIndex=0;
		tagedText= document.getText(0, document.getLength());
		String lineSeparator=System.getProperty("line.separator");
		while(tagedText.indexOf(lineSeparator,pointer)!=-1){
			tagIndex=tagedText.indexOf(lineSeparator,pointer);
			document.remove(tagIndex,lineSeparator.length());
			document.insertString(tagIndex,NewCSVColumnDialog.EOL,
					NewCSVColumnDialog.getEOLStyle());
			pointer=tagIndex+NewCSVColumnDialog.EOL.length();
			tagedText= document.getText(0, document.getLength());
		}		
	}catch(Exception e){}
	return document;
}
 
开发者ID:3dcitydb,项目名称:plugin-spreadsheet-generator,代码行数:39,代码来源:Translator.java

示例3: parseElement

import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
private static void parseElement( DefaultStyledDocument document,
		Element parent, RTFDocumentHandler handler, boolean lostLast )
{
	for ( int i = 0; i < parent.getElementCount( ); i++ )
	{
		if (lostLast && i==parent.getElementCount( )-1 && parent.getElementCount( ) != 1)
		{
			break;
		}
		Element element = parent.getElement( i );
		AttributeSet attributeset = element.getAttributes( );
		handler.startElement( element.getName( ), attributeset );
		if ( element.getName( ).equalsIgnoreCase( "content" ) )
		{
			try
			{
				int start = element.getStartOffset( );
				int end = element.getEndOffset( );
				String s = document.getText( start, end - start );
				handler.content( s );
			}
			catch ( BadLocationException e )
			{
			}
		}
		parseElement( document, element, handler, false );
		handler.endElement( element.getName( ) );
	}
}
 
开发者ID:eclipse,项目名称:birt,代码行数:30,代码来源:RTFParser.java

示例4: action

import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
public void action()
{
	JEditorPane ed = getEditor();
	if(ed != null)
	{
		try
		{
			Caret ca = ed.getCaret();
			int beg = Math.min(ca.getMark(), ca.getDot());
			int end = Math.max(ca.getMark(), ca.getDot());
			if(beg == end)
			{
				// select word
				beg = getWordStart(ed, beg);
				end = getWordEnd(ed, end);
				if(beg < 0)
				{
					return;
				}
				else if(end < 0)
				{
					return;
				}
				else if(beg == end)
				{
					return;
				}
			}
			
			DefaultStyledDocument d = getStyledDocument(ed);
			String s = d.getText(beg, end - beg);
			Locale loc = CEditorKit.getLocale(ed);
			s = s.toLowerCase(loc);
			d.replace(beg, end - beg, s, null);
		}
		catch(Exception e)
		{
			Log.ex(e);
			UI.beep();
		}
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:43,代码来源:CEditorToLowerCaseAction.java

示例5: action

import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
public void action()
{
	JEditorPane ed = getEditor();
	if(ed != null)
	{
		try
		{
			Caret ca = ed.getCaret();
			int beg = Math.min(ca.getMark(), ca.getDot());
			int end = Math.max(ca.getMark(), ca.getDot());
			if(beg == end)
			{
				// select word
				beg = getWordStart(ed, beg);
				end = getWordEnd(ed, end);
				if(beg < 0)
				{
					return;
				}
				else if(end < 0)
				{
					return;
				}
				else if(beg == end)
				{
					return;
				}
			}
			
			DefaultStyledDocument d = getStyledDocument(ed);
			String s = d.getText(beg, end - beg);
			Locale loc = CEditorKit.getLocale(ed);
			s = s.toUpperCase(loc);
			d.replace(beg, end - beg, s, null);
		}
		catch(Exception e)
		{
			Log.ex(e);
			UI.beep();
		}
	}
}
 
开发者ID:andy-goryachev,项目名称:PasswordSafe,代码行数:43,代码来源:CEditorToUpperCaseAction.java

示例6: rtf2text

import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
public String rtf2text(InputStream is) throws Exception {
    DefaultStyledDocument styledDoc = new DefaultStyledDocument();
    new RTFEditorKit().read(is, styledDoc, 0);
    return styledDoc.getText(0, styledDoc.getLength());
}
 
开发者ID:mariosotil,项目名称:text-extractor,代码行数:6,代码来源:TextExtractor.java

示例7: getText

import javax.swing.text.DefaultStyledDocument; //导入方法依赖的package包/类
/**
 * Extract text from the Rich text file document 
 * @throws Exception 
 * 
 * @see edu.ur.ir.index.FileTextExtractor#getText(java.io.File)
 */
public String getText(File f) throws Exception {
	String text = null;
	// don't even try if the file is too large
	if( isFileTooLarge(f) || f.length() <= 0l)
	{
		return text;
	}
	DefaultStyledDocument styledDoc = new DefaultStyledDocument();
	RTFEditorKit editorKit = new RTFEditorKit();
	FileInputStream inputStream = null;
	
	try
	{
	    inputStream = new FileInputStream(f);
	    editorKit.read(inputStream, styledDoc, 0);
	    String myText = styledDoc.getText(0, styledDoc.getLength());
	    if( myText != null && !myText.trim().equals(""))
	    {
	    	text = myText;
	    }
	}
	catch(OutOfMemoryError oome)
	{
		text = null;
		log.error("could not extract text", oome);
		throw(oome);
	}
	catch(Exception e)
	{
		text = null;
		log.error("could not get text for rich text document " + f.getAbsolutePath(), e);
		throw(e);
	}
	
	finally
	{
		closeInputStream(inputStream);
		editorKit = null;
	}
	
	return text;
}
 
开发者ID:nate-rcl,项目名称:irplus,代码行数:49,代码来源:DefaultRtfTextExtractor.java


注:本文中的javax.swing.text.DefaultStyledDocument.getText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。