Set fourth file version digit to signify rebuild.
[shibboleth/cpp-xmltooling.git] / xmltooling / impl / UnknownElement.cpp
index 00b234e..270b50f 100644 (file)
@@ -1,46 +1,63 @@
-/*
-*  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
+/**
+ * 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.
  */
 
 /**
  * UnknownElement.cpp
  * 
- * Basic implementation suitable for use as default for unrecognized content
+ * Basic implementation suitable for use as default for unrecognized content.
  */
 
 #include "internal.h"
 #include "exceptions.h"
+#include "logging.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::logging;
 using namespace xmltooling;
-using namespace log4cpp;
+using namespace xercesc;
 using namespace std;
+#ifndef XMLTOOLING_NO_XMLSEC
+using xmlsignature::Signature;
+#endif
+
+UnknownElementImpl::UnknownElementImpl(const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix)
+    : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix)
+{
+}
+
+UnknownElementImpl::~UnknownElementImpl()
+{
+}
 
 void UnknownElementImpl::releaseDOM() const
 {
 #ifdef _DEBUG
     xmltooling::NDC ndc("releaseDOM");
 #endif
-    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".UnknownElementImpl");
+    Category& log=Category::getInstance(XMLTOOLING_LOGCAT ".XMLObject");
     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.
@@ -64,6 +81,25 @@ XMLObject* UnknownElementImpl::clone() const
     return ret;
 }
 
+const XMLCh* UnknownElementImpl::getTextContent(unsigned int position) const
+{
+    throw XMLObjectException("Direct access to content is not permitted.");
+}
+
+void UnknownElementImpl::setTextContent(const XMLCh*, unsigned int position)
+{
+    throw XMLObjectException("Direct access to content is not permitted.");
+}
+
+void UnknownElementImpl::setDocumentElement(DOMDocument* document, DOMElement* element) const
+{
+    DOMElement* documentRoot = document->getDocumentElement();
+    if (documentRoot)
+        document->replaceChild(element, documentRoot);
+    else
+        document->appendChild(element);
+}
+
 void UnknownElementImpl::serialize(string& s) const
 {
     if (getDOM())
@@ -73,7 +109,8 @@ void UnknownElementImpl::serialize(string& s) const
 DOMElement* UnknownElementImpl::marshall(
     DOMDocument* document
 #ifndef XMLTOOLING_NO_XMLSEC
-    ,const std::vector<xmlsignature::Signature*>* sigs
+    ,const vector<Signature*>* sigs
+    ,const Credential* credential
 #endif
     ) const
 {
@@ -81,7 +118,7 @@ DOMElement* UnknownElementImpl::marshall(
     xmltooling::NDC ndc("marshall");
 #endif
     
-    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");
+    Category& log=Category::getInstance(XMLTOOLING_LOGCAT ".XMLObject");
     log.debug("marshalling unknown content");
 
     DOMElement* cachedDOM=getDOM();
@@ -96,7 +133,15 @@ DOMElement* UnknownElementImpl::marshall(
         
         // 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));
+        try {
+            cachedDOM=static_cast<DOMElement*>(document->importNode(cachedDOM, true));
+        }
+        catch (XMLException& ex) {
+            auto_ptr_char temp(ex.getMessage());
+            throw XMLParserException(
+                string("Error importing DOM into caller-supplied document: ") + (temp.get() ? temp.get() : "no message")
+                );
+        }
 
         // Recache the DOM.
         setDocumentElement(document, cachedDOM);
@@ -117,7 +162,16 @@ DOMElement* UnknownElementImpl::marshall(
         // 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));
+        try {
+            cachedDOM=static_cast<DOMElement*>(document->importNode(internalDoc->getDocumentElement(), true));
+        }
+        catch (XMLException& ex) {
+            internalDoc->release();
+            auto_ptr_char temp(ex.getMessage());
+            throw XMLParserException(
+                string("Error importing DOM into caller-supplied document: ") + (temp.get() ? temp.get() : "no message")
+                );
+        }
         internalDoc->release();
     }
     else {
@@ -140,7 +194,8 @@ DOMElement* UnknownElementImpl::marshall(
 DOMElement* UnknownElementImpl::marshall(
     DOMElement* parentElement
 #ifndef XMLTOOLING_NO_XMLSEC
-    ,const std::vector<xmlsignature::Signature*>* sigs
+    ,const vector<Signature*>* sigs
+    ,const Credential* credential
 #endif
     ) const
 {
@@ -148,7 +203,7 @@ DOMElement* UnknownElementImpl::marshall(
     xmltooling::NDC ndc("marshall");
 #endif
     
-    Category& log=Category::getInstance(XMLTOOLING_LOGCAT".Marshaller");
+    Category& log=Category::getInstance(XMLTOOLING_LOGCAT ".XMLObject");
     log.debug("marshalling unknown content");
 
     DOMElement* cachedDOM=getDOM();
@@ -162,7 +217,15 @@ DOMElement* UnknownElementImpl::marshall(
         
         // 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));
+        try {
+            cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(cachedDOM, true));
+        }
+        catch (XMLException& ex) {
+            auto_ptr_char temp(ex.getMessage());
+            throw XMLParserException(
+                string("Error importing DOM into caller-supplied document: ") + (temp.get() ? temp.get() : "no message")
+                );
+        }
 
         // Recache the DOM.
         parentElement->appendChild(cachedDOM);
@@ -180,7 +243,16 @@ DOMElement* UnknownElementImpl::marshall(
     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));
+    try {
+        cachedDOM=static_cast<DOMElement*>(parentElement->getOwnerDocument()->importNode(internalDoc->getDocumentElement(), true));
+    }
+    catch (XMLException& ex) {
+        internalDoc->release();
+        auto_ptr_char temp(ex.getMessage());
+        throw XMLParserException(
+            string("Error importing DOM into caller-supplied document: ") + (temp.get() ? temp.get() : "no message")
+            );
+    }
     internalDoc->release();
 
     // Recache the DOM and clear the serialized copy.
@@ -199,8 +271,9 @@ XMLObject* UnknownElementImpl::unmarshall(DOMElement* element, bool bindDocument
 }
 
 XMLObject* UnknownElementBuilder::buildObject(
-            const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType
-            ) const {
-            return new UnknownElementImpl(nsURI,localName,prefix);
+    const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const xmltooling::QName* schemaType
+    ) const
+{
+    return new UnknownElementImpl(nsURI,localName,prefix);
 }