Class Text
- java.lang.Object
-
- org.jdom.Content
-
- org.jdom.Text
-
- All Implemented Interfaces:
Serializable,Cloneable,NamespaceAware
- Direct Known Subclasses:
CDATA,LocatedText
public class Text extends Content
An XML character sequence. Provides a modular, parentable method of representing text. Text makes no guarantees about the underlying textual representation of character data, but does expose that data as a Java String.- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.jdom.Content
Content.CType
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedText()This is the protected, no-args constructor standard in all JDOM classes.Text(String str)This constructor creates a newTextnode, with the supplied string value as it's character content.protectedText(Content.CType ctype)CData type extends Text, and it needs to be able to change the Content type of this Content.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(String str)This will append character content to whatever content already exists within thisTextnode.voidappend(Text text)This will append the content of anotherTextnode to this node.Textclone()Return a deep clone of this instance.Textdetach()Detaches this child from its parent or does nothing if the child has no parent.ElementgetParent()Return this child's parent, or null if this child is currently not attached.StringgetText()This returns the value of thisTextnode as a JavaString.StringgetTextNormalize()This returns the textual content with all surrounding whitespace removed and internal whitespace normalized to a single space.StringgetTextTrim()This returns the textual content with all surrounding whitespace removed.StringgetValue()Returns the XPath 1.0 string value of this element, which is the text itself.static StringnormalizeString(String str)This returns a new string with all surrounding whitespace removed and internal whitespace normalized to a single space.protected TextsetParent(Parent parent)Sets the parent of this Content.TextsetText(String str)This will set the value of thisTextnode.StringtoString()This returns aStringrepresentation of theTextnode, suitable for debugging.-
Methods inherited from class org.jdom.Content
equals, getCType, getDocument, getNamespacesInherited, getNamespacesInScope, getNamespacesIntroduced, getParentElement, hashCode
-
-
-
-
Field Detail
-
value
protected String value
The actual character content
-
-
Constructor Detail
-
Text
protected Text(Content.CType ctype)
CData type extends Text, and it needs to be able to change the Content type of this Content.- Parameters:
ctype- The CType to set for this Text-based Content.
-
Text
protected Text()
This is the protected, no-args constructor standard in all JDOM classes. It allows subclassers to get a raw instance with no initialization.
-
Text
public Text(String str)
This constructor creates a newTextnode, with the supplied string value as it's character content.- Parameters:
str- the node's character content.- Throws:
IllegalDataException- ifstrcontains an illegal character such as a vertical tab (as determined byVerifier.checkCharacterData(java.lang.String))
-
-
Method Detail
-
getText
public String getText()
This returns the value of thisTextnode as a JavaString.- Returns:
String- character content of this node.
-
getTextTrim
public String getTextTrim()
This returns the textual content with all surrounding whitespace removed. If only whitespace exists, the empty string is returned.- Returns:
- trimmed text content or empty string
-
getTextNormalize
public String getTextNormalize()
This returns the textual content with all surrounding whitespace removed and internal whitespace normalized to a single space. If only whitespace exists, the empty string is returned.- Returns:
- normalized text content or empty string
-
normalizeString
public static String normalizeString(String str)
This returns a new string with all surrounding whitespace removed and internal whitespace normalized to a single space. If only whitespace exists, the empty string is returned.Per XML 1.0 Production 3 whitespace includes: #x20, #x9, #xD, #xA
- Parameters:
str- string to be normalized.- Returns:
- normalized string or empty string
-
setText
public Text setText(String str)
This will set the value of thisTextnode.- Parameters:
str- value for node's content.- Returns:
- the object on which the method was invoked
- Throws:
IllegalDataException- ifstrcontains an illegal character such as a vertical tab (as determined byVerifier.checkCharacterData(java.lang.String))
-
append
public void append(String str)
This will append character content to whatever content already exists within thisTextnode.- Parameters:
str- character content to append.- Throws:
IllegalDataException- ifstrcontains an illegal character such as a vertical tab (as determined byVerifier.checkCharacterData(java.lang.String))
-
append
public void append(Text text)
This will append the content of anotherTextnode to this node.- Parameters:
text- Text node to append.
-
getValue
public String getValue()
Returns the XPath 1.0 string value of this element, which is the text itself.
-
toString
public String toString()
This returns aStringrepresentation of theTextnode, suitable for debugging. If the XML representation of theTextnode is desired, eitherorgetText()XMLOutputter2.outputString(Text)should be used.
-
clone
public Text clone()
Return a deep clone of this instance. Even if this instance has a parent, the returned clone will not.All JDOM core classes are Cloneable, and never throw CloneNotSupportedException. Additionally all Cloneable JDOM classes return the correct type of instance from this method and there is no need to cast the result (co-variant return vaue).
Subclasses of this should still call super.clone() in their clone method.
-
detach
public Text detach()
Description copied from class:ContentDetaches this child from its parent or does nothing if the child has no parent.This method can be overridden by particular Content subclasses to return a specific type of Content (co-variant return type). All overriding subclasses must call
super.detach();
-
setParent
protected Text setParent(Parent parent)
Description copied from class:ContentSets the parent of this Content. The caller is responsible for removing any pre-existing parentage.This method can be overridden by particular Content subclasses to return a specific type of Content (co-variant return type). All overriding subclasses must call
super.setParent(Parent);
-
getParent
public Element getParent()
Description copied from class:ContentReturn this child's parent, or null if this child is currently not attached. The parent can be either anElementor aDocument.This method can be overridden by particular Content subclasses to return a specific type of Parent (co-variant return type). All overriding subclasses must call
super.getParent();
-
-