Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER Copyright 2010 IBM. All rights reserved. Use is subject to license terms. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. You can also obtain a copy of the License at http://odftoolkit.org/docs/license.txt Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. /
 
 package org.odftoolkit.simple.common;
 
 import java.util.List;
 
It's a sub class of TextExtractor, which provides a method getText() to return all the text that the user can typically edit in a document, including text in cotent.xml, header and footer in styles.xml, meta data in meta.xml.

This function can be used by search engine, and text analytic operations.

 
 public class EditableTextExtractor extends TextExtractor {
 
 	Document mDocument = null;
 	boolean mIsDocumentExtractor = false;

An instance of EditableTextExtractor will be created to extract the editable text content in specified document.

Parameters:
doc the document whose text will be extracted.
Returns:
An instance of EditableTextExtractor
 
 		return new EditableTextExtractor(doc);
 	}

An instance of EditableTextExtractor will be created to extract the editable text content of an ODF element.

Parameters:
element the ODF element whose text will be extracted.
Returns:
An instance of EditableTextExtractor
 
 		return new EditableTextExtractor(element);
 	}

Return the text content of a element as String

Parameters:
ele the ODF element
Returns:
the text content of the element
 
 	public static synchronized String getText(OdfElement ele) {
 		return extractor.getText();
 	}

Return the text content of document as String

Parameters:
doc the document
Returns:
the text content of the document
	public static synchronized String getText(Document doc) {
		return extractor.getText();
	}

Return the editable text content as a string

Returns:
the editable text content as a string
	public String getText() {
			return getDocumentText();
else {
		}
	}

Constructor with a document as parameter

Parameters:
doc the document whose editable text would be extracted.
		super();
		 = doc;
	}

Constructor with an ODF element as parameter

Parameters:
element the ODF element whose editable text would be extracted.
	private EditableTextExtractor(OdfElement element) {
		super(element);
	}

The end users needn't to care of this method, if you don't want to override the text content handling strategy of draw:object.

	public void visit(DrawObjectElement element) {
		String embedDocPath = element.getXlinkHrefAttribute();
		Document embedDoc = ((Document) (((OdfContentDomelement.getOwnerDocument()).getDocument()))
				.getEmbeddedDocument(embedDocPath);
		if (embedDoc != null) {
			try {
				.append(EditableTextExtractor.newOdfEditableTextExtractor(embedDoc).getText());
catch (Exception e) {
			}
		}
	}

The end users needn't to care of this method, if you don't want to override the text content handling strategy of text:tracked-changes.

	public void visit(TextTrackedChangesElement ele) {
		return;
	}

The end users needn't to care of this method, if you don't want to override the text content handling strategy of text:a.

	public void visit(TextAElement ele) {
	}

The end users needn't to care of this method, if you don't want to override the text content handling strategy of table:table.

	public void visit(TableTableElement ele) {
		Table table = Table.getInstance(ele);
		List<Rowrowlist = table.getRowList();
		int column = table.getColumnCount();
		for (int i = 0; i < rowlist.size(); i++) {
			Row row = rowlist.get(i);
			for (int j = 0; j < columnj++) {
			}
		}
	}
	private String getDocumentText() {
		StringBuilder builder = new StringBuilder();
		try {
			// Extract text from content.xml
			builder.append(contentDomExtractor.getText());
			// Extract text from style.xml
			if (styleDom != null) {
				StyleMasterPageElement masterpage = null;
				NodeList list = styleDom.getElementsByTagName("style:master-page");
				if (list.getLength() > 0) {
					masterpage = (StyleMasterPageElementlist.item(0);
				}
				if (masterpage != null) {
				}
			}
			// Extract text from meta.xml
			if (metaDom != null) {
				OdfElement root = metaDom.getRootElement();
				OfficeMetaElement officemeta = OdfElement.findFirstChildNode(OfficeMetaElement.classroot);
				if (officemeta != null) {
				}
			}
			return builder.toString();
catch (Exception e) {
			return builder.toString();
		}
	}
New to GrepCode? Check out our FAQ X