java.lang.Object
org.xml.sax.helpers.DefaultHandler
com.sun.xml.fastinfoset.Encoder
com.sun.xml.fastinfoset.stax.StAXDocumentSerializer
- All Implemented Interfaces:
XMLStreamWriter
,FastInfosetSerializer
,LowLevelFastInfosetStreamWriter
,ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
public class StAXDocumentSerializer
extends Encoder
implements XMLStreamWriter, LowLevelFastInfosetStreamWriter
The Fast Infoset StAX serializer.
Instantiate this serializer to serialize a fast infoset document in accordance with the StAX API.
More than one fast infoset document may be encoded to the
OutputStream
.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected String[]
List of attributes qnames and values defined in the current element.protected int
protected String
Local name of current element.protected String
Prefix of current element.protected String
Namespace of current element.protected String
protected boolean
This flag indicates when there is a pending start element event.protected boolean
This flag indicates if the current element is empty.protected StAXManager
protected String[]
List of namespaces defined in the current element.protected int
protected NamespaceContextImplementation
Mapping between uris and prefixes.protected boolean[]
protected int
Fields inherited from class com.sun.xml.fastinfoset.Encoder
_b, _characterEncodingSchemeSystemDefault, _charBuffer, _markIndex, _octetBuffer, _octetBufferIndex, _s, _terminate, _v, _vData, attributeValueMapTotalCharactersConstraint, CHARACTER_ENCODING_SCHEME_SYSTEM_PROPERTY, characterContentChunkMapTotalCharactersConstraint, maxAttributeValueSize, maxCharacterContentChunkSize, minAttributeValueSize, minCharacterContentChunkSize
Fields inherited from interface org.jvnet.fastinfoset.FastInfosetSerializer
ATTRIBUTE_VALUE_MAP_MEMORY_CONSTRAINT, BUFFER_SIZE_PROPERTY, CHARACTER_CONTENT_CHUNK_MAP_MEMORY_CONSTRAINT, EXTERNAL_VOCABULARIES_PROPERTY, IGNORE_COMMENTS_FEATURE, IGNORE_DTD_FEATURE, IGNORE_PROCESSING_INSTRUCTIONS_FEATURE, IGNORE_WHITE_SPACE_TEXT_CONTENT_FEATURE, MAX_ATTRIBUTE_VALUE_SIZE, MAX_CHARACTER_CONTENT_CHUNK_SIZE, MIN_ATTRIBUTE_VALUE_SIZE, MIN_CHARACTER_CONTENT_CHUNK_SIZE, REGISTERED_ENCODING_ALGORITHMS_PROPERTY, UTF_16BE, UTF_8
-
Constructor Summary
ConstructorsConstructorDescriptionStAXDocumentSerializer
(OutputStream outputStream) StAXDocumentSerializer
(OutputStream outputStream, StAXManager manager) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
private boolean
encodeAttribute
(String namespaceURI, String prefix, String localName) private boolean
encodeElement
(int type, String namespaceURI, String prefix, String localName) private void
encodeLiteral
(int type, String namespaceURI, String prefix, String localName) private void
encodeLiteralHeader
(int type, String namespaceURI, String prefix) protected void
encodeTerminationAndCurrentElement
(boolean terminateAfter) void
flush()
final int
Get the current index that was applied to an [local name] of an Element or Attribute Information Item.final int
Get the next index to apply to an Attribute Information Item.final int
Get the next index to apply to an Element Information Item.final int
Get the next index to apply to an [local name] of an Element or Attribute Information Item.getProperty
(String name) final void
Initiate low level writing of an element fragment.void
reset()
Reset the encoder for reuse encoding another XML infoset.void
void
setEncoding
(String encoding) void
setManager
(StAXManager manager) void
setNamespaceContext
(NamespaceContext context) Sets the current namespace context for prefix and uri bindings.void
void
writeAttribute
(String localName, String value) void
writeAttribute
(String namespaceURI, String localName, String value) void
writeAttribute
(String prefix, String namespaceURI, String localName, String value) void
writeCData
(String text) void
writeCharacters
(char[] text, int start, int len) void
writeCharacters
(String text) void
writeComment
(String data) void
writeDefaultNamespace
(String namespaceURI) void
void
writeEmptyElement
(String localName) void
writeEmptyElement
(String namespaceURI, String localName) void
writeEmptyElement
(String prefix, String localName, String namespaceURI) void
void
void
writeEntityRef
(String name) final boolean
writeLowLevelAttribute
(String prefix, String namespaceURI, String localName) Write an attribute.final void
writeLowLevelAttributeIndexed
(int index) final void
final void
final void
final void
final void
writeLowLevelNamespace
(String prefix, String namespaceName) final void
writeLowLevelOctets
(byte[] octets, int length) final void
final boolean
writeLowLevelStartElement
(int type, String prefix, String localName, String namespaceURI) Write the start of an element.final void
writeLowLevelStartElementIndexed
(int type, int index) final void
writeLowLevelStartNameLiteral
(int type, String prefix, byte[] utf8LocalName, String namespaceURI) final void
writeLowLevelStartNameLiteral
(int type, String prefix, int localNameIndex, String namespaceURI) final void
final void
final void
writeLowLevelText
(char[] text, int length) final void
writeLowLevelText
(String text) void
writeNamespace
(String prefix, String namespaceURI) void
writeOctets
(byte[] b, int start, int len) void
writeProcessingInstruction
(String target) void
writeProcessingInstruction
(String target, String data) void
void
writeStartDocument
(String version) void
writeStartDocument
(String encoding, String version) void
writeStartElement
(String localName) void
writeStartElement
(String namespaceURI, String localName) void
writeStartElement
(String prefix, String localName, String namespaceURI) Methods inherited from class com.sun.xml.fastinfoset.Encoder
canAddAttributeToTable, canAddCharacterContentToTable, encodeAIIBuiltInAlgorithmData, encodeAIIObjectAlgorithmData, encodeAIIOctetAlgorithmData, encodeAlphabetCharacters, encodeAttributeQualifiedNameOnSecondBit, encodeCharacters, encodeCharactersNoClone, encodeCIIBuiltInAlgorithmData, encodeCIIBuiltInAlgorithmDataAsCDATA, encodeCIIObjectAlgorithmData, encodeCIIOctetAlgorithmData, encodeComment, encodeCommentNoClone, encodeDateTimeFourBitCharacters, encodeDateTimeNonIdentifyingStringOnFirstBit, encodeDocumentTermination, encodeDocumentTypeDeclaration, encodeElementQualifiedNameOnThirdBit, encodeElementTermination, encodeFourBitCharacters, encodeHeader, encodeIdentifyingNonEmptyStringOnFirstBit, encodeInitialVocabulary, encodeLiteralAttributeQualifiedNameOnSecondBit, encodeLiteralElementQualifiedNameOnThirdBit, encodeNamespaceAttribute, encodeNonEmptyCharacterStringOnFifthBit, encodeNonEmptyCharacterStringOnFifthBit, encodeNonEmptyCharacterStringOnSeventhBit, encodeNonEmptyFourBitCharacterString, encodeNonEmptyFourBitCharacterStringOnSeventhBit, encodeNonEmptyNBitCharacterStringOnSeventhBit, encodeNonEmptyOctetStringOnSecondBit, encodeNonEmptyUTF8StringAsOctetString, encodeNonEmptyUTF8StringAsOctetString, encodeNonIdentifyingStringOnFirstBit, encodeNonIdentifyingStringOnFirstBit, encodeNonIdentifyingStringOnFirstBit, encodeNonIdentifyingStringOnFirstBit, encodeNonIdentifyingStringOnFirstBit, encodeNonIdentifyingStringOnThirdBit, encodeNonIdentifyingStringOnThirdBit, encodeNonIdentifyingStringOnThirdBit, encodeNonZeroInteger, encodeNonZeroIntegerOnFourthBit, encodeNonZeroIntegerOnSecondBitFirstBitOne, encodeNonZeroIntegerOnSecondBitFirstBitZero, encodeNonZeroIntegerOnThirdBit, encodeNonZeroOctetStringLength, encodeNonZeroOctetStringLengthOnFifthBit, encodeNonZeroOctetStringLengthOnSecondBit, encodeNonZeroOctetStringLengthOnSenventhBit, encodeNumericFourBitCharacters, encodeNumericNonIdentifyingStringOnFirstBit, encodeProcessingInstruction, encodeTermination, encodeUtf16String, encodeUtf16String, encodeUTF8String, encodeUTF8String, getAttributeValueMapMemoryLimit, getCharacterContentChunkMapMemoryLimit, getCharacterEncodingScheme, getIgnoreComments, getIgnoreDTD, getIgnoreProcesingInstructions, getIgnoreWhiteSpaceTextContent, getMaxAttributeValueSize, getMaxCharacterContentChunkSize, getMinAttributeValueSize, getMinCharacterContentChunkSize, getPrefixFromQualifiedName, getRegisteredEncodingAlgorithms, getVocabularyApplicationData, hasMark, isAttributeValueLengthMatchesLimit, isCharacterContentChunkLengthMatchesLimit, isWhiteSpace, isWhiteSpace, mark, resetMark, setAttributeValueMapMemoryLimit, setCharacterContentChunkMapMemoryLimit, setCharacterEncodingScheme, setExternalVocabulary, setIgnoreComments, setIgnoreDTD, setIgnoreProcesingInstructions, setIgnoreWhiteSpaceTextContent, setMaxAttributeValueSize, setMaxCharacterContentChunkSize, setMinAttributeValueSize, setMinCharacterContentChunkSize, setOutputStream, setRegisteredEncodingAlgorithms, setVocabulary, setVocabularyApplicationData, write, write, write
Methods inherited from class org.xml.sax.helpers.DefaultHandler
characters, endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startElement, startPrefixMapping, unparsedEntityDecl, warning
-
Field Details
-
_manager
-
_encoding
-
_currentLocalName
Local name of current element. -
_currentUri
Namespace of current element. -
_currentPrefix
Prefix of current element. -
_inStartElement
protected boolean _inStartElementThis flag indicates when there is a pending start element event. -
_isEmptyElement
protected boolean _isEmptyElementThis flag indicates if the current element is empty. -
_attributesArray
List of attributes qnames and values defined in the current element. -
_attributesArrayIndex
protected int _attributesArrayIndex -
_nsSupportContextStack
protected boolean[] _nsSupportContextStack -
_stackCount
protected int _stackCount -
_nsContext
Mapping between uris and prefixes. -
_namespacesArray
List of namespaces defined in the current element. -
_namespacesArrayIndex
protected int _namespacesArrayIndex
-
-
Constructor Details
-
StAXDocumentSerializer
public StAXDocumentSerializer() -
StAXDocumentSerializer
-
StAXDocumentSerializer
-
-
Method Details
-
reset
public void reset()Description copied from class:Encoder
Reset the encoder for reuse encoding another XML infoset.- Specified by:
reset
in interfaceFastInfosetSerializer
- Overrides:
reset
in classEncoder
-
writeStartDocument
- Specified by:
writeStartDocument
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeStartDocument
- Specified by:
writeStartDocument
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeStartDocument
- Specified by:
writeStartDocument
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeEndDocument
- Specified by:
writeEndDocument
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
close
- Specified by:
close
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
flush
- Specified by:
flush
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeStartElement
- Specified by:
writeStartElement
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeStartElement
- Specified by:
writeStartElement
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeStartElement
public void writeStartElement(String prefix, String localName, String namespaceURI) throws XMLStreamException - Specified by:
writeStartElement
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeEmptyElement
- Specified by:
writeEmptyElement
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeEmptyElement
- Specified by:
writeEmptyElement
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(String prefix, String localName, String namespaceURI) throws XMLStreamException - Specified by:
writeEmptyElement
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeEndElement
- Specified by:
writeEndElement
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeAttribute
- Specified by:
writeAttribute
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String namespaceURI, String localName, String value) throws XMLStreamException - Specified by:
writeAttribute
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeAttribute
public void writeAttribute(String prefix, String namespaceURI, String localName, String value) throws XMLStreamException - Specified by:
writeAttribute
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeNamespace
- Specified by:
writeNamespace
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeDefaultNamespace
- Specified by:
writeDefaultNamespace
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeComment
- Specified by:
writeComment
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeProcessingInstruction
- Specified by:
writeProcessingInstruction
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeProcessingInstruction
- Specified by:
writeProcessingInstruction
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeCData
- Specified by:
writeCData
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeDTD
- Specified by:
writeDTD
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeEntityRef
- Specified by:
writeEntityRef
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeCharacters
- Specified by:
writeCharacters
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
writeCharacters
- Specified by:
writeCharacters
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
getPrefix
- Specified by:
getPrefix
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
setPrefix
- Specified by:
setPrefix
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
setDefaultNamespace
- Specified by:
setDefaultNamespace
in interfaceXMLStreamWriter
- Throws:
XMLStreamException
-
setNamespaceContext
Sets the current namespace context for prefix and uri bindings. This context becomes the root namespace context for writing and will replace the current root namespace context. Subsequent calls to setPrefix and setDefaultNamespace will bind namespaces using the context passed to the method as the root context for resolving namespaces. This method may only be called once at the start of the document. It does not cause the namespaces to be declared. If a namespace URI to prefix mapping is found in the namespace context it is treated as declared and the prefix may be used by the StreamWriter.- Specified by:
setNamespaceContext
in interfaceXMLStreamWriter
- Parameters:
context
- the namespace context to use for this writer, may not be null- Throws:
XMLStreamException
-
getNamespaceContext
- Specified by:
getNamespaceContext
in interfaceXMLStreamWriter
-
getProperty
- Specified by:
getProperty
in interfaceXMLStreamWriter
- Throws:
IllegalArgumentException
-
setManager
-
setEncoding
-
writeOctets
- Throws:
XMLStreamException
-
encodeTerminationAndCurrentElement
- Throws:
XMLStreamException
-
initiateLowLevelWriting
Description copied from interface:LowLevelFastInfosetStreamWriter
Initiate low level writing of an element fragment.This method must be invoked before other low level method.
- Specified by:
initiateLowLevelWriting
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
XMLStreamException
-
getNextElementIndex
public final int getNextElementIndex()Description copied from interface:LowLevelFastInfosetStreamWriter
Get the next index to apply to an Element Information Item.This will increment the next obtained index such that:
i = w.getNextElementIndex(); j = w.getNextElementIndex(); i == j + 1;
- Specified by:
getNextElementIndex
in interfaceLowLevelFastInfosetStreamWriter
- Returns:
- the index.
-
getNextAttributeIndex
public final int getNextAttributeIndex()Description copied from interface:LowLevelFastInfosetStreamWriter
Get the next index to apply to an Attribute Information Item. This will increment the next obtained index such that:i = w.getNextAttributeIndex(); j = w.getNextAttributeIndex(); i == j + 1;
- Specified by:
getNextAttributeIndex
in interfaceLowLevelFastInfosetStreamWriter
- Returns:
- the index.
-
getLocalNameIndex
public final int getLocalNameIndex()Description copied from interface:LowLevelFastInfosetStreamWriter
Get the current index that was applied to an [local name] of an Element or Attribute Information Item.- Specified by:
getLocalNameIndex
in interfaceLowLevelFastInfosetStreamWriter
- Returns:
- the index.
-
getNextLocalNameIndex
public final int getNextLocalNameIndex()Description copied from interface:LowLevelFastInfosetStreamWriter
Get the next index to apply to an [local name] of an Element or Attribute Information Item. This will increment the next obtained index such that:i = w.getNextLocalNameIndex(); j = w.getNextLocalNameIndex(); i == j + 1;
- Specified by:
getNextLocalNameIndex
in interfaceLowLevelFastInfosetStreamWriter
- Returns:
- the index.
-
writeLowLevelTerminationAndMark
- Specified by:
writeLowLevelTerminationAndMark
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelStartElementIndexed
- Specified by:
writeLowLevelStartElementIndexed
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelStartElement
public final boolean writeLowLevelStartElement(int type, String prefix, String localName, String namespaceURI) throws IOException Description copied from interface:LowLevelFastInfosetStreamWriter
Write the start of an element.- Specified by:
writeLowLevelStartElement
in interfaceLowLevelFastInfosetStreamWriter
- Returns:
- true if element is indexed, otherwise false.
- Throws:
IOException
-
writeLowLevelStartNamespaces
- Specified by:
writeLowLevelStartNamespaces
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelNamespace
- Specified by:
writeLowLevelNamespace
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelEndNamespaces
- Specified by:
writeLowLevelEndNamespaces
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelStartAttributes
- Specified by:
writeLowLevelStartAttributes
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelAttributeIndexed
- Specified by:
writeLowLevelAttributeIndexed
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelAttribute
public final boolean writeLowLevelAttribute(String prefix, String namespaceURI, String localName) throws IOException Description copied from interface:LowLevelFastInfosetStreamWriter
Write an attribute.- Specified by:
writeLowLevelAttribute
in interfaceLowLevelFastInfosetStreamWriter
- Returns:
- true if attribute is indexed, otherwise false.
- Throws:
IOException
-
writeLowLevelAttributeValue
- Specified by:
writeLowLevelAttributeValue
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelStartNameLiteral
public final void writeLowLevelStartNameLiteral(int type, String prefix, byte[] utf8LocalName, String namespaceURI) throws IOException - Specified by:
writeLowLevelStartNameLiteral
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelStartNameLiteral
public final void writeLowLevelStartNameLiteral(int type, String prefix, int localNameIndex, String namespaceURI) throws IOException - Specified by:
writeLowLevelStartNameLiteral
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelEndStartElement
- Specified by:
writeLowLevelEndStartElement
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelEndElement
- Specified by:
writeLowLevelEndElement
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelText
- Specified by:
writeLowLevelText
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelText
- Specified by:
writeLowLevelText
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
writeLowLevelOctets
- Specified by:
writeLowLevelOctets
in interfaceLowLevelFastInfosetStreamWriter
- Throws:
IOException
-
encodeElement
private boolean encodeElement(int type, String namespaceURI, String prefix, String localName) throws IOException - Throws:
IOException
-
encodeAttribute
private boolean encodeAttribute(String namespaceURI, String prefix, String localName) throws IOException - Throws:
IOException
-
encodeLiteralHeader
- Throws:
IOException
-
encodeLiteral
private void encodeLiteral(int type, String namespaceURI, String prefix, String localName) throws IOException - Throws:
IOException
-