org.jdom
Class Entity

java.lang.Object
  |
  +--org.jdom.Entity

public class Entity
extends java.lang.Object

Entity Defines an XML entity in Java.

Version:
1.0
Author:
Brett McLaughlin, Jason Hunter

Field Summary
protected  java.util.List content
          The mixed content of the Entity
protected  java.lang.String name
          The name of the Entity
 
Constructor Summary
protected Entity()
           Default, no-args constructor for implementations to use if needed.
  Entity(java.lang.String name)
           This will create a new Entity with the supplied name.
 
Method Summary
 Entity addChild(Element element)
           This will add an Element as a child of this Entity.
 Entity addChild(java.lang.String s)
           This will add a String as a child of this Entity.
 Entity addText(java.lang.String text)
           This will add text to the content of this Entity.
 java.util.List getChildren()
           This will return a List of all the XML elements nested directly (one level deep) within this Entity, each in Element form.
 java.lang.String getContent()
           This will return the actual textual content of this Entity.
 java.util.List getMixedContent()
           This will return the content of the entity.
 java.lang.String getName()
           This returns the name of the Entity.
 boolean hasMixedContent()
           This will indicate whether the entity has mixed content or not.
 Entity setChildren(java.util.List children)
           This will set the children of this Entity to the Elements within the supplied :ost.
 Entity setContent(java.lang.String textContent)
           This will set the textual content of the Entity.
 Entity setMixedContent(java.util.List mixedContent)
           This will return the content of the element.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

name

protected java.lang.String name
The name of the Entity

content

protected java.util.List content
The mixed content of the Entity
Constructor Detail

Entity

protected Entity()

Default, no-args constructor for implementations to use if needed.


Entity

public Entity(java.lang.String name)

This will create a new Entity with the supplied name.

Parameters:
name - String name of element.
Method Detail

getName

public java.lang.String getName()

This returns the name of the Entity.

Returns:
String - entity name.

getContent

public java.lang.String getContent()

This will return the actual textual content of this Entity. This will include all text within this single element, including CDATA sections if they exist. If no textual value exists for the Entity, an empty String is returned.

Returns:
String - value for this element.

setContent

public Entity setContent(java.lang.String textContent)

This will set the textual content of the Entity. If this Entity will have both textual content and nexted elements, setMixedContent(java.util.List) should be used instead,

Parameters:
textContent - String content for Entity.
Returns:
Entity - this element modified.

hasMixedContent

public boolean hasMixedContent()

This will indicate whether the entity has mixed content or not. Mixed content is when an element contains both textual and element data within it. When this evaluates to true, getMixedContent() should be used for getting element data.

Note:I think there's a better way to do this, maybe store a member variable, but I'm too tired to really think of what it is... (brett).

Returns:
boolean - indicating whether there is mixed content (both textual data and elements).

getMixedContent

public java.util.List getMixedContent()

This will return the content of the entity. This should be used when the hasMixedContent() evaluates to true. When there is no mixed content, it returns a List with a single String (when only data is present) or a List with only elements (when only nested elements are present).

Returns:
List - the mixed content of the Element: contains String, Element, and Comment, objects.

setMixedContent

public Entity setMixedContent(java.util.List mixedContent)

This will return the content of the element. This should be used when the hasMixedContent() evaluates to true. When there is no mixed content, it returns a List with a single String (when only data is present) or a List with only elements (when only nested elements are present).

Returns:
Entity - this entity modified.

getChildren

public java.util.List getChildren()

This will return a List of all the XML elements nested directly (one level deep) within this Entity, each in Element form. If the Wntity has no nested elements, an empty list will be returned.

This performs no recursion, so an elements nested two levels deep would have to be obtained with:

 
   List nestedElements = currentEntity.getChildren();
   for (int i=0; i<nestedElements.size(); i++) {
     Element oneLevelDeep = (Element)nestedElements.get(i);
     List twoLevelsDeep = oneLevelDeep.getChildren();
     // Do something with these children
   }
 
 

Returns:
List - list of nested Element instances for this entity.

setChildren

public Entity setChildren(java.util.List children)

This will set the children of this Entity to the Elements within the supplied :ost. All existing children of this Entity are replaced.

Parameters:
children - List of Elements to add.
Returns:
Entity - this element modified.

addText

public Entity addText(java.lang.String text)

This will add text to the content of this Entity.

Parameters:
text - String to add as content.
Returns:
Entity - this Entity modified.

addChild

public Entity addChild(Element element)

This will add an Element as a child of this Entity.

Parameters:
element - Element to add as a child.
Returns:
Entity - this Entity modified.

addChild

public Entity addChild(java.lang.String s)

This will add a String as a child of this Entity.

Parameters:
s - String to add as a child.
Returns:
Entity - this Entity modified.


Copyright © 2000 Brett McLaughlin, Jason Hunter. All Rights Reserved.