Package com.ctc.wstx.sw
Class BaseNsStreamWriter
- java.lang.Object
-
- org.codehaus.stax2.ri.Stax2WriterImpl
-
- com.ctc.wstx.sw.BaseStreamWriter
-
- com.ctc.wstx.sw.TypedStreamWriter
-
- com.ctc.wstx.sw.BaseNsStreamWriter
-
- All Implemented Interfaces:
OutputConfigFlags,javax.xml.stream.XMLStreamConstants,javax.xml.stream.XMLStreamWriter,org.codehaus.stax2.typed.TypedXMLStreamWriter,org.codehaus.stax2.validation.Validatable,org.codehaus.stax2.validation.ValidationContext,org.codehaus.stax2.XMLStreamWriter2
- Direct Known Subclasses:
RepairingNsStreamWriter,SimpleNsStreamWriter
public abstract class BaseNsStreamWriter extends TypedStreamWriter
Mid-level base class of namespace-aware stream writers. Contains shared functionality between repairing and non-repairing implementations.
-
-
Field Summary
Fields Modifier and Type Field Description protected static java.lang.StringERR_NSDECL_WRONG_STATEprotected booleanmAutomaticNSTrue, if writer needs to automatically output namespace declarations (we are in repairing mode)(package private) static intMAX_POOL_SIZEAlthough pooled objects are small, let's limit the pool size nonetheless, to optimize memory usage for deeply nested documents.protected SimpleOutputElementmCurrElemprotected EmptyElementHandlermEmptyElementHandlerprotected SimpleOutputElementmOutputElemPoolprotected intmPoolSizeprotected javax.xml.namespace.NamespaceContextmRootNsContextOptional "root" namespace context that application can set.protected static java.lang.StringsPrefixXmlprotected static java.lang.StringsPrefixXmlns-
Fields inherited from class com.ctc.wstx.sw.TypedStreamWriter
mValueEncoderFactory
-
Fields inherited from class com.ctc.wstx.sw.BaseStreamWriter
ATTR_MIN_ARRAYCOPY, CHAR_SPACE, DEFAULT_COPYBUFFER_LEN, mAnyOutput, mCfgAutomaticEmptyElems, mCfgCDataAsText, mCfgCopyDefaultAttrs, mCheckAttrs, mCheckStructure, mConfig, mCopyBuffer, mDtdRootElem, mEmptyElement, mEncoding, MIN_ARRAYCOPY, mReturnNullForDefaultNamespace, mStartElementOpen, mState, mValidator, mVldContent, mVldProbHandler, mWriter, mXml11, STATE_EPILOG, STATE_PROLOG, STATE_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
-
-
Constructor Summary
Constructors Constructor Description BaseNsStreamWriter(XmlWriter xw, java.lang.String enc, WriterConfig cfg, boolean repairing)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected voidcheckStartElement(java.lang.String localName, java.lang.String prefix)Method that is called to ensure that we can start writing an element, both from structural point of view, and from syntactic (close previously open start element, if any).protected 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.abstract voiddoSetPrefix(java.lang.String prefix, java.lang.String uri)protected voiddoWriteAttr(java.lang.String localName, java.lang.String nsURI, java.lang.String prefix, char[] buf, int start, int len)protected voiddoWriteAttr(java.lang.String localName, java.lang.String nsURI, java.lang.String prefix, java.lang.String value)protected voiddoWriteDefaultNs(java.lang.String nsURI)protected voiddoWriteEndTag(javax.xml.namespace.QName expName, boolean allowEmpty)protected voiddoWriteNamespace(java.lang.String prefix, java.lang.String nsURI)protected voiddoWriteStartTag(java.lang.String localName)protected voiddoWriteStartTag(java.lang.String prefix, java.lang.String localName)javax.xml.namespace.QNamegetCurrentElementName()javax.xml.namespace.NamespaceContextgetNamespaceContext()java.lang.StringgetNamespaceURI(java.lang.String prefix)java.lang.StringgetPrefix(java.lang.String uri)protected java.lang.StringgetTopElementDesc()Method needed for error message generationabstract voidsetDefaultNamespace(java.lang.String uri)voidsetNamespaceContext(javax.xml.namespace.NamespaceContext ctxt)Note: Root namespace context works best if automatic prefix creation ("namespace/prefix repairing" in StAX lingo) is enabled.voidsetPrefix(java.lang.String prefix, java.lang.String uri)voidwriteAttribute(java.lang.String localName, java.lang.String value)It's assumed calling this method implies caller just wants to add an attribute that does not belong to any namespace; as such no namespace checking or prefix generation is needed.abstract voidwriteAttribute(java.lang.String nsURI, java.lang.String localName, java.lang.String value)abstract voidwriteAttribute(java.lang.String prefix, java.lang.String nsURI, java.lang.String localName, java.lang.String value)abstract voidwriteDefaultNamespace(java.lang.String nsURI)voidwriteEmptyElement(java.lang.String localName)Note: It is assumed caller just wants the element to belong to whatever is the current default namespace.voidwriteEmptyElement(java.lang.String nsURI, java.lang.String localName)voidwriteEmptyElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)voidwriteEndElement()voidwriteEndElement(javax.xml.namespace.QName name)Method called byXMLEventWriterimplementation (instead of the version that takes no argument), so that we can verify it does match the start element, if necessaryvoidwriteFullEndElement()Similar towriteEndElement(), but never allows implicit creation of empty elements.abstract voidwriteNamespace(java.lang.String prefix, java.lang.String nsURI)voidwriteStartElement(java.lang.String localName)This method is assumed to just use default namespace (if any), and no further checks should be done.voidwriteStartElement(java.lang.String nsURI, java.lang.String localName)voidwriteStartElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)abstract voidwriteStartElement(javax.xml.stream.events.StartElement elem)Convenience method needed byXMLEventWriterimplementation, to use when writing a start element, and possibly its attributes and namespace declarations.protected abstract voidwriteStartOrEmpty(java.lang.String localName, java.lang.String nsURI)protected abstract voidwriteStartOrEmpty(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)protected voidwriteTypedAttribute(java.lang.String prefix, java.lang.String nsURI, java.lang.String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc)Method that will write attribute with value that is known not to require additional escaping.-
Methods inherited from class com.ctc.wstx.sw.TypedStreamWriter
valueEncoderFactory, 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, writeTypedElement
-
Methods inherited from class com.ctc.wstx.sw.BaseStreamWriter
addDefaultAttribute, close, closeCompletely, copyEventFromReader, copyStartElement, doReportProblem, doReportProblem, doWriteStartDocument, findAttributeIndex, flush, getAttributeCount, getAttributeLocalName, getAttributeNamespace, getAttributePrefix, getAttributeType, getAttributeValue, getAttributeValue, getBaseUri, getCopyBuffer, getCopyBuffer, getEncoding, getLocation, getProperty, getValidationLocation, getXmlVersion, inPrologOrEpilog, isNotationDeclared, isPropertySupported, isUnparsedEntityDeclared, isValidating, reportIllegalArg, reportIllegalMethod, reportInvalidContent, reportNwfAttr, reportNwfAttr, reportNwfContent, reportNwfContent, reportNwfStructure, reportNwfStructure, reportProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, reportValidationProblem, setProperty, setValidationProblemHandler, stopValidatingAgainst, stopValidatingAgainst, throwFromIOE, throwOutputError, throwOutputError, toString, validateAgainst, validateQNamePrefix, verifyRootElement, verifyWriteCData, verifyWriteDTD, wrapAsRawWriter, wrapAsTextWriter, writeCData, writeCData, writeCharacters, writeCharacters, writeCharacters, writeComment, writeDTD, writeDTD, writeDTD, writeEndDocument, writeEntityRef, writeProcessingInstruction, writeProcessingInstruction, writeRaw, writeRaw, writeRaw, writeSpace, writeSpace, writeStartDocument, writeStartDocument, writeStartDocument, writeStartDocument
-
-
-
-
Field Detail
-
sPrefixXml
protected static final java.lang.String sPrefixXml
-
sPrefixXmlns
protected static final java.lang.String sPrefixXmlns
-
ERR_NSDECL_WRONG_STATE
protected static final java.lang.String ERR_NSDECL_WRONG_STATE
- See Also:
- Constant Field Values
-
mAutomaticNS
protected final boolean mAutomaticNS
True, if writer needs to automatically output namespace declarations (we are in repairing mode)
-
mEmptyElementHandler
protected final EmptyElementHandler mEmptyElementHandler
-
mCurrElem
protected SimpleOutputElement mCurrElem
-
mRootNsContext
protected javax.xml.namespace.NamespaceContext mRootNsContext
Optional "root" namespace context that application can set. If so, it can be used to lookup namespace/prefix mappings
-
mOutputElemPool
protected SimpleOutputElement mOutputElemPool
-
MAX_POOL_SIZE
static final int MAX_POOL_SIZE
Although pooled objects are small, let's limit the pool size nonetheless, to optimize memory usage for deeply nested documents. In general, even just low number like 4 levels gets decent return, but 8 should get 99% hit rate.- See Also:
- Constant Field Values
-
mPoolSize
protected int mPoolSize
-
-
Constructor Detail
-
BaseNsStreamWriter
public BaseNsStreamWriter(XmlWriter xw, java.lang.String enc, WriterConfig cfg, boolean repairing)
-
-
Method Detail
-
getNamespaceContext
public javax.xml.namespace.NamespaceContext getNamespaceContext()
- Specified by:
getNamespaceContextin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
getNamespaceContextin classBaseStreamWriter
-
getPrefix
public java.lang.String getPrefix(java.lang.String uri)
- Specified by:
getPrefixin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
getPrefixin classBaseStreamWriter
-
setDefaultNamespace
public abstract void setDefaultNamespace(java.lang.String uri) throws javax.xml.stream.XMLStreamException- Specified by:
setDefaultNamespacein interfacejavax.xml.stream.XMLStreamWriter- Specified by:
setDefaultNamespacein classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
setNamespaceContext
public void setNamespaceContext(javax.xml.namespace.NamespaceContext ctxt) throws javax.xml.stream.XMLStreamExceptionNote: Root namespace context works best if automatic prefix creation ("namespace/prefix repairing" in StAX lingo) is enabled.
- Specified by:
setNamespaceContextin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
setNamespaceContextin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
setPrefix
public void setPrefix(java.lang.String prefix, java.lang.String uri) throws javax.xml.stream.XMLStreamException- Specified by:
setPrefixin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
setPrefixin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeAttribute
public void writeAttribute(java.lang.String localName, java.lang.String value) throws javax.xml.stream.XMLStreamExceptionIt's assumed calling this method implies caller just wants to add an attribute that does not belong to any namespace; as such no namespace checking or prefix generation is needed.- Specified by:
writeAttributein interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeAttributein classBaseStreamWriter- 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:
writeAttributein interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeAttributein classBaseStreamWriter- 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:
writeAttributein interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeAttributein classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(java.lang.String localName) throws javax.xml.stream.XMLStreamExceptionNote: It is assumed caller just wants the element to belong to whatever is the current default namespace.
- Specified by:
writeEmptyElementin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeEmptyElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(java.lang.String nsURI, java.lang.String localName) throws javax.xml.stream.XMLStreamException- Specified by:
writeEmptyElementin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeEmptyElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI) throws javax.xml.stream.XMLStreamException- Specified by:
writeEmptyElementin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeEmptyElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeEndElement
public void writeEndElement() throws javax.xml.stream.XMLStreamException- Specified by:
writeEndElementin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeEndElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeStartElement
public void writeStartElement(java.lang.String localName) throws javax.xml.stream.XMLStreamExceptionThis method is assumed to just use default namespace (if any), and no further checks should be done.- Specified by:
writeStartElementin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeStartElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeStartElement
public void writeStartElement(java.lang.String nsURI, java.lang.String localName) throws javax.xml.stream.XMLStreamException- Specified by:
writeStartElementin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeStartElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeStartElement
public void writeStartElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI) throws javax.xml.stream.XMLStreamException- Specified by:
writeStartElementin interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeStartElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeTypedAttribute
protected void writeTypedAttribute(java.lang.String prefix, java.lang.String nsURI, java.lang.String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws javax.xml.stream.XMLStreamExceptionDescription copied from class:TypedStreamWriterMethod that will write attribute with value that is known not to require additional escaping.- Specified by:
writeTypedAttributein classTypedStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeFullEndElement
public void writeFullEndElement() throws javax.xml.stream.XMLStreamExceptionSimilar towriteEndElement(), but never allows implicit creation of empty elements.- Specified by:
writeFullEndElementin interfaceorg.codehaus.stax2.XMLStreamWriter2- Specified by:
writeFullEndElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
getCurrentElementName
public javax.xml.namespace.QName getCurrentElementName()
- Specified by:
getCurrentElementNamein interfaceorg.codehaus.stax2.validation.ValidationContext- Specified by:
getCurrentElementNamein classBaseStreamWriter
-
getNamespaceURI
public java.lang.String getNamespaceURI(java.lang.String prefix)
- Specified by:
getNamespaceURIin interfaceorg.codehaus.stax2.validation.ValidationContext- Specified by:
getNamespaceURIin classBaseStreamWriter
-
writeEndElement
public void writeEndElement(javax.xml.namespace.QName name) throws javax.xml.stream.XMLStreamExceptionMethod called byXMLEventWriterimplementation (instead of the version that takes no argument), so that we can verify it does match the start element, if necessary- Specified by:
writeEndElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
closeStartElement
protected void closeStartElement(boolean emptyElem) throws javax.xml.stream.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.- Specified by:
closeStartElementin classBaseStreamWriter- Parameters:
emptyElem- If true, the element being closed is an empty element; if false, a separate stand-alone start element.- Throws:
javax.xml.stream.XMLStreamException
-
getTopElementDesc
protected java.lang.String getTopElementDesc()
Description copied from class:BaseStreamWriterMethod needed for error message generation- Specified by:
getTopElementDescin classBaseStreamWriter
-
checkStartElement
protected void checkStartElement(java.lang.String localName, java.lang.String prefix) throws javax.xml.stream.XMLStreamExceptionMethod that is called to ensure that we can start writing an element, both from structural point of view, and from syntactic (close previously open start element, if any).- Throws:
javax.xml.stream.XMLStreamException
-
doWriteAttr
protected final void doWriteAttr(java.lang.String localName, java.lang.String nsURI, java.lang.String prefix, java.lang.String value) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
doWriteAttr
protected final void doWriteAttr(java.lang.String localName, java.lang.String nsURI, java.lang.String prefix, char[] buf, int start, int len) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
doWriteNamespace
protected void doWriteNamespace(java.lang.String prefix, java.lang.String nsURI) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
doWriteDefaultNs
protected void doWriteDefaultNs(java.lang.String nsURI) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
doWriteStartTag
protected final void doWriteStartTag(java.lang.String localName) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
doWriteStartTag
protected final void doWriteStartTag(java.lang.String prefix, java.lang.String localName) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
doWriteEndTag
protected void doWriteEndTag(javax.xml.namespace.QName expName, boolean allowEmpty) throws javax.xml.stream.XMLStreamException- Parameters:
expName- Name that the closing element should have; null if whatever is in stack should be usedallowEmpty- If true, is allowed to create the empty element if the closing element was truly empty; if false, has to write the full empty element no matter what- Throws:
javax.xml.stream.XMLStreamException
-
doSetPrefix
public abstract void doSetPrefix(java.lang.String prefix, java.lang.String uri) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
writeDefaultNamespace
public abstract void writeDefaultNamespace(java.lang.String nsURI) throws javax.xml.stream.XMLStreamException- Specified by:
writeDefaultNamespacein interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeDefaultNamespacein classBaseStreamWriter- 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:
writeNamespacein interfacejavax.xml.stream.XMLStreamWriter- Specified by:
writeNamespacein classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeStartElement
public abstract void writeStartElement(javax.xml.stream.events.StartElement elem) throws javax.xml.stream.XMLStreamExceptionDescription copied from class:BaseStreamWriterConvenience method needed byXMLEventWriterimplementation, to use when writing a start element, and possibly its attributes and namespace declarations.- Specified by:
writeStartElementin classBaseStreamWriter- Throws:
javax.xml.stream.XMLStreamException
-
writeStartOrEmpty
protected abstract void writeStartOrEmpty(java.lang.String localName, java.lang.String nsURI) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
writeStartOrEmpty
protected abstract void writeStartOrEmpty(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI) throws javax.xml.stream.XMLStreamException- Throws:
javax.xml.stream.XMLStreamException
-
-