APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.util.xml.impl

public Class XMLStreamWriterImpl

extends Object
implements XMLStreamWriter
Class Inheritance
All Implemented Interfaces
jdk.internal.util.xml.XMLStreamWriter
Imports
java.io.OutputStream, .UnsupportedEncodingException, java.nio.charset.Charset, .IllegalCharsetNameException, .UnsupportedCharsetException, jdk.internal.util.xml.XMLStreamException, .XMLStreamWriter

Implementation of a reduced version of XMLStreamWriter
Author
Joe Wang

Nested and Inner Type Summary

Modifier and TypeClass and Description
protected static class

Field Summary

Modifier and TypeField and Description
private Charset
private XMLStreamWriterImpl.Element
private boolean
pack-priv boolean
_escapeCharacters

This flag can be used to turn escaping off for content.

private char[]
private int
private XMLWriter
public static final char
public static final String
public static final char
public static final char
public static final char
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int
public static final String
public static final String
public static final String
public static final char
public static final char
public static final char
public static final String
pack-priv static final int
pack-priv static final int
pack-priv static final int
pack-priv static final int

Constructor Summary

AccessConstructor and Description
public
public

Method Summary

Modifier and TypeMethod and Description
private Charset

Returns:

the charset
checkCharset
(Charset
the specified charset
charset
)

Checks for charset support.

public void
close()

Implements jdk.internal.util.xml.XMLStreamWriter.close.

Close this XMLStreamWriter by closing underlying writer.

private void
closeStartTag()

marks close of start tag and writes the same into the writer.

public void
flush()

Implements jdk.internal.util.xml.XMLStreamWriter.flush.

Flush this XMLStreamWriter by flushing underlying writer.

private Charset

Returns:

a charset object
getCharset
(String encoding)

Returns a charset object for the specified encoding

private void
openStartTag()

marks open of start tag and writes the same into the writer.

public void
setDoIndent(boolean doIndent)

Set the flag to indicate if the writer should add line separator

public void
writeAttribute(String
the local name of the attribute
localName
,
String
the value of the attribute
value
)

Implements jdk.internal.util.xml.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream without a prefix.

public void
writeCData(String cdata)

Implements jdk.internal.util.xml.XMLStreamWriter.writeCData.

Writes a CData section

public void
public void
writeCharacters(char[] data, int start, int len)

Implements jdk.internal.util.xml.XMLStreamWriter.writeCharacters.

Write text to the output

private void
writeCharRef(int codePoint)

Writes character reference in hex format.

public void
writeDTD(String
the DTD to be written
dtd
)

Implements jdk.internal.util.xml.XMLStreamWriter.writeDTD.

Write a DTD section.

public void
writeEmptyElement(String
local name of the tag, may not be null
localName
)

Implements jdk.internal.util.xml.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output

public void
writeEndDocument()

Implements jdk.internal.util.xml.XMLStreamWriter.writeEndDocument.

Closes any start tags and writes corresponding end tags.

public void
writeEndElement()

Implements jdk.internal.util.xml.XMLStreamWriter.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.

private void
writeLineSeparator()

Write a line separator

public void
public void
writeStartDocument(String
version of the xml document
version
)

Implements jdk.internal.util.xml.XMLStreamWriter.writeStartDocument.

Write the XML Declaration.

public void
writeStartDocument(String
encoding of the xml declaration
encoding
,
String
version of the xml document
version
)

Implements jdk.internal.util.xml.XMLStreamWriter.writeStartDocument.

Write the XML Declaration.

public void
writeStartDocument(String
encoding of the xml declaration
encoding
,
String
version of the xml document
version
,
String
indicate if the xml document is standalone
standalone
)

Write the XML Declaration.

public void
writeStartElement(String
local name of the tag, may not be null
localName
)

Implements jdk.internal.util.xml.XMLStreamWriter.writeStartElement.

Writes a start tag to the output.

private void
writeXMLContent(char[] content, int start, int length, boolean escapeChars)

Writes XML content to underlying writer.

private void
private void
writeXMLContent(String content, boolean escapeChars, boolean escapeDoubleQuotes)

Writes XML content to underlying writer.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_charsetback to summary
private Charset _charset
_currentEleback to summary
private XMLStreamWriterImpl.Element _currentEle
_doIndentback to summary
private boolean _doIndent
_escapeCharactersback to summary
pack-priv boolean _escapeCharacters

