JXTA

net.jxta.impl.document
Class LiteXMLDocument

java.lang.Object
  extended by net.jxta.impl.document.LiteXMLElement
      extended by net.jxta.impl.document.LiteXMLDocument
All Implemented Interfaces:
Attributable, Document, DocumentStreamIO, Element<LiteXMLElement>, StructuredDocument<LiteXMLElement>, StructuredTextDocument<LiteXMLElement>, TextDocument, TextDocumentReaderIO, TextElement<LiteXMLElement>, XMLDocument<LiteXMLElement>, XMLElement<LiteXMLElement>

public class LiteXMLDocument
extends LiteXMLElement
implements XMLDocument<LiteXMLElement>

This class is an implementation of the StructuredDocument interface using a simplified XML implementation.


Nested Class Summary
 
Nested classes/interfaces inherited from class net.jxta.impl.document.LiteXMLElement
LiteXMLElement.charRange, LiteXMLElement.tagRange
 
Field Summary
(package private)  StringBuilder docContent
          The actual document contents.
static StructuredDocumentFactory.TextInstantiator INSTANTIATOR
          The instantiator for instances of our documents.
 
Fields inherited from class net.jxta.impl.document.LiteXMLElement
doc, loc, paranoidConsistencyChecking, parent
 
Constructor Summary
LiteXMLDocument(MimeMediaType mimeType, InputStream in)
          Creates new LiteXMLDocument
LiteXMLDocument(MimeMediaType mimeType, Reader in)
          Creates new LiteXMLDocument
LiteXMLDocument(MimeMediaType mimeType, String type)
          Creates new LiteXMLDocument
LiteXMLDocument(MimeMediaType mimeType, String type, String textValue)
          Creates new LiteXMLDocument with a textValue in the root element
 
Method Summary
protected  LiteXMLElement createElement(LiteXMLElement.tagRange loc)
          Create a new text element as a sub-range of this document.
 LiteXMLElement createElement(Object key)
          Create a new element without value.
 LiteXMLElement createElement(Object key, Object val)
          Create a new element with value.
 LiteXMLElement createElement(String name)
          Create a new element without value.
 LiteXMLElement createElement(String name, String val)
          Create a new element with value.
protected  LiteXMLElement.tagRange getDocType(StringBuilder source, boolean wholeElement)
           
(package private)  LiteXMLDocument getDocument()
          The document we are a part of.
 String getFileExtension()
          Returns the file extension type used by this Document.
 MimeMediaType getMimeType()
          Returns the MIME Media type of this Document per IETF RFC 2046 MIME : Media Types.
 Reader getReader()
          Returns the sequence of characters which represents the content of the TextDocument.
 LiteXMLDocument getRoot()
          Get the root document element of the hierarchy this element belongs to.
 InputStream getStream()
          Returns the stream of bytes which represents the content of this Document.
protected  void init(Reader in)
          Initialises LiteXMLDocument.
 void sendToStream(OutputStream stream)
          Send the contents of this Document to the specified stream.
 void sendToWriter(Writer writer)
          Send the contents of this TextDocument to the specified Writer.
 String toString()
          

A toString implementation for debugging purposes.

 
Methods inherited from class net.jxta.impl.document.LiteXMLElement
addAttribute, addAttribute, addChildTags, adjustLocations, appendChild, checkConsistency, decodeEscaped, encodeEscaped, equals, getAttribute, getAttributeLoc, getAttributes, getChildren, getChildren, getChildren, getKey, getName, getParent, getTagRanges, getTextValue, getTextValue, getValue, printNice
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface net.jxta.document.Attributable
addAttribute, addAttribute, getAttribute, getAttributes
 
Methods inherited from interface net.jxta.document.TextElement
getChildren, getKey, getName, getTextValue, getValue
 
Methods inherited from interface net.jxta.document.Element
appendChild, getChildren, getChildren, getParent
 

Field Detail

INSTANTIATOR

public static final StructuredDocumentFactory.TextInstantiator INSTANTIATOR
The instantiator for instances of our documents.


docContent

final StringBuilder docContent
The actual document contents.

Constructor Detail

LiteXMLDocument

