Top Description Inners Fields Constructors Methods
org.jdom2

public abstract Class Content

extends CloneBase
implements Serializable, NamespaceAware
Class Inheritance
All Implemented Interfaces
org.jdom2.NamespaceAware, java.io.Serializable
Known Direct Subclasses
org.jdom2.DocType, org.jdom2.Element, org.jdom2.EntityRef, org.jdom2.ProcessingInstruction, org.jdom2.Text, org.jdom2.Comment
Imports
java.io.*, java.util.Collections, .List

Superclass for JDOM objects which can be legal child content of org.jdom2.Parent nodes.
Authors
Bradley S. Huffman, Jason Hunter, Rolf Lear
See Also
org.jdom2.Comment, org.jdom2.DocType, org.jdom2.Element, org.jdom2.EntityRef, org.jdom2.Parent, org.jdom2.ProcessingInstruction, org.jdom2.Text

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
Content.CType

An enumeration useful for identifying content types without having to do instanceof type conditionals.

Field Summary

Modifier and TypeField and Description
protected final Content.CType
ctype

The content type enumerate value for this Content

protected transient Parent
parent

The parent Parent of this Content.

private static final long
serialVersionUID

JDOM2 Serialization.

Constructor Summary

AccessConstructor and Description
protected
Content(Content.CType
The CType of this Content
type
)

Create a new Content instance of a particular type.

Method Summary

Modifier and TypeMethod and Description
public Content
clone()

Overrides org.jdom2.CloneBase.clone.

Return a deep clone of this instance.
public Content

Returns:

this child detached
detach
()

Detaches this child from its parent or does nothing if the child has no parent.

public final boolean

Returns:

boolean - whether the Content is equal to the supplied Object.
equals
(Object
Object to compare to.
ob
)

Overrides java.lang.Object.equals.

This tests for equality of this Content object to the supplied object.
public final Content.CType

Returns:

A CType enumerated value representing this content.
getCType
()

All content has an enumerated type expressing the type of content.

public Document

Returns:

this child's owning document or null if none
getDocument
()

Return this child's owning document or null if the branch containing this child is currently not attached to a document.

public List<Namespace>
getNamespacesInherited()

Implements org.jdom2.NamespaceAware.getNamespacesInherited.

Obtain a list of all namespaces that are in scope for this content, but were not introduced by this content.
public List<Namespace>
getNamespacesInScope()

Implements org.jdom2.NamespaceAware.getNamespacesInScope.

Obtain a list of all namespaces that are in scope for the current content.
public List<Namespace>
getNamespacesIntroduced()

Implements org.jdom2.NamespaceAware.getNamespacesIntroduced.

Obtain a list of all namespaces that are introduced to the XML tree by this node.
public Parent

Returns:

this child's parent or null if none
getParent
()

Return this child's parent, or null if this child is currently not attached.

public final Element

Returns:

the containing Element or null if unattached or a root element
getParentElement
()

A convenience method that returns any parent element for this element, or null if the element is unattached or is a root element.

public abstract String

Returns:

xpath string value of this child.
getValue
()

Returns the XPath 1.0 string value of this child.

public final int

Returns:

int - hash code.
hashCode
()

Overrides java.lang.Object.hashCode.

This returns the hash code for this Content item.
protected Content

Returns:

the target element
setParent
(Parent
new parent element
parent
)

Sets the parent of this Content.

Field Detail

ctypeback to summary
protected final Content.CType ctype

The content type enumerate value for this Content

Serial Fields:
This:is
an Enum, and cannot be null.
parentback to summary
protected transient Parent parent

The parent Parent of this Content. Note that the field is not serialized, thus deserialized Content instances are 'detached'

serialVersionUIDback to summary
private static final long serialVersionUID

JDOM2 Serialization.

Constructor Detail

Contentback to summary
protected Content(Content.CType type)

Create a new Content instance of a particular type.

Parameters
type:Content.CType

The CType of this Content

Method Detail

cloneback to summary
public Content clone()

Overrides org.jdom2.CloneBase.clone.

Doc from org.jdom2.CloneBase.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.

Returns:Content

Doc from java.lang.Object.clone.

a clone of this instance.

Annotations
@Override
detachback to summary
public Content detach()

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

Returns:Content

this child detached

equalsback to summary
public final boolean equals(Object ob)

Overrides java.lang.Object.equals.

This tests for equality of this Content object to the supplied object. Content items are considered equal only if they are referentially equal (i.e. the same object). User code may choose to compare objects based on their properties instead.

Parameters
ob:Object

Object to compare to.

Returns:boolean

boolean - whether the Content is equal to the supplied Object.

Annotations
@Override
getCTypeback to summary
public final Content.CType getCType()

