public abstract class XmlWriter extends Object
Note that implementations can have different operating modes: specifically, when dealing with illegal content (such as "--" in a comment, "?>" in processing instruction, or "]]>" within CDATA section), implementations can do one of 3 things:
Modifier and Type | Field and Description |
---|---|
protected static char |
DEFAULT_QUOTE_CHAR |
protected Writer |
mAttrValueWriter
Optional escaping writer used for escaping characters like '"'
'&' and '<' in attribute values.
|
protected boolean |
mAutoCloseOutput
Flag that defines whether close() on this writer should call
close on the underlying output object (stream, writer)
|
protected boolean |
mCheckContent |
protected boolean |
mCheckNames |
protected boolean |
mCheckStructure |
protected WriterConfig |
mConfig |
protected String |
mEncoding |
protected boolean |
mFixContent |
protected int |
mLocPastChars
Number of characters output prior to currently buffered output
|
protected int |
mLocRowNr |
protected int |
mLocRowStartOffset
Offset of the first character on this line.
|
protected boolean |
mNsAware |
protected XmlWriterWrapper |
mRawWrapper
Lazy-constructed wrapper object, which will route all calls to
Writer API, to matching
writeRaw methods of this
XmlWriter instance. |
protected XmlWriterWrapper |
mTextWrapper
Lazy-constructed wrapper object, which will route all calls to
Writer API, to matching
writeCharacters methods of this
XmlWriter instance. |
protected Writer |
mTextWriter
Optional escaping writer used for escaping characters like '<'
'&' and '>' in textual content.
|
protected boolean |
mXml11
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 |
SURR1_FIRST |
protected static int |
SURR1_LAST |
protected static int |
SURR2_FIRST |
protected static int |
SURR2_LAST |
Modifier | Constructor and Description |
---|---|
protected |
XmlWriter(WriterConfig cfg,
String encoding,
boolean autoclose) |
Modifier and Type | Method and Description |
---|---|
abstract void |
close(boolean forceRealClose)
Method called to flush the buffer(s), and close the output
sink (stream or writer) if enabled (auto-closing) or
forced.
|
void |
enableXml11() |
abstract void |
flush() |
int |
getAbsOffset() |
int |
getColumn() |
protected abstract int |
getOutputPtr() |
protected abstract OutputStream |
getOutputStream() |
int |
getRow() |
protected abstract Writer |
getWriter() |
protected char |
handleInvalidChar(int c)
Method called to handle invalid character in textual content requested
to be output.
|
protected void |
reportNwfContent(String msg) |
protected void |
reportNwfName(String msg)
This is the method called when an output method call violates
name well-formedness checks
and
WstxOutputProperties.P_OUTPUT_VALIDATE_NAMES is
is enabled. |
protected void |
reportNwfName(String msg,
Object arg) |
protected void |
throwOutputError(String msg) |
protected void |
throwOutputError(String format,
Object arg) |
void |
verifyNameValidity(String name,
boolean checkNs)
Method called to verify that the name is a legal XML name.
|
Writer |
wrapAsRawWriter()
Method that can be called to get a wrapper instance that
can be used to essentially call the
writeRaw
method. |
Writer |
wrapAsTextWriter() |
abstract void |
writeAttribute(String localName,
char[] value,
int offset,
int len) |
abstract void |
writeAttribute(String localName,
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(String prefix,
String localName,
char[] value,
int offset,
int len) |
abstract void |
writeAttribute(String prefix,
String localName,
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 int |
writeCData(char[] cbuf,
int offset,
int len) |
abstract int |
writeCData(String data) |
abstract void |
writeCDataEnd() |
abstract void |
writeCDataStart() |
abstract void |
writeCharacters(char[] cbuf,
int offset,
int len) |
abstract void |
writeCharacters(String data) |
abstract int |
writeComment(String data)
Method that will try to output the content as specified.
|
abstract void |
writeCommentEnd() |
abstract void |
writeCommentStart() |
abstract void |
writeDTD(String data)
Older "legacy" output method for outputting DOCTYPE declaration.
|
abstract void |
writeDTD(String rootName,
String systemId,
String publicId,
String internalSubset) |
abstract void |
writeEndTag(String localName) |
abstract void |
writeEndTag(String prefix,
String localName) |
abstract void |
writeEntityReference(String name) |
abstract int |
writePI(String target,
String data) |
abstract void |
writePIEnd() |
abstract void |
writePIStart(String target,
boolean addSpace) |
abstract void |
writeRaw(char[] cbuf,
int offset,
int len) |
void |
writeRaw(String str) |
abstract void |
writeRaw(String str,
int offset,
int len) |
abstract void |
writeRawAscii(char[] cbuf,
int offset,
int len)
Like
writeRaw(java.lang.String, int, int) , but caller guarantees that the contents
additionally are known to be in 7-bit ascii range. |
abstract void |
writeStartTagEmptyEnd() |
abstract void |
writeStartTagEnd() |
abstract void |
writeStartTagStart(String localName)
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 |
writeStartTagStart(String prefix,
String localName)
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 |
writeTypedAttribute(String localName,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
Method similar to
writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. |
abstract void |
writeTypedAttribute(String prefix,
String localName,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
Method similar to
writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. |
abstract void |
writeTypedAttribute(String prefix,
String localName,
String nsURI,
org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
org.codehaus.stax2.validation.XMLValidator validator,
char[] copyBuffer)
Method similar to
writeAttribute(String,String,char[],int,int)
but where is known not to require escaping. |
abstract void |
writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)
Like
writeRaw(java.lang.String, int, int) , but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to. |
abstract void |
writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc,
org.codehaus.stax2.validation.XMLValidator validator,
char[] copyBuffer)
Like
writeRaw(java.lang.String, int, int) , but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to. |
abstract void |
writeXmlDeclaration(String version,
String enc,
String standalone) |
protected static final int SURR1_FIRST
protected static final int SURR1_LAST
protected static final int SURR2_FIRST
protected static final int SURR2_LAST
protected static final char DEFAULT_QUOTE_CHAR
protected final WriterConfig mConfig
protected final String mEncoding
protected final boolean mNsAware
protected final boolean mCheckStructure
protected final boolean mCheckContent
protected final boolean mCheckNames
protected final boolean mFixContent
protected final boolean mAutoCloseOutput
protected Writer mTextWriter
protected Writer mAttrValueWriter
protected boolean mXml11
protected XmlWriterWrapper mRawWrapper
writeRaw
methods of this
XmlWriter instance.protected XmlWriterWrapper mTextWrapper
writeCharacters
methods of this
XmlWriter instance.protected int mLocPastChars
protected int mLocRowNr
protected int mLocRowStartOffset
protected XmlWriter(WriterConfig cfg, String encoding, boolean autoclose) throws IOException
IOException
public void enableXml11()
protected abstract OutputStream getOutputStream()
protected abstract Writer getWriter()
public abstract void close(boolean forceRealClose) throws IOException
IOException
public abstract void flush() throws IOException
IOException
public abstract void writeRaw(String str, int offset, int len) throws IOException
IOException
public void writeRaw(String str) throws IOException
IOException
public abstract void writeRaw(char[] cbuf, int offset, int len) throws IOException
IOException
public abstract void writeRawAscii(char[] cbuf, int offset, int len) throws IOException
writeRaw(java.lang.String, int, int)
, but caller guarantees that the contents
additionally are known to be in 7-bit ascii range.IOException
public abstract void writeCDataStart() throws IOException
IOException
public abstract void writeCDataEnd() throws IOException
IOException
public abstract void writeCommentStart() throws IOException
IOException
public abstract void writeCommentEnd() throws IOException
IOException
public abstract void writePIStart(String target, boolean addSpace) throws IOException
IOException
public abstract void writePIEnd() throws IOException
IOException
public abstract int writeCData(String data) throws IOException, XMLStreamException
data
- Contents of the CDATA section to write outIOException
XMLStreamException
public abstract int writeCData(char[] cbuf, int offset, int len) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract void writeCharacters(String data) throws IOException
IOException
public abstract void writeCharacters(char[] cbuf, int offset, int len) throws IOException
IOException
public abstract int writeComment(String data) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract void writeDTD(String data) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract void writeEntityReference(String name) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract int writePI(String target, String data) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract void writeXmlDeclaration(String version, String enc, String standalone) throws IOException
IOException
public abstract void writeStartTagStart(String localName) throws IOException, 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)
IOException
XMLStreamException
public abstract void writeStartTagStart(String prefix, String localName) throws IOException, 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)
IOException
XMLStreamException
public abstract void writeStartTagEnd() throws IOException
IOException
public abstract void writeStartTagEmptyEnd() throws IOException
IOException
public abstract void writeEndTag(String localName) throws IOException
IOException
public abstract void writeEndTag(String prefix, String localName) throws IOException
IOException
public abstract void writeAttribute(String localName, String value) throws IOException, 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)
IOException
XMLStreamException
public abstract void writeAttribute(String localName, char[] value, int offset, int len) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract void writeAttribute(String prefix, String localName, String value) throws IOException, 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)
IOException
XMLStreamException
public abstract void writeAttribute(String prefix, String localName, char[] value, int offset, int len) throws IOException, XMLStreamException
IOException
XMLStreamException
public abstract void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException
writeRaw(java.lang.String, int, int)
, but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to.enc
- Encoder that will produce contentIOException
public abstract void writeTypedElement(org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException
writeRaw(java.lang.String, int, int)
, but caller guarantees that the contents
additionally are known to be in 7-bit ascii range, and also
passes an encoder object that will encode values only when
being handed a buffer to append to.enc
- Encoder that will produce contentvalidator
- Validator to use for validating serialized textual
content (can not be null)copyBuffer
- Temporary buffer that writer can use for temporary
copies as necessaryIOException
XMLStreamException
public abstract void writeTypedAttribute(String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, XMLStreamException
writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.
No validation needs to be performed.IOException
XMLStreamException
public abstract void writeTypedAttribute(String prefix, String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws IOException, XMLStreamException
writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.
No validation needs to be performed.IOException
XMLStreamException
public abstract void writeTypedAttribute(String prefix, String localName, String nsURI, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc, org.codehaus.stax2.validation.XMLValidator validator, char[] copyBuffer) throws IOException, XMLStreamException
writeAttribute(String,String,char[],int,int)
but where is known not to require escaping.
Validation of the attribute value must be done by calling given
validator appropriately.IOException
XMLStreamException
protected abstract int getOutputPtr()
public int getRow()
public int getColumn()
public int getAbsOffset()
public final Writer wrapAsRawWriter()
writeRaw
method.public final Writer wrapAsTextWriter()
public final void verifyNameValidity(String name, boolean checkNs) throws XMLStreamException
XMLStreamException
protected void reportNwfName(String msg) throws XMLStreamException
WstxOutputProperties.P_OUTPUT_VALIDATE_NAMES
is
is enabled.XMLStreamException
protected void reportNwfName(String msg, Object arg) throws XMLStreamException
XMLStreamException
protected void reportNwfContent(String msg) throws XMLStreamException
XMLStreamException
protected void throwOutputError(String msg) throws XMLStreamException
XMLStreamException
protected void throwOutputError(String format, Object arg) throws XMLStreamException
XMLStreamException
protected char handleInvalidChar(int c) throws IOException
WstxOutputProperties.P_OUTPUT_INVALID_CHAR_HANDLER
.IOException
Copyright © 2018 FasterXML. All rights reserved.