JXTA

net.jxta.impl.document
Class PlainTextElement

java.lang.Object
  extended by net.jxta.impl.document.PlainTextElement
All Implemented Interfaces:
Attributable, Element<PlainTextElement>, TextElement<PlainTextElement>
Direct Known Subclasses:
PlainTextDocument

public class PlainTextElement
extends Object
implements TextElement<PlainTextElement>, Attributable

This class is an implementation of the StructuredDocument interface using simple text


Field Summary
protected  PlainTextDocument doc
           
protected  String name
           
protected  PlainTextElement parent
           
protected  String val
           
 
Constructor Summary
protected PlainTextElement(PlainTextDocument doc, String name)
          Creates new PlainTextElement
protected PlainTextElement(PlainTextDocument doc, String name, String val)
          Creates new PlainTextElement
 
Method Summary
 String addAttribute(Attribute newAttrib)
          Adds an attribute with the given name and value.
 String addAttribute(String name, String value)
          Adds an attribute with the given name and value.
 void appendChild(PlainTextElement element)
          Add a child element to this element.
 boolean equals(Object element)
          
 Attribute getAttribute(String name)
          Returns a single attribute which matches the name provided.
 Enumeration getAttributes()
          Returns an enumerations of the attributes associated with this object.
 Enumeration getChildren()
          Returns an enumeration of the immediate children of this element.
 Enumeration<PlainTextElement> getChildren(Object key)
          Returns an enumeration of the immediate children of this element who match the specified key.
 Enumeration<PlainTextElement> getChildren(String name)
          Returns an enumeration of the immediate children of this element whose name match the specified string.
 String getKey()
          Get the name associated with an element.
 String getName()
          Get the name associated with an element.
 PlainTextElement getParent()
          Get the parent element of this element.
 StructuredTextDocument getRoot()
          Get the root document element of the hierarchy this element belongs to.
 String getTextValue()
          Get the value (if any) associated with an element.
 String getValue()
          Get the value (if any) associated with an element.
protected  void printNice(Writer into, int indent, boolean recurse)
          Write the contents of this element and optionally its children.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

doc

protected PlainTextDocument doc

parent

protected PlainTextElement parent

name

protected final String name

val

protected final String val
Constructor Detail

PlainTextElement

protected PlainTextElement(PlainTextDocument doc,
                           String name)
Creates new PlainTextElement


PlainTextElement

protected PlainTextElement(PlainTextDocument doc,
                           String name,
                           String val)
Creates new PlainTextElement

Method Detail

equals

public boolean equals(Object element)

Overrides:
equals in class Object

getRoot

public StructuredTextDocument getRoot()
Get the root document element of the hierarchy this element belongs to.

Specified by:
getRoot in interface Element<PlainTextElement>
Specified by:
getRoot in interface TextElement<PlainTextElement>
Returns:
The root document element of this element's hierarchy.

getKey

public String getKey()
Get the name associated with an element.

Specified by:
getKey in interface Element<PlainTextElement>
Specified by:
getKey in interface TextElement<PlainTextElement>
Returns:
A string containing the key of this element.

getValue

public String getValue()
Get the value (if any) associated with an element.

Specified by:
getValue in interface Element<PlainTextElement>
Specified by:
getValue in interface TextElement<PlainTextElement>
Returns:
A string containing the value of this element, if any, otherwise null.

getParent

public PlainTextElement getParent()
Get the parent element of this element. If this Element has not been inserted into the Document then null is returned. If this element is the root element of the Document then it returns itself. ie., this == this.getParent().

Specified by:
getParent in interface Element<PlainTextElement>
Returns:
The parent of this element. If the element has no parent then null will be returned. If the element is the root Element of the hierarchy then it will return itself.

getChildren

public Enumeration getChildren()
Returns an enumeration of the immediate children of this element.

Specified by:
getChildren in interface Element<PlainTextElement>
Returns:
Enumeration containing all of the children of this element.

getName

public String getName()
Get the name associated with an element.

Specified by:
getName in interface TextElement<PlainTextElement>
Returns:
A string containing the name of this element.

getTextValue

public String getTextValue()
Get the value (if any) associated with an element.

Specified by:
getTextValue in interface TextElement<PlainTextElement>
Returns:
A string containing the value of this element, if any, otherwise null.

appendChild

public void appendChild(PlainTextElement element)
Add a child element to this element. The child element must be from the document as the element it is to be added to. Elements are created using either StructuredDocument.createElement(Object) or StructuredDocument.createElement(Object, Object).

Specified by:
appendChild in interface Element<PlainTextElement>
Parameters:
element - The element to be added as a child.

getChildren

public Enumeration<PlainTextElement> getChildren(Object key)
Returns an enumeration of the immediate children of this element who match the specified key.

Specified by:
getChildren in interface Element<PlainTextElement>
Parameters:
key - The key which will be matched against.
Returns:
Enumeration containing all of the matching children of this element.

getChildren

public Enumeration<PlainTextElement> getChildren(String name)
Returns an enumeration of the immediate children of this element whose name match the specified string.

Specified by:
getChildren in interface TextElement<PlainTextElement>
Parameters:
name - The name which will be matched against.
Returns:
An enumeration containing all of the children of this element.

printNice

protected void printNice(Writer into,
                         int indent,
                         boolean recurse)
                  throws IOException
Write the contents of this element and optionally its children. The writing is done to a provided java.io.Writer. The writing can optionally be indented

Parameters:
into - The java.io.Writer that the output will be sent to.
indent - the number of tabs which will be inserted before each line.
recurse - if true then also print the children of this element.
Throws:
IOException

addAttribute

public String addAttribute(String name,
                           String value)
Adds an attribute with the given name and value. Some implementations may support only a single value for each distinct name. Others may support multiple values for each name. If the value being provided replaces some other value then that value is returned otherwise null is returned.

Specified by:
addAttribute in interface Attributable
Parameters:
name - name of the attribute.
value - value for the attribute.
Returns:
String containing previous value for this name if the value is being replaced otherwise null.

addAttribute

public String addAttribute(Attribute newAttrib)
Adds an attribute with the given name and value. Some implementations may support only a single value for each distinct name. Others may support multiple values for each name. If the value being provided replaces some other value then that value is returned otherwise null is returned.

Specified by:
addAttribute in interface Attributable
Parameters:
newAttrib - new attribute.
Returns:
String containing previous value for this name if the value is being replaced otherwise null.

getAttributes

public Enumeration getAttributes()
Returns an enumerations of the attributes associated with this object. Each element is of type Attribute.

Specified by:
getAttributes in interface Attributable
Returns:
Enumeration the attributes associated with this object.

getAttribute

public Attribute getAttribute(String name)
Returns a single attribute which matches the name provided. If no such named attribute exists then null is returned. For implementations of this interface which support multiple values for each name only the first value will be returned. To access all values for a name you must use getAttributes.

Specified by:
getAttribute in interface Attributable
Parameters:
name - the attribute name
Returns:
Attribute the attributes matching the given name.

JXSE