com.ctc.wstx.sw
Class BaseStreamWriter

java.lang.Object
  extended by com.ctc.wstx.sw.BaseStreamWriter
All Implemented Interfaces:
OutputConfigFlags, javax.xml.stream.XMLStreamConstants, javax.xml.stream.XMLStreamWriter, Validatable, ValidationContext, XMLStreamWriter2
Direct Known Subclasses:
BaseNsStreamWriter, NonNsStreamWriter

public abstract class BaseStreamWriter
extends java.lang.Object
implements XMLStreamWriter2, ValidationContext, javax.xml.stream.XMLStreamConstants, OutputConfigFlags

Base class for XMLStreamWriter implementations Woodstox has. Contains partial stream writer implementation, plus utility methods shared by concrete implementation classes. Main reason for such abstract base class is to allow other parts of Woodstox core to refer to any of stream writer implementations in general way.


Field Summary
protected static int ATTR_MIN_ARRAYCOPY
           
protected static char CHAR_SPACE
           
protected static int DEFAULT_COPYBUFFER_LEN
           
protected  boolean mAnyOutput
          Flag that is set to true first time something has been output.
protected  AttributeCollector mAttrCollector
           
protected  boolean mCfgAutomaticEmptyElems
           
protected  boolean mCfgCDataAsText
           
protected  boolean mCfgCopyDefaultAttrs
           
protected  boolean mCheckAttrs
           
protected  boolean mCheckStructure
           
protected  WriterConfig mConfig
           
protected  char[] mCopyBuffer
          Intermediate buffer into which characters of a String can be copied, in cases where such a copy followed by array access is faster than calling String.charAt() (which perhaps surprisingly is often case, and especially significant for longer buffers).
protected  java.lang.String mDtdRootElem
          Value passed as the expected root element, when using the multiple argument writeDTD(java.lang.String) method.
protected  boolean mEmptyElement
          Flag that indicates that current element is an empty element (one that is explicitly defined as one, by calling a method -- NOT one that just happens to be empty).
protected  java.lang.String mEncoding
          Encoding to use; may be passed from the factory (when a method that defines encoding is used), updated by a call to writeStartDocument(), or null if neither.
protected static int MIN_ARRAYCOPY
          This constant defines minimum length of a String, for which it is beneficial to do an intermediate copy (using String.getChars()), and iterate over intermediate array, instead of iterating using String.charAt().
protected  InputElementStack mInputElemStack
           
protected  XMLStreamReader2 mLastReader
          Reader that was last used for copy-through operation; used in conjunction with the other copy-through state variables.
protected  StreamReaderImpl mLastReaderImpl
           
protected  boolean mStartElementOpen
          Flag that is set during time that a start element is "open", ie.
protected  int mState
           
protected  XMLValidator mValidator
          Optional validator to use for validating output against one or more schemas, and/or for safe pretty-printing (indentation).
protected  int mVldContent
          State value used with validation, to track types of content that is allowed at this point in output stream.
protected  ValidationProblemHandler mVldProbHandler
          Custom validation problem handler, if any.
protected  XmlWriter mWriter
          Actual physical writer to output serialized XML content to
protected  boolean mXml11
          Since XML 1.1 has some differences to 1.0, we need to keep a flag to indicate if we were to output XML 1.1 document.
protected static java.lang.String NO_NS_URI
           
protected static java.lang.String NO_PREFIX
           
protected static int STATE_EPILOG
           
protected static int STATE_PROLOG
           
protected static int STATE_TREE
           
 
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
 
Fields inherited from interface com.ctc.wstx.cfg.OutputConfigFlags
CFG_AUTOMATIC_EMPTY_ELEMS, CFG_AUTOMATIC_NS, CFG_COPY_DEFAULT_ATTRS, CFG_ENABLE_NS, CFG_ESCAPE_CR, CFG_FIX_CONTENT, CFG_OUTPUT_CDATA_AS_TEXT, CFG_VALIDATE_ATTR, CFG_VALIDATE_CONTENT, CFG_VALIDATE_NAMES, CFG_VALIDATE_STRUCTURE
 
Constructor Summary
protected BaseStreamWriter(XmlWriter xw, java.lang.String enc, WriterConfig cfg)
           
 
Method Summary
 int addDefaultAttribute(java.lang.String localName, java.lang.String uri, java.lang.String prefix, java.lang.String value)
          Adding default attribute values does not usually make sense on output side, so the implementation is a NOP for now.
 void close()
           
protected abstract  void closeStartElement(boolean emptyElem)
          Method called to close an open start element, when another main-level element (not namespace declaration or attribute) is being output; except for end element which is handled differently.
 void copyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData)
          Method that essentially copies event that the specified reader has just read.
abstract  void copyStartElement(InputElementStack elemStack, AttributeCollector attrCollector)
          Implementation-dependant method called to fully copy START_ELEMENT event that the passed-in stream reader points to
protected  void doReportProblem(javax.xml.stream.XMLReporter rep, java.lang.String probType, java.lang.String msg, javax.xml.stream.Location loc)
           
