X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FAbstractAttributeExtensibleXMLObject.cpp;h=166e96c696a50c7b1773fb321cba160892577387;hb=d1c1478d26cfd9b87a4deb80c3638dc42e111735;hp=44b07bcdfaccf41126342b2678cffaf7674c5066;hpb=ce200eaef5c771e132b64437d78540bfd4683572;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp index 44b07bc..166e96c 100644 --- a/xmltooling/AbstractAttributeExtensibleXMLObject.cpp +++ b/xmltooling/AbstractAttributeExtensibleXMLObject.cpp @@ -1,17 +1,21 @@ -/* - * 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. - * You may obtain a copy of the License at +/** + * Licensed to the University Corporation for Advanced Internet + * Development, Inc. (UCAID) under one or more contributor license + * agreements. See the NOTICE file distributed with this work for + * additional information regarding copyright ownership. + * + * UCAID licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. You may obtain a copy of the + * License at * - * http://www.apache.org/licenses/LICENSE-2.0 + * http://www.apache.org/licenses/LICENSE-2.0 * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific + * language governing permissions and limitations under the License. */ /** @@ -27,14 +31,16 @@ #include #include +#include +#include +#include using namespace xmltooling; +using namespace xercesc; +using namespace boost::lambda; +using namespace boost; using namespace std; -using xercesc::chColon; -using xercesc::DOMAttr; -using xercesc::DOMElement; -using xercesc::XMLString; ElementExtensibleXMLObject::ElementExtensibleXMLObject() { @@ -52,7 +58,7 @@ ElementProxy::~ElementProxy() { } -set AttributeExtensibleXMLObject::m_idAttributeSet; +set AttributeExtensibleXMLObject::m_idAttributeSet; AttributeExtensibleXMLObject::AttributeExtensibleXMLObject() { @@ -62,22 +68,22 @@ AttributeExtensibleXMLObject::~AttributeExtensibleXMLObject() { } -const set& AttributeExtensibleXMLObject::getRegisteredIDAttributes() +const set& AttributeExtensibleXMLObject::getRegisteredIDAttributes() { return m_idAttributeSet; } -bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const QName& name) +bool AttributeExtensibleXMLObject::isRegisteredIDAttribute(const xmltooling::QName& name) { return m_idAttributeSet.find(name)!=m_idAttributeSet.end(); } -void AttributeExtensibleXMLObject::registerIDAttribute(const QName& name) +void AttributeExtensibleXMLObject::registerIDAttribute(const xmltooling::QName& name) { m_idAttributeSet.insert(name); } -void AttributeExtensibleXMLObject::deregisterIDAttribute(const QName& name) +void AttributeExtensibleXMLObject::deregisterIDAttribute(const xmltooling::QName& name) { m_idAttributeSet.erase(name); } @@ -96,7 +102,7 @@ AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const : AbstractXMLObject(src) { m_idAttribute = m_attributeMap.end(); - for (map::const_iterator i=src.m_attributeMap.begin(); i!=src.m_attributeMap.end(); i++) { + for (map::const_iterator i = src.m_attributeMap.begin(); i != src.m_attributeMap.end(); ++i) { m_attributeMap[i->first] = XMLString::replicate(i->second); } if (src.m_idAttribute != src.m_attributeMap.end()) { @@ -106,44 +112,64 @@ AbstractAttributeExtensibleXMLObject::AbstractAttributeExtensibleXMLObject(const AbstractAttributeExtensibleXMLObject::~AbstractAttributeExtensibleXMLObject() { - for (map::iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) - XMLString::release(&(i->second)); +#ifdef XMLTOOLING_XERCESC_HAS_XMLBYTE_RELEASE + static void (*release)(XMLCh**) = &XMLString::release; +#else + static void (*release)(XMLCh**,MemoryManager*) = &XMLString::release; +#endif + for_each( + m_attributeMap.begin(), m_attributeMap.end(), + lambda::bind( + release, + &lambda::bind(&map::value_type::second, boost::ref(_1)) +#ifndef XMLTOOLING_XERCESC_HAS_XMLBYTE_RELEASE + ,XMLPlatformUtils::fgMemoryManager +#endif + ) + ); +} + +const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const xmltooling::QName& qualifiedName) const +{ + map::const_iterator i = m_attributeMap.find(qualifiedName); + return (i != m_attributeMap.end()) ? i->second : nullptr; } -const XMLCh* AbstractAttributeExtensibleXMLObject::getAttribute(const QName& qualifiedName) const +const XMLCh* AbstractAttributeExtensibleXMLObject::getLang() const { - map::const_iterator i=m_attributeMap.find(qualifiedName); - return (i==m_attributeMap.end()) ? NULL : i->second; + static const XMLCh _lang[] = UNICODE_LITERAL_4(l,a,n,g); + static xmltooling::QName qname(xmlconstants::XML_NS, _lang); + return getAttribute(qname); } -void AbstractAttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const XMLCh* value, bool ID) +void AbstractAttributeExtensibleXMLObject::setAttribute(const xmltooling::QName& qualifiedName, const XMLCh* value, bool ID) { - map::iterator i=m_attributeMap.find(qualifiedName); - if (i!=m_attributeMap.end()) { + map::iterator i=m_attributeMap.find(qualifiedName); + if (i != m_attributeMap.end()) { releaseThisandParentDOM(); XMLString::release(&(i->second)); if (value && *value) { - i->second=XMLString::replicate(value); + i->second = XMLString::replicate(value); if (ID) - m_idAttribute=i; + m_idAttribute = i; } else { - if (m_idAttribute==i) - m_idAttribute=m_attributeMap.end(); + if (m_idAttribute == i) + m_idAttribute = m_attributeMap.end(); m_attributeMap.erase(i); } } else if (value && *value) { releaseThisandParentDOM(); - m_attributeMap[qualifiedName]=XMLString::replicate(value); + m_attributeMap[qualifiedName] = XMLString::replicate(value); if (ID) m_idAttribute = m_attributeMap.find(qualifiedName); - Namespace newNamespace(qualifiedName.getNamespaceURI(), qualifiedName.getPrefix()); + Namespace newNamespace(qualifiedName.getNamespaceURI(), qualifiedName.getPrefix(), false, Namespace::VisiblyUsed); addNamespace(newNamespace); } } -void AttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, const QName& value) +void AttributeExtensibleXMLObject::setAttribute(const xmltooling::QName& qualifiedName, const xmltooling::QName& value) { if (!value.hasLocalPart()) return; @@ -157,23 +183,22 @@ void AttributeExtensibleXMLObject::setAttribute(const QName& qualifiedName, cons setAttribute(qualifiedName, value.getLocalPart()); } - // Attach a non-visibly used namespace. - Namespace newNamespace(value.getNamespaceURI(), value.getPrefix(), false, false); + Namespace newNamespace(value.getNamespaceURI(), value.getPrefix(), false, Namespace::NonVisiblyUsed); addNamespace(newNamespace); } -const map& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const +const map& AbstractAttributeExtensibleXMLObject::getExtensionAttributes() const { return m_attributeMap; } const XMLCh* AbstractAttributeExtensibleXMLObject::getXMLID() const { - return (m_idAttribute == m_attributeMap.end()) ? NULL : m_idAttribute->second; + return (m_idAttribute != m_attributeMap.end()) ? m_idAttribute->second : nullptr; } void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DOMAttr* attribute) { - QName q(attribute->getNamespaceURI(),attribute->getLocalName(),attribute->getPrefix()); + xmltooling::QName q(attribute->getNamespaceURI(), attribute->getLocalName(), attribute->getPrefix()); bool ID = attribute->isId() || isRegisteredIDAttribute(q); setAttribute(q,attribute->getNodeValue(),ID); if (ID) { @@ -187,13 +212,13 @@ void AbstractAttributeExtensibleXMLObject::unmarshallExtensionAttribute(const DO void AbstractAttributeExtensibleXMLObject::marshallExtensionAttributes(DOMElement* domElement) const { - for (map::const_iterator i=m_attributeMap.begin(); i!=m_attributeMap.end(); i++) { - DOMAttr* attr=domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(),i->first.getLocalPart()); + for (map::const_iterator i = m_attributeMap.begin(); i != m_attributeMap.end(); ++i) { + DOMAttr* attr = domElement->getOwnerDocument()->createAttributeNS(i->first.getNamespaceURI(), i->first.getLocalPart()); if (i->first.hasPrefix()) 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