This flag can be used to turn escaping off for content. It does not apply to attribute content.

_lineSepback to summary
private char[] _lineSep
_stateback to summary
private int _state
_writerback to summary
private XMLWriter _writer
AMPERSANDback to summary
public static final char AMPERSAND
CLOSE_EMPTY_ELEMENTback to summary
public static final String CLOSE_EMPTY_ELEMENT
CLOSE_END_TAGback to summary
public static final char CLOSE_END_TAG
CLOSE_START_TAGback to summary
public static final char CLOSE_START_TAG
DOUBLEQUOTback to summary
public static final char DOUBLEQUOT
ELEMENT_ENDTAG_CLOSEback to summary
pack-priv static final int ELEMENT_ENDTAG_CLOSE
ELEMENT_ENDTAG_OPENback to summary
pack-priv static final int ELEMENT_ENDTAG_OPEN
ELEMENT_STARTTAG_CLOSEback to summary
pack-priv static final int ELEMENT_STARTTAG_CLOSE
ELEMENT_STARTTAG_OPENback to summary
pack-priv static final int ELEMENT_STARTTAG_OPEN
ENCODING_PREFIXback to summary
public static final String ENCODING_PREFIX
END_CDATAback to summary
public static final String END_CDATA
OPEN_END_TAGback to summary
public static final String OPEN_END_TAG
OPEN_START_TAGback to summary
public static final char OPEN_START_TAG
SEMICOLONback to summary
public static final char SEMICOLON
SPACEback to summary
public static final char SPACE
START_CDATAback to summary
public static final String START_CDATA
STATE_DTD_DECLback to summary
pack-priv static final int STATE_DTD_DECL
STATE_ELEMENTback to summary
pack-priv static final int STATE_ELEMENT
STATE_PROLOGback to summary
pack-priv static final int STATE_PROLOG
STATE_XML_DECLback to summary
pack-priv static final int STATE_XML_DECL

Constructor Detail

XMLStreamWriterImplback to summary
public XMLStreamWriterImpl(OutputStream os) throws XMLStreamException
XMLStreamWriterImplback to summary
public XMLStreamWriterImpl(OutputStream os, Charset cs) throws XMLStreamException

Method Detail

checkCharsetback to summary
private Charset checkCharset(Charset charset) throws UnsupportedEncodingException

Checks for charset support.

Parameters
charset:Charset

the specified charset

Returns:Charset

the charset

Exceptions
UnsupportedEncodingException:
if the charset is not supported
closeback to summary
public void close() throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.close.

Close this XMLStreamWriter by closing underlying writer.

closeStartTagback to summary
private void closeStartTag() throws XMLStreamException

marks close of start tag and writes the same into the writer.

flushback to summary
public void flush() throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.flush.

Flush this XMLStreamWriter by flushing underlying writer.

getCharsetback to summary
private Charset getCharset(String encoding) throws UnsupportedEncodingException

Returns a charset object for the specified encoding

Returns:Charset

a charset object

Exceptions
UnsupportedEncodingException:
if the encoding is not supported
openStartTagback to summary
private void openStartTag() throws XMLStreamException

marks open of start tag and writes the same into the writer.

setDoIndentback to summary
public void setDoIndent(boolean doIndent)

Set the flag to indicate if the writer should add line separator

writeAttributeback to summary
public void writeAttribute(String localName, String value) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeAttribute.

Writes an attribute to the output stream without a prefix.

Parameters
localName:String

the local name of the attribute

value:String

the value of the attribute

Exceptions
IllegalStateException:
if the current state does not allow Attribute writing
writeCDataback to summary
public void writeCData(String cdata) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeCData.

Doc from jdk.internal.util.xml.XMLStreamWriter.writeCData.

Writes a CData section

writeCharactersback to summary
public void writeCharacters(String data) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeCharacters.

Doc from jdk.internal.util.xml.XMLStreamWriter.writeCharacters.

Write text to the output

writeCharactersback to summary
public void writeCharacters(char[] data, int start, int len) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeCharacters.

Doc from jdk.internal.util.xml.XMLStreamWriter.writeCharacters.

Write text to the output

writeCharRefback to summary
private void writeCharRef(int codePoint) throws XMLStreamException

Writes character reference in hex format.

writeDTDback to summary
public void writeDTD(String dtd) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeDTD.

