Project JXTA

net.jxta.impl.document
Class LiteXMLElement

java.lang.Object
  extended bynet.jxta.impl.document.TextElementCommon
      extended bynet.jxta.impl.document.XMLElementCommon
          extended bynet.jxta.impl.document.LiteXMLElement
All Implemented Interfaces:
Attributable, Element, TextElement, XMLElement
Direct Known Subclasses:
LiteXMLDocument

public class LiteXMLElement
extends XMLElementCommon

An element of a StructuredDocument. StructuredDocuments are made up of hierarchies of elements. LiteXMLElement is part of an implementation while makes use of XML-style document conventions, but without the overhead of a full parser.


Nested Class Summary
protected static class LiteXMLElement.charRange
          Defines a range of characters, probably within a string.
protected static class LiteXMLElement.tagRange
          A tagRange is a collection of char ranges useful for describing XML structures.
 
Field Summary
protected  LiteXMLDocument doc
          The document associated with this Element.
protected  LiteXMLElement.tagRange loc
          The portion of the source XML associated with this node
protected static boolean paranoidConsistencyChecking
          If true then every operation which modifies the state of the document will perform a consistency check.
protected  Element parent
          Identifies the element which is the parent of this element.
protected static boolean verboseLogging
          Causes additional logging while parsing.
 
Constructor Summary
protected LiteXMLElement(LiteXMLDocument doc, LiteXMLElement.tagRange loc)
          Creates new LiteXMLElement
  LiteXMLElement(LiteXMLDocument doc, String name, String val)
          Creates new LiteElement
 
Method Summary
 String addAttribute(Attribute newAttrib)
          
 String addAttribute(String name, String value)
          
protected  void addChildTags(LiteXMLElement.charRange scanRange, LiteXMLElement addTo)
          Parse a charRange and add any tags found as content as children of a specified element.
protected  void adjustLocations(int beginningAt, int by)
          For this element and all its children adjust the location of its ranges by the amount specified.
 void appendChild(TextElement element)
          
protected  boolean checkConsistency()
           
protected  StringBuffer decodeEscaped(StringBuffer target)
          Given a StringBuffer find all occurances of escaped characters which must be decoded and convert them back to their non-escaped equivalents.
protected  void encodeEscaped(StringBuffer target)
          Given a StringBuffer find all occurances of characters which must be escaped and convert them to their escaped equivalents.
 boolean equals(Object element)
          
 Attribute getAttribute(String name)
          
protected  LiteXMLElement.tagRange getAttributeLoc(String name, LiteXMLElement.charRange inRange)
          Returns the tagRange of the next attribute contained in the range provided.
 Enumeration getAttributes()
          Returns an enumerations of the attributes assosicated with this object.
 Enumeration getChildren()
          
 Enumeration getChildren(String name)
          
(package private)  LiteXMLDocument getDocument()
          The document we are a part of.
 String getName()
          
 Element getParent()
          
 StructuredDocument getRoot()
          
protected  LiteXMLElement.tagRange getTagRanges(StringBuffer source, String tag, LiteXMLElement.charRange range)
          Given a source string, an optional tag and a range with in the source find either the tag specified or the next tag.
 String getTextValue()
          
protected  String getTextValue(boolean getEncoded, boolean trim)
          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.
 String toString()
          

A toString implementation for debugging purposes.

 
Methods inherited from class net.jxta.impl.document.TextElementCommon
appendChild, getChildren, getKey, getValue
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.jxta.document.Element
appendChild, getChildren, getKey, getValue
 

Field Detail

paranoidConsistencyChecking

protected static final transient boolean paranoidConsistencyChecking
If true then every operation which modifies the state of the document will perform a consistency check. This is a deadly performance killer but helps a lot in isolating bugs.

See Also:
Constant Field Values

verboseLogging

protected static final transient boolean verboseLogging
Causes additional logging while parsing. This is a deadly performance killer but helps a lot in isolating bugs.

See Also:
Constant Field Values

doc

protected final transient LiteXMLDocument doc
The document associated with this Element.


parent

protected transient Element parent
Identifies the element which is the parent of this element. If this.parent == this then this element is the root of the document. If null == parent then this element has not yet been inserted into the document.