LiteXMLDocument(MimeMediaType mimeType,
                String type)
Creates new LiteXMLDocument


LiteXMLDocument

LiteXMLDocument(MimeMediaType mimeType,
                String type,
                String textValue)
Creates new LiteXMLDocument with a textValue in the root element


LiteXMLDocument

LiteXMLDocument(MimeMediaType mimeType,
                InputStream in)
          throws IOException
Creates new LiteXMLDocument

Throws:
IOException

LiteXMLDocument

LiteXMLDocument(MimeMediaType mimeType,
                Reader in)
          throws IOException
Creates new LiteXMLDocument

Throws:
IOException
Method Detail

toString

public String toString()

A toString implementation for debugging purposes.

Overrides:
toString in class LiteXMLElement

getMimeType

public MimeMediaType getMimeType()
Returns the MIME Media type of this Document per IETF RFC 2046 MIME : Media Types.

JXTA does not currently support the 'Multipart' or 'Message' media types.

Specified by:
getMimeType in interface Document
Returns:
The MIME Media Type for this Document.

getFileExtension

public String getFileExtension()
Returns the file extension type used by this Document. This value is usually chosen based upon the MIME Media Type.

Specified by:
getFileExtension in interface Document
Returns:
An appropriate file extension for this Document.

createElement

public LiteXMLElement createElement(Object key)
Create a new element without value.

Specified by:
createElement in interface StructuredDocument<LiteXMLElement>
Parameters:
key - The key of the element to be created.
Returns:
The new element.

createElement

public LiteXMLElement createElement(Object key,
                                    Object val)
Create a new element with value.

Specified by:
createElement in interface StructuredDocument<LiteXMLElement>
Parameters:
key - The name of the element to be created.
val - The value of the element to be created or null if no value is desired.
Returns:
The new element.

createElement

public LiteXMLElement createElement(String name)
Create a new element without value.

Specified by:
createElement in interface StructuredTextDocument<LiteXMLElement>
Specified by:
createElement in interface XMLDocument<LiteXMLElement>
Parameters:
name - The name of the element to be created.
Returns:
The new element.

createElement

public LiteXMLElement createElement(String name,
                                    String val)
Create a new element with value.

Specified by:
createElement in interface StructuredTextDocument<LiteXMLElement>
Specified by:
createElement in interface XMLDocument<LiteXMLElement>
Parameters:
name - The name of the element to be created.
val - The value of the element to be created.
Returns:
The new element.

createElement

protected LiteXMLElement createElement(LiteXMLElement.tagRange loc)
Create a new text element as a sub-range of this document.

Parameters:
loc - The document range for the new element.
Returns:
The newly created element.

getReader

public Reader getReader()
Returns the sequence of characters which represents the content of the TextDocument.

Specified by:
getReader in interface TextDocumentReaderIO
Returns:
An Reader containing the characters of the TextDocument.

getRoot

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

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

getStream

public InputStream getStream()
                      throws IOException
Returns the stream of bytes which represents the content of this Document.

Specified by:
getStream in interface DocumentStreamIO
Returns:
An InputStream containing the bytes of this Document.
Throws:
IOException - For errors while writing the Document.

sendToWriter

public void sendToWriter(Writer writer)
                  throws IOException
Send the contents of this TextDocument to the specified Writer.

Specified by:
sendToWriter in interface TextDocumentReaderIO
Parameters:
writer - The Writer to which the characters of the TextDocument will be written.
Throws:
IOException - If an I/O error occurs.

sendToStream

public void sendToStream(OutputStream stream)
                  throws IOException
Send the contents of this Document to the specified stream.

Specified by:
sendToStream in interface DocumentStreamIO
Parameters:
stream - The OutputStream to which the Document will be written.
Throws:
IOException - For errors while writing the Document.

init

protected void init(Reader in)
             throws IOException
Initialises LiteXMLDocument.

Throws:
IOException

getDocType

protected LiteXMLElement.tagRange getDocType(StringBuilder source,
                                             boolean wholeElement)

getDocument

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

Overrides:
getDocument in class LiteXMLElement
Returns:
The document we are a part of.

JXSE