Package org.jdom2

Class Comment

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.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:
    Serialized Form
    • Field Detail

      • text

        protected java.lang.String text
        Text of the Comment
    • Constructor Detail

      • Comment

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

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

      • getValue

        public java.lang.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 java.lang.String getText()
        This returns the textual data within the Comment.
        Returns:
        String - text of comment.
      • setText

        public Comment setText​(java.lang.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 vaue).

        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 java.lang.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 java.lang.Object
        Returns:
        String - information about the Comment