com.ctc.wstx.sw
Class BaseNsStreamWriter

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

public abstract class BaseNsStreamWriter
extends BaseStreamWriter

Mid-level base class of namespace-aware stream writers. Contains shared functionality between repairing and non-repairing implementations.


Field Summary
protected static java.lang.String ERR_NSDECL_WRONG_STATE
           
protected  boolean mAutomaticNS
          True, if writer needs to automatically output namespace declarations (we are in repairing mode)
protected  SimpleOutputElement mCurrElem
           
protected  SimpleOutputElement mOutputElemPool
           
protected  int mPoolSize
           
protected  javax.xml.namespace.NamespaceContext mRootNsContext
          Optional "root" namespace context that application can set.
protected static java.lang.String sPrefixXml
           
protected static java.lang.String sPrefixXmlns
           
 
Fields inherited from class com.ctc.wstx.sw.BaseStreamWriter
ATTR_MIN_ARRAYCOPY, CHAR_SPACE, DEFAULT_COPYBUFFER_LEN, mAnyOutput, mAttrCollector, mCfgAutomaticEmptyElems, mCfgCDataAsText, mCfgCopyDefaultAttrs, mCheckAttrs, mCheckStructure, mConfig, mCopyBuffer, mDtdRootElem, mEmptyElement, mEncoding, MIN_ARRAYCOPY, mInputElemStack, mLastReader, mLastReaderImpl, mStartElementOpen, mState, mValidator, mVldContent, mVldProbHandler, mWriter, mXml11, NO_NS_URI, NO_PREFIX, STATE_EPILOG, STATE_PROLOG, STATE_TREE
 
Fields inherited from interface javax.xml.stream.XMLStreamConstants
ATTRIBUTE, CDATA, CHARACTERS, COMMENT, DTD, END_DOCUMENT, END_ELEMENT, ENTITY_DECLARATION, ENTITY_REFERENCE, NAMESPACE, NOTATION_DECLARATION, PROCESSING_INSTRUCTION, SPACE, START_DOCUMENT, START_ELEMENT
 
Fields inherited from interface com.ctc.wstx.cfg.OutputConfigFlags
CFG_AUTOMATIC_EMPTY_ELEMS, CFG_AUTOMATIC_NS, CFG_COPY_DEFAULT_ATTRS, CFG_ENABLE_NS, CFG_ESCAPE_CR, CFG_FIX_CONTENT, CFG_OUTPUT_CDATA_AS_TEXT, CFG_VALIDATE_ATTR, CFG_VALIDATE_CONTENT, CFG_VALIDATE_NAMES, CFG_VALIDATE_STRUCTURE
 
Constructor Summary
BaseNsStreamWriter(XmlWriter xw, java.lang.String enc, WriterConfig cfg, boolean repairing)
           
 
Method Summary
protected  void checkStartElement(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  void closeStartElement(boolean emptyElem)
          Method called to close an open start element, when another main-level element (not namespace declaration or attribute) is being output; except for end element which is handled differently.
abstract  void doSetPrefix(java.lang.String prefix, java.lang.String uri)
           
protected  void doWriteAttr(java.lang.String localName, java.lang.String nsURI, java.lang.String prefix, java.lang.String value)
           
protected  void doWriteDefaultNs(java.lang.String nsURI)
           
protected  void doWriteEndTag(javax.xml.namespace.QName expName, boolean allowEmpty)
           
protected  void doWriteNamespace(java.lang.String prefix, java.lang.String nsURI)
           
protected  void doWriteStartTag(java.lang.String localName)
           
protected  void doWriteStartTag(java.lang.String prefix, java.lang.String localName)
           
 javax.xml.namespace.QName getCurrentElementName()
          Method that can be used to access name information of the innermost (top) element in the element stack.
 javax.xml.namespace.NamespaceContext getNamespaceContext()
           
 java.lang.String getNamespaceURI(java.lang.String prefix)
          Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element.
 java.lang.String getPrefix(java.lang.String uri)
           
protected  java.lang.String getTopElementDesc()
           
abstract  void setDefaultNamespace(java.lang.String uri)
           
 void setNamespaceContext(javax.xml.namespace.NamespaceContext ctxt)
           Note: Root namespace context works best if automatic prefix creation ("namespace/prefix repairing" in StAX lingo) is enabled.
 void setPrefix(java.lang.String prefix, java.lang.String uri)
           
 void writeAttribute(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  void writeAttribute(java.lang.String nsURI, java.lang.String localName, java.lang.String value)
           
abstract  void writeAttribute(java.lang.String prefix, java.lang.String nsURI, java.lang.String localName, java.lang.String value)
           
abstract  void writeDefaultNamespace(java.lang.String nsURI)
           
 void writeEmptyElement(java.lang.String localName)
           Note: It is assumed caller just wants the element to belong to whatever is the current default namespace.
 void writeEmptyElement(java.lang.String nsURI, java.lang.String localName)
           
 void writeEmptyElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)
           
 void writeEndElement()
           
 void writeEndElement(javax.xml.namespace.QName name)
          Method called by WstxEventWriter (instead of the version that takes no argument), so that we can verify it does match the start element, if necessary
 void writeFullEndElement()
          Similar to writeEndElement(), but never allows implicit creation of empty elements.
abstract  void writeNamespace(java.lang.String prefix, java.lang.String nsURI)
           
abstract  void writeStartElement(javax.xml.stream.events.StartElement elem)
          Convenience method needed by WstxEventWriter, to use when writing a start element, and possibly its attributes and namespace declarations.
 void writeStartElement(java.lang.String localName)
          This method is assumed to just use default namespace (if any), and no further checks should be done.
 void writeStartElement(java.lang.String nsURI, java.lang.String localName)
           
 void writeStartElement(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)
           
protected abstract  void writeStartOrEmpty(java.lang.String localName, java.lang.String nsURI)
           
protected abstract  void writeStartOrEmpty(java.lang.String prefix, java.lang.String localName, java.lang.String nsURI)
           
 
Methods inherited from class com.ctc.wstx.sw.BaseStreamWriter
addDefaultAttribute, close, copyEventFromReader, copyStartElement, doReportProblem, doWriteStartDocument, findAttributeIndex, flush, getAttributeCount, getAttributeLocalName, getAttributeNamespace, getAttributePrefix, getAttributeValue, getAttributeValue, getBaseUri, 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, verifyRootElement, verifyWriteCData, verifyWriteDTD, wrapAsRawWriter, wrapAsTextWriter, writeCData, writeCData, writeCharacters, writeCharacters, writeCharacters, writeComment, writeDTD, writeDTD, writeDTD, writeEndDocument, writeEntityRef, writeProcessingInstruction, writeProcessingInstruction, writeRaw, writeRaw, writeRaw, writeStartDocument, writeStartDocument, writeStartDocument, writeStartDocument
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

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)


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

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:
getNamespaceContext in interface javax.xml.stream.XMLStreamWriter
Specified by:
getNamespaceContext in class BaseStreamWriter

