com.ctc.wstx.sw
Class BaseNsStreamWriter

java.lang.Object
  extended by org.codehaus.stax2.ri.Stax2WriterImpl
      extended by com.ctc.wstx.sw.BaseStreamWriter
          extended by com.ctc.wstx.sw.TypedStreamWriter
              extended by 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

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
protected static 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  EmptyElementHandler mEmptyElementHandler
           
protected  SimpleOutputElement mOutputElemPool
           
protected  int mPoolSize
           
protected  NamespaceContext mRootNsContext
          Optional "root" namespace context that application can set.
protected static String sPrefixXml
           
protected static String sPrefixXmlns
           
 
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_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
BaseNsStreamWriter(XmlWriter xw, String enc, WriterConfig cfg, boolean repairing)
           
 
Method Summary
protected  void checkStartElement(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  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(String prefix, String uri)
           
protected  void doWriteAttr(String localName, String nsURI, String prefix, char[] buf, int start, int len)
           
protected  void doWriteAttr(String localName, String nsURI, String prefix, String value)
           
protected  void doWriteDefaultNs(String nsURI)
           
protected  void doWriteEndTag(QName expName, boolean allowEmpty)
           
protected  void doWriteNamespace(String prefix, String nsURI)
           
protected  void doWriteStartTag(String localName)
           
protected  void doWriteStartTag(String prefix, String localName)
           
 QName getCurrentElementName()
           
 NamespaceContext getNamespaceContext()
           
 String getNamespaceURI(String prefix)
           
 String getPrefix(String uri)
           
protected  String getTopElementDesc()
          Method needed for error message generation
abstract  void setDefaultNamespace(String uri)
           
 void setNamespaceContext(NamespaceContext ctxt)
           Note: Root namespace context works best if automatic prefix creation ("namespace/prefix repairing" in StAX lingo) is enabled.
 void setPrefix(String prefix, String uri)
           
 void writeAttribute(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  void writeAttribute(String nsURI, String localName, String value)
           
abstract  void writeAttribute(String prefix, String nsURI, String localName, String value)
           
abstract  void writeDefaultNamespace(String nsURI)
           
 void writeEmptyElement(String localName)
           Note: It is assumed caller just wants the element to belong to whatever is the current default namespace.
 void writeEmptyElement(String nsURI, String localName)
           
 void writeEmptyElement(String prefix, String localName, String nsURI)
           
 void writeEndElement()
           
 void writeEndElement(QName name)
          Method called by XMLEventWriter implementation (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(String prefix, String nsURI)
           
abstract  void writeStartElement(StartElement elem)
          Convenience method needed by XMLEventWriter implementation, to use when writing a start element, and possibly its attributes and namespace declarations.
 void writeStartElement(String localName)
          This method is assumed to just use default namespace (if any), and no further checks should be done.
 void writeStartElement(String nsURI, String localName)
           
 void writeStartElement(String prefix, String localName, String nsURI)
           
protected abstract  void writeStartOrEmpty(String localName, String nsURI)
           
protected abstract  void writeStartOrEmpty(String prefix, String localName, String nsURI)
           
protected  void writeTypedAttribute(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 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
 
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
 

Field Detail

sPrefixXml

protected static final String sPrefixXml

sPrefixXmlns

protected static final String sPrefixXmlns

ERR_NSDECL_WRONG_STATE

protected static final 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 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,
                          String enc,
                          WriterConfig cfg,
                          boolean repairing)
Method Detail

getNamespaceContext

public NamespaceContext getNamespaceContext()
Specified by:
getNamespaceContext in interface XMLStreamWriter
Specified by:
getNamespaceContext in class BaseStreamWriter

getPrefix

public String getPrefix(String uri)
Specified by:
getPrefix in interface XMLStreamWriter
Specified by:
getPrefix in class BaseStreamWriter

setDefaultNamespace

public abstract void setDefaultNamespace(String uri)
                                  throws XMLStreamException
Specified by:
setDefaultNamespace in interface XMLStreamWriter
Specified by:
setDefaultNamespace in class BaseStreamWriter
Throws:
XMLStreamException

setNamespaceContext

public void setNamespaceContext(NamespaceContext ctxt)
                         throws XMLStreamException

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

Specified by:
setNamespaceContext in interface XMLStreamWriter
Specified by:
setNamespaceContext in class BaseStreamWriter
Throws:
XMLStreamException

setPrefix

public void setPrefix(String prefix,
                      String uri)
               throws XMLStreamException
Specified by:
setPrefix in interface XMLStreamWriter
Specified by:
setPrefix in class BaseStreamWriter
Throws:
XMLStreamException

writeAttribute

public void writeAttribute(String localName,
                           String value)
                    throws 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 XMLStreamWriter
Specified by:
writeAttribute in class BaseStreamWriter
Throws:
XMLStreamException

writeAttribute

public abstract void writeAttribute(String nsURI,
                                    String localName,
                                    String value)
                             throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Specified by:
writeAttribute in class BaseStreamWriter
Throws:
XMLStreamException

writeAttribute

public abstract void writeAttribute(String prefix,
                                    String nsURI,
                                    String localName,
                                    String value)
                             throws XMLStreamException
Specified by:
writeAttribute in interface XMLStreamWriter
Specified by:
writeAttribute in class BaseStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String localName)
                       throws XMLStreamException

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

Specified by:
writeEmptyElement in interface XMLStreamWriter
Specified by:
writeEmptyElement in class BaseStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String nsURI,
                              String localName)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Specified by:
writeEmptyElement in class BaseStreamWriter
Throws:
XMLStreamException

writeEmptyElement

public void writeEmptyElement(String prefix,
                              String localName,
                              String nsURI)
                       throws XMLStreamException
Specified by:
writeEmptyElement in interface XMLStreamWriter
Specified by:
writeEmptyElement in class BaseStreamWriter
Throws:
XMLStreamException

writeEndElement

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

writeStartElement

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

Specified by:
writeStartElement in interface XMLStreamWriter
Specified by:
writeStartElement in class BaseStreamWriter
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(String nsURI,
                              String localName)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Specified by:
writeStartElement in class BaseStreamWriter
Throws:
XMLStreamException

writeStartElement

public void writeStartElement(String prefix,
                              String localName,
                              String nsURI)
                       throws XMLStreamException
Specified by:
writeStartElement in interface XMLStreamWriter
Specified by:
writeStartElement in class BaseStreamWriter
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: TypedStreamWriter
Method that will write attribute with value that is known not to require additional escaping.

Specified by:
writeTypedAttribute in class TypedStreamWriter
Throws:
XMLStreamException

writeFullEndElement

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

Specified by:
writeFullEndElement in interface org.codehaus.stax2.XMLStreamWriter2
Specified by:
writeFullEndElement in class BaseStreamWriter
Throws:
XMLStreamException

getCurrentElementName

public QName getCurrentElementName()
Specified by:
getCurrentElementName in interface org.codehaus.stax2.validation.ValidationContext
Specified by:
getCurrentElementName in class BaseStreamWriter

getNamespaceURI

public String getNamespaceURI(String prefix)
Specified by:
getNamespaceURI in interface org.codehaus.stax2.validation.ValidationContext
Specified by:
getNamespaceURI in class BaseStreamWriter

writeEndElement

public void writeEndElement(QName name)
                     throws XMLStreamException
Method called by XMLEventWriter implementation (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:
XMLStreamException

closeStartElement

protected void closeStartElement(boolean emptyElem)
                          throws 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:
XMLStreamException

getTopElementDesc

protected String getTopElementDesc()
Description copied from class: BaseStreamWriter
Method needed for error message generation

Specified by:
getTopElementDesc in class BaseStreamWriter

checkStartElement

protected void checkStartElement(String localName,
                                 String prefix)
                          throws 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:
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

protected void doWriteNamespace(String prefix,
                                String nsURI)
                         throws XMLStreamException
Throws:
XMLStreamException

doWriteDefaultNs

protected void doWriteDefaultNs(String nsURI)
                         throws XMLStreamException
Throws:
XMLStreamException

doWriteStartTag

protected final void doWriteStartTag(String localName)
                              throws XMLStreamException
Throws:
XMLStreamException

doWriteStartTag

protected final void doWriteStartTag(String prefix,
                                     String localName)
                              throws XMLStreamException
Throws:
XMLStreamException

doWriteEndTag

protected void doWriteEndTag(QName expName,
                             boolean allowEmpty)
                      throws 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:
XMLStreamException

doSetPrefix

public abstract void doSetPrefix(String prefix,
                                 String uri)
                          throws XMLStreamException
Throws:
XMLStreamException

writeDefaultNamespace

public abstract void writeDefaultNamespace(String nsURI)
                                    throws XMLStreamException
Specified by:
writeDefaultNamespace in interface XMLStreamWriter
Specified by:
writeDefaultNamespace in class BaseStreamWriter
Throws:
XMLStreamException

writeNamespace

public abstract void writeNamespace(String prefix,
                                    String nsURI)
                             throws XMLStreamException
Specified by:
writeNamespace in interface XMLStreamWriter
Specified by:
writeNamespace in class BaseStreamWriter
Throws:
XMLStreamException

writeStartElement

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

Specified by:
writeStartElement in class BaseStreamWriter
Throws:
XMLStreamException

writeStartOrEmpty

protected abstract void writeStartOrEmpty(String localName,
                                          String nsURI)
                                   throws XMLStreamException
Throws:
XMLStreamException

writeStartOrEmpty

protected abstract void writeStartOrEmpty(String prefix,
                                          String localName,
                                          String nsURI)
                                   throws XMLStreamException
Throws:
XMLStreamException


Copyright © 2011 Codehaus. All Rights Reserved.