Class Text
- All Implemented Interfaces:
Serializable
,Cloneable
,NamespaceAware
- Direct Known Subclasses:
CDATA
,LocatedText
- Author:
- Brett McLaughlin, Jason Hunter, Bradley S. Huffman
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jdom2.Content
Content.CType
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Text()
This is the protected, no-args constructor standard in all JDOM classes.This constructor creates a newText
node, with the supplied string value as its character content.protected
Text
(Content.CType ctype) CData type extends Text, and it needs to be able to change the Content type of this Content. -
Method Summary
Modifier and TypeMethodDescriptionvoid
This will append character content to whatever content already exists within thisText
node.void
This will append the content of anotherText
node to this node.clone()
Return a deep clone of this instance.detach()
Detaches this child from its parent or does nothing if the child has no parent.Return this child's parent, or null if this child is currently not attached.getText()
This returns the value of thisText
node as a JavaString
.This returns the textual content with all surrounding whitespace removed and internal whitespace normalized to a single space.This returns the textual content with all surrounding whitespace removed.getValue()
Returns the XPath 1.0 string value of this element, which is the text itself.static String
normalizeString
(String str) This returns a new string with all surrounding whitespace removed and internal whitespace normalized to a single space.protected Text
Sets the parent of this Content.This will set the value of thisText
node.toString()
This returns aString
representation of theText
node, suitable for debugging.Methods inherited from class org.jdom2.Content
equals, getCType, getDocument, getNamespacesInherited, getNamespacesInScope, getNamespacesIntroduced, getParentElement, hashCode
-
Field Details
-
value
The actual character content
-
-
Constructor Details
-
Text
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
This constructor creates a newText
node, with the supplied string value as its character content.- Parameters:
str
- the node's character content.- Throws:
IllegalDataException
- ifstr
contains an illegal character such as a vertical tab (as determined byVerifier.checkCharacterData(java.lang.String)
)
-
-
Method Details
-
getText
This returns the value of thisText
node as a JavaString
.- Returns:
String
- character content of this node.
-
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
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
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
This will set the value of thisText
node.- Parameters:
str
- value for node's content.- Returns:
- the object on which the method was invoked
- Throws:
IllegalDataException
- ifstr
contains an illegal character such as a vertical tab (as determined byVerifier.checkCharacterData(java.lang.String)
)
-
append
This will append character content to whatever content already exists within thisText
node.- Parameters:
str
- character content to append.- Throws:
IllegalDataException
- ifstr
contains an illegal character such as a vertical tab (as determined byVerifier.checkCharacterData(java.lang.String)
)
-
append
This will append the content of anotherText
node to this node.- Parameters:
text
- Text node to append.
-
getValue
Returns the XPath 1.0 string value of this element, which is the text itself. -
toString
This returns aString
representation of theText
node, suitable for debugging. If the XML representation of theText
node is desired, either
orgetText()
XMLOutputter.outputString(Text)
should be used. -
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 value).
Subclasses of this should still call super.clone() in their clone method.
-
detach
Description copied from class:Content
Detaches 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
Description copied from class:Content
Sets 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
Description copied from class:Content
Return this child's parent, or null if this child is currently not attached. The parent can be either anElement
or 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()
;
-