Package org.apache.uima.cas.impl
Class XCASSerializer
- java.lang.Object
-
- org.apache.uima.cas.impl.XCASSerializer
-
public class XCASSerializer extends java.lang.Object
XCAS serializer. Create a serializer from a type system, then encode individual CASes by writing to a SAX content handler. This class is thread safe. *
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
XCASSerializer.XCASDocSerializer
Use an inner class to hold the data for serializing a CAS.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
ARRAY_ELEMENT_TAG
static java.lang.String
ARRAY_SIZE_ATTR
static java.lang.String
casTagName
static java.lang.String
CONTENT_ATTR_NAME
static java.lang.String
CURRENT_VERSION
static java.lang.String
DEFAULT_DOC_TEXT_FEAT
static java.lang.String
DEFAULT_DOC_TYPE_NAME
private java.lang.String
docTextFeature
private java.lang.String
docTypeName
private java.lang.String[]
featureNames
static java.lang.String
ID_ATTR_NAME
static java.lang.String
INDEXED_ATTR_NAME
private int
numChildren
static java.lang.String
REF_PREFIX
static java.lang.String
TRUE_VALUE
private TypeSystemImpl
ts
static java.lang.String
VERSION_ATTR
-
Constructor Summary
Constructors Constructor Description XCASSerializer(TypeSystem ts)
XCASSerializer(TypeSystem ts, UimaContext uimaContext)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getDocumentTextFeature()
Gets the name of the feature holding the documeng text.java.lang.String
getDocumentTypeName()
Gets the name of the type representing the document.int
getNumChildren()
private java.lang.String
getXCasElementName(java.lang.String aTagName)
Gets the XCAS element name for a CAS type name.static void
serialize(CAS aCAS, java.io.OutputStream aStream)
Serializes an XCAS to a stream.static void
serialize(CAS aCAS, java.io.OutputStream aStream, boolean isFormattedOutput)
Serializes an XCAS to a stream.static void
serialize(CAS aCAS, java.io.OutputStream aStream, boolean isFormattedOutput, boolean useXml_1_1)
Serializes an XCAS to a stream.void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler)
Write the CAS data to a SAX content handler.void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, boolean encodeDoc)
Write the CAS data to a SAX content handler.void
serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, boolean encodeDoc, OutOfTypeSystemData outOfTypeSystemData)
Write the CAS data to a SAX content handler.void
setDocumentTextFeature(java.lang.String aDocTextFeature)
Sets the name of the feature holding the documeng text.void
setDocumentTypeName(java.lang.String aDocTypeName)
Gets the name of the type representing the document.
-
-
-
Field Detail
-
numChildren
private int numChildren
-
casTagName
public static final java.lang.String casTagName
- See Also:
- Constant Field Values
-
VERSION_ATTR
public static final java.lang.String VERSION_ATTR
- See Also:
- Constant Field Values
-
CURRENT_VERSION
public static final java.lang.String CURRENT_VERSION
- See Also:
- Constant Field Values
-
DEFAULT_DOC_TYPE_NAME
public static final java.lang.String DEFAULT_DOC_TYPE_NAME
- See Also:
- Constant Field Values
-
DEFAULT_DOC_TEXT_FEAT
public static final java.lang.String DEFAULT_DOC_TEXT_FEAT
- See Also:
- Constant Field Values
-
INDEXED_ATTR_NAME
public static final java.lang.String INDEXED_ATTR_NAME
- See Also:
- Constant Field Values
-
REF_PREFIX
public static final java.lang.String REF_PREFIX
- See Also:
- Constant Field Values
-
ID_ATTR_NAME
public static final java.lang.String ID_ATTR_NAME
- See Also:
- Constant Field Values
-
CONTENT_ATTR_NAME
public static final java.lang.String CONTENT_ATTR_NAME
- See Also:
- Constant Field Values
-
ARRAY_SIZE_ATTR
public static final java.lang.String ARRAY_SIZE_ATTR
- See Also:
- Constant Field Values
-
ARRAY_ELEMENT_TAG
public static final java.lang.String ARRAY_ELEMENT_TAG
- See Also:
- Constant Field Values
-
TRUE_VALUE
public static final java.lang.String TRUE_VALUE
- See Also:
- Constant Field Values
-
ts
private TypeSystemImpl ts
-
featureNames
private java.lang.String[] featureNames
-
docTypeName
private java.lang.String docTypeName
-
docTextFeature
private java.lang.String docTextFeature
-
-
Constructor Detail
-
XCASSerializer
public XCASSerializer(TypeSystem ts, UimaContext uimaContext)
-
XCASSerializer
public XCASSerializer(TypeSystem ts)
-
-
Method Detail
-
getNumChildren
public int getNumChildren()
-
getXCasElementName
private java.lang.String getXCasElementName(java.lang.String aTagName)
Gets the XCAS element name for a CAS type name. The element name is usually the same as the type name, but the sequences _colon_ and _dash_ are translated to the characters : and -, respectively.- Parameters:
aCasTypeName
- CAS type name- Returns:
- XCAS element name for this type name
-
serialize
public void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler) throws java.io.IOException, org.xml.sax.SAXException
Write the CAS data to a SAX content handler.- Parameters:
cas
- The CAS to be serialized.contentHandler
- The SAX content handler the data is written to.- Throws:
java.io.IOException
- passed thruorg.xml.sax.SAXException
- passed thru
-
serialize
public void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, boolean encodeDoc) throws java.io.IOException, org.xml.sax.SAXException
Write the CAS data to a SAX content handler.- Parameters:
cas
- The CAS to be serialized.contentHandler
- The SAX content handler the data is written to.encodeDoc
- If set to false, no uima.tcas.Document structure will be created, and the document text will not be serialized.- Throws:
java.io.IOException
- passed thruorg.xml.sax.SAXException
- passed thru
-
serialize
public void serialize(CAS cas, org.xml.sax.ContentHandler contentHandler, boolean encodeDoc, OutOfTypeSystemData outOfTypeSystemData) throws java.io.IOException, org.xml.sax.SAXException
Write the CAS data to a SAX content handler.- Parameters:
cas
- The CAS to be serialized.contentHandler
- The SAX content handler the data is written to.encodeDoc
- If set to false, no uima.tcas.Document structure will be created, and the document text will not be serialized.outOfTypeSystemData
- data not part of the CAS type system, which should be inserted into the XCAS output- Throws:
java.io.IOException
- passed thruorg.xml.sax.SAXException
- passed thru
-
getDocumentTypeName
public java.lang.String getDocumentTypeName()
Gets the name of the type representing the document. This will become the name of the XML element that will hold the document text.- Returns:
- the document type name
-
setDocumentTypeName
public void setDocumentTypeName(java.lang.String aDocTypeName)
Gets the name of the type representing the document. This will become the name of the XML element that will hold the document text. If not set, defaults toDEFAULT_DOC_TYPE_NAME
.- Parameters:
aDocTypeName
- the document type name
-
getDocumentTextFeature
public java.lang.String getDocumentTextFeature()
Gets the name of the feature holding the documeng text. This will become the value of the _content attribute on the document element.- Returns:
- the document text feature
-
setDocumentTextFeature
public void setDocumentTextFeature(java.lang.String aDocTextFeature)
Sets the name of the feature holding the documeng text. This will become the value of the _content attribute on the document element. If not set, defaults toDEFAULT_DOC_TEXT_FEAT
. If set to null, no _content attribute will be emitted.- Parameters:
aDocTextFeature
- the document text feature
-
serialize
public static void serialize(CAS aCAS, java.io.OutputStream aStream) throws org.xml.sax.SAXException, java.io.IOException
Serializes an XCAS to a stream.- Parameters:
aCAS
- CAS to serialize.aStream
- output stream to which to write the XCAS XML document- Throws:
org.xml.sax.SAXException
- if a problem occurs during XCAS serializationjava.io.IOException
- if an I/O failure occurs
-
serialize
public static void serialize(CAS aCAS, java.io.OutputStream aStream, boolean isFormattedOutput) throws org.xml.sax.SAXException, java.io.IOException
Serializes an XCAS to a stream.- Parameters:
aCAS
- CAS to serialize.aStream
- output stream to which to write the XCAS XML documentisFormattedOutput
- if true the XCAS will be serialized formatted- Throws:
org.xml.sax.SAXException
- if a problem occurs during XCAS serializationjava.io.IOException
- if an I/O failure occurs
-
serialize
public static void serialize(CAS aCAS, java.io.OutputStream aStream, boolean isFormattedOutput, boolean useXml_1_1) throws org.xml.sax.SAXException, java.io.IOException
Serializes an XCAS to a stream.- Parameters:
aCAS
- CAS to serialize.aStream
- output stream to which to write the XCAS XML documentisFormattedOutput
- if true the XCAS will be serialized formatted *useXml_1_1
- if true, the output serializer is set with the OutputKeys.VERSION to "1.1".- Throws:
org.xml.sax.SAXException
- if a problem occurs during XCAS serializationjava.io.IOException
- if an I/O failure occurs
-
-