diff options
Diffstat (limited to 'project2/xslRows.cpp')
-rw-r--r-- | project2/xslRows.cpp | 23 |
1 files changed, 11 insertions, 12 deletions
diff --git a/project2/xslRows.cpp b/project2/xslRows.cpp index 537a459..1a7d6f4 100644 --- a/project2/xslRows.cpp +++ b/project2/xslRows.cpp @@ -1,5 +1,6 @@ #include "xslRows.h" #include "rowProcessor.h" +#include "logger.h" #include "xml.h" #include "exceptions.h" #include "xmlObjectLoader.h" @@ -11,10 +12,9 @@ DECLARE_LOADER("xslrows", XslRows); -class XmlParseError : public std::exception { }; -class XpathInitError : public std::exception { }; -class XpathEvalError : public std::exception { }; -class ResourceDownloadError : public std::exception { }; +SimpleMessageException(XmlParseError); +SimpleMessageException(XpathInitError); +SimpleMessageException(XpathEvalError); XslRows::XslRows(const xmlpp::Element * p) : SourceObject(p), @@ -52,7 +52,7 @@ XslRows::setFilter(const Glib::ustring & f) { FilterViews::const_iterator i = fvs.find(f); if (i == fvs.end()) { - throw FilterNotFound(); + throw FilterNotFound(f); } fv = i->second; } @@ -78,9 +78,7 @@ XslRows::getDocument(const Glib::ustring & url) const std::string buf; c->setopt(CURLOPT_WRITEDATA, &buf); c->setopt(CURLOPT_WRITEFUNCTION, &handleDataHelper); - if (c->perform()) { - throw ResourceDownloadError(); - } + c->perform(); int flags = 0; flags |= warnings ? 0 : XML_PARSE_NOWARNING | XML_PARSE_NOERROR; @@ -88,7 +86,7 @@ XslRows::getDocument(const Glib::ustring & url) const htmlReadMemory(buf.c_str(), buf.length(), url.c_str(), NULL, flags) : xmlReadMemory(buf.c_str(), buf.length(), url.c_str(), NULL, flags); if (!doc) { - throw XmlParseError(); + throw XmlParseError(xmlGetLastError()->message); } documents.insert(Documents::value_type(url, Documents::value_type::second_type(doc, xmlFreeDoc))); return doc; @@ -106,16 +104,17 @@ XslRows::execute(const RowProcessor * rp) const xmlDocPtr doc = getDocument(url()); xmlXPathContextSPtr xpathCtx = xmlXPathContextSPtr(xmlXPathNewContext(doc), xmlXPathFreeContext); if (!xpathCtx) { - throw XpathInitError(); + throw XpathInitError(xmlGetLastError()->message); } BOOST_FOREACH(const Namespaces::value_type & ns, namespaces) { xmlXPathRegisterNs(xpathCtx.get(), BAD_CAST ns.first.c_str(), BAD_CAST ns.second.c_str()); } xmlXPathObjectSPtr xpathObj = xmlXPathObjectSPtr(xmlXPathEvalExpression(fv->root(), xpathCtx.get()), xmlXPathFreeObject); if (!xpathObj || !xpathObj->nodesetval) { - throw XpathEvalError(); + throw XpathEvalError(xmlGetLastError()->message); } rowNum = 1; + Logger()->messagef(LOG_INFO, "%d nodes matched %s", xpathObj->nodesetval->nodeNr, (const char *)(fv->root())); for (int row = 0; row < xpathObj->nodesetval->nodeNr; row += 1) { xmlNodePtr rowRoot = xpathObj->nodesetval->nodeTab[row]; xpathCtx->node = rowRoot; @@ -123,7 +122,7 @@ XslRows::execute(const RowProcessor * rp) const BOOST_FOREACH(const FilterView::XPaths::value_type & xp, fv->xpaths) { xmlXPathObjectSPtr xpathObjI = xmlXPathObjectSPtr(xmlXPathEvalExpression(xp.second(), xpathCtx.get()), xmlXPathFreeObject); if (!xpathObjI) { - throw XpathEvalError(); + throw XpathEvalError(xmlGetLastError()->message); } if (xpathObjI->floatval) { values[xp.first] = xpathObjI->floatval; |