void AbstractXMLObject::addNamespace(const Namespace& ns) const
{
- std::set<Namespace>::iterator i = m_namespaces.find(ns);
- if (i == m_namespaces.end())
- m_namespaces.insert(ns);
- else {
- if (ns.alwaysDeclare())
- const_cast<Namespace&>(*i).setAlwaysDeclare(true);
- switch (ns.usage()) {
- case Namespace::Indeterminate:
- break;
- case Namespace::VisiblyUsed:
- const_cast<Namespace&>(*i).setUsage(Namespace::VisiblyUsed);
- break;
- case Namespace::NonVisiblyUsed:
- if (i->usage() == Namespace::Indeterminate)
- const_cast<Namespace&>(*i).setUsage(Namespace::NonVisiblyUsed);
- break;
+ for (set<Namespace>::const_iterator n = m_namespaces.begin(); n != m_namespaces.end(); ++n) {
+ // Look for the prefix in the existing set.
+ if (XMLString::equals(ns.getNamespacePrefix(), n->getNamespacePrefix())) {
+ // See if it's the same declaration, and overlay various properties if so.
+ if (XMLString::equals(ns.getNamespaceURI(), n->getNamespaceURI())) {
+ if (ns.alwaysDeclare())
+ const_cast<Namespace&>(*n).setAlwaysDeclare(true);
+ switch (ns.usage()) {
+ case Namespace::Indeterminate:
+ break;
+ case Namespace::VisiblyUsed:
+ const_cast<Namespace&>(*n).setUsage(Namespace::VisiblyUsed);
+ break;
+ case Namespace::NonVisiblyUsed:
+ if (n->usage() == Namespace::Indeterminate)
+ const_cast<Namespace&>(*n).setUsage(Namespace::NonVisiblyUsed);
+ break;
+ }
+ }
+ return;
}
}
+
+ // If the prefix is now, go ahead and add it.
+ m_namespaces.insert(ns);
}
void AbstractXMLObject::removeNamespace(const Namespace& ns)
}
// If we get here, we didn't have a usable DOM (and/or we released the one we had).
+ prepareForMarshalling();
+
// We may need to create our own document.
bool bindDocument=false;
if (!document) {
}
// If we get here, we didn't have a usable DOM (and/or we released the one we had).
+ prepareForMarshalling();
+
m_log.debug("creating root element to marshall");
DOMElement* domElement = parentElement->getOwnerDocument()->createElementNS(
getElementQName().getNamespaceURI(), getElementQName().getLocalPart()
void AbstractXMLObjectMarshaller::marshallAttributes(DOMElement* domElement) const
{
}
+
+void AbstractXMLObjectMarshaller::prepareForMarshalling() const
+{
+}
* @throws MarshallingException thrown if there is a problem marshalling an attribute
*/
virtual void marshallAttributes(xercesc::DOMElement* domElement) const;
+
+ /**
+ * Called before marshalling in the event that a new DOM is being generated.
+ * <p>Allows objects to adjust internal state prior to the marshalling step.
+ */
+ virtual void prepareForMarshalling() const;
};
};
return nullptr;
}
-void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, set<xstring>& prefixes)
+void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& prefixes)
{
- set<xstring> child_prefixes;
+ map<xstring,xstring> child_prefixes;
const list<XMLObject*>& children = tree.getOrderedChildren();
for (list<XMLObject*>::const_iterator i = children.begin(); i != children.end(); ++i) {
if (*i)
case Namespace::Indeterminate:
break;
case Namespace::VisiblyUsed:
- child_prefixes.erase(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+ {
+ // See if the prefix was noted as non-visible below.
+ const XMLCh* p = ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull;
+ map<xstring,xstring>::iterator decl = child_prefixes.find(p);
+ if (decl != child_prefixes.end()) {
+ // It's declared below, see if it's the same namespace. If so, pull it from the set,
+ // otherwise leave it in the set.
+ if (decl->second == (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull))
+ child_prefixes.erase(decl);
+ }
break;
+ }
case Namespace::NonVisiblyUsed:
- prefixes.insert(ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull);
+ // It may already be in the map from another branch of the tree, but as long
+ // as it's set to something so the parent knows about it, we're good.
+ prefixes[ns->getNamespacePrefix() ? ns->getNamespacePrefix() : &chNull] = (ns->getNamespaceURI() ? ns->getNamespaceURI() : &chNull);
break;
}
}
+
prefixes.insert(child_prefixes.begin(), child_prefixes.end());
}
static XMLObject* getXMLObjectById(XMLObject& tree, const XMLCh* id);
/**
- * Returns a list of non-visibly-used namespace prefixes found in a tree.
+ * Returns the set of non-visibly-used namespace declarations found in a tree.
+ * <p>Each member of the set is a prefix/URI pair.
*
* @param tree root of tree to search
- * @param prefixes container to store prefix list
+ * @param prefixes container to store declarations
*/
- static void getNonVisiblyUsedPrefixes(const XMLObject& tree, std::set<xstring>& prefixes);
+ static void getNonVisiblyUsedPrefixes(const XMLObject& tree, std::map<xstring,xstring>& prefixes);
/**
* Gets the QName for the given DOM node.