Class ExportXmlStreamWriter
- java.lang.Object
-
- com._1c.g5.v8.dt.export.xml.writer.ExportXmlStreamWriter
-
- All Implemented Interfaces:
AutoCloseable
- Direct Known Subclasses:
CaiXmlDocumentWriter
,DcsatXmlStreamWriter
,ExportXmlStreamWriterExtension
,ExternalPropertiesDocumentWriter
,FormDocumentWriter
,GraphicalSchemeDocumentWriter
,MetadataDocumentWriter
,PredefinedDocumentWriter
,RightsDocumentWriter
public class ExportXmlStreamWriter extends Object implements AutoCloseable
The ExportXMLStreamWriter specifies how to write pretty XML
-
-
Field Summary
Fields Modifier and Type Field Description protected LineFeedConverter.ConvertOption
charactersExportConvertOption
Define option to convert lines feed inside exporting characters (convert to system line endings by default)protected static String
ENCODING
Default writer char encodingprotected static String
INDENT_STRING
Default writer xml text indentprotected static String
LINE_END
Default writer line seporatorprotected XMLStreamWriter
xmlWriter
-
Constructor Summary
Constructors Constructor Description ExportXmlStreamWriter(OutputStream outputStream, boolean prettyPrint, boolean forceOptimizedPrefix)
Constructor of XmlStreamWriter with prettyPrint and utf-8 encodingExportXmlStreamWriter(XMLStreamWriter xmlWriter, boolean prettyPrint, boolean forceOptimizedPrefix)
Constructor of XmlStreamWriter with prettyPrint and utf-8 encoding
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addKnownPrefix(String prefix, String namespaceURI)
Add new alias from namespace URI to prefix.void
beginDocument()
Write xml document header with namespacesvoid
beginDocument(String xmlVersion)
Write xml document header with namespaces and extended xml version attributevoid
close()
protected void
decreaseIndent()
Decrease indent value.protected int
getIndent()
Returns the current indent value.String
getNewPrefix(String uri)
Gets the prefix or generate new local prefix the uri is bound toString
getPrefix(String uri)
Gets the prefix the uri is bound toXMLStreamWriter
getXmlWriter()
WrappedXMLStreamWriter
protected void
increaseIndent()
Increase indent value.protected QName
optimizeQName(QName name)
Optimize QName before writing.void
writeAttribute(String localName, Object value)
Write xml attribute in current element with prefixvoid
writeAttribute(String localName, String value)
Write xml attribute in current element without prefixvoid
writeAttribute(QName qName, Object value)
Write xml attribute in current element with prefixvoid
writeAttribute(QName qName, String value)
Write xml attribute in current element with prefixvoid
writeAttribute(QName qName, QName qValue)
Write xml attribute in current elementvoid
writeCharacters(String text)
Write text to the outputvoid
writeDefaultNamespace(String namespaceURI)
Writes the default namespace to the streamvoid
writeEmptyElement(String localName)
Writes an empty element tag to the outputvoid
writeEmptyElement(QName qName)
Writes an empty element tag to the outputvoid
writeEndDocument()
Closes any start tags and writes corresponding end tags.void
writeEndElement()
Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.void
writeInlineEndElement()
Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.void
writeLineFeed()
Writes a line feedvoid
writeNamespace(String prefix, String namespaceURI)
Writes a namespace to the output stream If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace.void
writeStartDocument(String encoding, String version)
Write the XML Declaration.void
writeStartDocument(String encoding, String version, boolean writeBom)
Write the XML Declaration.void
writeStartElement(String localName)
Writes a start tag to the outputvoid
writeStartElement(QName qName)
Writes a start tag to the outputvoid
writeTextElement(QName qName, Object obj)
Writes a tag with text to the outputvoid
writeTextElement(QName qName, String text)
Writes a tag with text to the output
-
-
-
Field Detail
-
ENCODING
protected static final String ENCODING
Default writer char encoding
-
LINE_END
protected static final String LINE_END
Default writer line seporator- See Also:
- Constant Field Values
-
INDENT_STRING
protected static final String INDENT_STRING
Default writer xml text indent- See Also:
- Constant Field Values
-
xmlWriter
protected final XMLStreamWriter xmlWriter
-
charactersExportConvertOption
protected LineFeedConverter.ConvertOption charactersExportConvertOption
Define option to convert lines feed inside exporting characters (convert to system line endings by default)
-
-
Constructor Detail
-
ExportXmlStreamWriter
public ExportXmlStreamWriter(XMLStreamWriter xmlWriter, boolean prettyPrint, boolean forceOptimizedPrefix)
Constructor of XmlStreamWriter with prettyPrint and utf-8 encoding- Parameters:
xmlWriter
- the targetXMLStreamWriter
, cannot benull
prettyPrint
- enable write XML elements with indentation by levelforceOptimizedPrefix
- enable force write prefix for QNames with known XML namespace
-
ExportXmlStreamWriter
public ExportXmlStreamWriter(OutputStream outputStream, boolean prettyPrint, boolean forceOptimizedPrefix) throws XMLStreamException, FactoryConfigurationError
Constructor of XmlStreamWriter with prettyPrint and utf-8 encoding- Parameters:
outputStream
- the stream to write to, cannot benull
prettyPrint
- enable write XML elements with indentation by levelforceOptimizedPrefix
- enable force write prefix for QNames with known XML namespace- Throws:
XMLStreamException
- if an error occurred of write in streamFactoryConfigurationError
- if an instance ofXMLOutputFactory
cannot be loaded
-
-
Method Detail
-
getXmlWriter
public XMLStreamWriter getXmlWriter()
WrappedXMLStreamWriter
- Returns:
- the xmlWriter, never
null
-
close
public void close() throws XMLStreamException
- Specified by:
close
in interfaceAutoCloseable
- Throws:
XMLStreamException
-
beginDocument
public void beginDocument() throws XMLStreamException, ExportException
Write xml document header with namespaces- Throws:
XMLStreamException
- if an error occurred of write in streamExportException
- if export processing errors
-
beginDocument
public void beginDocument(String xmlVersion) throws XMLStreamException, ExportException
Write xml document header with namespaces and extended xml version attribute
- Parameters:
xmlVersion
- the xml format version, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in streamExportException
- if export processing errors
-
writeStartDocument
public void writeStartDocument(String encoding, String version) throws XMLStreamException
Write the XML Declaration. Note that the encoding parameter does not set the actual encoding of the underlying output. That must be set when the instance of theXMLStreamWriter
is created using theXMLOutputFactory
.- Parameters:
encoding
- encoding of the xml declaration, cannot benull
version
- version of the xml document, can benull
to write default XML version- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeStartDocument
public void writeStartDocument(String encoding, String version, boolean writeBom) throws XMLStreamException
Write the XML Declaration. Note that the encoding parameter does not set the actual encoding of the underlying output. That must be set when the instance of theXMLStreamWriter
is created using theXMLOutputFactory
.- Parameters:
encoding
- encoding of the xml declaration, cannot benull
version
- version of the xml document, can benull
to write default XML versionwriteBom
- settrue
for writing UTF-8 BOM in start of file, orfalse
in otherwice- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeEndDocument
public void writeEndDocument() throws XMLStreamException
Closes any start tags and writes corresponding end tags.- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeAttribute
public void writeAttribute(String localName, Object value) throws XMLStreamException, ExportException
Write xml attribute in current element with prefix- Parameters:
localName
- of attribute, cannot benull
value
- of attribute, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in streamExportException
- if an error occurred of write invalid data
-
writeAttribute
public void writeAttribute(String localName, String value) throws XMLStreamException, ExportException
Write xml attribute in current element without prefix- Parameters:
localName
- of attribute, cannot benull
value
- of attribute, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in streamExportException
- if an error occurred of write invalid data
-
writeAttribute
public void writeAttribute(QName qName, Object value) throws XMLStreamException, ExportException
Write xml attribute in current element with prefix- Parameters:
qName
- of attribute, cannot benull
value
- of attribute, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in streamExportException
- if an error occurred of write invalid data
-
writeAttribute
public void writeAttribute(QName qName, String value) throws XMLStreamException, ExportException
Write xml attribute in current element with prefix- Parameters:
qName
- of attribute, cannot benull
value
- of attribute, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in streamExportException
- if an error occurred of write invalid data
-
writeAttribute
public void writeAttribute(QName qName, QName qValue) throws XMLStreamException, ExportException
Write xml attribute in current element- Parameters:
qName
- of attribute, cannot benull
qValue
- of attribute, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in streamExportException
-
writeCharacters
public void writeCharacters(String text) throws XMLStreamException
Write text to the output- Parameters:
text
- the value to write, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeDefaultNamespace
public void writeDefaultNamespace(String namespaceURI) throws XMLStreamException
Writes the default namespace to the stream- Parameters:
namespaceURI
- the uri to bind the default namespace to, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeNamespace
public void writeNamespace(String prefix, String namespaceURI) throws XMLStreamException
Writes a namespace to the output stream If the prefix argument to this method is the empty string, "xmlns", or null this method will delegate to writeDefaultNamespace.- Parameters:
prefix
- the prefix to bind this namespace to, cannot benull
namespaceURI
- the uri to bind the prefix to, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeEmptyElement
public void writeEmptyElement(QName qName) throws XMLStreamException
Writes an empty element tag to the output- Parameters:
qName
- the name of the tag, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeEmptyElement
public void writeEmptyElement(String localName) throws XMLStreamException
Writes an empty element tag to the output- Parameters:
localName
- the local name of the tag, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeEndElement
public void writeEndElement() throws XMLStreamException
Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeInlineEndElement
public void writeInlineEndElement() throws XMLStreamException
Writes an end tag to the output relying on the internal state of the writer to determine the prefix and local name of the event.- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeStartElement
public void writeStartElement(String localName) throws XMLStreamException
Writes a start tag to the output- Parameters:
localName
- local name of the tag, cannot benull
- Throws:
XMLStreamException
-
writeStartElement
public void writeStartElement(QName qName) throws XMLStreamException
Writes a start tag to the output- Parameters:
qName
- the name of the tag, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeTextElement
public void writeTextElement(QName qName, Object obj) throws XMLStreamException
Writes a tag with text to the output- Parameters:
qName
- the name of the tag, cannot benull
obj
- the value to write, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeTextElement
public void writeTextElement(QName qName, String text) throws XMLStreamException
Writes a tag with text to the output- Parameters:
qName
- the name of tag, cannot benull
text
- the value to write, cannot benull
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
writeLineFeed
public void writeLineFeed() throws XMLStreamException
Writes a line feed- Throws:
XMLStreamException
- if an error occurred of write in stream
-
getPrefix
public String getPrefix(String uri) throws XMLStreamException
Gets the prefix the uri is bound to- Parameters:
uri
- target namespace uri, cannot benull
- Returns:
- the prefix or
null
if no prifix registred for specifed URI - Throws:
XMLStreamException
- if an error occurred of write in stream
-
getNewPrefix
public String getNewPrefix(String uri) throws XMLStreamException
Gets the prefix or generate new local prefix the uri is bound to- Parameters:
uri
- target namespace uri, cannot benull
- Returns:
- the registred or generate prefix value, never
null
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
addKnownPrefix
protected void addKnownPrefix(String prefix, String namespaceURI)
Add new alias from namespace URI to prefix.This prefix will be used for elements with specifed namespaceURI if this prefix not overided in XML.
- Parameters:
prefix
- the String presentation of prefix, cannot benull
namespaceURI
- the String presentation of namespace URI, cannot benull
-
optimizeQName
protected QName optimizeQName(QName name) throws XMLStreamException
Optimize QName before writing.Enable only if forceOptimizedPrefix sets
true
in constructor, in otherwise return given name as is.- Parameters:
name
- input QName value to optimize, cannot benull
- Returns:
- optimized QName value, never
null
- Throws:
XMLStreamException
- if an error occurred of write in stream
-
getIndent
protected int getIndent()
Returns the current indent value.- Returns:
- the current indent value
-
decreaseIndent
protected void decreaseIndent()
Decrease indent value.
-
increaseIndent
protected void increaseIndent()
Increase indent value.
-
-