Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.odftoolkit.simple.text;
  
  import java.net.URI;
  import java.util.Iterator;
  
This class represents the application of a style to the character data of a portion of text.

It provides convenient methods to create a span and manipulate attributes of a span.

Since:
0.5.5
 
 public class Span extends Component implements TextHyperlinkContainer {
 
 
 	private Span(TextSpanElement element) {
 		 = element;
 		 = new DefaultStyleHandler(element);
 	}

Get a span instance by an instance of TextSpanElement.

Parameters:
sElement - the instance of TextSpanElement
Returns:
an instance of span
 
 	public static Span getInstanceof(TextSpanElement sElement) {
 		if (sElement == null)
 			return null;
 
 		Span span = null;
 		span = (Span) Component.getComponentByElement(sElement);
 		if (span != null)
 			return span;
 
 		span = new Span(sElement);
 		Component.registerComponent(spansElement);
 		return span;
 	}

Create a span instance with a text selection

Parameters:
text
Returns:
an instance of span
See also:
org.odftoolkit.simple.common.navigation.TextSelection
 
 	public static Span newSpan(TextSelection textSelection) {
 		try {
 			TextSpanElement element = textSelection.createSpanElement();
 			return Span.getInstanceof(element);
 		} catch (InvalidNavigationException e) {
 		}
 		return null;
 	}

Get the style handler of this span.

The style handler is an instance of DefaultStyleHandler

Returns:
an instance of DefaultStyleHandler
See also:
org.odftoolkit.simple.style.DefaultStyleHandler
 
 		if ( != null)
 			return ;
 		else {
 			return ;
 		}
 	}

Get the owner document of this span

Returns:
the document who owns this span
	}

Return the instance of "text:span" element

Returns:
the instance of "text:span" element
		return ;
	}

Remove the text content of this span.
	public void removeTextContent() {
		// remove empty hyperlink
		for (int i = 0; i < nodeList.getLength(); i++) {
			Node node;
			node = nodeList.item(i);
			if (node.getNodeType() == .) {
				String nodename = node.getNodeName();
				if (nodename.equals("text:a") && node.hasChildNodes() == false)
			}
		}
	}

Set the text content of this span.

All the existing text content of this paragraph would be removed, and then new text content would be set.

Parameters:
content - the text content
	public void setTextContent(String content) {
		Node lastNode = getOdfElement().getLastChild();
		if (lastNode.getNodeName() != null && lastNode.getNodeName().equals("text:a")) {
			if (content != null && !content.equals(""))
				Paragraph.appendTextElements((TextAElementlastNodecontenttrue);
else {
			if (content != null && !content.equals(""))
				Paragraph.appendTextElements(getOdfElement(), contenttrue);
		}
		// remove empty hyperlink
	}

Return the text content of this span.

The other child elements except text content will not be returned.

Returns:
- the text content of this span
	public String getTextContent() {
		return Paragraph.getTextContent(getOdfElement());
	}

Append the text content at the end of this span.

The appended text would follow the style of the last character.

Parameters:
content - the text content
	public void appendTextContent(String content) {
		appendTextContent(contenttrue);
	}

Append the text content at the end of this span.

The appended text would follow the style of the last character if the second parameter is set to true; Or else, the appended text would follow the default style of this paragraph.

Parameters:
content - the text content
isStyleInherited - whether the hyperlink style would be inherited by the appended text
	public void appendTextContent(String contentboolean isStyleInherited) {
		boolean canInherited = false;
		Node lastNode = getOdfElement().getLastChild();
		if (lastNode != null && lastNode.getNodeName() != null && lastNode.getNodeName().equals("text:a"))
			canInherited = true;
		if (isStyleInherited && canInherited) {
			if (content != null && !content.equals(""))
				Paragraph.appendTextElements((OdfElementlastNodecontenttrue);
else {
			if (content != null && !content.equals(""))
				Paragraph.appendTextElements(getOdfElement(), contenttrue);
		}
	}

Hyperlink support **********
	public TextHyperlink applyHyperlink(URI linkto) {
	}
	}
	public void removeHyperlinks() {
	}
	public TextHyperlink appendHyperlink(String textURI linkto) {
	}
			super(parent);
		}
	}
	}
End of Hyperlink support **********
New to GrepCode? Check out our FAQ X