protected  void doWriteStartDocument(java.lang.String version, java.lang.String encoding, java.lang.String standAlone)
           
 int findAttributeIndex(java.lang.String nsURI, java.lang.String localName)
           
 void flush()
           
 int getAttributeCount()
          This method returns number of attributes accessible from within currently active start element.
 java.lang.String getAttributeLocalName(int index)
           
 java.lang.String getAttributeNamespace(int index)
           
 java.lang.String getAttributePrefix(int index)
           
 java.lang.String getAttributeValue(int index)
           
 java.lang.String getAttributeValue(java.lang.String nsURI, java.lang.String localName)
           
 java.lang.String getBaseUri()
          As of now, there is no way to specify the base URI.
abstract  javax.xml.namespace.QName getCurrentElementName()
          Method that can be used to access name information of the innermost (top) element in the element stack.
 java.lang.String getEncoding()
          Method that can be called to get information about encoding that this writer is using (or at least claims is using).
 XMLStreamLocation2 getLocation()
          Method that should return current output location, if the writer keeps track of it; null if it does not.
abstract  javax.xml.namespace.NamespaceContext getNamespaceContext()
           
abstract  java.lang.String getNamespaceURI(java.lang.String prefix)
          Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element.
abstract  java.lang.String getPrefix(java.lang.String uri)
           
 java.lang.Object getProperty(java.lang.String name)
           
protected abstract  java.lang.String getTopElementDesc()
           
 javax.xml.stream.Location getValidationLocation()
          Method that will return the location that best represents current location within document to be validated, if such information is available.
 java.lang.String getXmlVersion()
          Method that validator can call to figure out which xml version document being validated declared (if none, "1.0" is assumed as per xml specifications 1.0 and 1.1).
protected  boolean inPrologOrEpilog()
           
 boolean isNotationDeclared(java.lang.String name)
           
 boolean isPropertySupported(java.lang.String name)
          Method similar to XMLOutputFactory.isPropertySupported(java.lang.String), used to determine whether a property is supported by the Writer instance.
 boolean isUnparsedEntityDeclared(java.lang.String name)
           
protected  boolean isValidating()
          Method that is used by output classes to determine whether we are in validating mode.
protected static void reportIllegalArg(java.lang.String msg)
           
protected static void reportIllegalMethod(java.lang.String msg)
          Method called when an illegal method (namespace-specific method on non-ns writer) is called by the application.
protected  void reportInvalidContent(int evtType)
           
protected static void reportNwfAttr(java.lang.String msg)
          This is the method called when an output method call violates attribute well-formedness checks (trying to output dup attrs) and WstxOutputProperties.P_OUTPUT_VALIDATE_NAMES is is enabled.
protected static void reportNwfAttr(java.lang.String msg, java.lang.Object arg)
           
protected static void reportNwfContent(java.lang.String msg)
          This is the method called when an output method call violates content well-formedness checks and WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT is is enabled.
protected static void reportNwfContent(java.lang.String msg, java.lang.Object arg)
           
protected static void reportNwfStructure(java.lang.String msg)
          This is the method called when an output method call violates structural well-formedness checks and WstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTURE is is enabled.
protected static void reportNwfStructure(java.lang.String msg, java.lang.Object arg)
           
 void reportProblem(XMLValidationProblem prob)
          Method called by the validator, upon encountering a validation problem.
 void reportValidationProblem(javax.xml.stream.Location loc, java.lang.String msg)
           
 void reportValidationProblem(java.lang.String msg)
           
 void reportValidationProblem(java.lang.String msg, int severity)
           
 void reportValidationProblem(java.lang.String msg, javax.xml.stream.Location loc, int severity)
           
 void reportValidationProblem(java.lang.String format, java.lang.Object arg)
           
 void reportValidationProblem(java.lang.String format, java.lang.Object arg, java.lang.Object arg2)
           
abstract  void setDefaultNamespace(java.lang.String uri)
           
abstract  void setNamespaceContext(javax.xml.namespace.NamespaceContext context)
           
abstract  void setPrefix(java.lang.String prefix, java.lang.String uri)
           
 boolean setProperty(java.lang.String name, java.lang.Object value)
          Method that can be used to set per-writer properties; a subset of properties one can set via matching XMLOutputFactory2 instance.
 ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
          Method that application can call to define a custom handler for validation problems encountered during validation process.
 XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
          Method that can be called by application to stop validating output against a schema, for which Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema) was called earlier.
 XMLValidator stopValidatingAgainst(XMLValidator validator)
          Method that can be called by application to stop validating output using specified validator.
protected static void throwFromIOE(java.io.IOException ioe)
           
protected static void throwOutputError(java.lang.String msg)
           
