com.languagecomputer.api.text
Class DocumentXML

java.lang.Object
  extended by com.languagecomputer.api.text.DocumentXML

public class DocumentXML
extends Object

Handles XML conversion for Documents. Designed to be capable of handling different Document versions. The XML version number does not depend on the API version number.

Since:
1.0
Author:
Kirk Roberts

Field Summary
static String CURRENT_VERSION
           
 
Constructor Summary
DocumentXML()
          Creates a new DocumentXML that writes using the current Document XML version.
DocumentXML(String version)
          Creates a new DocumentXML that writes using the given version.
 
Method Summary
 void marshal(Object toMarshal, Writer writer)
          Marshalls the Object using a JAXB Marshaller.
 Collection<Text> readAnnotations(Reader reader, Document document)
          Reads the XML into a new Collection of Texts and adds any services to the Document's service list.
 Document readDocument(Reader reader)
          Reads the XML into a new Document.
 List<Document> readDocuments(Reader reader)
          Reads the XML into a new List of Document.
 Object unmarshal(Reader reader)
          Unmarshalls the Object using a JAXB Unmarshaller.
 void writeAnnotations(Collection<? extends Text> annotations, Collection<String> services, Writer writer)
          Writes the given Text objects (just annotations, cannot contain any Documents) to the given Writer.
 void writeDocument(Document document, Writer writer)
          Writes the given Document to XML in the given Writer.
 void writeDocuments(List<Document> documents, Writer writer)
          Writes the given Documents to XML in the given Writer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CURRENT_VERSION

public static final String CURRENT_VERSION
See Also:
Constant Field Values
Constructor Detail

DocumentXML

public DocumentXML()
Creates a new DocumentXML that writes using the current Document XML version. Is capable of reading all known versions.

See Also:
CURRENT_VERSION

DocumentXML

public DocumentXML(String version)
Creates a new DocumentXML that writes using the given version. Is capable of reading all known versions.

Parameters:
version - The version number to use for writing/reading. Using old versions for writing is not guaranteed.
Method Detail

writeDocuments

public void writeDocuments(List<Document> documents,
                           Writer writer)
                    throws IOException
Writes the given Documents to XML in the given Writer. Does not close the Writer.

Parameters:
documents - Documents to serialize to XML.
writer - Writer to write the XML to.
Throws:
IllegalStateException - If the version number is unknown.
IOException - If there is a problem writing to XML.

writeDocument

public void writeDocument(Document document,
                          Writer writer)
                   throws IOException
Writes the given Document to XML in the given Writer. Does not close the Writer.

Parameters:
document - Document to serialize to XML.
writer - Writer to write the XML to.
Throws:
IllegalStateException - If the version number is unknown.
IOException - If there is a problem writing to XML.

writeAnnotations

public void writeAnnotations(Collection<? extends Text> annotations,
                             Collection<String> services,
                             Writer writer)
                      throws IOException
Writes the given Text objects (just annotations, cannot contain any Documents) to the given Writer. Does not close the Writer.

Parameters:
annotations - Collection of Text annotations to serialize to XML.
services - The services that the annotations come from.
writer - Writer to write the XML to.
Throws:
IllegalArgumentException - If any of the annotations is a Document.
IOException - If there is a problem writing to XML.

readDocuments

public List<Document> readDocuments(Reader reader)
                             throws IOException
Reads the XML into a new List of Document.

Parameters:
reader - Reader to read the XML from.
Returns:
New Documents from the XML.
Throws:
IllegalArgumentException - If the Documents are an unknown version or are un-readable.
IOException - If there is a problem reading the XML.

readDocument

public Document readDocument(Reader reader)
                      throws IOException
Reads the XML into a new Document.

Parameters:
reader - Reader to read the XML from.
Returns:
New Document from the XML.
Throws:
IllegalArgumentException - If the Document is an unknown version or is un-readable.
IOException - If there is a problem reading the XML.

readAnnotations

public Collection<Text> readAnnotations(Reader reader,
                                        Document document)
                                 throws IOException
Reads the XML into a new Collection of Texts and adds any services to the Document's service list. The returned Texts have no Document, so it is highly recommended that the caller sets the Document upon reading. Note: If the document is a DefaultDocument, then the annotations will be added to it, otherwise they must be added explicitly.

Parameters:
reader - Reader to read the XML from.
Returns:
New Collection of Texts from the XML.
Throws:
IllegalArgumentException - If the Document is an unknown version or is un-readable.
IOException - If there is a problem reading the XML.

marshal

public void marshal(Object toMarshal,
                    Writer writer)
             throws IOException
Marshalls the Object using a JAXB Marshaller.

Parameters:
toMarshal - The Object to serialize to XML.
writer - The Writer to write the XML to.
Throws:
IOException - Wrapper for an JAXBException that occurs during the serialization.

unmarshal

public Object unmarshal(Reader reader)
                 throws IOException
Unmarshalls the Object using a JAXB Unmarshaller.

Parameters:
reader - The Reader to read the XML from.
Throws:
IOException - Wrapper for an JAXBException that occurs during the serialization.


Copyright © 2009. All Rights Reserved.