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, XMLStreamConstants, 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
Mid-level base class of namespace-aware stream writers. Contains
shared functionality between repairing and non-repairing implementations.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final Stringprotected final booleanTrue, if writer needs to automatically output namespace declarations (we are in repairing mode)(package private) static final intAlthough pooled objects are small, let's limit the pool size nonetheless, to optimize memory usage for deeply nested documents.protected SimpleOutputElementprotected final EmptyElementHandlerprotected SimpleOutputElementprotected intprotected NamespaceContextOptional "root" namespace context that application can set.protected static final Stringprotected static final StringFields inherited from class TypedStreamWriter
mValueEncoderFactoryFields inherited from class 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_TREEFields inherited from interface 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_STRUCTUREFields inherited from interface 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
ConstructorsConstructorDescriptionBaseNsStreamWriter(XmlWriter xw, String enc, WriterConfig cfg, boolean repairing) -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcheckStartElement(String localName, 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(String prefix, String uri) protected final voiddoWriteAttr(String localName, String nsURI, String prefix, char[] buf, int start, int len) protected final voiddoWriteAttr(String localName, String nsURI, String prefix, String value) protected voiddoWriteDefaultNs(String nsURI) protected voiddoWriteEndTag(QName expName, boolean allowEmpty) protected voiddoWriteNamespace(String prefix, String nsURI) protected final voiddoWriteStartTag(String localName) protected final voiddoWriteStartTag(String prefix, String localName) getNamespaceURI(String prefix) protected StringMethod needed for error message generationabstract voidvoidNote: Root namespace context works best if automatic prefix creation ("namespace/prefix repairing" in StAX lingo) is enabled.voidvoidwriteAttribute(String localName, 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(String nsURI, String localName, String value) abstract voidwriteAttribute(String prefix, String nsURI, String localName, String value) abstract voidwriteDefaultNamespace(String nsURI) voidwriteEmptyElement(String localName) Note: It is assumed caller just wants the element to belong to whatever is the current default namespace.voidwriteEmptyElement(String nsURI, String localName) voidwriteEmptyElement(String prefix, String localName, String nsURI) voidvoidwriteEndElement(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 necessaryvoidSimilar towriteEndElement(), but never allows implicit creation of empty elements.abstract voidwriteNamespace(String prefix, String nsURI) voidwriteStartElement(String localName) This method is assumed to just use default namespace (if any), and no further checks should be done.voidwriteStartElement(String nsURI, String localName) voidwriteStartElement(String prefix, String localName, String nsURI) abstract voidConvenience method needed byXMLEventWriterimplementation, to use when writing a start element, and possibly its attributes and namespace declarations.protected abstract voidwriteStartOrEmpty(String localName, String nsURI) protected abstract voidwriteStartOrEmpty(String prefix, String localName, String nsURI) protected voidwriteTypedAttribute(String prefix, String nsURI, 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 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, writeTypedElementMethods inherited from class 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, writeStartDocumentMethods inherited from class org.codehaus.stax2.ri.Stax2WriterImpl
copyStartElement
-
Field Details
-
sPrefixXml
-
sPrefixXmlns
-
ERR_NSDECL_WRONG_STATE
- See Also:
-
mAutomaticNS
protected final boolean mAutomaticNSTrue, if writer needs to automatically output namespace declarations (we are in repairing mode) -
mEmptyElementHandler
-
mCurrElem
-
mRootNsContext
Optional "root" namespace context that application can set. If so, it can be used to lookup namespace/prefix mappings -
mOutputElemPool
-
MAX_POOL_SIZE
static final int MAX_POOL_SIZEAlthough 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:
-
mPoolSize
protected int mPoolSize
-
-
Constructor Details
-
BaseNsStreamWriter
-
-
Method Details
-
getNamespaceContext
- Specified by:
getNamespaceContextin interfaceXMLStreamWriter- Specified by:
getNamespaceContextin classBaseStreamWriter
-
getPrefix
- Specified by:
getPrefixin interfaceXMLStreamWriter- Specified by:
getPrefixin classBaseStreamWriter
-
setDefaultNamespace
- Specified by:
setDefaultNamespacein interfaceXMLStreamWriter- Specified by:
setDefaultNamespacein classBaseStreamWriter- Throws:
XMLStreamException
-
setNamespaceContext
Note: Root namespace context works best if automatic prefix creation ("namespace/prefix repairing" in StAX lingo) is enabled.
- Specified by:
setNamespaceContextin interfaceXMLStreamWriter- Specified by:
setNamespaceContextin classBaseStreamWriter- Throws:
XMLStreamException
-
setPrefix
- Specified by:
setPrefixin interfaceXMLStreamWriter- Specified by:
setPrefixin classBaseStreamWriter- Throws:
XMLStreamException
-
writeAttribute
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.- Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classBaseStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public abstract void writeAttribute(String nsURI, String localName, String value) throws XMLStreamException - Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classBaseStreamWriter- Throws:
XMLStreamException
-
writeAttribute
public abstract void writeAttribute(String prefix, String nsURI, String localName, String value) throws XMLStreamException - Specified by:
writeAttributein interfaceXMLStreamWriter- Specified by:
writeAttributein classBaseStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
Note: It is assumed caller just wants the element to belong to whatever is the current default namespace.
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Specified by:
writeEmptyElementin classBaseStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
- Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Specified by:
writeEmptyElementin classBaseStreamWriter- Throws:
XMLStreamException
-
writeEmptyElement
public void writeEmptyElement(String prefix, String localName, String nsURI) throws XMLStreamException - Specified by:
writeEmptyElementin interfaceXMLStreamWriter- Specified by:
writeEmptyElementin classBaseStreamWriter- Throws:
XMLStreamException
-
writeEndElement
- Specified by:
writeEndElementin interfaceXMLStreamWriter- Specified by:
writeEndElementin classBaseStreamWriter- Throws:
XMLStreamException
-
writeStartElement
This method is assumed to just use default namespace (if any), and no further checks should be done.- Specified by:
writeStartElementin interfaceXMLStreamWriter- Specified by:
writeStartElementin classBaseStreamWriter- Throws:
XMLStreamException
-
writeStartElement
- Specified by:
writeStartElementin interfaceXMLStreamWriter- Specified by:
writeStartElementin classBaseStreamWriter- Throws:
XMLStreamException
-
writeStartElement
public void writeStartElement(String prefix, String localName, String nsURI) throws XMLStreamException - Specified by:
writeStartElementin interfaceXMLStreamWriter- Specified by:
writeStartElementin classBaseStreamWriter- Throws:
XMLStreamException
-
writeTypedAttribute
protected void writeTypedAttribute(String prefix, String nsURI, String localName, org.codehaus.stax2.ri.typed.AsciiValueEncoder enc) throws XMLStreamException Description copied from class:TypedStreamWriterMethod that will write attribute with value that is known not to require additional escaping.- Specified by:
writeTypedAttributein classTypedStreamWriter- Throws:
XMLStreamException
-
writeFullEndElement
Similar towriteEndElement(), but never allows implicit creation of empty elements.- Specified by:
writeFullEndElementin interfaceorg.codehaus.stax2.XMLStreamWriter2- Specified by:
writeFullEndElementin classBaseStreamWriter- Throws:
XMLStreamException
-
getCurrentElementName
- Specified by:
getCurrentElementNamein interfaceorg.codehaus.stax2.validation.ValidationContext- Specified by:
getCurrentElementNamein classBaseStreamWriter
-
getNamespaceURI
- Specified by:
getNamespaceURIin interfaceorg.codehaus.stax2.validation.ValidationContext- Specified by:
getNamespaceURIin classBaseStreamWriter
-
writeEndElement
Method 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:
XMLStreamException
-
closeStartElement
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.- 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:
XMLStreamException
-
getTopElementDesc
Description copied from class:BaseStreamWriterMethod needed for error message generation- Specified by:
getTopElementDescin classBaseStreamWriter
-
checkStartElement
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).- Throws:
XMLStreamException
-
doWriteAttr
protected final void doWriteAttr(String localName, String nsURI, String prefix, String value) throws XMLStreamException - Throws:
XMLStreamException
-
doWriteAttr
protected final void doWriteAttr(String localName, String nsURI, String prefix, char[] buf, int start, int len) throws XMLStreamException - Throws:
XMLStreamException
-
doWriteNamespace
- Throws:
XMLStreamException
-
doWriteDefaultNs
- Throws:
XMLStreamException
-
doWriteStartTag
- Throws:
XMLStreamException
-
doWriteStartTag
- Throws:
XMLStreamException
-
doWriteEndTag
- 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:
XMLStreamException
-
doSetPrefix
- Throws:
XMLStreamException
-
writeDefaultNamespace
- Specified by:
writeDefaultNamespacein interfaceXMLStreamWriter- Specified by:
writeDefaultNamespacein classBaseStreamWriter- Throws:
XMLStreamException
-
writeNamespace
- Specified by:
writeNamespacein interfaceXMLStreamWriter- Specified by:
writeNamespacein classBaseStreamWriter- Throws:
XMLStreamException
-
writeStartElement
Description 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:
XMLStreamException
-
writeStartOrEmpty
- Throws:
XMLStreamException
-
writeStartOrEmpty
protected abstract void writeStartOrEmpty(String prefix, String localName, String nsURI) throws XMLStreamException - Throws:
XMLStreamException
-