Class Stax2WriterImpl
- java.lang.Object
-
- org.codehaus.stax2.ri.Stax2WriterImpl
-
- All Implemented Interfaces:
XMLStreamConstants,XMLStreamWriter,TypedXMLStreamWriter,Validatable,XMLStreamWriter2
public abstract class Stax2WriterImpl extends Object implements XMLStreamWriter2, XMLStreamConstants
This is a partial base implementation ofXMLStreamWriter2, the extended stream writer that is part of Stax2.
-
-
Field Summary
-
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 protectedStax2WriterImpl()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidcopyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData)Method that essentially copies event that the specified reader has just read.protected voidcopyStartElement(XMLStreamReader sr)Basic implementation of copy operation.abstract StringgetEncoding()Method that can be called to get information about encoding that this writer is using (or at least claims is using).abstract XMLStreamLocation2getLocation()Method that should return current output location, if the writer keeps track of it; null if it does not.booleanisPropertySupported(String name)Method similar toXMLOutputFactory.isPropertySupported(java.lang.String), used to determine whether a property is supported by the Writer instance.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.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).voidwriteCData(char[] text, int start, int len)voidwriteDTD(String rootName, String systemId, String publicId, String internalSubset)voidwriteFullEndElement()Method similar toXMLStreamWriter.writeEndElement(), but that will always write the full end element, instead of empty element.abstract voidwriteRaw(char[] text, int offset, int length)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.abstract voidwriteRaw(String text, int offset, int len)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.abstract voidwriteStartDocument(String version, String encoding, boolean standAlone)-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, 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
-
Methods inherited from interface javax.xml.stream.XMLStreamWriter
close, flush, getNamespaceContext, getPrefix, getProperty, setDefaultNamespace, setNamespaceContext, setPrefix, writeAttribute, writeAttribute, writeAttribute, writeCData, writeCharacters, writeCharacters, writeComment, writeDefaultNamespace, writeDTD, writeEmptyElement, writeEmptyElement, writeEmptyElement, writeEndDocument, writeEndElement, writeEntityRef, writeNamespace, writeProcessingInstruction, writeProcessingInstruction, writeStartDocument, writeStartDocument, writeStartDocument, writeStartElement, writeStartElement, writeStartElement
-
Methods inherited from interface org.codehaus.stax2.XMLStreamWriter2
closeCompletely
-
-
-
-
Method Detail
-
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
-
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- 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
-
getLocation
public abstract 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
-
getEncoding
public abstract 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
- Passed to one of factory methods of
-
writeCData
public void writeCData(char[] text, int start, int len) throws XMLStreamException- Specified by:
writeCDatain interfaceXMLStreamWriter2- Throws:
XMLStreamException
-
writeDTD
public void writeDTD(String rootName, String systemId, String publicId, String internalSubset) throws XMLStreamException
- Specified by:
writeDTDin interfaceXMLStreamWriter2- Throws:
XMLStreamException
-
writeFullEndElement
public 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- 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- 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- Throws:
XMLStreamException
-
writeStartDocument
public abstract void writeStartDocument(String version, String encoding, boolean standAlone) throws XMLStreamException
- Specified by:
writeStartDocumentin interfaceXMLStreamWriter2- 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- Throws:
XMLStreamException
-
writeRaw
public abstract void writeRaw(String text, int offset, int len) 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- Throws:
XMLStreamException
-
writeRaw
public abstract void writeRaw(char[] text, int offset, int length) 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- Throws:
XMLStreamException
-
copyEventFromReader
public void copyEventFromReader(XMLStreamReader2 sr, boolean preserveEventData) throws XMLStreamException
Description copied from interface:XMLStreamWriter2Method that essentially copies event that the specified reader has just read. This can be both more convenient (no need to worry about details) and more efficient than separately calling access methods of the reader and write methods of the writer, since writer may know more about reader than the application (and may be able to use non-public methods)- Specified by:
copyEventFromReaderin interfaceXMLStreamWriter2- Parameters:
sr- 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
-
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- 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- 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- 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- 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
-
copyStartElement
protected void copyStartElement(XMLStreamReader sr) throws XMLStreamException
Basic implementation of copy operation. It is likely that sub-classes can implement more efficient copy operations: if so, they should do so.- Throws:
XMLStreamException
-
-