X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FAbstractAttributeExtensibleXMLObject.cpp;h=44b07bcdfaccf41126342b2678cffaf7674c5066;hb=ce200eaef5c771e132b64437d78540bfd4683572;hp=47b8223ccc1311c0730004dbd67570e1225f98e2;hpb=931fecc63df965ccbce776827794ff03cf490cb0;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp index 47b8223..44b07bc 100644 --- a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp @@ -1,5 +1,5 @@ /* - * Copyright 2001-2006 Internet2 + * Copyright 2001-2010 Internet2 * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,19 +22,74 @@ #include "internal.h" #include "AbstractAttributeExtensibleXMLObject.h" +#include "ElementExtensibleXMLObject.h" +#include "ElementProxy.h" #include #include using namespace xmltooling; using namespace std; +using xercesc::chColon; + +using xercesc::DOMAttr; +using xercesc::DOMElement; +using xercesc::XMLString; + +ElementExtensibleXMLObject::ElementExtensibleXMLObject() +{ +} + +ElementExtensibleXMLObject::~ElementExtensibleXMLObject() +{ +} + +ElementProxy::ElementProxy() +{ +} + +ElementProxy::~ElementProxy() +{ +} set AttributeExtensibleXMLObject::m_idAttributeSet; -AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject() +AttributeExtensibleXMLObject::AttributeExtensibleXMLObject() { - for (map::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) - XMLString::release(&(i->second)); +} + +AttributeExtensibleXMLObject::~AttributeExtensibleXMLObject() +{ +} + +const set& AttributeExtensibleXMLObject::getRegisteredIDAttributes() +{ + return m_idAttributeSet; +} + +bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const QName& name) +{ + return m_idAttributeSet.find(name)!=m_idAttributeSet.end(); +} + +void AttributeExtensibleXMLObject::registerIDAttribute(const QName& name) +{ + m_idAttributeSet.insert(name); +} + +void AttributeExtensibleXMLObject::deregisterIDAttribute(const QName& name) +{ + m_idAttributeSet.erase(name); +} + +void AttributeExtensibleXMLObject::deregisterIDAttributes() +{ + m_idAttributeSet.clear(); +} + +AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject() +{ + m_idAttribute = m_attributeMap.end(); } AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject& src) @@ -49,41 +104,84 @@ AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const } } +AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject() +{ + for (map::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) + XMLString::release(&(i->second)); +} + +const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const QName& qualifiedName) const +{ + map::const_iterator i=m_attributeMap.find(qualifiedName); + return (i==m_attributeMap.end()) ? NULL : i->second; +} + void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID) { map::iterator i=m_attributeMap.find(qualifiedName); if (i!=m_attributeMap.end()) { releaseThisandParentDOM(); XMLString::release(&(i->second)); - if (value) { + if (value && *value) { i->second=XMLString::replicate(value); + if (ID) + m_idAttribute=i; } else { if (m_idAttribute==i) m_idAttribute=m_attributeMap.end(); m_attributeMap.erase(i); } - - if (ID) { - m_idAttribute=i; - } } - else if (value) { + else if (value && *value) { releaseThisandParentDOM(); m_attributeMap[qualifiedName]=XMLString::replicate(value); - if (ID) { + if (ID) m_idAttribute = m_attributeMap.find(qualifiedName); - } + Namespace newNamespace(qualifiedName.getNamespaceURI(), qualifiedName.getPrefix()); + addNamespace(newNamespace); } } +void AttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const QName& value) +{ + if (!value.hasLocalPart()) + return; + + if (value.hasPrefix()) { + xstring buf(value.getPrefix()); + buf = buf + chColon + value.getLocalPart(); + setAttribute(qualifiedName, buf.c_str()); + } + else { + setAttribute(qualifiedName, value.getLocalPart()); + } + + // Attach a non-visibly used namespace. + Namespace newNamespace(value.getNamespaceURI(), value.getPrefix(), false, false); + addNamespace(newNamespace); +} + +const map& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const +{ + return m_attributeMap; +} +const XMLCh* AbstractAttributeExtensibleXMLObject::getXMLID() const +{ + return (m_idAttribute == m_attributeMap.end()) ? NULL : m_idAttribute->second; +} + void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute) { QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); bool ID = attribute->isId() || isRegisteredIDAttribute(q); setAttribute(q,attribute->getNodeValue(),ID); if (ID) { +#ifdef XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE + attribute->getOwnerElement()->setIdAttributeNode(attribute, true); +#else attribute->getOwnerElement()->setIdAttributeNode(attribute); +#endif } } @@ -95,7 +193,12 @@ void AbstractAttributeExtensibleXMLObject::marshallExtensionAttributes(DOMElemen attr->setPrefix(i->first.getPrefix()); attr->setNodeValue(i->second); domElement->setAttributeNodeNS(attr); - if (m_idAttribute==i) + if (m_idAttribute==i) { +#ifdef XMLTOOLING_XERCESC_BOOLSETIDATTRIBUTE + domElement->setIdAttributeNode(attr, true); +#else domElement->setIdAttributeNode(attr); +#endif + } } }