protected static void throwOutputError(java.lang.String format, java.lang.Object arg)
           
 java.lang.String toString()
          Helper method used for ensuring that each type of a problem is only reported once per instance.
 XMLValidator validateAgainst(XMLValidationSchema schema)
          Method that will construct a XMLValidator instance from the given schema (unless a validator for that schema has already been added), initialize it if necessary, and make validatable object (reader, writer) call appropriate validation methods from this point on until the end of the document (that is, it's not scoped with sub-trees), or until validator is removed by an explicit call to Validatable.stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema).
protected  void verifyRootElement(java.lang.String localName, java.lang.String prefix)
           
protected  void verifyWriteCData()
           
protected  void verifyWriteDTD()
           
 java.io.Writer wrapAsRawWriter()
          Method that can be called to get a wrapper instance that can be used to essentially call the writeRaw method via regular Writer interface.
 java.io.Writer wrapAsTextWriter()
          Method that can be called to get a wrapper instance that can be used to essentially call the writeCharacters method via regular Writer interface.
abstract  void writeAttribute(java.lang.String localName, java.lang.String value)
           
abstract  void writeAttribute(java.lang.String nsURI, java.lang.String localName, java.lang.String value)
           
abstract  void writeAttribute(java.lang.String prefix, java.lang.String nsURI, java.lang.String localName, java.lang.String value)
           
 void writeCData(char[] cbuf, int start, int len)
           
 void writeCData(java.lang.String data)
           
 void writeCharacters(char[] text, int start, int len)
           
 void writeCharacters(javax.xml.stream.events.Characters ch)
          Method called by WstxEventWriter (instead of more generic text output methods), so that we can verify (if necessary) that this character output type is legal in this context.
 void writeCharacters(java.lang.String text)
           
 void writeComment(java.lang.String data)
           
abstract  void writeDefaultNamespace(java.lang.String nsURI)
           
 void writeDTD(DTDInfo info)
           
 void writeDTD(java.lang.String dtd)
           
 void writeDTD(java.lang.String rootName, java.lang.String systemId, java.lang.String publicId, java.lang.String internalSubset)
           
abstract  void writeEmptyElement(java.lang.String localName)
           
abstract  void writeEmptyElement(java.lang.String nsURI, java.lang.String localName)
           
abstract  void writeEmptyElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)
           
 void writeEndDocument()
           
abstract  void writeEndElement()
           
abstract  void writeEndElement(javax.xml.namespace.QName name)
          Method called by WstxEventWriter (instead of the version that takes no argument), so that we can verify it does match the start element, if necessary
 void writeEntityRef(java.lang.String name)
           
abstract  void writeFullEndElement()
          Method similar to XMLStreamWriter.writeEndElement(), but that will always write the full end element, instead of empty element.
abstract  void writeNamespace(java.lang.String prefix, java.lang.String nsURI)
           
 void writeProcessingInstruction(java.lang.String target)
           
 void writeProcessingInstruction(java.lang.String target, java.lang.String data)
           
 void writeRaw(char[] text, int offset, int length)
          Method that writes specified content as is, without encoding or deciphering it in any way.
 void writeRaw(java.lang.String text)
          Method that writes specified content as is, without encoding or deciphering it in any way.
 void writeRaw(java.lang.String text, int start, int offset)
           
 void writeStartDocument()
           
 void writeStartDocument(java.lang.String version)
           
 void writeStartDocument(java.lang.String encoding, java.lang.String version)
           
 void writeStartDocument(java.lang.String version, java.lang.String encoding, boolean standAlone)
           
abstract  void writeStartElement(javax.xml.stream.events.StartElement elem)
          Convenience method needed by WstxEventWriter, to use when writing a start element, and possibly its attributes and namespace declarations.
abstract  void writeStartElement(java.lang.String localName)
           
abstract  void writeStartElement(java.lang.String nsURI, java.lang.String localName)
           
abstract  void writeStartElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

STATE_PROLOG

protected static final int STATE_PROLOG
See Also:
Constant Field Values

STATE_TREE

protected static final int STATE_TREE
See Also:
Constant Field Values

STATE_EPILOG

protected static final int STATE_EPILOG
See Also:
Constant Field Values

CHAR_SPACE

protected static final char CHAR_SPACE
See Also:
Constant Field Values

NO_NS_URI

protected static final java.lang.String NO_NS_URI
See Also:
Constant Field Values

NO_PREFIX

protected static final java.lang.String NO_PREFIX

MIN_ARRAYCOPY

protected static final int MIN_ARRAYCOPY
This constant defines minimum length of a String, for which it is beneficial to do an intermediate copy (using String.getChars()), and iterate over intermediate array, instead of iterating using String.charAt(). Former is generally faster for longer Strings, but has some overhead for shorter Strings. Tests indicate that the threshold is somewhere between 8 and 16 characters, at least on x86 platform.

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

mWriter

protected final XmlWriter mWriter
Actual physical writer to output serialized XML content to


mCopyBuffer

protected char[] mCopyBuffer
Intermediate buffer into which characters of a String can be copied, in cases where such a copy followed by array access is faster than calling String.charAt() (which perhaps surprisingly is often case, and especially significant for longer buffers).


mConfig

protected final WriterConfig mConfig

mCfgCDataAsText

protected final boolean mCfgCDataAsText

mCfgCopyDefaultAttrs

protected final boolean mCfgCopyDefaultAttrs

mCfgAutomaticEmptyElems

protected final boolean mCfgAutomaticEmptyElems

mCheckStructure

protected boolean mCheckStructure

mCheckAttrs

protected boolean mCheckAttrs

mEncoding

