Package org.jdom2

Class Comment

All Implemented Interfaces:
Serializable, Cloneable, NamespaceAware
Direct Known Subclasses:
LocatedComment

public class Comment extends Content
An XML comment. Methods allow the user to get and set the text of the comment.
Author:
Brett McLaughlin, Jason Hunter
See Also:
  • Field Details

    • text

      protected String text
      Text of the Comment
  • Constructor Details

    • Comment

      protected Comment()
      Default, no-args constructor for implementations to use if needed.
    • Comment

      public Comment(String text)
      This creates the comment with the supplied text.
      Parameters:
      text - String content of comment.
  • Method Details

    • getValue

      public String getValue()
      Returns the XPath 1.0 string value of this element, which is the text of this comment.
      Specified by:
      getValue in class Content
      Returns:
      the text of this comment
    • getText

      public String getText()
      This returns the textual data within the Comment.
      Returns:
      String - text of comment.
    • setText

      public Comment setText(String text)
      This will set the value of the Comment.
      Parameters:
      text - String text for comment.
      Returns:
      Comment - this Comment modified.
      Throws:
      IllegalDataException - if the given text is illegal for a Comment.
    • clone

      public Comment 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.

      Overrides:
      clone in class Content
    • detach

      public Comment 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();

      Overrides:
      detach in class Content
      Returns:
      this child detached
    • setParent

      protected Comment setParent(Parent parent)
      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);

      Overrides:
      setParent in class Content
      Parameters:
      parent - new parent element
      Returns:
      the target element
    • toString

      public String toString()
      This returns a String representation of the Comment, suitable for debugging. If the XML representation of the Comment is desired, XMLOutputter.outputString(Comment) should be used.
      Overrides:
      toString in class Object
      Returns:
      String - information about the Comment