Wrap importNode call in exception handler.
authorcantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Mon, 15 Feb 2010 15:51:38 +0000 (15:51 +0000)
committercantor <cantor@de75baf8-a10c-0410-a50a-987c0e22f00f>
Mon, 15 Feb 2010 15:51:38 +0000 (15:51 +0000)
git-svn-id: https://svn.middleware.georgetown.edu/cpp-xmltooling/branches/REL_1@719 de75baf8-a10c-0410-a50a-987c0e22f00f

xmltooling/AbstractDOMCachingXMLObject.cpp
xmltooling/impl/UnknownElement.cpp
xmltooling/signature/impl/XMLSecSignatureImpl.cpp

index 117225a..87f02a4 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright 2001-2009 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.
index 9f68476..1cf0373 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright 2001-2009 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.
@@ -129,7 +129,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);
@@ -150,7 +158,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 {
@@ -196,7 +213,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);
@@ -214,7 +239,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.
index dec07c1..6880452 100644 (file)
@@ -1,5 +1,5 @@
 /*
-*  Copyright 2001-2009 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.
@@ -295,7 +295,16 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMDocument* document, const vector<Si
             // 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 {
@@ -392,7 +401,16 @@ DOMElement* XMLSecSignatureImpl::marshall(DOMElement* parentElement, const vecto
         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();
 
         // Now reload the signature from the DOM.