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_cfgNsAwareprotected boolean_checkContentprotected boolean_checkNamesprotected WriterConfig_configprotected char[]_copyBufferIntermediate buffer, in which content (esp.protected int_copyBufferLenprotected int_locPastCharsNumber of characters output prior to currently buffered outputprotected int_locRowNrprotected int_locRowStartOffsetOffset of the first character on this line.protected boolean_xml11Indicates whether output is to be compliant; if false, is to be xml 1.0 compliant, if true, xml 1.1 compliant.protected static intATTR_MIN_ARRAYCOPYprotected static intDEFAULT_COPYBUFFER_LENprotected static intMIN_ARRAYCOPYprotected static intSURR1_FIRSTprotected static intSURR1_LASTprotected static intSURR2_FIRSTprotected static intSURR2_LAST
-
Constructor Summary
Constructors Modifier Constructor Description protectedXmlWriter(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()voidclose(boolean forceTargetClose)Method called to flush the buffer(s), and close the output sink (stream or writer).abstract WNameconstructName(java.lang.String localName)abstract WNameconstructName(java.lang.String prefix, java.lang.String localName)voidenableXml11()abstract voidflush()intgetAbsOffset()intgetColumn()abstract intgetHighestEncodable()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 intgetOutputPtr()intgetRow()static intguessEncodingBitSize(WriterConfig cfg)Method used to figure out which part of the Unicode char set the encoding can natively support.protected voidreportFailedEscaping(java.lang.String type, int ch)protected voidreportInvalidChar(int c)protected voidreportInvalidEmptyName()protected voidreportNwfContent(java.lang.String msg)protected voidreportNwfContent(java.lang.String format, java.lang.Object arg1, java.lang.Object arg2)protected voidreportNwfName(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 voidreportNwfName(java.lang.String msg, java.lang.Object arg)protected voidthrowOutputError(java.lang.String msg)protected voidthrowOutputError(java.lang.String format, java.lang.Object arg)abstract voidwriteAttribute(WName name, char[] value, int offset, int len)abstract voidwriteAttribute(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 voidwriteAttribute(WName name, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)abstract intwriteCData(char[] cbuf, int offset, int len)abstract intwriteCData(java.lang.String data)abstract voidwriteCharacters(char[] cbuf, int offset, int len)abstract voidwriteCharacters(java.lang.String data)abstract intwriteComment(java.lang.String data)Method that will try to output the content as specified.abstract voidwriteDTD(WName rootName, java.lang.String systemId, java.lang.String publicId, java.lang.String internalSubset)abstract voidwriteDTD(java.lang.String data)Older "legacy" output method for outputting DOCTYPE declaration.abstract voidwriteEndTag(WName name)abstract voidwriteEntityReference(WName name)abstract intwritePI(WName target, java.lang.String data)abstract voidwriteRaw(char[] cbuf, int offset, int len)abstract voidwriteRaw(java.lang.String str, int offset, int len)abstract voidwriteSpace(char[] cbuf, int offset, int len)abstract voidwriteSpace(java.lang.String data)abstract voidwriteStartTagEmptyEnd()abstract voidwriteStartTagEnd()abstract voidwriteStartTagStart(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 voidwriteTypedValue(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)abstract voidwriteXmlDeclaration(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:
constructNamein 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:
constructNamein 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.IOExceptionMethod 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.IOExceptionjavax.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.IOExceptionjavax.xml.stream.XMLStreamException
-
writeCharacters
public abstract void writeCharacters(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException- Throws:
java.io.IOExceptionjavax.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.IOExceptionjavax.xml.stream.XMLStreamException
-
writeSpace
public abstract void writeSpace(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamException- Throws:
java.io.IOExceptionjavax.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.IOExceptionjavax.xml.stream.XMLStreamException
-
writeComment
public abstract int writeComment(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamExceptionMethod 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.IOExceptionjavax.xml.stream.XMLStreamException
-
writeDTD
public abstract void writeDTD(java.lang.String data) throws java.io.IOException, javax.xml.stream.XMLStreamExceptionOlder "legacy" output method for outputting DOCTYPE declaration. Assumes that the passed-in String contains a complete DOCTYPE declaration properly quoted.- Throws:
java.io.IOExceptionjavax.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.IOExceptionjavax.xml.stream.XMLStreamException
-
writeEntityReference
public abstract void writeEntityReference(WName name) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOExceptionjavax.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.IOExceptionjavax.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.IOExceptionjavax.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.IOExceptionjavax.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.IOExceptionjavax.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.IOExceptionjavax.xml.stream.XMLStreamException
-
writeStartTagEnd
public abstract void writeStartTagEnd() throws java.io.IOException, javax.xml.stream.XMLStreamException- Throws:
java.io.IOExceptionjavax.xml.stream.XMLStreamException
-
writeStartTagEmptyEnd
public abstract void writeStartTagEmptyEnd() throws java.io.IOException, javax.xml.stream.XMLStreamException- Throws:
java.io.IOExceptionjavax.xml.stream.XMLStreamException
-
writeEndTag
public abstract void writeEndTag(WName name) throws java.io.IOException, javax.xml.stream.XMLStreamException
- Throws:
java.io.IOExceptionjavax.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.IOExceptionjavax.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.IOExceptionjavax.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.IOExceptionjavax.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.IOExceptionjavax.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.XMLStreamExceptionThis 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
-
-