gcc const fix, converted linefeeds
[shibboleth/cpp-xmltooling.git] / xmltooling / impl / UnknownElement.cpp
index e8ea23e..00b234e 100644 (file)
-/*\r
-*  Copyright 2001-2006 Internet2\r
- * \r
-* Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *     http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- */\r
-\r
-/**\r
- * UnknownElement.cpp\r
- * \r
- * Basic implementation suitable for use as default for unrecognized content\r
- */\r
-\r
-#include "internal.h"\r
-#include "exceptions.h"\r
-#include "impl/UnknownElement.h"\r
-#include "util/NDC.h"\r
-#include "util/XMLHelper.h"\r
-\r
-#include <log4cpp/Category.hh>\r
-#include <xercesc/framework/MemBufInputSource.hpp>\r
-#include <xercesc/framework/Wrapper4InputSource.hpp>\r
-#include <xercesc/util/XMLUniDefs.hpp>\r
-\r
-using namespace xmltooling;\r
-using namespace log4cpp;\r
-using namespace std;\r
-\r
-void UnknownElementImpl::releaseDOM() const\r
-{\r
-#ifdef _DEBUG\r
-    xmltooling::NDC ndc("releaseDOM");\r
-#endif\r
-    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".UnknownElementImpl");\r
-    log.debug("releasing DOM for unknown content, preserving current DOM in XML form");\r
-\r
-    // We're losing our DOM, so assuming we have one, we preserve it.\r
-    serialize(m_xml);\r
-\r
-    // This takes care of the generic housekeeping now that we've preserved things.\r
-    AbstractDOMCachingXMLObject::releaseDOM();\r
-}\r
-\r
-XMLObject* UnknownElementImpl::clone() const\r
-{\r
-    UnknownElementImpl* ret=new UnknownElementImpl();\r
-\r
-    // If there's no XML locally, serialize this object into the new one.\r
-    // Otherwise just copy it over.\r
-    if (m_xml.empty())\r
-        serialize(ret->m_xml);\r
-    else\r
-        ret->m_xml=m_xml;\r
-\r
-    return ret;\r
-}\r
-\r
-void UnknownElementImpl::serialize(string& s) const\r
-{\r
-    if (getDOM())\r
-        XMLHelper::serialize(getDOM(),s);\r
-}\r
-\r
-DOMElement* UnknownElementImpl::marshall(\r
-    DOMDocument* document\r
-#ifndef XMLTOOLING_NO_XMLSEC\r
-    ,const std::vector<xmlsignature::Signature*>* sigs\r
-#endif\r
-    ) const\r
-{\r
-#ifdef _DEBUG\r
-    xmltooling::NDC ndc("marshall");\r
-#endif\r
-    \r
-    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");\r
-    log.debug("marshalling unknown content");\r
-\r
-    DOMElement* cachedDOM=getDOM();\r
-    if (cachedDOM) {\r
-        if (!document || document==cachedDOM->getOwnerDocument()) {\r
-            log.debug("XMLObject has a usable cached DOM, reusing it");\r
-            if (document)\r
-                setDocumentElement(cachedDOM->getOwnerDocument(),cachedDOM);\r
-            releaseParentDOM(true);\r
-            return cachedDOM;\r
-        }\r
-        \r
-        // We have a DOM but it doesn't match the document we were given, so we import\r
-        // it into the new document.\r
-        cachedDOM=static_cast<DOMElement*>(document->importNode(cachedDOM, true));\r
-\r
-        // Recache the DOM.\r
-        setDocumentElement(document, cachedDOM);\r
-        log.debug("caching imported DOM for XMLObject");\r
-        setDOM(cachedDOM, false);\r
-        releaseParentDOM(true);\r
-        return cachedDOM;\r
-    }\r
-    \r
-    // If we get here, we didn't have a usable DOM.\r
-    // We need to reparse the XML we saved off into a new DOM.\r
-    bool bindDocument=false;\r
-    MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"UnknownElementImpl");\r
-    Wrapper4InputSource dsrc(&src,false);\r
-    log.debug("parsing XML back into DOM tree");\r
-    DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);\r
-    if (document) {\r
-        // The caller insists on using his own document, so we now have to import the thing\r
-        // into it. Then we're just dumping the one we built.\r
-        log.debug("reimporting new DOM into caller-supplied document");\r
-        cachedDOM=static_cast<DOMElement*>(document->importNode(internalDoc->getDocumentElement(), true));\r
-        internalDoc->release();\r
-    }\r
-    else {\r
-        // We just bind the document we built to the object as the result.\r
-        cachedDOM=static_cast<DOMElement*>(internalDoc->getDocumentElement());\r
-        document=internalDoc;\r
-        bindDocument=true;\r
-    }\r
-\r
-    // Recache the DOM and clear the serialized copy.\r
-    setDocumentElement(document, cachedDOM);\r
-    log.debug("caching DOM for XMLObject (document is %sbound)", bindDocument ? "" : "not ");\r
-    setDOM(cachedDOM, bindDocument);\r
-    releaseParentDOM(true);\r
-    m_xml.erase();\r
-    return cachedDOM;\r
-}\r
-\r
-\r
-DOMElement* UnknownElementImpl::marshall(\r
-    DOMElement* parentElement\r
-#ifndef XMLTOOLING_NO_XMLSEC\r
-    ,const std::vector<xmlsignature::Signature*>* sigs\r
-#endif\r
-    ) const\r
-{\r
-#ifdef _DEBUG\r
-    xmltooling::NDC ndc("marshall");\r
-#endif\r
-    \r
-    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");\r
-    log.debug("marshalling unknown content");\r
-\r
-    DOMElement* cachedDOM=getDOM();\r
-    if (cachedDOM) {\r
-        if (parentElement->getOwnerDocument()==cachedDOM->getOwnerDocument()) {\r
-            log.debug("XMLObject has a usable cached DOM, reusing it");\r
-            parentElement->appendChild(cachedDOM);\r
-            releaseParentDOM(true);\r
-            return cachedDOM;\r
-        }\r
-        \r
-        // We have a DOM but it doesn't match the document we were given, so we import\r
-        // it into the new document.\r
-        cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(cachedDOM, true));\r
-\r
-        // Recache the DOM.\r
-        parentElement->appendChild(cachedDOM);\r
-        log.debug("caching imported DOM for XMLObject");\r
-        setDOM(cachedDOM, false);\r
-        releaseParentDOM(true);\r
-        return cachedDOM;\r
-    }\r
-    \r
-    // If we get here, we didn't have a usable DOM (and/or we flushed the one we had).\r
-    // We need to reparse the XML we saved off into a new DOM.\r
-    MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"UnknownElementImpl");\r
-    Wrapper4InputSource dsrc(&src,false);\r
-    log.debug("parsing XML back into DOM tree");\r
-    DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);\r
-    \r
-    log.debug("reimporting new DOM into caller-supplied document");\r
-    cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(internalDoc->getDocumentElement(), true));\r
-    internalDoc->release();\r
-\r
-    // Recache the DOM and clear the serialized copy.\r
-    parentElement->appendChild(cachedDOM);\r
-    log.debug("caching DOM for XMLObject");\r
-    setDOM(cachedDOM, false);\r
-    releaseParentDOM(true);\r
-    m_xml.erase();\r
-    return cachedDOM;\r
-}\r
-\r
-XMLObject* UnknownElementImpl::unmarshall(DOMElement* element, bool bindDocument)\r
-{\r
-    setDOM(element, bindDocument);\r
-    return this;\r
-}\r
-\r
-XMLObject* UnknownElementBuilder::buildObject(\r
-            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType\r
-            ) const {\r
-            return new UnknownElementImpl(nsURI,localName,prefix);\r
-}\r
-\r
+/*
+*  Copyright 2001-2006 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
+ *
+ *     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.
+ */
+
+/**
+ * UnknownElement.cpp
+ * 
+ * Basic implementation suitable for use as default for unrecognized content
+ */
+
+#include "internal.h"
+#include "exceptions.h"
+#include "impl/UnknownElement.h"
+#include "util/NDC.h"
+#include "util/XMLHelper.h"
+
+#include <log4cpp/Category.hh>
+#include <xercesc/framework/MemBufInputSource.hpp>
+#include <xercesc/framework/Wrapper4InputSource.hpp>
+#include <xercesc/util/XMLUniDefs.hpp>
+
+using namespace xmltooling;
+using namespace log4cpp;
+using namespace std;
+
+void UnknownElementImpl::releaseDOM() const
+{
+#ifdef _DEBUG
+    xmltooling::NDC ndc("releaseDOM");
+#endif
+    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".UnknownElementImpl");
+    log.debug("releasing DOM for unknown content, preserving current DOM in XML form");
+
+    // We're losing our DOM, so assuming we have one, we preserve it.
+    serialize(m_xml);
+
+    // This takes care of the generic housekeeping now that we've preserved things.
+    AbstractDOMCachingXMLObject::releaseDOM();
+}
+
+XMLObject* UnknownElementImpl::clone() const
+{
+    UnknownElementImpl* ret=new UnknownElementImpl();
+
+    // If there's no XML locally, serialize this object into the new one.
+    // Otherwise just copy it over.
+    if (m_xml.empty())
+        serialize(ret->m_xml);
+    else
+        ret->m_xml=m_xml;
+
+    return ret;
+}
+
+void UnknownElementImpl::serialize(string& s) const
+{
+    if (getDOM())
+        XMLHelper::serialize(getDOM(),s);
+}
+
+DOMElement* UnknownElementImpl::marshall(
+    DOMDocument* document
+#ifndef XMLTOOLING_NO_XMLSEC
+    ,const std::vector<xmlsignature::Signature*>* sigs
+#endif
+    ) const
+{
+#ifdef _DEBUG
+    xmltooling::NDC ndc("marshall");
+#endif
+    
+    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");
+    log.debug("marshalling unknown content");
+
+    DOMElement* cachedDOM=getDOM();
+    if (cachedDOM) {
+        if (!document || document==cachedDOM->getOwnerDocument()) {
+            log.debug("XMLObject has a usable cached DOM, reusing it");
+            if (document)
+                setDocumentElement(cachedDOM->getOwnerDocument(),cachedDOM);
+            releaseParentDOM(true);
+            return cachedDOM;
+        }
+        
+        // We have a DOM but it doesn't match the document we were given, so we import
+        // it into the new document.
+        cachedDOM=static_cast<DOMElement*>(document->importNode(cachedDOM, true));
+
+        // Recache the DOM.
+        setDocumentElement(document, cachedDOM);
+        log.debug("caching imported DOM for XMLObject");
+        setDOM(cachedDOM, false);
+        releaseParentDOM(true);
+        return cachedDOM;
+    }
+    
+    // If we get here, we didn't have a usable DOM.
+    // We need to reparse the XML we saved off into a new DOM.
+    bool bindDocument=false;
+    MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"UnknownElementImpl");
+    Wrapper4InputSource dsrc(&src,false);
+    log.debug("parsing XML back into DOM tree");
+    DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);
+    if (document) {
+        // The caller insists on using his own document, so we now have to import the thing
+        // into it. Then we're just dumping the one we built.
+        log.debug("reimporting new DOM into caller-supplied document");
+        cachedDOM=static_cast<DOMElement*>(document->importNode(internalDoc->getDocumentElement(), true));
+        internalDoc->release();
+    }
+    else {
+        // We just bind the document we built to the object as the result.
+        cachedDOM=static_cast<DOMElement*>(internalDoc->getDocumentElement());
+        document=internalDoc;
+        bindDocument=true;
+    }
+
+    // Recache the DOM and clear the serialized copy.
+    setDocumentElement(document, cachedDOM);
+    log.debug("caching DOM for XMLObject (document is %sbound)", bindDocument ? "" : "not ");
+    setDOM(cachedDOM, bindDocument);
+    releaseParentDOM(true);
+    m_xml.erase();
+    return cachedDOM;
+}
+
+
+DOMElement* UnknownElementImpl::marshall(
+    DOMElement* parentElement
+#ifndef XMLTOOLING_NO_XMLSEC
+    ,const std::vector<xmlsignature::Signature*>* sigs
+#endif
+    ) const
+{
+#ifdef _DEBUG
+    xmltooling::NDC ndc("marshall");
+#endif
+    
+    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");
+    log.debug("marshalling unknown content");
+
+    DOMElement* cachedDOM=getDOM();
+    if (cachedDOM) {
+        if (parentElement->getOwnerDocument()==cachedDOM->getOwnerDocument()) {
+            log.debug("XMLObject has a usable cached DOM, reusing it");
+            parentElement->appendChild(cachedDOM);
+            releaseParentDOM(true);
+            return cachedDOM;
+        }
+        
+        // We have a DOM but it doesn't match the document we were given, so we import
+        // it into the new document.
+        cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(cachedDOM, true));
+
+        // Recache the DOM.
+        parentElement->appendChild(cachedDOM);
+        log.debug("caching imported DOM for XMLObject");
+        setDOM(cachedDOM, false);
+        releaseParentDOM(true);
+        return cachedDOM;
+    }
+    
+    // If we get here, we didn't have a usable DOM (and/or we flushed the one we had).
+    // We need to reparse the XML we saved off into a new DOM.
+    MemBufInputSource src(reinterpret_cast<const XMLByte*>(m_xml.c_str()),m_xml.length(),"UnknownElementImpl");
+    Wrapper4InputSource dsrc(&src,false);
+    log.debug("parsing XML back into DOM tree");
+    DOMDocument* internalDoc=XMLToolingConfig::getConfig().getParser().parse(dsrc);
+    
+    log.debug("reimporting new DOM into caller-supplied document");
+    cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(internalDoc->getDocumentElement(), true));
+    internalDoc->release();
+
+    // Recache the DOM and clear the serialized copy.
+    parentElement->appendChild(cachedDOM);
+    log.debug("caching DOM for XMLObject");
+    setDOM(cachedDOM, false);
+    releaseParentDOM(true);
+    m_xml.erase();
+    return cachedDOM;
+}
+
+XMLObject* UnknownElementImpl::unmarshall(DOMElement* element, bool bindDocument)
+{
+    setDOM(element, bindDocument);
+    return this;
+}
+
+XMLObject* UnknownElementBuilder::buildObject(
+            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType
+            ) const {
+            return new UnknownElementImpl(nsURI,localName,prefix);
+}
+