loc

protected transient LiteXMLElement.tagRange loc
The portion of the source XML associated with this node

Constructor Detail

LiteXMLElement

protected LiteXMLElement(LiteXMLDocument doc,
                         LiteXMLElement.tagRange loc)
Creates new LiteXMLElement

Parameters:
loc - The location of the element within the document.
doc - The LiteXMLDocument which is the root of the document.

LiteXMLElement

public LiteXMLElement(LiteXMLDocument doc,
                      String name,
                      String val)
Creates new LiteElement

Parameters:
doc - The LiteXMLDocument which is the root of the document.
name - The name of the element being created.
val - The value of the element being created or null if there is no content to the element.
Method Detail

equals

public boolean equals(Object element)


toString

public String toString()

A toString implementation for debugging purposes.


getRoot

public StructuredDocument getRoot()


getParent

public Element getParent()


getChildren

public Enumeration getChildren()


getName

public String getName()


appendChild

public void appendChild(TextElement element)


getChildren

public Enumeration getChildren(String name)


getTextValue

public String getTextValue()


getTextValue

protected String getTextValue(boolean getEncoded,
                              boolean trim)
Get the value (if any) associated with an element.

Parameters:
getEncoded - if true then the contents will be encoded such that the contents will not be interpreted as XML. see W3C XML 1.0 Specification ie. < -> < & -> &
Returns:
A string containing the value of this element, if any, otherwise null.

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

getTagRanges

protected LiteXMLElement.tagRange getTagRanges(StringBuffer source,
                                               String tag,
                                               LiteXMLElement.charRange range)
Given a source string, an optional tag and a range with in the source find either the tag specified or the next tag. The search consists of 4 phases : 0. If no tag was specified, determine if a tag can be found and learn its name. 1. Search for the start of the named tag. 2. Search for the end tag. Each time we think we have found a tag which might be the end tag we make sure it is not the end tag of another element with the same name as our tag. 3. Calculate the position of the body of the tag given the locations of the start and end.

Parameters:
source - the string to search
tag - the tag to search for in the source string. If this tag is empty or null then we will search for the next tag.
range - describes the range of character locations in the source string to which the search will be limited.
Returns:
tagRange containing the ranges of the found tag.

addChildTags

protected void addChildTags(LiteXMLElement.charRange scanRange,
                            LiteXMLElement addTo)
Parse a charRange and add any tags found as content as children of a specified element. This process is repeated recursivly.

Parameters:
scanRange - the range to be parsed for sub-tags
addTo - the element to add any discovered children to.

adjustLocations

protected void adjustLocations(int beginningAt,
                               int by)
For this element and all its children adjust the location of its ranges by the amount specified.

Parameters:
beginningAt - adjust all locations which are at or past this location.
by - amount to adjust all matching locations.

decodeEscaped

protected StringBuffer decodeEscaped(StringBuffer target)
Given a StringBuffer find all occurances of escaped characters which must be decoded and convert them back to their non-escaped equivalents.

Also does end of line folding per:

Parameters:
target - The stringbuffer which will be decoded.
Returns:
The decoded version of the stringbuffer.

encodeEscaped

protected void encodeEscaped(StringBuffer target)
Given a StringBuffer find all occurances of characters which must be escaped and convert them to their escaped equivalents.

Parameters:
target - The stringbuffer which will be encoded in place.

getAttributes

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

Returns:
Enumeration the attributes associated with this object.

getAttributeLoc

protected LiteXMLElement.tagRange getAttributeLoc(String name,
                                                  LiteXMLElement.charRange inRange)
Returns the tagRange of the next attribute contained in the range provided. The tag range returned consists of the startTag indicating the location of the name, body indicating the location of the value and endTag indicating the location of the final quote delimiter.

Parameters:
name - Name to match. null means match any name.
inRange - the limits of the locations to scan.
Returns:
tagRange containing the location of the next attribute

addAttribute

public String addAttribute(String name,
                           String value)


addAttribute

public String addAttribute(Attribute newAttrib)


getAttribute

public Attribute getAttribute(String name)


checkConsistency

protected boolean checkConsistency()

getDocument

LiteXMLDocument getDocument()
The document we are a part of.


JXTA J2SE