CPPXT-104 - Add exception handling to integer conversions
[shibboleth/cpp-xmltooling.git] / xmltooling / util / XMLHelper.cpp
index be7401d..2682395 100644 (file)
@@ -131,10 +131,11 @@ XMLObject* XMLHelper::getXMLObjectById(XMLObject& tree, const XMLCh* id)
 void XMLHelper::getNonVisiblyUsedPrefixes(const XMLObject& tree, map<xstring,xstring>& prefixes)
 {
     map<xstring,xstring> child_prefixes;
-    for_each(
-        tree.getOrderedChildren().begin(), tree.getOrderedChildren().end(),
-        if_(_1 != nullptr)[lambda::bind(&getNonVisiblyUsedPrefixes, boost::ref(*_1), boost::ref(child_prefixes))]
-        );
+    for(list<XMLObject*>::const_iterator i = tree.getOrderedChildren().begin(); i != tree.getOrderedChildren().end(); ++i) {
+        if (*i) {
+            getNonVisiblyUsedPrefixes(*(*i), child_prefixes);
+        }
+    }
     const set<Namespace>& nsset = tree.getNamespaces();
     for (set<Namespace>::const_iterator ns = nsset.begin(); ns != nsset.end(); ++ns) {
         // Check for xmlns:xml.
@@ -337,9 +338,11 @@ int XMLHelper::getAttrInt(const DOMElement* e, int defValue, const XMLCh* localN
     if (e) {
         const XMLCh* val = e->getAttributeNS(ns, localName);
         if (val && *val) {
-            int i = XMLString::parseInt(val);
-            if (i)
-                return i;
+            try {
+                return XMLString::parseInt(val);
+            }
+            catch (XMLException&) {
+            }
         }
     }
     return defValue;
@@ -451,5 +454,11 @@ ostream& xmltooling::operator<<(ostream& ostr, const DOMNode& node)
 
 ostream& xmltooling::operator<<(ostream& ostr, const XMLObject& obj)
 {
-    return ostr << *(obj.marshall());
+    try {
+        return ostr << *(obj.marshall());
+    }
+    catch (DOMException& ex) {
+        auto_ptr_char msg(ex.getMessage());
+        throw XMLParserException(msg.get());
+    }
 }