X-Git-Url: http://www.project-moonshot.org/gitweb/?a=blobdiff_plain;f=xmltooling%2FAbstractDOMCachingXMLObject.cpp;h=061df1a0373997d464516b00a9453dd3163a6ba0;hb=d1c1478d26cfd9b87a4deb80c3638dc42e111735;hp=117225aa68d5bdfe071b72a54a0ffd657553fab5;hpb=cdb13e786c99d2517591a172fa46523a8bc42729;p=shibboleth%2Fcpp-xmltooling.git diff --git a/xmltooling/AbstractDOMCachingXMLObject.cpp b/xmltooling/AbstractDOMCachingXMLObject.cpp index 117225a..061df1a 100644 --- a/xmltooling/AbstractDOMCachingXMLObject.cpp +++ b/xmltooling/AbstractDOMCachingXMLObject.cpp @@ -1,17 +1,21 @@ -/* - * Copyright 2001-2009 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. * - * http://www.apache.org/licenses/LICENSE-2.0 + * 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 * - * 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. + * 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. */ /** @@ -33,12 +37,12 @@ using namespace xmltooling; using namespace xercesc; using namespace std; -AbstractDOMCachingXMLObject::AbstractDOMCachingXMLObject() : m_dom(NULL), m_document(NULL) +AbstractDOMCachingXMLObject::AbstractDOMCachingXMLObject() : m_dom(nullptr), m_document(nullptr) { } AbstractDOMCachingXMLObject::AbstractDOMCachingXMLObject(const AbstractDOMCachingXMLObject& src) - : AbstractXMLObject(src), m_dom(NULL), m_document(NULL) + : AbstractXMLObject(src), m_dom(nullptr), m_document(nullptr) { } @@ -55,11 +59,15 @@ DOMElement* AbstractDOMCachingXMLObject::getDOM() const void AbstractDOMCachingXMLObject::setDOM(DOMElement* dom, bool bindDocument) const { - m_dom=dom; - if (dom) { - if (bindDocument) { - setDocument(dom->getOwnerDocument()); - } + m_dom = dom; + if (dom && bindDocument) { + DOMDocument* doc = dom->getOwnerDocument(); + setDocument(doc); + DOMElement* documentRoot = doc->getDocumentElement(); + if (!documentRoot) + doc->appendChild(dom); + else if (documentRoot != dom) + doc->replaceChild(dom, documentRoot); } } @@ -79,7 +87,7 @@ void AbstractDOMCachingXMLObject::releaseDOM() const string qname=getElementQName().toString(); m_log.debug("releasing cached DOM representation for (%s)", qname.empty() ? "unknown" : qname.c_str()); } - setDOM(NULL); + setDOM(nullptr); } } @@ -126,7 +134,7 @@ DOMElement* AbstractDOMCachingXMLObject::cloneDOM(DOMDocument* doc) const if (getDOM()) { DOMDocument* cloneDoc = doc; if (!cloneDoc) - cloneDoc=DOMImplementationRegistry::getDOMImplementation(NULL)->createDocument(); + cloneDoc=DOMImplementationRegistry::getDOMImplementation(nullptr)->createDocument(); try { return static_cast(cloneDoc->importNode(getDOM(),true)); } @@ -137,7 +145,7 @@ DOMElement* AbstractDOMCachingXMLObject::cloneDOM(DOMDocument* doc) const m_log.error("DOM clone failed: %s", temp.get()); } } - return NULL; + return nullptr; } XMLObject* AbstractDOMCachingXMLObject::clone() const @@ -160,7 +168,7 @@ XMLObject* AbstractDOMCachingXMLObject::clone() const janitor.release(); // safely transferred return ret; } - return NULL; + return nullptr; } void AbstractDOMCachingXMLObject::detach() @@ -178,7 +186,7 @@ void AbstractDOMCachingXMLObject::detach() if (parent && parent->m_document) { // Transfer control of document to me... setDocument(parent->m_document); - parent->m_document = NULL; + parent->m_document = nullptr; } // The rest is done by the base. AbstractXMLObject::detach();