public static SimpleOutputElement createRoot() { return new SimpleOutputElement(); }
int status = elem.isPrefixValid(suggPrefix, nsURI, false); if (status == SimpleOutputElement.PREFIX_OK) { return suggPrefix; elem.addPrefix(suggPrefix, nsURI); doWriteNamespace(suggPrefix, nsURI); return suggPrefix; String prefix = elem.getExplicitPrefix(nsURI); if (prefix != null) { // already had a mapping for the URI... cool. return prefix; || (elem.getNamespaceURI(prefix) != null)) { prefix = null; mAutoNsSeq[0] = 1; prefix = mCurrElem.generateMapping(mAutomaticNsPrefix, nsURI, mAutoNsSeq); elem.addPrefix(prefix, nsURI); doWriteNamespace(prefix, nsURI); return prefix;
mCurrElem = curr.getParent(); if (mCurrElem.isRoot()) { // Did we close the root? (isRoot() returns true for the virtual "document node") mState = STATE_EPILOG; (curr.getLocalName(), curr.getNamespaceURI(), curr.getPrefix()); curr.addToPool(mOutputElemPool); mOutputElemPool = curr; ++mPoolSize;
/** * Method called to find an existing prefix for the given namespace, * if any exists in the scope. If one is found, it's returned (including * "" for the current default namespace); if not, null is returned. * * @param nsURI URI of namespace for which we need a prefix */ protected final String findElemPrefix(String nsURI, SimpleOutputElement elem) throws XMLStreamException { /* Special case: empty NS URI can only be bound to the empty * prefix... */ if (nsURI == null || nsURI.length() == 0) { String currDefNsURI = elem.getDefaultNsUri(); if (currDefNsURI != null && currDefNsURI.length() > 0) { // Nope; won't do... has to be re-bound, but not here: return null; } return ""; } return mCurrElem.getPrefix(nsURI); }
String currURL = elem.getDefaultNsUri(); if (currURL == null || currURL.length() == 0) { int status = elem.isPrefixValid(prefix, nsURI, true); if (status == SimpleOutputElement.PREFIX_OK) { return prefix;
protected void writeStartOrEmpty(String localName, String nsURI) throws XMLStreamException { // Need a prefix... String prefix = mCurrElem.getPrefix(nsURI); if (prefix == null) { throw new XMLStreamException("Unbound namespace URI '"+nsURI+"'"); } checkStartElement(localName, prefix); if (mValidator != null) { mValidator.validateElementStart(localName, nsURI, prefix); } if (mOutputElemPool != null) { SimpleOutputElement newCurr = mOutputElemPool; mOutputElemPool = newCurr.reuseAsChild(mCurrElem, prefix, localName, nsURI); --mPoolSize; mCurrElem = newCurr; } else { mCurrElem = mCurrElem.createChild(prefix, localName, nsURI); } doWriteStartTag(prefix, localName); }
mOutputElemPool = newCurr.reuseAsChild(mCurrElem, actPrefix, localName, nsURI); --mPoolSize; mCurrElem = newCurr; } else { mCurrElem = mCurrElem.createChild(actPrefix, localName, nsURI); mOutputElemPool = newCurr.reuseAsChild(mCurrElem, actPrefix, localName, nsURI); --mPoolSize; mCurrElem = newCurr; } else { mCurrElem = mCurrElem.createChild(actPrefix, localName, nsURI); mCurrElem.setPrefix(actPrefix); doWriteStartTag(actPrefix, localName); if (actPrefix == null || actPrefix.length() == 0) { // def NS mCurrElem.setDefaultNsUri(nsURI); doWriteDefaultNs(nsURI); } else { // explicit NS mCurrElem.addPrefix(actPrefix, nsURI); doWriteNamespace(actPrefix, nsURI);
protected void writeStartOrEmpty(String prefix, String localName, String nsURI) throws XMLStreamException { checkStartElement(localName, prefix); if (mValidator != null) { mValidator.validateElementStart(localName, nsURI, prefix); } if (mOutputElemPool != null) { SimpleOutputElement newCurr = mOutputElemPool; mOutputElemPool = newCurr.reuseAsChild(mCurrElem, prefix, localName, nsURI); --mPoolSize; mCurrElem = newCurr; } else { mCurrElem = mCurrElem.createChild(prefix, localName, nsURI); } doWriteStartTag(prefix, localName); }
protected final void doWriteAttr(String localName, String nsURI, String prefix, char[] buf, int start, int len) throws XMLStreamException { if (mCheckAttrs) { // still need to ensure no duplicate attrs? mCurrElem.checkAttrWrite(nsURI, localName); } if (mValidator != null) { /* No need to get it normalized... even if validator does normalize * it, we don't use that for anything */ mValidator.validateAttribute(localName, nsURI, prefix, buf, start, len); } try { if (prefix != null && prefix.length() > 0) { mWriter.writeAttribute(prefix, localName, buf, start, len); } else { mWriter.writeAttribute(localName, buf, start, len); } } catch (IOException ioe) { throw new WstxIOException(ioe); } }
public void doSetPrefix(String prefix, String uri) throws XMLStreamException { mCurrElem.addPrefix(prefix, uri); }
public void writeAttribute(String nsURI, String localName, String value) throws XMLStreamException { // No need to set mAnyOutput, nor close the element if (!mStartElementOpen) { throwOutputError(ErrorConsts.WERR_ATTR_NO_ELEM); } String prefix = mCurrElem.getExplicitPrefix(nsURI); if (!mReturnNullForDefaultNamespace && prefix == null) { throwOutputError("Unbound namespace URI '" + nsURI + "'"); } doWriteAttr(localName, nsURI, prefix, value); }
public void writeNamespace(String prefix, String nsURI) throws XMLStreamException { /* (see discussion in 'writeDefaultNamespace()' for details on * if and how this method may get called in repairing mode) */ if (prefix == null || prefix.length() == 0) { writeDefaultNamespace(nsURI); return; } if (!mStartElementOpen) { throwOutputError(ERR_NSDECL_WRONG_STATE); } /* 01-Sep-2006, TSa: Let's only add the declaration if the prefix * is as of yet unbound. If we have to re-bind things in future, * so be it -- for now, this should suffice (and if we have to * add re-binding, must verify that no attribute, nor element * itself, is using overridden prefix) */ int value = mCurrElem.isPrefixValid(prefix, nsURI, true); if (value == SimpleOutputElement.PREFIX_UNBOUND) { mCurrElem.addPrefix(prefix, nsURI); doWriteNamespace(prefix, nsURI); } }
mAutoNsSeq[0] = 1; suggPrefix = elem.generateMapping(mAutomaticNsPrefix, nsURI, mAutoNsSeq);
protected SimpleOutputElement mCurrElem = SimpleOutputElement.createRoot();
mOutputElemPool = newCurr.reuseAsChild(mCurrElem, prefix, localName, nsURI); --mPoolSize; mCurrElem = newCurr; } else { mCurrElem = mCurrElem.createChild(prefix, localName, nsURI); mValidator.validateElementStart(localName, nsURI, prefix); mCurrElem.setPrefix(prefix); doWriteStartTag(prefix, localName); if (prefix == null || prefix.length() == 0) { // def NS mCurrElem.setDefaultNsUri(nsURI); doWriteDefaultNs(nsURI); } else { // explicit NS mCurrElem.addPrefix(prefix, nsURI); doWriteNamespace(prefix, nsURI);
/** * 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 called to find an existing prefix for the given namespace, * if any exists in the scope. If one is found, it's returned (including * "" for the current default namespace); if not, null is returned. * * @param nsURI URI of namespace for which we need a prefix */ protected final String findElemPrefix(String nsURI, SimpleOutputElement elem) throws XMLStreamException { /* Special case: empty NS URI can only be bound to the empty * prefix... */ if (nsURI == null || nsURI.length() == 0) { String currDefNsURI = elem.getDefaultNsUri(); if (currDefNsURI != null && currDefNsURI.length() > 0) { // Nope; won't do... has to be re-bound, but not here: return null; } return ""; } return mCurrElem.getPrefix(nsURI); }
String currURL = elem.getDefaultNsUri(); if (currURL == null || currURL.length() == 0) { int status = elem.isPrefixValid(prefix, nsURI, true); if (status == SimpleOutputElement.PREFIX_OK) { return prefix;
mCurrElem.checkAttrWrite(nsURI, localName);
public void doSetPrefix(String prefix, String uri) throws XMLStreamException { mCurrElem.addPrefix(prefix, uri); }