Class BaseStreamWriter
- java.lang.Object
-
- org.codehaus.stax2.ri.Stax2WriterImpl
-
- com.ctc.wstx.sw.BaseStreamWriter
-
- All Implemented Interfaces:
OutputConfigFlags,XMLStreamConstants,XMLStreamWriter,TypedXMLStreamWriter,Validatable,ValidationContext,XMLStreamWriter2
- Direct Known Subclasses:
TypedStreamWriter
public abstract class BaseStreamWriter extends Stax2WriterImpl implements ValidationContext, OutputConfigFlags
Base class forXMLStreamWriterimplementations 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
Fields Modifier and Type Field Description protected static intATTR_MIN_ARRAYCOPYprotected static charCHAR_SPACEprotected static intDEFAULT_COPYBUFFER_LENprotected booleanmAnyOutputFlag that is set to true first time something has been output.protected booleanmCfgAutomaticEmptyElemsprotected booleanmCfgCDataAsTextprotected booleanmCfgCopyDefaultAttrsprotected booleanmCheckAttrsprotected booleanmCheckStructureprotected WriterConfigmConfigprotected char[]mCopyBufferIntermediate buffer into which characters of a String can be copied, in cases where such a copy followed by array access is faster than callingString.charAt()(which perhaps surprisingly is often case, and especially significant for longer buffers).protected StringmDtdRootElemValue passed as the expected root element, when using the multiple argumentwriteDTD(java.lang.String)method.protected booleanmEmptyElementFlag 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 StringmEncodingEncoding to use; may be passed from the factory (when a method that defines encoding is used), updated by a call towriteStartDocument(), or null if neither.protected static intMIN_ARRAYCOPYThis 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 booleanmReturnNullForDefaultNamespaceprotected booleanmStartElementOpenFlag that is set during time that a start element is "open", ie.protected intmStateprotected XMLValidatormValidatorOptional validator to use for validating output against one or more schemas, and/or for safe pretty-printing (indentation).protected intmVldContentState value used with validation, to track types of content that is allowed at this point in output stream.protected ValidationProblemHandlermVldProbHandlerCustom validation problem handler, if any.protected XmlWritermWriterActual physical writer to output serialized XML content toprotected booleanmXml11Since 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 intSTATE_EPILOGprotected static intSTATE_PROLOGprotected static intSTATE_TREE-
Fields inherited from interface com.ctc.wstx.cfg.OutputConfigFlags
CFG_ADD_SPACE_AFTER_EMPTY_ELEM, CFG_AUTO_CLOSE_OUTPUT, CFG_AUTOMATIC_EMPTY_ELEMENTS, CFG_AUTOMATIC_END_ELEMENTS, CFG_AUTOMATIC_NS, CFG_COPY_DEFAULT_ATTRS, CFG_ENABLE_NS, CFG_ESCAPE_CR, CFG_FIX_CONTENT, CFG_OUTPUT_CDATA_AS_TEXT, CFG_USE_DOUBLE_QUOTES_IN_XML_DECL, CFG_VALIDATE_ATTR, CFG_VALIDATE_CONTENT, CFG_VALIDATE_NAMES, CFG_VALIDATE_STRUCTURE
-
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
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedBaseStreamWriter(XmlWriter xw, String enc, WriterConfig cfg)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description intaddDefaultAttribute(String localName, String uri, String prefix, String value)Adding default attribute values does not usually make sense on output side, so the implementation is a NOP for now.voidclose()voidcloseCompletely()Method similar toXMLStreamWriter.close(), except that this method also does close the underlying output destination (stream) if it has not yet been closed.protected abstract voidcloseStartElement(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.voidcopyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData)Method that essentially copies event that the specified reader has just read.abstract voidcopyStartElement(InputElementStack elemStack, AttributeCollector attrCollector)Implementation-dependant method called to fully copy START_ELEMENT event that the passed-in stream reader points toprotected voiddoReportProblem(XMLReporter rep, String probType, String msg, Location loc)protected voiddoReportProblem(XMLReporter rep, XMLValidationProblem prob)protected voiddoWriteStartDocument(String version, String encoding, String standAlone)intfindAttributeIndex(String nsURI, String localName)voidflush()intgetAttributeCount()This method returns number of attributes accessible from within currently active start element.StringgetAttributeLocalName(int index)StringgetAttributeNamespace(int index)StringgetAttributePrefix(int index)StringgetAttributeType(int index)StringgetAttributeValue(int index)StringgetAttributeValue(String nsURI, String localName)StringgetBaseUri()As of now, there is no way to specify the base URI.protected char[]getCopyBuffer()protected char[]getCopyBuffer(int minLen)abstract QNamegetCurrentElementName()Method that can be used to access name information of the innermost (top) element in the element stack.StringgetEncoding()Method that can be called to get information about encoding that this writer is using (or at least claims is using).XMLStreamLocation2getLocation()Method that should return current output location, if the writer keeps track of it; null if it does not.abstract NamespaceContextgetNamespaceContext()abstract StringgetNamespaceURI(String prefix)Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element.abstract StringgetPrefix(String uri)ObjectgetProperty(String name)protected abstract StringgetTopElementDesc()Method needed for error message generationLocationgetValidationLocation()Method that will return the location that best represents current location within document to be validated, if such information is available.StringgetXmlVersion()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 booleaninPrologOrEpilog()booleanisNotationDeclared(String name)booleanisPropertySupported(String name)Method similar toXMLOutputFactory.isPropertySupported(java.lang.String), used to determine whether a property is supported by the Writer instance.booleanisUnparsedEntityDeclared(String name)protected booleanisValidating()Method that is used by output classes to determine whether we are in validating mode.protected static voidreportIllegalArg(String msg)protected static voidreportIllegalMethod(String msg)Method called when an illegal method (namespace-specific method on non-ns writer) is called by the application.protected voidreportInvalidContent(int evtType)protected static voidreportNwfAttr(String msg)This is the method called when an output method call violates attribute well-formedness checks (trying to output dup attrs) andWstxOutputProperties.P_OUTPUT_VALIDATE_NAMESis is enabled.protected static voidreportNwfAttr(String msg, Object arg)protected static voidreportNwfContent(String msg)This is the method called when an output method call violates content well-formedness checks andWstxOutputProperties.P_OUTPUT_VALIDATE_CONTENTis is enabled.protected static voidreportNwfContent(String msg, Object arg)protected static voidreportNwfStructure(String msg)This is the method called when an output method call violates structural well-formedness checks andWstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTUREis is enabled.protected static voidreportNwfStructure(String msg, Object arg)voidreportProblem(XMLValidationProblem prob)Method called by the validator, upon encountering a validation problem.voidreportValidationProblem(String msg)voidreportValidationProblem(String msg, int severity)voidreportValidationProblem(String format, Object arg)voidreportValidationProblem(String format, Object arg, Object arg2)voidreportValidationProblem(String msg, Location loc, int severity)voidreportValidationProblem(Location loc, String msg)abstract voidsetDefaultNamespace(String uri)abstract voidsetNamespaceContext(NamespaceContext context)abstract voidsetPrefix(String prefix, String uri)booleansetProperty(String name, Object value)Method that can be used to set per-writer properties; a subset of properties one can set via matchingXMLOutputFactory2instance.ValidationProblemHandlersetValidationProblemHandler(ValidationProblemHandler h)Method that application can call to define a custom handler for validation problems encountered during validation process.XMLValidatorstopValidatingAgainst(XMLValidationSchema schema)Method that can be called by application to stop validating output against a schema, for whichValidatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema)was called earlier.XMLValidatorstopValidatingAgainst(XMLValidator validator)Method that can be called by application to stop validating output using specified validator.protected static voidthrowFromIOE(IOException ioe)protected static voidthrowOutputError(String msg)protected static voidthrowOutputError(String format, Object arg)StringtoString()XMLValidatorvalidateAgainst(XMLValidationSchema schema)Method that will construct aXMLValidatorinstance 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 toValidatable.stopValidatingAgainst(org.codehaus.stax2.validation.XMLValidationSchema).abstract StringvalidateQNamePrefix(QName name)Method called before writing a QName via Typed Access API.protected voidverifyRootElement(String localName, String prefix)protected voidverifyWriteCData()protected voidverifyWriteDTD()WriterwrapAsRawWriter()Method that can be called to get a wrapper instance that can be used to essentially call thewriteRawmethod via regularWriterinterface.WriterwrapAsTextWriter()Method that can be called to get a wrapper instance that can be used to essentially call thewriteCharactersmethod via regularWriterinterface.abstract voidwriteAttribute(String localName, String value)abstract voidwriteAttribute(String nsURI, String localName, String value)abstract voidwriteAttribute(String prefix, String nsURI, String localName, String value)voidwriteCData(char[] cbuf, int start, int len)voidwriteCData(String data)voidwriteCharacters(char[] text, int start, int len)voidwriteCharacters(String text)voidwriteCharacters(Characters ch)Method called byXMLEventWriter(instead of more generic text output methods), so that we can verify (if necessary) that this character output type is legal in this context.voidwriteComment(String data)abstract voidwriteDefaultNamespace(String nsURI)voidwriteDTD(String dtd)voidwriteDTD(String rootName, String systemId, String publicId, String internalSubset)voidwriteDTD(DTDInfo info)abstract voidwriteEmptyElement(String localName)abstract voidwriteEmptyElement(String nsURI, String localName)abstract voidwriteEmptyElement(String prefix, String localName, String nsURI)voidwriteEndDocument()abstract voidwriteEndElement()abstract voidwriteEndElement(QName name)Method called byXMLEventWriter(instead of the version that takes no argument), so that we can verify it does match the start element if necessary.voidwriteEntityRef(String name)abstract voidwriteFullEndElement()Method similar toXMLStreamWriter.writeEndElement(), but that will always write the full end element, instead of empty element.abstract voidwriteNamespace(String prefix, String nsURI)voidwriteProcessingInstruction(String target)voidwriteProcessingInstruction(String target, String data)voidwriteRaw(char[] text, int start, int offset)Method that writes specified content as is, without encoding or deciphering it in any way.voidwriteRaw(String text)Method that writes specified content as is, without encoding or deciphering it in any way.voidwriteRaw(String text, int start, int offset)Method that writes specified content as is, without encoding or deciphering it in any way.voidwriteSpace(char[] text, int offset, int length)Method that can be called to write whitespace-only content.voidwriteSpace(String text)Method that can be called to write whitespace-only content.voidwriteStartDocument()voidwriteStartDocument(String version)voidwriteStartDocument(String encoding, String version)voidwriteStartDocument(String version, String encoding, boolean standAlone)abstract voidwriteStartElement(String localName)abstract voidwriteStartElement(String nsURI, String localName)abstract voidwriteStartElement(String prefix, String localName, String nsURI)abstract voidwriteStartElement(StartElement elem)Convenience method needed byXMLEventWriterimplementation, to use when writing a start element, and possibly its attributes and namespace declarations.-
Methods inherited from class org.codehaus.stax2.ri.Stax2WriterImpl
copyStartElement
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.codehaus.stax2.typed.TypedXMLStreamWriter
writeBinary, writeBinary, writeBinaryAttribute, writeBinaryAttribute, writeBoolean, writeBooleanAttribute, writeDecimal, writeDecimalAttribute, writeDouble, writeDoubleArray, writeDoubleArrayAttribute, writeDoubleAttribute, writeFloat, writeFloatArray, writeFloatArrayAttribute, writeFloatAttribute, writeInt, writeIntArray, writeIntArrayAttribute, writeIntAttribute, writeInteger, writeIntegerAttribute, writeLong, writeLongArray, writeLongArrayAttribute, writeLongAttribute, writeQName, writeQNameAttribute
-
-
-
-
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
-
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 callingString.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 String mEncoding
Encoding to use; may be passed from the factory (when a method that defines encoding is used), updated by a call towriteStartDocument(), 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 String mDtdRootElem
Value passed as the expected root element, when using the multiple argumentwriteDTD(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).
-
mReturnNullForDefaultNamespace
protected boolean mReturnNullForDefaultNamespace
-
-
Constructor Detail
-
BaseStreamWriter
protected BaseStreamWriter(XmlWriter xw, String enc, WriterConfig cfg)
-
-
Method Detail
-
close
public void close() throws XMLStreamException- Specified by:
closein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
flush
public void flush() throws XMLStreamException- Specified by:
flushin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
getNamespaceContext
public abstract NamespaceContext getNamespaceContext()
- Specified by:
getNamespaceContextin interfaceXMLStreamWriter
-
getPrefix
public abstract String getPrefix(String uri)
- Specified by:
getPrefixin interfaceXMLStreamWriter
-
getProperty
public Object getProperty(String name)
- Specified by:
getPropertyin interfaceXMLStreamWriter
-
setDefaultNamespace
public abstract void setDefaultNamespace(String uri) throws XMLStreamException
- Specified by:
setDefaultNamespacein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
setNamespaceContext
public abstract void setNamespaceContext(NamespaceContext context) throws XMLStreamException
- Specified by:
setNamespaceContextin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
setPrefix
public abstract void setPrefix(String prefix, String uri) throws XMLStreamException
- Specified by:
setPrefixin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public abstract void writeAttribute(String localName, String value) throws XMLStreamException
- Specified by:
writeAttributein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public abstract void writeAttribute(String nsURI, String localName, String value) throws XMLStreamException
- Specified by:
writeAttributein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public abstract void writeAttribute(String prefix, String nsURI, String localName, String value) throws XMLStreamException
- Specified by:
writeAttributein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeCData
public void writeCData(String data) throws XMLStreamException
- Specified by:
writeCDatain interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeCharacters
public void writeCharacters(char[] text, int start, int len) throws XMLStreamException- Specified by:
writeCharactersin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeCharacters
public void writeCharacters(String text) throws XMLStreamException
- Specified by:
writeCharactersin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeComment
public void writeComment(String data) throws XMLStreamException
- Specified by:
writeCommentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeDefaultNamespace
public abstract void writeDefaultNamespace(String nsURI) throws XMLStreamException
- Specified by:
writeDefaultNamespacein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeDTD
public void writeDTD(String dtd) throws XMLStreamException
- Specified by:
writeDTDin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
public abstract void writeEmptyElement(String localName) throws XMLStreamException
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
public abstract void writeEmptyElement(String nsURI, String localName) throws XMLStreamException
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
public abstract void writeEmptyElement(String prefix, String localName, String nsURI) throws XMLStreamException
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEndDocument
public void writeEndDocument() throws XMLStreamException- Specified by:
writeEndDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEndElement
public abstract void writeEndElement() throws XMLStreamException- Specified by:
writeEndElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeEntityRef
public void writeEntityRef(String name) throws XMLStreamException
- Specified by:
writeEntityRefin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeNamespace
public abstract void writeNamespace(String prefix, String nsURI) throws XMLStreamException
- Specified by:
writeNamespacein interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeProcessingInstruction
public void writeProcessingInstruction(String target) throws XMLStreamException
- Specified by:
writeProcessingInstructionin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeProcessingInstruction
public void writeProcessingInstruction(String target, String data) throws XMLStreamException
- Specified by:
writeProcessingInstructionin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartDocument
public void writeStartDocument() throws XMLStreamException- Specified by:
writeStartDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartDocument
public void writeStartDocument(String version) throws XMLStreamException
- Specified by:
writeStartDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartDocument
public void writeStartDocument(String encoding, String version) throws XMLStreamException
- Specified by:
writeStartDocumentin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
doWriteStartDocument
protected void doWriteStartDocument(String version, String encoding, String standAlone) throws XMLStreamException
- Throws:
XMLStreamException
-
writeStartElement
public abstract void writeStartElement(String localName) throws XMLStreamException
- Specified by:
writeStartElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartElement
public abstract void writeStartElement(String nsURI, String localName) throws XMLStreamException
- Specified by:
writeStartElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
writeStartElement
public abstract void writeStartElement(String prefix, String localName, String nsURI) throws XMLStreamException
- Specified by:
writeStartElementin interfaceXMLStreamWriter- Throws:
XMLStreamException
-
copyEventFromReader
public void copyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData) throws XMLStreamException
Method that essentially copies event that the specified reader has just read.- Specified by:
copyEventFromReaderin interfaceXMLStreamWriter2- Overrides:
copyEventFromReaderin classStax2WriterImpl- Parameters:
sr- Stream reader to use for accessing event to copypreserveEventData- 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:
XMLStreamException
-
closeCompletely
public void closeCompletely() throws XMLStreamExceptionDescription copied from interface:XMLStreamWriter2Method similar toXMLStreamWriter.close(), except that this method also does close the underlying output destination (stream) if it has not yet been closed. It is specifically necessary to call this method if the parsing ends in an exception to ensure that the output destination does get properly closed, even if the stream writer would otherwise close it (as is the case for destinations it manages where calling application has no access)- Specified by:
closeCompletelyin interfaceXMLStreamWriter2- Throws:
XMLStreamException
-
isPropertySupported
public boolean isPropertySupported(String name)
Description copied from interface:XMLStreamWriter2Method similar toXMLOutputFactory.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:
isPropertySupportedin interfaceXMLStreamWriter2- Overrides:
isPropertySupportedin classStax2WriterImpl
-
setProperty
public boolean setProperty(String name, Object value)
Description copied from interface:XMLStreamWriter2Method that can be used to set per-writer properties; a subset of properties one can set via matchingXMLOutputFactory2instance. Exactly which methods are mutable is implementation specific.- Specified by:
setPropertyin interfaceXMLStreamWriter2- Overrides:
setPropertyin classStax2WriterImpl- Parameters:
name- Name of the property to setvalue- 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 XMLStreamException
Description copied from interface:ValidatableMethod that will construct aXMLValidatorinstance 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 toValidatable.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:
validateAgainstin interfaceValidatable- Overrides:
validateAgainstin classStax2WriterImpl- Returns:
- Validator instance constructed, if validator was added, or null if a validator for the schema has already been constructed.
- Throws:
XMLStreamException
-
stopValidatingAgainst
public XMLValidator stopValidatingAgainst(XMLValidationSchema schema) throws XMLStreamException
Description copied from interface:ValidatableMethod that can be called by application to stop validating output against a schema, for whichValidatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema)was called earlier.- Specified by:
stopValidatingAgainstin interfaceValidatable- Overrides:
stopValidatingAgainstin classStax2WriterImpl- Returns:
- Validator instance created from the schema that was removed, if one was in use; null if no such schema in use.
- Throws:
XMLStreamException
-
stopValidatingAgainst
public XMLValidator stopValidatingAgainst(XMLValidator validator) throws XMLStreamException
Description copied from interface:ValidatableMethod 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 toValidatable.validateAgainst(org.codehaus.stax2.validation.XMLValidationSchema).Note: the specified validator is compared for identity with validators in use, not for equality.
- Specified by:
stopValidatingAgainstin interfaceValidatable- Overrides:
stopValidatingAgainstin classStax2WriterImpl- Returns:
- Validator instance found (ie. argument
validator) if it was being used for validating current document; null if not. - Throws:
XMLStreamException
-
setValidationProblemHandler
public ValidationProblemHandler setValidationProblemHandler(ValidationProblemHandler h)
Description copied from interface:ValidatableMethod that application can call to define a custom handler for validation problems encountered during validation process.- Specified by:
setValidationProblemHandlerin interfaceValidatable- Overrides:
setValidationProblemHandlerin classStax2WriterImpl- 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:XMLStreamWriter2Method that should return current output location, if the writer keeps track of it; null if it does not.- Specified by:
getLocationin interfaceXMLStreamWriter2- Specified by:
getLocationin classStax2WriterImpl
-
getEncoding
public String getEncoding()
Description copied from interface:XMLStreamWriter2Method 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):- Passed to one of factory methods of
XMLOutputFactory - Passed to
writeStartDocumentmethod (explicitly or implicity; latter in cases where defaults are imposed by Stax specification)
- Specified by:
getEncodingin interfaceXMLStreamWriter2- Specified by:
getEncodingin classStax2WriterImpl
- Passed to one of factory methods of
-
writeCData
public void writeCData(char[] cbuf, int start, int len) throws XMLStreamException- Specified by:
writeCDatain interfaceXMLStreamWriter2- Overrides:
writeCDatain classStax2WriterImpl- Throws:
XMLStreamException
-
writeDTD
public void writeDTD(DTDInfo info) throws XMLStreamException
- Throws:
XMLStreamException
-
writeDTD
public void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws XMLStreamException
- Specified by:
writeDTDin interfaceXMLStreamWriter2- Overrides:
writeDTDin classStax2WriterImpl- Throws:
XMLStreamException
-
writeFullEndElement
public abstract void writeFullEndElement() throws XMLStreamExceptionDescription copied from interface:XMLStreamWriter2Method similar toXMLStreamWriter.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:
writeFullEndElementin interfaceXMLStreamWriter2- Overrides:
writeFullEndElementin classStax2WriterImpl- Throws:
XMLStreamException
-
writeStartDocument
public void writeStartDocument(String version, String encoding, boolean standAlone) throws XMLStreamException
- Specified by:
writeStartDocumentin interfaceXMLStreamWriter2- Specified by:
writeStartDocumentin classStax2WriterImpl- Throws:
XMLStreamException
-
writeRaw
public void writeRaw(String text) throws XMLStreamException
Description copied from interface:XMLStreamWriter2Method 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.
NOTE: since text to be written may be anything, including markup, it can not be reliably validated. Because of this, validator(s) attached to the writer will NOT be informed about writes.
- Specified by:
writeRawin interfaceXMLStreamWriter2- Overrides:
writeRawin classStax2WriterImpl- Throws:
XMLStreamException
-
writeRaw
public void writeRaw(String text, int start, int offset) throws XMLStreamException
Description copied from interface:XMLStreamWriter2Method 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.
NOTE: since text to be written may be anything, including markup, it can not be reliably validated. Because of this, validator(s) attached to the writer will NOT be informed about writes.
- Specified by:
writeRawin interfaceXMLStreamWriter2- Specified by:
writeRawin classStax2WriterImpl- Throws:
XMLStreamException
-
writeRaw
public void writeRaw(char[] text, int start, int offset) throws XMLStreamExceptionDescription copied from interface:XMLStreamWriter2Method 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.
NOTE: since text to be written may be anything, including markup, it can not be reliably validated. Because of this, validator(s) attached to the writer will NOT be informed about writes.
- Specified by:
writeRawin interfaceXMLStreamWriter2- Specified by:
writeRawin classStax2WriterImpl- Throws:
XMLStreamException
-
writeSpace
public void writeSpace(String text) throws XMLStreamException
Description copied from interface:XMLStreamWriter2Method that can be called to write whitespace-only content. If so, it is to be written as is (with no escaping), and does not contain non-whitespace characters (writer may validate this, and throw an exception if it does).This method is useful for things like outputting indentation.
- Specified by:
writeSpacein interfaceXMLStreamWriter2- Overrides:
writeSpacein classStax2WriterImpl- Throws:
XMLStreamException
-
writeSpace
public void writeSpace(char[] text, int offset, int length) throws XMLStreamExceptionDescription copied from interface:XMLStreamWriter2Method that can be called to write whitespace-only content. If so, it is to be written as is (with no escaping), and does not contain non-whitespace characters (writer may validate this, and throw an exception if it does).This method is useful for things like outputting indentation.
- Specified by:
writeSpacein interfaceXMLStreamWriter2- Overrides:
writeSpacein classStax2WriterImpl- Throws:
XMLStreamException
-
getXmlVersion
public String getXmlVersion()
Description copied from interface:ValidationContextMethod 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:
getXmlVersionin interfaceValidationContext- Returns:
- Xml version of the document: currently has to be either "1.0" or "1.1".
-
getCurrentElementName
public abstract QName getCurrentElementName()
Description copied from interface:ValidationContextMethod that can be used to access name information of the innermost (top) element in the element stack.- Specified by:
getCurrentElementNamein interfaceValidationContext- 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 String getNamespaceURI(String prefix)
Description copied from interface:ValidationContextMethod 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:
getNamespaceURIin interfaceValidationContext
-
getBaseUri
public 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:
getBaseUriin interfaceValidationContext- Returns:
- Base URI active in the current location of the document being validated, if known; null to indicate no base URI known.
-
getValidationLocation
public Location getValidationLocation()
Description copied from interface:ValidationContextMethod 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:
getValidationLocationin interfaceValidationContext
-
reportProblem
public void reportProblem(XMLValidationProblem prob) throws XMLStreamException
Description copied from interface:ValidationContextMethod called by the validator, upon encountering a validation problem. Implementations are encouraged to allow an optionalValidationProblemHandlerbe set by the application, to define handling.Note: Stax2 version 2 only allowed throwing instances of
XMLValidationProblem; version 3 allows generic base class to be thrown, to support other interfaces such as basic Stax interfaceXMLReporter.- Specified by:
reportProblemin interfaceValidationContext- Throws:
XMLStreamException
-
addDefaultAttribute
public int addDefaultAttribute(String localName, String uri, String prefix, String value)
Adding default attribute values does not usually make sense on output side, so the implementation is a NOP for now.- Specified by:
addDefaultAttributein interfaceValidationContext- Returns:
- Index of the newly added attribute, if operation was succesful; -1 if not.
-
isNotationDeclared
public boolean isNotationDeclared(String name)
- Specified by:
isNotationDeclaredin interfaceValidationContext- Returns:
- True, if a notation with specified name has been declared in the document being validated; false if not.
-
isUnparsedEntityDeclared
public boolean isUnparsedEntityDeclared(String name)
- Specified by:
isUnparsedEntityDeclaredin interfaceValidationContext- 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:ValidationContextThis method returns number of attributes accessible from within currently active start element.Note: this method is only guaranteed to be callable during execution of
XMLValidatormethodsXMLValidator.validateElementStart(java.lang.String, java.lang.String, java.lang.String),XMLValidator.validateAttribute(java.lang.String, java.lang.String, java.lang.String, java.lang.String)andXMLValidator.validateElementAndAttributes(). At other times implementations may choose to allow it to be called (for example, with information regarding last start element processed), to throw aIllegalArgumentException, 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:
getAttributeCountin interfaceValidationContext- Returns:
- Number of attributes accessible for the currently active start element.
-
getAttributeLocalName
public String getAttributeLocalName(int index)
- Specified by:
getAttributeLocalNamein interfaceValidationContext
-
getAttributeNamespace
public String getAttributeNamespace(int index)
- Specified by:
getAttributeNamespacein interfaceValidationContext
-
getAttributePrefix
public String getAttributePrefix(int index)
- Specified by:
getAttributePrefixin interfaceValidationContext
-
getAttributeValue
public String getAttributeValue(int index)
- Specified by:
getAttributeValuein interfaceValidationContext
-
getAttributeValue
public String getAttributeValue(String nsURI, String localName)
- Specified by:
getAttributeValuein interfaceValidationContext
-
getAttributeType
public String getAttributeType(int index)
- Specified by:
getAttributeTypein interfaceValidationContext
-
findAttributeIndex
public int findAttributeIndex(String nsURI, String localName)
- Specified by:
findAttributeIndexin interfaceValidationContext- Returns:
- Index of the specified attribute, if one present; -1 otherwise.
-
wrapAsRawWriter
public final Writer wrapAsRawWriter()
Method that can be called to get a wrapper instance that can be used to essentially call thewriteRawmethod via regularWriterinterface.
-
wrapAsTextWriter
public final Writer wrapAsTextWriter()
Method that can be called to get a wrapper instance that can be used to essentially call thewriteCharactersmethod via regularWriterinterface.
-
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(StartElement elem) throws XMLStreamException
Convenience method needed byXMLEventWriterimplementation, to use when writing a start element, and possibly its attributes and namespace declarations.- Throws:
XMLStreamException
-
writeEndElement
public abstract void writeEndElement(QName name) throws XMLStreamException
Method called byXMLEventWriter(instead of the version that takes no argument), so that we can verify it does match the start element if necessary.- Throws:
XMLStreamException
-
writeCharacters
public void writeCharacters(Characters ch) throws XMLStreamException
Method called byXMLEventWriter(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:
XMLStreamException
-
closeStartElement
protected abstract void closeStartElement(boolean emptyElem) throws XMLStreamExceptionMethod 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:
XMLStreamException
-
inPrologOrEpilog
protected final boolean inPrologOrEpilog()
-
copyStartElement
public abstract void copyStartElement(InputElementStack elemStack, AttributeCollector attrCollector) throws IOException, XMLStreamException
Implementation-dependant method called to fully copy START_ELEMENT event that the passed-in stream reader points to- Throws:
IOExceptionXMLStreamException
-
validateQNamePrefix
public abstract String validateQNamePrefix(QName name) throws XMLStreamException
Method called before writing a QName via Typed Access API. In namespace-repairing mode it should take appropriate actions to ensure that the given namespace URI is bound to a namespace and return whatever it maps to. In non-repairing work no additional work is to be done and methods- Returns:
- Prefix to use when writing out given QName as an element or attribute value
- Throws:
XMLStreamException
-
verifyWriteCData
protected final void verifyWriteCData() throws XMLStreamException- Throws:
XMLStreamException
-
verifyWriteDTD
protected final void verifyWriteDTD() throws XMLStreamException- Throws:
XMLStreamException
-
verifyRootElement
protected void verifyRootElement(String localName, String prefix) throws XMLStreamException
- Throws:
XMLStreamException
-
throwOutputError
protected static void throwOutputError(String msg) throws XMLStreamException
- Throws:
XMLStreamException
-
throwOutputError
protected static void throwOutputError(String format, Object arg) throws XMLStreamException
- Throws:
XMLStreamException
-
reportIllegalMethod
protected static void reportIllegalMethod(String msg) throws XMLStreamException
Method called when an illegal method (namespace-specific method on non-ns writer) is called by the application.- Throws:
XMLStreamException
-
reportNwfStructure
protected static void reportNwfStructure(String msg) throws XMLStreamException
This is the method called when an output method call violates structural well-formedness checks andWstxOutputProperties.P_OUTPUT_VALIDATE_STRUCTUREis is enabled.- Throws:
XMLStreamException
-
reportNwfStructure
protected static void reportNwfStructure(String msg, Object arg) throws XMLStreamException
- Throws:
XMLStreamException
-
reportNwfContent
protected static void reportNwfContent(String msg) throws XMLStreamException
This is the method called when an output method call violates content well-formedness checks andWstxOutputProperties.P_OUTPUT_VALIDATE_CONTENTis is enabled.- Throws:
XMLStreamException
-
reportNwfContent
protected static void reportNwfContent(String msg, Object arg) throws XMLStreamException
- Throws:
XMLStreamException
-
reportNwfAttr
protected static void reportNwfAttr(String msg) throws XMLStreamException
This is the method called when an output method call violates attribute well-formedness checks (trying to output dup attrs) andWstxOutputProperties.P_OUTPUT_VALIDATE_NAMESis is enabled.- Throws:
XMLStreamException
-
reportNwfAttr
protected static void reportNwfAttr(String msg, Object arg) throws XMLStreamException
- Throws:
XMLStreamException
-
throwFromIOE
protected static void throwFromIOE(IOException ioe) throws XMLStreamException
- Throws:
XMLStreamException
-
reportIllegalArg
protected static void reportIllegalArg(String msg) throws IllegalArgumentException
- Throws:
IllegalArgumentException
-
reportInvalidContent
protected void reportInvalidContent(int evtType) throws XMLStreamException- Throws:
XMLStreamException
-
reportValidationProblem
public void reportValidationProblem(String msg, Location loc, int severity) throws XMLStreamException
- Throws:
XMLStreamException
-
reportValidationProblem
public void reportValidationProblem(String msg, int severity) throws XMLStreamException
- Throws:
XMLStreamException
-
reportValidationProblem
public void reportValidationProblem(String msg) throws XMLStreamException
- Throws:
XMLStreamException
-
reportValidationProblem
public void reportValidationProblem(Location loc, String msg) throws XMLStreamException
- Throws:
XMLStreamException
-
reportValidationProblem
public void reportValidationProblem(String format, Object arg) throws XMLStreamException
- Throws:
XMLStreamException
-
reportValidationProblem
public void reportValidationProblem(String format, Object arg, Object arg2) throws XMLStreamException
- Throws:
XMLStreamException
-
doReportProblem
protected void doReportProblem(XMLReporter rep, String probType, String msg, Location loc) throws XMLStreamException
- Throws:
XMLStreamException
-
doReportProblem
protected void doReportProblem(XMLReporter rep, XMLValidationProblem prob) throws XMLStreamException
- Throws:
XMLStreamException
-
getTopElementDesc
protected abstract String getTopElementDesc()
Method needed for error message generation
-
getCopyBuffer
protected final char[] getCopyBuffer()
-
getCopyBuffer
protected final char[] getCopyBuffer(int minLen)
-
-