protected java.lang.String mEncoding
Encoding to use; may be passed from the factory (when a method that defines encoding is used), updated by a call to writeStartDocument(), or null if neither. Is passed to the escaping writer factory to allow escaping writers to do additional escaping if necessary (like encapsulating non-ascii chars in a doc encoded usig ascii).


mValidator

protected XMLValidator mValidator
Optional validator to use for validating output against one or more schemas, and/or for safe pretty-printing (indentation).


mXml11

protected boolean mXml11
Since XML 1.1 has some differences to 1.0, we need to keep a flag to indicate if we were to output XML 1.1 document.


mVldProbHandler

protected ValidationProblemHandler mVldProbHandler
Custom validation problem handler, if any.


mState

protected int mState

mAnyOutput

protected boolean mAnyOutput
Flag that is set to true first time something has been output. Generally needed to keep track of whether XML declaration (START_DOCUMENT) can be output or not.


mStartElementOpen

protected boolean mStartElementOpen
Flag that is set during time that a start element is "open", ie. START_ELEMENT has been output (and possibly zero or more name space declarations and attributes), before other main-level constructs have been output.


mEmptyElement

protected boolean mEmptyElement
Flag that indicates that current element is an empty element (one that is explicitly defined as one, by calling a method -- NOT one that just happens to be empty). This is needed to know what to do when next non-ns/attr node is output; normally a new context is opened, but for empty elements not.


mVldContent

protected int mVldContent
State value used with validation, to track types of content that is allowed at this point in output stream. Only used if validation is enabled: if so, value is determined via validation callbacks.


mDtdRootElem

protected java.lang.String mDtdRootElem
Value passed as the expected root element, when using the multiple argument writeDTD(java.lang.String) method. Will be used in structurally validating mode (and in dtd-validating mode, since that automatically enables structural validation as well, to pre-filter well-formedness errors that validators might have trouble dealing with).


mLastReader

protected XMLStreamReader2 mLastReader
Reader that was last used for copy-through operation; used in conjunction with the other copy-through state variables.


mLastReaderImpl

protected StreamReaderImpl mLastReaderImpl

mAttrCollector

protected AttributeCollector mAttrCollector

mInputElemStack

protected InputElementStack mInputElemStack
Constructor Detail

BaseStreamWriter

protected BaseStreamWriter(XmlWriter xw,
                           java.lang.String enc,
                           WriterConfig cfg)
Method Detail

close

public void close()
           throws javax.xml.stream.XMLStreamException
Specified by:
close in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

flush

public void flush()
           throws javax.xml.stream.XMLStreamException
Specified by:
flush in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

getNamespaceContext

public abstract javax.xml.namespace.NamespaceContext getNamespaceContext()
Specified by:
getNamespaceContext in interface javax.xml.stream.XMLStreamWriter

getPrefix

public abstract java.lang.String getPrefix(java.lang.String uri)
Specified by:
getPrefix in interface javax.xml.stream.XMLStreamWriter

getProperty

public java.lang.Object getProperty(java.lang.String name)
Specified by:
getProperty in interface javax.xml.stream.XMLStreamWriter

setDefaultNamespace

public abstract void setDefaultNamespace(java.lang.String uri)
                                  throws javax.xml.stream.XMLStreamException
Specified by:
setDefaultNamespace in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

setNamespaceContext

public abstract void setNamespaceContext(javax.xml.namespace.NamespaceContext context)
                                  throws javax.xml.stream.XMLStreamException
Specified by:
setNamespaceContext in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

setPrefix

public abstract void setPrefix(java.lang.String prefix,
                               java.lang.String uri)
                        throws javax.xml.stream.XMLStreamException
Specified by:
setPrefix in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeAttribute

public abstract void writeAttribute(java.lang.String localName,
                                    java.lang.String value)
                             throws javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeAttribute

public abstract void writeAttribute(java.lang.String nsURI,
                                    java.lang.String localName,
                                    java.lang.String value)
                             throws javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeAttribute

public abstract void writeAttribute(java.lang.String prefix,
                                    java.lang.String nsURI,
                                    java.lang.String localName,
                                    java.lang.String value)
                             throws javax.xml.stream.XMLStreamException
Specified by:
writeAttribute in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeCData

public void writeCData(java.lang.String data)
                throws javax.xml.stream.XMLStreamException
Specified by:
writeCData in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeCharacters

public void writeCharacters(char[] text,
                            int start,
                            int len)
                     throws javax.xml.stream.XMLStreamException
Specified by:
writeCharacters in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeCharacters

public void writeCharacters(java.lang.String text)
                     throws javax.xml.stream.XMLStreamException
Specified by:
writeCharacters in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeComment

public void writeComment(java.lang.String data)
                  throws javax.xml.stream.XMLStreamException
Specified by:
writeComment in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeDefaultNamespace

public abstract void writeDefaultNamespace(java.lang.String nsURI)
                                    throws javax.xml.stream.XMLStreamException
Specified by:
writeDefaultNamespace in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeDTD

public void writeDTD(java.lang.String dtd)
              throws javax.xml.stream.XMLStreamException
Specified by:
writeDTD in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEmptyElement

public abstract void writeEmptyElement(java.lang.String localName)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEmptyElement

public abstract void writeEmptyElement(java.lang.String nsURI,
                                       java.lang.String localName)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEmptyElement

public abstract void writeEmptyElement(java.lang.String prefix,
                                       java.lang.String localName,
                                       java.lang.String nsURI)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEndDocument

public void writeEndDocument()
                      throws javax.xml.stream.XMLStreamException
Specified by:
writeEndDocument in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEndElement

public abstract void writeEndElement()
                              throws javax.xml.stream.XMLStreamException
Specified by:
writeEndElement in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEntityRef

public void writeEntityRef(java.lang.String name)
                    throws javax.xml.stream.XMLStreamException
Specified by:
writeEntityRef in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeNamespace

public abstract void writeNamespace(java.lang.String prefix,
                                    java.lang.String nsURI)
                             throws javax.xml.stream.XMLStreamException
Specified by:
writeNamespace in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(java.lang.String target)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeProcessingInstruction in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeProcessingInstruction

public void writeProcessingInstruction(java.lang.String target,
                                       java.lang.String data)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeProcessingInstruction in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeStartDocument

public void writeStartDocument()
                        throws javax.xml.stream.XMLStreamException
Specified by:
writeStartDocument in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeStartDocument

public void writeStartDocument(java.lang.String version)
                        throws javax.xml.stream.XMLStreamException
Specified by:
writeStartDocument in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeStartDocument

public void writeStartDocument(java.lang.String encoding,
                               java.lang.String version)
                        throws javax.xml.stream.XMLStreamException
Specified by:
writeStartDocument in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

doWriteStartDocument

protected void doWriteStartDocument(java.lang.String version,
                                    java.lang.String encoding,
                                    java.lang.String standAlone)
                             throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

writeStartElement

public abstract void writeStartElement(java.lang.String localName)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeStartElement in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeStartElement

public abstract void writeStartElement(java.lang.String nsURI,
                                       java.lang.String localName)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeStartElement in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeStartElement

public abstract void writeStartElement(java.lang.String prefix,
                                       java.lang.String localName,
                                       java.lang.String nsURI)
                                throws javax.xml.stream.XMLStreamException
Specified by:
writeStartElement in interface javax.xml.stream.XMLStreamWriter
Throws:
javax.xml.stream.XMLStreamException

copyEventFromReader

public void copyEventFromReader(XMLStreamReader2 sr,
                                boolean preserveEventData)
                         throws javax.xml.stream.XMLStreamException
Method that essentially copies event that the specified reader has just read.

Specified by:
copyEventFromReader in interface XMLStreamWriter2
Parameters:
sr - Stream reader to use for accessing event to copy
preserveEventData - If true, writer is not allowed to change the state of the reader (so that all the data associated with the current event has to be preserved); if false, writer is allowed to use methods that may cause some data to be discarded. Setting this to false may improve the performance, since it may allow full no-copy streaming of data, especially textual contents.
Throws:
javax.xml.stream.XMLStreamException

isPropertySupported

public boolean isPropertySupported(java.lang.String name)
Description copied from interface: XMLStreamWriter2
Method similar to XMLOutputFactory.isPropertySupported(java.lang.String), used to determine whether a property is supported by the Writer instance. This means that this method may return false for some properties that the output factory does support: specifically, it should only return true if the value is mutable on per-instance basis. False means that either the property is not recognized, or is not mutable via writer instance.

Specified by:
isPropertySupported in interface XMLStreamWriter2

setProperty

public boolean setProperty(java.lang.String name,
                           java.lang.Object value)
Description copied from interface: XMLStreamWriter2
Method that can be used to set per-writer properties; a subset of properties one can set via matching XMLOutputFactory2 instance. Exactly which methods are mutable is implementation specific.

Specified by:
setProperty in interface XMLStreamWriter2
Parameters:
name - Name of the property to set
value - Value to set property to.
Returns:
True, if the specified property was succesfully set to specified value; false if its value was not changed

validateAgainst

public XMLValidator validateAgainst(XMLValidationSchema schema)
                             throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
Method that will construct a XMLValidator instance from the given schema (unless a validator for that schema has already been added), initialize it if necessary, and make validatable object (reader, writer) call appropriate validation methods from this point on until the end of the document (that is, it's not scoped with sub-trees), or until validator is removed by an explicit call to Validatable.stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema).

Note that while this method can be called at any point in output processing, validator instances are not required to be able to handle addition at other points than right before outputting the root element.

Specified by:
validateAgainst in interface Validatable
Returns:
Validator instance constructed, if validator was added, or null if a validator for the schema has already been constructed.
Throws:
javax.xml.stream.XMLStreamException

stopValidatingAgainst

public XMLValidator stopValidatingAgainst(XMLValidationSchema schema)
                                   throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
Method that can be called by application to stop validating output against a schema, for which Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema) was called earlier.

Specified by:
stopValidatingAgainst in interface Validatable
Returns:
Validator instance created from the schema that was removed, if one was in use; null if no such schema in use.
Throws:
javax.xml.stream.XMLStreamException

stopValidatingAgainst

public XMLValidator stopValidatingAgainst(XMLValidator validator)
                                   throws javax.xml.stream.XMLStreamException