All content has an enumerated type expressing the type of content. This makes it possible to use switch-type statements on the content.

Returns:Content.CType

A CType enumerated value representing this content.

getDocumentback to summary
public Document getDocument()

Return this child's owning document or null if the branch containing this child is currently not attached to a document.

Returns:Document

this child's owning document or null if none

getNamespacesInheritedback to summary
public List<Namespace> getNamespacesInherited()

Implements org.jdom2.NamespaceAware.getNamespacesInherited.

Doc from org.jdom2.NamespaceAware.getNamespacesInherited.

Obtain a list of all namespaces that are in scope for this content, but were not introduced by this content.

The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesIntroduced()

Returns:List<Namespace>

a read-only list of Namespaces.

Annotations
@Override
getNamespacesInScopeback to summary
public List<Namespace> getNamespacesInScope()

Implements org.jdom2.NamespaceAware.getNamespacesInScope.

Doc from org.jdom2.NamespaceAware.getNamespacesInScope.

Obtain a list of all namespaces that are in scope for the current content.

The contents of this list will always be the combination of getNamespacesIntroduced() and getNamespacesInherited().

See NamespaceAware documentation for details on what the order of the Namespaces will be in the returned list.

Returns:List<Namespace>

a read-only list of Namespaces.

Annotations
@Override
getNamespacesIntroducedback to summary
public List<Namespace> getNamespacesIntroduced()

Implements org.jdom2.NamespaceAware.getNamespacesIntroduced.

Doc from org.jdom2.NamespaceAware.getNamespacesIntroduced.

Obtain a list of all namespaces that are introduced to the XML tree by this node. Only Elements and Attributes can introduce namespaces, so all other Content types will return an empty list.

The contents of this list will always be a subset (but in the same order) of getNamespacesInScope(), and will never intersect getNamspacesInherited()

Returns:List<Namespace>

a read-only list of Namespaces.

Annotations
@Override
getParentback to summary
public Parent getParent()

Return this child's parent, or null if this child is currently not attached. The parent can be either an Element or a Document.

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

Returns:Parent

this child's parent or null if none

getParentElementback to summary
public final Element getParentElement()

A convenience method that returns any parent element for this element, or null if the element is unattached or is a root element. This was the original behavior of getParent() in JDOM Beta 9 which began returning Parent in Beta 10. This method provides a convenient upgrade path for JDOM Beta 10 and 1.0 users.

Returns:Element

the containing Element or null if unattached or a root element

getValueback to summary
public abstract String getValue()

Returns the XPath 1.0 string value of this child.

Returns:String

xpath string value of this child.

hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

This returns the hash code for this Content item.

Returns:int

int - hash code.

Annotations
@Override
setParentback to summary
protected Content setParent(Parent parent)

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);

Parameters
parent:Parent

new parent element

Returns:Content

the target element

org.jdom2 back to summary

public final Enum Content.CType

extends Enum<Content.CType>
Class Inheritance

An enumeration useful for identifying content types without having to do instanceof type conditionals.

instanceof is not a particularly safe way to test content in JDOM because CDATA extends Text ( a CDATA instance is an instanceof Text).

This CType enumeration provides a direct and sure mechanism for identifying JDOM content.

These can be used in switch-type statements too (which is much neater than chained if (instanceof) else if (instanceof) else .... expressions):

   switch(content.getCType()) {
       case Text :
            .....
            break; 
       case CDATA :
            .....
            break;
       ....
   }
Author
Rolf Lear
Since
JDOM2

Field Summary

Modifier and TypeField and Description
public static final Content.CType
CDATA

Represents CDATA content

public static final Content.CType
Comment

Represents Comment content

public static final Content.CType
DocType

Represents DocType content

public static final Content.CType
Element

Represents Element content

public static final Content.CType
EntityRef

Represents EntityRef content

public static final Content.CType
public static final Content.CType
Text

Represents Text content

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static Content.CType
public static Content.CType[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CDATAback to summary
public static final Content.CType CDATA

Represents CDATA content

Commentback to summary
public static final Content.CType Comment

Represents Comment content

DocTypeback to summary
public static final Content.CType DocType

Represents DocType content

Elementback to summary
public static final Content.CType Element

Represents Element content

EntityRefback to summary
public static final Content.CType EntityRef

Represents EntityRef content

ProcessingInstructionback to summary
public static final Content.CType ProcessingInstruction

Represents ProcessingInstruction content

Textback to summary
public static final Content.CType Text

Represents Text content

Constructor Detail

CTypeback to summary
private CType()

Method Detail

valueOfback to summary
public static Content.CType valueOf(String name)
valuesback to summary
public static Content.CType[] values()