Package com.fasterxml.aalto.out
Class XmlWriter
- java.lang.Object
-
- com.fasterxml.aalto.out.WNameFactory
-
- com.fasterxml.aalto.out.XmlWriter
-
- Direct Known Subclasses:
ByteXmlWriter
,CharXmlWriter
public abstract class XmlWriter extends WNameFactory
Base class for output type / encoding-specific serializers used to do actual physical output of serialized xml content. At this level, no namespace handling is done, and only those checks directly related to encoding (including optional validity checks for xml content) are implemented.
-
-
Field Summary
Fields Modifier and Type Field Description protected boolean
_cfgNsAware
protected boolean
_checkContent
protected boolean
_checkNames
protected WriterConfig
_config
protected char[]
_copyBuffer
Intermediate buffer, in which content (esp.protected int
_copyBufferLen
protected int
_locPastChars
Number of characters output prior to currently buffered outputprotected int
_locRowNr
protected int
_locRowStartOffset
Offset of the first character on this line.protected boolean
_xml11
Indicates whether output is to be compliant; if false, is to be xml 1.0 compliant, if true, xml 1.1 compliant.protected static int
ATTR_MIN_ARRAYCOPY
protected static int
DEFAULT_COPYBUFFER_LEN
protected static int
MIN_ARRAYCOPY
protected static int
SURR1_FIRST
protected static int
SURR1_LAST
protected static int
SURR2_FIRST
protected static int
SURR2_LAST
-
Constructor Summary
Constructors Modifier Constructor Description protected
XmlWriter(WriterConfig cfg)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract void
_closeTarget(boolean doClose)
void
_releaseBuffers()
void
close(boolean forceTargetClose)
Method called to flush the buffer(s), and close the output sink (stream or writer).abstract WName
constructName(java.lang.String localName)
abstract WName
constructName(java.lang.String prefix, java.lang.String localName)
void
enableXml11()
abstract void
flush()
int
getAbsOffset()
int
getColumn()
abstract int
getHighestEncodable()
Method called by error reporting code, to figure out if a given character is encodable (without using character entities) with the current encoding or not.protected abstract int
getOutputPtr()
int
getRow()
static int
guessEncodingBitSize(WriterConfig cfg)
Method used to figure out which part of the Unicode char set the encoding can natively support.protected void
reportFailedEscaping(java.lang.String type, int ch)
protected void
reportInvalidChar(int c)
protected void
reportInvalidEmptyName()
protected void
reportNwfContent(java.lang.String msg)
protected void
reportNwfContent(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)
protected void
reportNwfName(java.lang.String msg)
This is the method called when an output method call violates name well-formedness checks and name validation is enabled.protected void
reportNwfName(java.lang.String msg, java.lang.Object arg)
protected void
throwOutputError(java.lang.String msg)
protected void
throwOutputError(java.lang.String format, java.lang.Object arg)
abstract void
writeAttribute(WName name, char[] value, int offset, int len)
abstract void
writeAttribute(WName name, java.lang.String value)
Note: can throw XMLStreamException, if name checking is enabled, and name is invalid (name check has to be in this writer, not caller, since it depends not only on xml limitations, but also on encoding limitations)abstract void
writeAttribute(WName name, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
abstract int
writeCData(char[] cbuf, int offset, int len)
abstract int
writeCData(java.lang.String data)
abstract void
writeCharacters(char[] cbuf, int offset, int len)
abstract void
writeCharacters(java.lang.String data)
abstract int
writeComment(java.lang.String data)
Method that will try to output the content as specified.abstract void
writeDTD(WName rootName, java.lang.String systemId, java.lang.String publicId, java.lang.String internalSubset)
abstract void
writeDTD(java.lang.String data)
Older "legacy" output method for outputting DOCTYPE declaration.abstract void
writeEndTag(WName name)
abstract void
writeEntityReference(WName name)
abstract int
writePI(WName target, java.lang.String data)
abstract void
writeRaw(char[] cbuf, int offset, int len)
abstract void
writeRaw(java.lang.String str, int offset, int len)
abstract void
writeSpace(char[] cbuf, int offset, int len)
abstract void
writeSpace(java.lang.String data)
abstract void
writeStartTagEmptyEnd()
abstract void
writeStartTagEnd()
abstract void
writeStartTagStart(WName name)
Note: can throw XMLStreamException, if name checking is enabled, and name is invalid (name check has to be in this writer, not caller, since it depends not only on xml limitations, but also on encoding limitations)abstract void
writeTypedValue(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
abstract void
writeXmlDeclaration(java.lang.String version, java.lang.String enc, java.lang.String standalone)
-
-
-
Field Detail
-
SURR1_FIRST
protected static final int SURR1_FIRST
- See Also:
- Constant Field Values
-
SURR1_LAST
protected static final int SURR1_LAST
- See Also:
- Constant Field Values
-
SURR2_FIRST
protected static final int SURR2_FIRST
- See Also:
- Constant Field Values
-
SURR2_LAST
protected static final int SURR2_LAST
- See Also:
- Constant Field Values
-
MIN_ARRAYCOPY
protected static final int MIN_ARRAYCOPY
- See Also:
- Constant Field Values
-
ATTR_MIN_ARRAYCOPY
protected static final int ATTR_MIN_ARRAYCOPY
- See Also:
- Constant Field Values
-
DEFAULT_COPYBUFFER_LEN
protected static final int DEFAULT_COPYBUFFER_LEN
- See Also:
- Constant Field Values
-
_config
protected final WriterConfig _config
-
_copyBuffer
protected char[] _copyBuffer
Intermediate buffer, in which content (esp. Strings) can be copied to, before being output.
-
_copyBufferLen
protected final int _copyBufferLen
-
_xml11
protected boolean _xml11
Indicates whether output is to be compliant; if false, is to be xml 1.0 compliant, if true, xml 1.1 compliant.
-
_cfgNsAware
protected final boolean _cfgNsAware
-
_locPastChars
protected int _locPastChars
Number of characters output prior to currently buffered output
-
_locRowNr
protected int _locRowNr
-
_locRowStartOffset
protected int _locRowStartOffset
Offset of the first character on this line. May be negative, if the offset was in a buffer that has been flushed out.
-
_checkContent
protected final boolean _checkContent
-
_checkNames
protected final boolean _checkNames
-
-
Constructor Detail
-
XmlWriter
protected XmlWriter(WriterConfig cfg)
-
-
Method Detail
-
constructName
public abstract WName constructName(java.lang.String localName) throws javax.xml.stream.XMLStreamException
- Specified by:
constructName
in classWNameFactory
- Throws:
javax.xml.stream.XMLStreamException
-
constructName
public abstract WName constructName(java.lang.String prefix, java.lang.String localName) throws javax.xml.stream.XMLStreamException
- Specified by:
constructName
in classWNameFactory
- Throws:
javax.xml.stream.XMLStreamException
-
enableXml11
public void enableXml11()
-
getOutputPtr
protected abstract int getOutputPtr()
-
getHighestEncodable
public abstract int getHighestEncodable()
Method called by error reporting code, to figure out if a given character is encodable (without using character entities) with the current encoding or not.- Returns:
- Character code of the highest character that can be natively encoded.
-
close
public final void close(boolean forceTargetClose) throws java.io.IOException
Method called to flush the buffer(s), and close the output sink (stream or writer).- Throws:
java.io.IOException
-
_releaseBuffers
public void _releaseBuffers()
-
_closeTarget
public abstract void _closeTarget(boolean doClose) throws java.io.IOException
- Throws:
java.io.IOException
-
flush
public abstract void flush() throws java.io.IOException
- Throws:
java.io.IOException
-
writeCData
public abstract int writeCData(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Parameters:
data
- Contents of the CDATA section to write out- Returns:
- offset of the (first) illegal content segment ("]]>") in passed content, if not in repairing mode; or -1 if none
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeCData
public abstract int writeCData(char[] cbuf, int offset, int len) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeCharacters
public abstract void writeCharacters(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeCharacters
public abstract void writeCharacters(char[] cbuf, int offset, int len) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeSpace
public abstract void writeSpace(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeSpace
public abstract void writeSpace(char[] cbuf, int offset, int len) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeComment
public abstract int writeComment(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException
Method that will try to output the content as specified. If the content passed in has embedded "--" in it, it will either add an intervening space between consequtive hyphens (if content fixing is enabled), or return the offset of the first hyphen in multi-hyphen sequence.- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeDTD
public abstract void writeDTD(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException
Older "legacy" output method for outputting DOCTYPE declaration. Assumes that the passed-in String contains a complete DOCTYPE declaration properly quoted.- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeDTD
public abstract void writeDTD(WName rootName, java.lang.String systemId, java.lang.String publicId, java.lang.String internalSubset) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeEntityReference
public abstract void writeEntityReference(WName name) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writePI
public abstract int writePI(WName target, java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeRaw
public abstract void writeRaw(java.lang.String str, int offset, int len) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeRaw
public abstract void writeRaw(char[] cbuf, int offset, int len) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeXmlDeclaration
public abstract void writeXmlDeclaration(java.lang.String version, java.lang.String enc, java.lang.String standalone) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeStartTagStart
public abstract void writeStartTagStart(WName name) throws java.io.IOException, javax.xml.stream.XMLStreamException
Note: can throw XMLStreamException, if name checking is enabled, and name is invalid (name check has to be in this writer, not caller, since it depends not only on xml limitations, but also on encoding limitations)
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeStartTagEnd
public abstract void writeStartTagEnd() throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeStartTagEmptyEnd
public abstract void writeStartTagEmptyEnd() throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeEndTag
public abstract void writeEndTag(WName name) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeAttribute
public abstract void writeAttribute(WName name, java.lang.String value) throws java.io.IOException, javax.xml.stream.XMLStreamException
Note: can throw XMLStreamException, if name checking is enabled, and name is invalid (name check has to be in this writer, not caller, since it depends not only on xml limitations, but also on encoding limitations)
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeAttribute
public abstract void writeAttribute(WName name, char[] value, int offset, int len) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeTypedValue
public abstract void writeTypedValue(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
writeAttribute
public abstract void writeAttribute(WName name, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOException
javax.xml.stream.XMLStreamException
-
getRow
public int getRow()
-
getColumn
public int getColumn()
-
getAbsOffset
public int getAbsOffset()
-
guessEncodingBitSize
public static final int guessEncodingBitSize(WriterConfig cfg)
Method used to figure out which part of the Unicode char set the encoding can natively support. Values returned are 7, 8 and 16, to indicate (respectively) "ascii", "ISO-Latin" and "native Unicode". These just best guesses, but should work ok for the most common encodings.
-
reportNwfName
protected void reportNwfName(java.lang.String msg) throws javax.xml.stream.XMLStreamException
This is the method called when an output method call violates name well-formedness checks and name validation is enabled.- Throws:
javax.xml.stream.XMLStreamException
-
reportNwfName
protected void reportNwfName(java.lang.String msg, java.lang.Object arg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
reportNwfContent
protected void reportNwfContent(java.lang.String msg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
reportNwfContent
protected void reportNwfContent(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
reportFailedEscaping
protected void reportFailedEscaping(java.lang.String type, int ch) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
reportInvalidEmptyName
protected void reportInvalidEmptyName() throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
reportInvalidChar
protected void reportInvalidChar(int c) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
throwOutputError
protected void throwOutputError(java.lang.String msg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
throwOutputError
protected void throwOutputError(java.lang.String format, java.lang.Object arg) throws javax.xml.stream.XMLStreamException
- Throws:
javax.xml.stream.XMLStreamException
-
-