Write a DTD section. This string represents the entire doctypedecl production from the XML 1.0 specification.

Parameters
dtd:String

the DTD to be written

writeEmptyElementback to summary
public void writeEmptyElement(String localName) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeEmptyElement.

Writes an empty element tag to the output

Parameters
localName:String

local name of the tag, may not be null

writeEndDocumentback to summary
public void writeEndDocument() throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeEndDocument.

Doc from jdk.internal.util.xml.XMLStreamWriter.writeEndDocument.

Closes any start tags and writes corresponding end tags.

writeEndElementback to summary
public void writeEndElement() throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeEndElement.

Doc from jdk.internal.util.xml.XMLStreamWriter.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.

writeLineSeparatorback to summary
private void writeLineSeparator() throws XMLStreamException

Write a line separator

writeStartDocumentback to summary
public void writeStartDocument() throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeStartDocument.

Write the XML Declaration. Defaults the XML version to 1.0, and the encoding to utf-8.

writeStartDocumentback to summary
public void writeStartDocument(String version) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeStartDocument.

Write the XML Declaration. Defaults the encoding to utf-8

Parameters
version:String

version of the xml document

writeStartDocumentback to summary
public void writeStartDocument(String encoding, String version) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeStartDocument.

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 the XMLStreamWriter is created

Parameters
encoding:String

encoding of the xml declaration

version:String

version of the xml document

Exceptions
XMLStreamException:
If given encoding does not match encoding of the underlying stream
writeStartDocumentback to summary
public void writeStartDocument(String encoding, String version, String standalone) 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 the XMLStreamWriter is created

Parameters
encoding:String

encoding of the xml declaration

version:String

version of the xml document

standalone:String

indicate if the xml document is standalone

Exceptions
XMLStreamException:
If given encoding does not match encoding of the underlying stream
writeStartElementback to summary
public void writeStartElement(String localName) throws XMLStreamException

Implements jdk.internal.util.xml.XMLStreamWriter.writeStartElement.

Writes a start tag to the output.

Parameters
localName:String

local name of the tag, may not be null

writeXMLContentback to summary
private void writeXMLContent(char[] content, int start, int length, boolean escapeChars) throws XMLStreamException

Writes XML content to underlying writer. Escapes characters unless escaping character feature is turned off.

writeXMLContentback to summary
private void writeXMLContent(String content) throws XMLStreamException
writeXMLContentback to summary
private void writeXMLContent(String content, boolean escapeChars, boolean escapeDoubleQuotes) throws XMLStreamException

Writes XML content to underlying writer. Escapes characters unless escaping character feature is turned off.

jdk.internal.util.xml.impl back to summary

protected Class XMLStreamWriterImpl.Element

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
pack-priv boolean
_isEmptyElement

indicate if an element is an empty one

pack-priv String
protected XMLStreamWriterImpl.Element
_parent

the parent element

pack-priv int

Constructor Summary

AccessConstructor and Description
public
Element()

Default constructor.

public
Element(XMLStreamWriterImpl.Element
the parent of the element
parent
,
String
name of the element
localpart
,
boolean
indicate if the element is an empty one
isEmpty
)

Method Summary

Modifier and TypeMethod and Description
public String
public XMLStreamWriterImpl.Element
public int
getState()

get the state of the element

public boolean
public void
setState(int
the state of the element
state
)

Set the state of the element

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

_isEmptyElementback to summary
pack-priv boolean _isEmptyElement

indicate if an element is an empty one

_localpartback to summary
pack-priv String _localpart
_parentback to summary
protected XMLStreamWriterImpl.Element _parent

the parent element

_stateback to summary
pack-priv int _state

Constructor Detail

Elementback to summary
public Element()

Default constructor.

Elementback to summary
public Element(XMLStreamWriterImpl.Element parent, String localpart, boolean isEmpty)
Parameters
parent:XMLStreamWriterImpl.Element

the parent of the element

localpart:String

name of the element

isEmpty:boolean

indicate if the element is an empty one

Method Detail

getLocalNameback to summary
public String getLocalName()
getParentback to summary
public XMLStreamWriterImpl.Element getParent()
getStateback to summary
public int getState()

get the state of the element

isEmptyback to summary
public boolean isEmpty()
setStateback to summary
public void setState(int state)

Set the state of the element

Parameters
state:int

the state of the element