Description copied from interface: Validatable
Method that can be called by application to stop validating output using specified validator. The validator passed should be an earlier return value for a call to Validatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema).

Note: the specified validator is compared for identity with validators in use, not for equality.

Specified by:
stopValidatingAgainst in interface Validatable
Returns:
Validator instance found (ie. argument validator) if it was being used for validating current document; null if not.
Throws:
javax.xml.stream.XMLStreamException

setValidationProblemHandler

public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
Description copied from interface: Validatable
Method that application can call to define a custom handler for validation problems encountered during validation process.

Specified by:
setValidationProblemHandler in interface Validatable
Parameters:
h - Handler to install, if non null; if null, indicates that the default (implementation-specific) handling should be used
Returns:
Previously set validation problem handler, if any; null if none was set

getLocation

public XMLStreamLocation2 getLocation()
Description copied from interface: XMLStreamWriter2
Method that should return current output location, if the writer keeps track of it; null if it does not.

Specified by:
getLocation in interface XMLStreamWriter2

getEncoding

public java.lang.String getEncoding()
Description copied from interface: XMLStreamWriter2
Method that can be called to get information about encoding that this writer is using (or at least claims is using). That is, it returns name of encoding specified when (in order of priority):

Specified by:
getEncoding in interface XMLStreamWriter2

writeCData

public void writeCData(char[] cbuf,
                       int start,
                       int len)
                throws javax.xml.stream.XMLStreamException
Specified by:
writeCData in interface XMLStreamWriter2
Throws:
javax.xml.stream.XMLStreamException

writeDTD

public void writeDTD(DTDInfo info)
              throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

writeDTD

public void writeDTD(java.lang.String rootName,
                     java.lang.String systemId,
                     java.lang.String publicId,
                     java.lang.String internalSubset)
              throws javax.xml.stream.XMLStreamException
Specified by:
writeDTD in interface XMLStreamWriter2
Throws:
javax.xml.stream.XMLStreamException

writeFullEndElement

public abstract void writeFullEndElement()
                                  throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamWriter2
Method similar to XMLStreamWriter.writeEndElement(), but that will always write the full end element, instead of empty element. This only matters for cases where the element itself has no content, and if writer is allowed to write empty elements when it encounters such start/end element write pairs.

Specified by:
writeFullEndElement in interface XMLStreamWriter2
Throws:
javax.xml.stream.XMLStreamException

writeStartDocument

public void writeStartDocument(java.lang.String version,
                               java.lang.String encoding,
                               boolean standAlone)
                        throws javax.xml.stream.XMLStreamException
Specified by:
writeStartDocument in interface XMLStreamWriter2
Throws:
javax.xml.stream.XMLStreamException

writeRaw

public void writeRaw(java.lang.String text)
              throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamWriter2
Method that writes specified content as is, without encoding or deciphering it in any way. It will not update state of the writer (except by possibly flushing output of previous writes, like finishing a start element), nor be validated in any way. As such, care must be taken, if this method is used.

Method is usually used when encapsulating output from another writer as a sub-tree, or when passing through XML fragments.

Specified by:
writeRaw in interface XMLStreamWriter2
Throws:
javax.xml.stream.XMLStreamException

writeRaw

public void writeRaw(java.lang.String text,
                     int start,
                     int offset)
              throws javax.xml.stream.XMLStreamException
Specified by:
writeRaw in interface XMLStreamWriter2
Throws:
javax.xml.stream.XMLStreamException

writeRaw

public void writeRaw(char[] text,
                     int offset,
                     int length)
              throws javax.xml.stream.XMLStreamException
Description copied from interface: XMLStreamWriter2
Method that writes specified content as is, without encoding or deciphering it in any way. It will not update state of the writer (except by possibly flushing output of previous writes, like finishing a start element), nor be validated in any way. As such, care must be taken, if this method is used.

Method is usually used when encapsulating output from another writer as a sub-tree, or when passing through XML fragments.

Specified by:
writeRaw in interface XMLStreamWriter2
Throws:
javax.xml.stream.XMLStreamException

getXmlVersion

public java.lang.String getXmlVersion()
Description copied from interface: ValidationContext
Method that validator can call to figure out which xml version document being validated declared (if none, "1.0" is assumed as per xml specifications 1.0 and 1.1).

Specified by:
getXmlVersion in interface ValidationContext
Returns:
Xml version of the document: currently has to be either "1.0" or "1.1".

getCurrentElementName

public abstract javax.xml.namespace.QName getCurrentElementName()
Description copied from interface: ValidationContext
Method that can be used to access name information of the innermost (top) element in the element stack.

Specified by:
getCurrentElementName in interface ValidationContext
Returns:
Name of the element at the top of the current element stack, if any. During validation calls it refers to the element being processed (start or end tag), or its parent (when processing text nodes), or null (in document prolog and epilog).

getNamespaceURI

public abstract java.lang.String getNamespaceURI(java.lang.String prefix)
Description copied from interface: ValidationContext
Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element. This may be necessary for things like DTD validators (which may need to heuristically guess proper namespace URI of attributes, esp. ones with default values).

Specified by:
getNamespaceURI in interface ValidationContext

