JXTA

net.jxta.impl.document
Class PlainTextDocument

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

public class PlainTextDocument
extends PlainTextElement
implements StructuredTextDocument<PlainTextElement>

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


Field Summary
static StructuredDocumentFactory.TextInstantiator INSTANTIATOR
           
 
Fields inherited from class net.jxta.impl.document.PlainTextElement
doc, name, parent, val
 
Constructor Summary
PlainTextDocument(MimeMediaType mimeType, String type)
          Creates new PlainTextDocument
PlainTextDocument(MimeMediaType mimeType, String type, String value)
          Creates new PlainTextDocument with a value for the root element
 
Method Summary
 PlainTextElement createElement(Object key)
          Create a new element without value.
 PlainTextElement createElement(Object key, Object val)
          Create a new element with value.
 PlainTextElement createElement(String name)
          Create a new element without value.
 PlainTextElement createElement(String name, String val)
          Create a new element with value.
 String getFileExtension()
          Returns the file extension type used by this Document.
 MimeMediaType getMimeType()
          get Type
 Reader getReader()
          Returns the sequence of characters which represents the content of the TextDocument.
 InputStream getStream()
          Returns the stream of bytes which represents the content of this Document.
 void sendToStream(OutputStream stream)
          Send the contents of this Document to the specified stream.
 void sendToWriter(Writer stream)
          Send the contents of this TextDocument to the specified Writer.
 String toString()
          
 
Methods inherited from class net.jxta.impl.document.PlainTextElement
addAttribute, addAttribute, appendChild, equals, getAttribute, getAttributes, getChildren, getChildren, getChildren, getKey, getName, getParent, getRoot, 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.TextElement
getChildren, getKey, getName, getRoot, getTextValue, getValue
 
Methods inherited from interface net.jxta.document.Element
appendChild, getChildren, getChildren, getParent
 

Field Detail

INSTANTIATOR

public static final StructuredDocumentFactory.TextInstantiator INSTANTIATOR
Constructor Detail

PlainTextDocument

public PlainTextDocument(MimeMediaType mimeType,
                         String type)
Creates new PlainTextDocument


PlainTextDocument

public PlainTextDocument(MimeMediaType mimeType,
                         String type,
                         String value)
Creates new PlainTextDocument with a value for the root element

Method Detail

toString

public String toString()

Overrides:
toString in class Object

getMimeType

public MimeMediaType getMimeType()
get Type

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 PlainTextElement createElement(Object key)
Create a new element without value.

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

createElement

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

Specified by:
createElement in interface StructuredDocument<PlainTextElement>
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 PlainTextElement createElement(String name)
Create a new element without value.

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

createElement

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

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

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.

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.

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.

sendToWriter

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

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

JXSE