/** * This method is assumed to just use default namespace (if any), * and no further checks should be done. */ public void writeStartElement(String localName) throws XMLStreamException { checkStartElement(localName, null); if (mValidator != null) { mValidator.validateElementStart(localName, XmlConsts.ELEM_NO_NS_URI, XmlConsts.ELEM_NO_PREFIX); } mEmptyElement = false; if (mOutputElemPool != null) { SimpleOutputElement newCurr = mOutputElemPool; mOutputElemPool = newCurr.reuseAsChild(mCurrElem, localName); --mPoolSize; mCurrElem = newCurr; } else { mCurrElem = mCurrElem.createChild(localName); } doWriteStartTag(localName); }
/** * 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 checkStartElement(String localName, String prefix) throws XMLStreamException { // Need to finish an open start element? if (mStartElementOpen) { closeStartElement(mEmptyElement); } else if (mState == STATE_PROLOG) { verifyRootElement(localName, prefix); } else if (mState == STATE_EPILOG) { if (mCheckStructure) { String name = (prefix == null || prefix.length() == 0) ? localName : (prefix + ":" + localName); reportNwfStructure(ErrorConsts.WERR_PROLOG_SECOND_ROOT, name); } /* When outputting a fragment, need to reset this to the * tree. No point in trying to verify the root element? */ mState = STATE_TREE; } }
setDefaultNamespace(uri); return; throwOutputError(ErrorConsts.ERR_NS_REDECL_XML, uri); throwOutputError(ErrorConsts.ERR_NS_REDECL_XMLNS, uri); throwOutputError(ErrorConsts.ERR_NS_REDECL_XML_URI, prefix); } else if (uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) { throwOutputError(ErrorConsts.ERR_NS_REDECL_XMLNS_URI, prefix); throwOutputError(ErrorConsts.ERR_NS_EMPTY); doSetPrefix(prefix, uri);
public abstract void writeAttribute(String nsURI, String localName, String value) throws XMLStreamException;
closeStartElement(true); reportNwfStructure("No open start element, when trying to write end element"); reportNwfStructure("Mismatching close element local name, '"+localName+"'; expected '"+expName.getLocalPart()+"'.");
/** * Similar to {@link #writeEndElement}, but never allows implicit * creation of empty elements. */ public void writeFullEndElement() throws XMLStreamException { doWriteEndTag(null, false); }
protected void writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc) throws XMLStreamException { if (!mStartElementOpen) { throwOutputError(ErrorConsts.WERR_ATTR_NO_ELEM); } if (mCheckAttrs) { // still need to ensure no duplicate attrs? mCurrElem.checkAttrWrite(nsURI, localName); } try { if (mValidator == null) { if (prefix == null || prefix.length() == 0) { mWriter.writeTypedAttribute(localName, enc); } else { mWriter.writeTypedAttribute(prefix, localName, enc); } } else { mWriter.writeTypedAttribute (prefix, localName, nsURI, enc, mValidator, getCopyBuffer()); } } catch (IOException ioe) { throw new WstxIOException(ioe); } }
/** *<p> * Note: Root namespace context works best if automatic prefix * creation ("namespace/prefix repairing" in StAX lingo) is enabled. */ public void setNamespaceContext(NamespaceContext ctxt) throws XMLStreamException { // This is only allowed before root element output: if (mState != STATE_PROLOG) { throwOutputError("Called setNamespaceContext() after having already output root element."); } mRootNsContext = ctxt; mCurrElem.setRootNsContext(ctxt); }
@Override public abstract void writeAttribute(String nsURI, String localName, String value) throws XMLStreamException;
closeStartElement(true); reportNwfStructure("No open start element, when trying to write end element"); reportNwfStructure("Mismatching close element local name, '"+localName+"'; expected '"+expName.getLocalPart()+"'.");
/** * Method called by {@link javax.xml.stream.XMLEventWriter} implementation * (instead of the version * that takes no argument), so that we can verify it does match the * start element, if necessary */ public void writeEndElement(QName name) throws XMLStreamException { doWriteEndTag(mCheckStructure ? name : null, mCfgAutomaticEmptyElems); }
protected void writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc) throws XMLStreamException { if (!mStartElementOpen) { throwOutputError(ErrorConsts.WERR_ATTR_NO_ELEM); } if (mCheckAttrs) { // still need to ensure no duplicate attrs? mCurrElem.checkAttrWrite(nsURI, localName); } try { if (mValidator == null) { if (prefix == null || prefix.length() == 0) { mWriter.writeTypedAttribute(localName, enc); } else { mWriter.writeTypedAttribute(prefix, localName, enc); } } else { mWriter.writeTypedAttribute (prefix, localName, nsURI, enc, mValidator, getCopyBuffer()); } } catch (IOException ioe) { throw new WstxIOException(ioe); } }
/** *<p> * Note: Root namespace context works best if automatic prefix * creation ("namespace/prefix repairing" in StAX lingo) is enabled. */ public void setNamespaceContext(NamespaceContext ctxt) throws XMLStreamException { // This is only allowed before root element output: if (mState != STATE_PROLOG) { throwOutputError("Called setNamespaceContext() after having already output root element."); } mRootNsContext = ctxt; mCurrElem.setRootNsContext(ctxt); }
/** * 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 checkStartElement(String localName, String prefix) throws XMLStreamException { // Need to finish an open start element? if (mStartElementOpen) { closeStartElement(mEmptyElement); } else if (mState == STATE_PROLOG) { verifyRootElement(localName, prefix); } else if (mState == STATE_EPILOG) { if (mCheckStructure) { String name = (prefix == null || prefix.length() == 0) ? localName : (prefix + ":" + localName); reportNwfStructure(ErrorConsts.WERR_PROLOG_SECOND_ROOT, name); } /* When outputting a fragment, need to reset this to the * tree. No point in trying to verify the root element? */ mState = STATE_TREE; } }
setDefaultNamespace(uri); return; throwOutputError(ErrorConsts.ERR_NS_REDECL_XML, uri); throwOutputError(ErrorConsts.ERR_NS_REDECL_XMLNS, uri); throwOutputError(ErrorConsts.ERR_NS_REDECL_XML_URI, prefix); } else if (uri.equals(XMLConstants.XMLNS_ATTRIBUTE_NS_URI)) { throwOutputError(ErrorConsts.ERR_NS_REDECL_XMLNS_URI, prefix); throwOutputError(ErrorConsts.ERR_NS_EMPTY); doSetPrefix(prefix, uri);
/** *<p> * Note: It is assumed caller just wants the element to belong to whatever * is the current default namespace. */ public void writeEmptyElement(String localName) throws XMLStreamException { checkStartElement(localName, null); if (mValidator != null) { mValidator.validateElementStart(localName, XmlConsts.ELEM_NO_NS_URI, XmlConsts.ELEM_NO_PREFIX); } mEmptyElement = true; if (mOutputElemPool != null) { SimpleOutputElement newCurr = mOutputElemPool; mOutputElemPool = newCurr.reuseAsChild(mCurrElem, localName); --mPoolSize; mCurrElem = newCurr; } else { mCurrElem = mCurrElem.createChild(localName); } doWriteStartTag(localName); }
@Override public abstract void writeAttribute(String nsURI, String localName, String value) throws XMLStreamException;
closeStartElement(true); reportNwfStructure("No open start element, when trying to write end element"); reportNwfStructure("Mismatching close element local name, '"+localName+"'; expected '"+expName.getLocalPart()+"'.");
public void writeEndElement() throws XMLStreamException { doWriteEndTag(null, mCfgAutomaticEmptyElems); }
@Override protected void writeTypedAttribute(String prefix, String nsURI, String localName, AsciiValueEncoder enc) throws XMLStreamException { if (!mStartElementOpen) { throwOutputError(ErrorConsts.WERR_ATTR_NO_ELEM); } if (mCheckAttrs) { // still need to ensure no duplicate attrs? mCurrElem.checkAttrWrite(nsURI, localName); } try { if (mValidator == null) { if (prefix == null || prefix.length() == 0) { mWriter.writeTypedAttribute(localName, enc); } else { mWriter.writeTypedAttribute(prefix, localName, enc); } } else { mWriter.writeTypedAttribute (prefix, localName, nsURI, enc, mValidator, getCopyBuffer()); } } catch (IOException ioe) { throw new WstxIOException(ioe); } }