getBaseUri

public java.lang.String getBaseUri()
As of now, there is no way to specify the base URI. Could be improved in future, if xml:base is supported.

Specified by:
getBaseUri in interface ValidationContext
Returns:
Base URI active in the current location of the document being validated, if known; null to indicate no base URI known.

getValidationLocation

public javax.xml.stream.Location getValidationLocation()
Description copied from interface: ValidationContext
Method that will return the location that best represents current location within document to be validated, if such information is available.

Note: it is likely that even when a location is known, it may not be very accurate; for example, when attributes are validated, it is possible that they all would point to a single location that may point to the start of the element that contains attributes.

Specified by:
getValidationLocation in interface ValidationContext

reportProblem

public void reportProblem(XMLValidationProblem prob)
                   throws XMLValidationException
Description copied from interface: ValidationContext
Method called by the validator, upon encountering a validation problem. Implementations are encouraged to allow an optional ValidationProblemHandler be set by the application, to define handling.

Specified by:
reportProblem in interface ValidationContext
Throws:
XMLValidationException

addDefaultAttribute

public int addDefaultAttribute(java.lang.String localName,
                               java.lang.String uri,
                               java.lang.String prefix,
                               java.lang.String value)
Adding default attribute values does not usually make sense on output side, so the implementation is a NOP for now.

Specified by:
addDefaultAttribute in interface ValidationContext
Returns:
Index of the newly added attribute, if operation was succesful; -1 if not.

isNotationDeclared

public boolean isNotationDeclared(java.lang.String name)
Specified by:
isNotationDeclared in interface ValidationContext
Returns:
True, if a notation with specified name has been declared in the document being validated; false if not.

isUnparsedEntityDeclared

public boolean isUnparsedEntityDeclared(java.lang.String name)
Specified by:
isUnparsedEntityDeclared in interface ValidationContext
Returns:
True, if an unparsed entity with specified name has been declared in the document being validated; false if not.

getAttributeCount

public int getAttributeCount()
Description copied from interface: ValidationContext
This method returns number of attributes accessible from within currently active start element.

Note: this method is only guaranteed to be callable during execution of XMLValidator methods XMLValidator.validateElementStart(java.lang.String, java.lang.String, java.lang.String), XMLValidator.validateAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String) and XMLValidator.validateElementAndAttributes(). At other times implementations may choose to allow it to be called (for example, with information regarding last start element processed), to throw a IllegalArgumentException, or to return 0 to indicate no attribute information is available.

Also note that whether defaulted attributes (attributes for which values are only available via attribute defaulting) are accessible depends on exact time when this method is called, and in general can not be assumed to function reliably.

Specified by:
getAttributeCount in interface ValidationContext
Returns:
Number of attributes accessible for the currently active start element.

getAttributeLocalName

public java.lang.String getAttributeLocalName(int index)
Specified by:
getAttributeLocalName in interface ValidationContext

getAttributeNamespace

public java.lang.String getAttributeNamespace(int index)
Specified by:
getAttributeNamespace in interface ValidationContext

getAttributePrefix

public java.lang.String getAttributePrefix(int index)
Specified by:
getAttributePrefix in interface ValidationContext

getAttributeValue

public java.lang.String getAttributeValue(int index)
Specified by:
getAttributeValue in interface ValidationContext

getAttributeValue

public java.lang.String getAttributeValue(java.lang.String nsURI,
                                          java.lang.String localName)
Specified by:
getAttributeValue in interface ValidationContext

findAttributeIndex

public int findAttributeIndex(java.lang.String nsURI,
                              java.lang.String localName)
Specified by:
findAttributeIndex in interface ValidationContext
Returns:
Index of the specified attribute, if one present; -1 otherwise.

wrapAsRawWriter

public final java.io.Writer wrapAsRawWriter()
Method that can be called to get a wrapper instance that can be used to essentially call the writeRaw method via regular Writer interface.


wrapAsTextWriter

public final java.io.Writer wrapAsTextWriter()
Method that can be called to get a wrapper instance that can be used to essentially call the writeCharacters method via regular Writer interface.


isValidating

protected boolean isValidating()
Method that is used by output classes to determine whether we are in validating mode.

Note: current implementation of this method is not perfect; it may be possible it can return true even if we are only using a DTD to get some limited info, without validating?


writeStartElement

public abstract void writeStartElement(javax.xml.stream.events.StartElement elem)
                                throws javax.xml.stream.XMLStreamException
Convenience method needed by WstxEventWriter, to use when writing a start element, and possibly its attributes and namespace declarations.

Throws:
javax.xml.stream.XMLStreamException

writeEndElement

public abstract void writeEndElement(javax.xml.namespace.QName name)
                              throws javax.xml.stream.XMLStreamException
Method called by WstxEventWriter (instead of the version that takes no argument), so that we can verify it does match the start element, if necessary

Throws:
javax.xml.stream.XMLStreamException

writeCharacters

public void writeCharacters(javax.xml.stream.events.Characters ch)
                     throws javax.xml.stream.XMLStreamException
Method called by WstxEventWriter (instead of more generic text output methods), so that we can verify (if necessary) that this character output type is legal in this context. Specifically, it's not acceptable to add non-whitespace content outside root element (in prolog/epilog).