getPrefix

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

setDefaultNamespace

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

setNamespaceContext

public void setNamespaceContext(javax.xml.namespace.NamespaceContext ctxt)
                         throws javax.xml.stream.XMLStreamException

Note: Root namespace context works best if automatic prefix creation ("namespace/prefix repairing" in StAX lingo) is enabled.

Specified by:
setNamespaceContext in interface javax.xml.stream.XMLStreamWriter
Specified by:
setNamespaceContext in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

setPrefix

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

writeAttribute

public void writeAttribute(java.lang.String localName,
                           java.lang.String value)
                    throws javax.xml.stream.XMLStreamException
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:
writeAttribute in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeAttribute in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeAttribute

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

writeAttribute

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

writeEmptyElement

public void writeEmptyElement(java.lang.String localName)
                       throws javax.xml.stream.XMLStreamException

Note: It is assumed caller just wants the element to belong to whatever is the current default namespace.

Specified by:
writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeEmptyElement in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEmptyElement

public void writeEmptyElement(java.lang.String nsURI,
                              java.lang.String localName)
                       throws javax.xml.stream.XMLStreamException
Specified by:
writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeEmptyElement in class BaseStreamWriter
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:
writeEmptyElement in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeEmptyElement in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeEndElement

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

writeStartElement

public void writeStartElement(java.lang.String localName)
                       throws javax.xml.stream.XMLStreamException
This method is assumed to just use default namespace (if any), and no further checks should be done.

Specified by:
writeStartElement in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeStartElement in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeStartElement

public void writeStartElement(java.lang.String nsURI,
                              java.lang.String localName)
                       throws javax.xml.stream.XMLStreamException
Specified by:
writeStartElement in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeStartElement in class BaseStreamWriter
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:
writeStartElement in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeStartElement in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeFullEndElement

public void writeFullEndElement()
                         throws javax.xml.stream.XMLStreamException
Similar to writeEndElement(), but never allows implicit creation of empty elements.

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

getCurrentElementName

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

Specified by:
getCurrentElementName in interface ValidationContext
Specified by:
getCurrentElementName in class BaseStreamWriter
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 java.lang.String getNamespaceURI(java.lang.String prefix)
Description copied from interface: ValidationContext
Method that can be called by the validator to resolve a namespace prefix of the currently active top-level element. This may be necessary for things like DTD validators (which may need to heuristically guess proper namespace URI of attributes, esp. ones with default values).

Specified by:
getNamespaceURI in interface ValidationContext
Specified by:
getNamespaceURI in class BaseStreamWriter

writeEndElement

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

Specified by:
writeEndElement in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

closeStartElement

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

Specified by:
closeStartElement in class BaseStreamWriter
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()
Specified by:
getTopElementDesc in class BaseStreamWriter

checkStartElement

protected void checkStartElement(java.lang.String localName,
                                 java.lang.String prefix)
                          throws javax.xml.stream.XMLStreamException
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:
javax.xml.stream.XMLStreamException

doWriteAttr

protected 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

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 used
allowEmpty - 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:
writeDefaultNamespace in interface javax.xml.stream.XMLStreamWriter
Specified by:
writeDefaultNamespace in class BaseStreamWriter
Throws:
javax.xml.stream.XMLStreamException

writeNamespace

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

writeStartElement

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

Specified by:
writeStartElement in class BaseStreamWriter
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