Moved URLEncoder down to tooling lib, added exception->querystring method.
[shibboleth/xmltooling.git] / xmltooling / exceptions.cpp
index 56ce6d3..3b37262 100644 (file)
@@ -23,6 +23,7 @@
 #include "internal.h"
 #include "exceptions.h"
 #include "XMLToolingConfig.h"
+#include "util/URLEncoder.h"
 #include "util/XMLConstants.h"
 #include "util/XMLHelper.h"
 
@@ -222,13 +223,22 @@ string XMLToolingException::toString() const
     const char* msg=getMessage();
     if (msg)
         xml=xml + "<message>" + msg + "</message>";
-    for (map<string,string>::const_iterator i=m_params.begin(); i!=m_params.end(); i++) {
+    for (map<string,string>::const_iterator i=m_params.begin(); i!=m_params.end(); i++)
         xml=xml + "<param name=\"" + i->first + "\">" + i->second + "</param>";
-    }
     xml+="</exception>";
     return xml;
 }
 
+string XMLToolingException::toQueryString() const
+{
+    const URLEncoder* enc = XMLToolingConfig::getConfig().getURLEncoder();
+    string q("type=");
+    q = q + enc->encode(getClassName()) + "&message=" + enc->encode(what());
+    for (map<string,string>::const_iterator i=m_params.begin(); i!=m_params.end(); i++)
+        q = q + '&' + i->first + '=' + enc->encode(i->second.c_str());
+    return q;
+}
+
 XMLToolingException* XMLToolingException::fromStream(std::istream& in)
 {
     static const XMLCh exception[] = { chLatin_e, chLatin_x, chLatin_c, chLatin_e, chLatin_p, chLatin_t, chLatin_i, chLatin_o, chLatin_n, chNull };