Note: cut'n pasted from the main writeCharacters; not good... but done to optimize white-space cases.

Throws:
javax.xml.stream.XMLStreamException

closeStartElement

protected abstract void closeStartElement(boolean emptyElem)
                                   throws javax.xml.stream.XMLStreamException
Method called to close an open start element, when another main-level element (not namespace declaration or attribute) is being output; except for end element which is handled differently.

Throws:
javax.xml.stream.XMLStreamException

inPrologOrEpilog

protected final boolean inPrologOrEpilog()

copyStartElement

public abstract void copyStartElement(InputElementStack elemStack,
                                      AttributeCollector attrCollector)
                               throws java.io.IOException,
                                      javax.xml.stream.XMLStreamException
Implementation-dependant method called to fully copy START_ELEMENT event that the passed-in stream reader points to

Throws:
java.io.IOException
javax.xml.stream.XMLStreamException

verifyWriteCData

protected final void verifyWriteCData()
                               throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

verifyWriteDTD

protected final void verifyWriteDTD()
                             throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

verifyRootElement

protected void verifyRootElement(java.lang.String localName,
                                 java.lang.String prefix)
                          throws XMLValidationException
Throws:
XMLValidationException

throwOutputError

protected static void throwOutputError(java.lang.String msg)
                                throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

throwOutputError

protected static void throwOutputError(java.lang.String format,
                                       java.lang.Object arg)
                                throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

reportIllegalMethod

protected static void reportIllegalMethod(java.lang.String msg)
                                   throws javax.xml.stream.XMLStreamException
Method called when an illegal method (namespace-specific method on non-ns writer) is called by the application.

Throws:
javax.xml.stream.XMLStreamException

reportNwfStructure

protected static void reportNwfStructure(java.lang.String msg)
                                  throws javax.xml.stream.XMLStreamException
This is the method called when an output method call violates structural well-formedness checks and WstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTURE is is enabled.

Throws:
javax.xml.stream.XMLStreamException

reportNwfStructure

protected static void reportNwfStructure(java.lang.String msg,
                                         java.lang.Object arg)
                                  throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

reportNwfContent

protected static void reportNwfContent(java.lang.String msg)
                                throws javax.xml.stream.XMLStreamException
This is the method called when an output method call violates content well-formedness checks and WstxOutputProperties.P_OUTPUT_VALIDATE_CONTENT is is enabled.

Throws:
javax.xml.stream.XMLStreamException

reportNwfContent

protected static void reportNwfContent(java.lang.String msg,
                                       java.lang.Object arg)
                                throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

reportNwfAttr

protected static void reportNwfAttr(java.lang.String msg)
                             throws javax.xml.stream.XMLStreamException
This is the method called when an output method call violates attribute well-formedness checks (trying to output dup attrs) and WstxOutputProperties.P_OUTPUT_VALIDATE_NAMES is is enabled.

Throws:
javax.xml.stream.XMLStreamException

reportNwfAttr

protected static void reportNwfAttr(java.lang.String msg,
                                    java.lang.Object arg)
                             throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

throwFromIOE

protected static void throwFromIOE(java.io.IOException ioe)
                            throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

reportIllegalArg

protected static void reportIllegalArg(java.lang.String msg)
                                throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException

reportInvalidContent

protected void reportInvalidContent(int evtType)
                             throws javax.xml.stream.XMLStreamException
Throws:
javax.xml.stream.XMLStreamException

reportValidationProblem

public void reportValidationProblem(java.lang.String msg,
                                    javax.xml.stream.Location loc,
                                    int severity)
                             throws XMLValidationException
Throws:
XMLValidationException

reportValidationProblem

public void reportValidationProblem(java.lang.String msg,
                                    int severity)
                             throws XMLValidationException
Throws:
XMLValidationException

reportValidationProblem

public void reportValidationProblem(java.lang.String msg)
                             throws XMLValidationException
Throws:
XMLValidationException

reportValidationProblem

public void reportValidationProblem(javax.xml.stream.Location loc,
                                    java.lang.String msg)
                             throws XMLValidationException
Throws:
XMLValidationException

reportValidationProblem

public void reportValidationProblem(java.lang.String format,
                                    java.lang.Object arg)
                             throws XMLValidationException
Throws:
XMLValidationException

reportValidationProblem

public void reportValidationProblem(java.lang.String format,
                                    java.lang.Object arg,
                                    java.lang.Object arg2)
                             throws XMLValidationException
Throws:
XMLValidationException

doReportProblem

protected final void doReportProblem(javax.xml.stream.XMLReporter rep,
                                     java.lang.String probType,
                                     java.lang.String msg,
                                     javax.xml.stream.Location loc)

getTopElementDesc

protected abstract java.lang.String getTopElementDesc()

toString

public java.lang.String toString()
Helper method used for ensuring that each type of a problem is only reported once per instance. Will be called to see if the specific type of a problem should be reported; the first time will mark the problem as being reported, and return true; afterwards, will return false for the type of the problem

Overrides:
toString in class java.lang.Object