Package org.jdom

Class Text

All Implemented Interfaces:
Serializable, Cloneable
Direct Known Subclasses:
CDATA

public class Text extends Content
Character-based XML content. 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.
Version:
$Revision: 1.25 $, $Date: 2007/11/10 05:28:59 $
Author:
Brett McLaughlin, Jason Hunter, Bradley S. Huffman
See Also:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected String
    The actual character content

    Fields inherited from class org.jdom.Content

    parent
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
    This is the protected, no-args constructor standard in all JDOM classes.
     
    Text(String str)
    This constructor creates a new Text node, with the supplied string value as it's character content.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    This will append character content to whatever content already exists within this Text node.
    void
    append(Text text)
    This will append the content of another Text node to this node.
    This will return a clone of this Text node, with the same character content, but no parent.
    This returns the value of this Text node as a Java String.
    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.
    Returns the XPath 1.0 string value of this element, which is the text itself.
    static String
    This returns a new string with all surrounding whitespace removed and internal whitespace normalized to a single space.
    This will set the value of this Text node.
    This returns a String representation of the Text node, suitable for debugging.

    Methods inherited from class org.jdom.Content

    detach, equals, getDocument, getParent, getParentElement, hashCode, setParent

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • value

      protected String value
      The actual character content
  • Constructor Details

    • 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 new Text node, with the supplied string value as it's character content.
      Parameters:
      str - the node's character content.
      Throws:
      IllegalDataException - if str contains an illegal character such as a vertical tab (as determined by Verifier.checkCharacterData(java.lang.String))
  • Method Details

    • getText

      public String getText()
      This returns the value of this Text node as a Java String.
      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 this Text node.
      Parameters:
      str - value for node's content.
      Returns:
      the object on which the method was invoked
      Throws:
      IllegalDataException - if str contains an illegal character such as a vertical tab (as determined by Verifier.checkCharacterData(java.lang.String))
    • append

      public void append(String str)
      This will append character content to whatever content already exists within this Text node.
      Parameters:
      str - character content to append.
      Throws:
      IllegalDataException - if str contains an illegal character such as a vertical tab (as determined by Verifier.checkCharacterData(java.lang.String))
    • append

      public void append(Text text)
      This will append the content of another Text node 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.
      Specified by:
      getValue in class Content
      Returns:
      the text
    • toString

      public String toString()
      This returns a String representation of the Text node, suitable for debugging. If the XML representation of the Text node is desired, either getText() or XMLOutputter.outputString(Text) should be used.
      Overrides:
      toString in class Object
      Returns:
      String - information about this node.
    • clone

      public Object clone()
      This will return a clone of this Text node, with the same character content, but no parent.
      Overrides:
      clone in class Content
      Returns:
      Text - cloned node.