diff options
28 files changed, 161 insertions, 96 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp index f3f8d56..b273fda 100644 --- a/project2/cgi/cgiAppEngine.cpp +++ b/project2/cgi/cgiAppEngine.cpp @@ -15,7 +15,7 @@ typedef std::string SValue; SessionContainer * sessionsContainer = new SessionContainerXml(); -class UnknownDomain : public std::exception { }; +SimpleMessageException(UnknownDomain); CgiApplicationEngine::CgiApplicationEngine(const CgiEnvironment * e) : ApplicationEngine("web/host"), @@ -208,7 +208,7 @@ CgiApplicationEngine::resolveCurrentConfig() const if (i != domplat.end()) { return i->second; } - throw UnknownDomain(); + throw UnknownDomain(_env->getServerName()); } void diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp index aa9e57f..f858262 100644 --- a/project2/cgi/cgiEnvironment.cpp +++ b/project2/cgi/cgiEnvironment.cpp @@ -45,7 +45,7 @@ Glib::ustring CgiEnvironment::getParamUri(unsigned int p) const { if (p >= elems.size()) { - throw UriElementOutOfRange(); + throw UriElementOutOfRange(p); } return elems[p]; } @@ -55,7 +55,7 @@ CgiEnvironment::getParamQuery(const std::string & p) const { cgicc::const_form_iterator i = cgi->getElement(p); if (i == cgi->getElements().end()) { - throw ParamNotFound(); + throw ParamNotFound(p); } return (*cgi)(p); } diff --git a/project2/commonObjects.cpp b/project2/commonObjects.cpp index 6d8fc08..31f81a9 100644 --- a/project2/commonObjects.cpp +++ b/project2/commonObjects.cpp @@ -7,7 +7,7 @@ CommonObjects::getSource(const std::string & name) const if (i != rowSets.get<bySOName>().end()) { return *i; } - throw CommonObjects::DataSourceNotFound(); + throw CommonObjects::DataSourceNotFound(name); } diff --git a/project2/commonObjects.h b/project2/commonObjects.h index 12b1f2b..e3c0d37 100644 --- a/project2/commonObjects.h +++ b/project2/commonObjects.h @@ -6,8 +6,8 @@ class CommonObjects : public virtual IntrusivePtrBase { public: - class DataSourceNotFound : public std::exception { }; - class DataSourceNotCompatible : public std::exception { }; + SimpleMessageException(DataSourceNotFound); + SimpleMessageException(DataSourceNotCompatible); RowSetPtr getSource(const std::string &) const; template <class DataSourceType> @@ -15,11 +15,11 @@ class CommonObjects : public virtual IntrusivePtrBase { { DataSources::index<bySOName>::type::const_iterator i = datasources.get<bySOName>().find(name); if (i == datasources.get<bySOName>().end()) { - throw DataSourceNotFound(); + throw DataSourceNotFound(name); } const DataSourceType * s = dynamic_cast<const DataSourceType *>(i->get()); if (!s) { - throw DataSourceNotCompatible(); + throw DataSourceNotCompatible(name); } return s; } diff --git a/project2/config.cpp b/project2/config.cpp index f973c05..c3823ff 100644 --- a/project2/config.cpp +++ b/project2/config.cpp @@ -5,8 +5,8 @@ #include <libxml/xinclude.h> #include <libxml++/parsers/domparser.h> -class NoSuchPlatform : public std::exception { }; -class NoSuchConfigurationValue : public std::exception { }; +SimpleMessageException(NoSuchPlatform); +SimpleMessageException(NoSuchConfigurationValue); Configuration::Configuration(const Glib::ustring & ek) : loaded(false), @@ -53,7 +53,7 @@ Configuration::getCurrentConfig() const Glib::ustring platformName(resolveCurrentConfig()); Platforms::const_iterator i = platforms.find(platformName); if (i == platforms.end()) { - throw NoSuchPlatform(); + throw NoSuchPlatform(platformName); } return i->second; } @@ -63,7 +63,7 @@ Configuration::Platform::getValue(const Glib::ustring & key) const { Values::const_iterator i = values.find(key); if (i == values.end()) { - throw NoSuchConfigurationValue(); + throw NoSuchConfigurationValue(key); } return i->second; } diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp index 0d0c71d..be88638 100644 --- a/project2/console/consoleAppEngine.cpp +++ b/project2/console/consoleAppEngine.cpp @@ -5,7 +5,7 @@ #include <libxml/xinclude.h> #include <libxml++/parsers/domparser.h> -class UnknownPlatformAlias : public std::exception { }; +SimpleMessageException(UnknownPlatformAlias); class ConsoleSession : public Session { public: @@ -20,7 +20,7 @@ class ConsoleSession : public Session { { Values::const_iterator i = vars.find(name); if (i == vars.end()) { - throw Session::VariableNotFound(); + throw Session::VariableNotFound(name); } return i->second; } @@ -174,15 +174,11 @@ ConsoleApplicationEngine::popSub() const Glib::ustring ConsoleApplicationEngine::resolveCurrentConfig() const { - const char * e = getenv("P2_PLATFORM"); - if (!e) { - e = ""; - } - ConsolePlatforms::const_iterator i = conplat.find(e); + ConsolePlatforms::const_iterator i = conplat.find(_env->getPlatform()); if (i != conplat.end()) { return i->second; } - throw UnknownPlatformAlias(); + throw UnknownPlatformAlias(_env->getPlatform()); } void diff --git a/project2/console/consoleEnvironment.cpp b/project2/console/consoleEnvironment.cpp index 31f9ac9..6b2a753 100644 --- a/project2/console/consoleEnvironment.cpp +++ b/project2/console/consoleEnvironment.cpp @@ -4,12 +4,24 @@ #include <stdio.h> #include <string.h> #include "../logger.h" +#include "../exceptions.h" #include <iostream> #include <string> #include <boost/program_options.hpp> namespace po = boost::program_options; +template<typename _CharT, typename _Traits> +std::basic_istream<_CharT, _Traits> & +operator>>(std::basic_istream<_CharT, _Traits> & s, ConsoleEnvironment::QueryParams & q) +{ + std::string n, v; + std::getline(s, n, '='); + std::getline(s, v); + q.insert(ConsoleEnvironment::QueryParams::value_type(n, v)); + return s; +} + ConsoleEnvironment::ConsoleEnvironment(int argc, char ** argv) : Environment(argc, argv) { @@ -27,6 +39,8 @@ ConsoleEnvironment::addOptions(boost::program_options::positional_options_descri //("version,v", "Print version and exit") ("help,h", "Print usage and exit") ("syslogident,i", po::value<std::string>(&scriptname)->default_value(scriptname), "Log to syslog with ident <arg>") + ("platform,p", po::value<std::string>(&platform), "Platform") + ("queryparam,q", po::value<QueryParams>(&queryParams), "Platform") ("file,f", po::value<ToDoList>(&todolist), "File to process") ; poptions.add("file", -1); @@ -49,13 +63,23 @@ ConsoleEnvironment::postinit(const boost::program_options::options_description & Glib::ustring ConsoleEnvironment::getParamUri(unsigned int) const { - throw std::runtime_error("Not implemented"); + throw NotSupported(__PRETTY_FUNCTION__); } Glib::ustring -ConsoleEnvironment::getParamQuery(const std::string &) const +ConsoleEnvironment::getParamQuery(const std::string & p) const +{ + QueryParams::const_iterator i = queryParams.find(p); + if (i != queryParams.end()) { + return i->second; + } + throw ParamNotFound(p); +} + +const std::string & +ConsoleEnvironment::getPlatform() const { - throw std::runtime_error("Not implemented"); + return platform; } std::string diff --git a/project2/console/consoleEnvironment.h b/project2/console/consoleEnvironment.h index 23bbd05..82fe11f 100644 --- a/project2/console/consoleEnvironment.h +++ b/project2/console/consoleEnvironment.h @@ -9,6 +9,7 @@ class ConsoleEnvironment : public Environment { public: typedef std::vector<boost::filesystem::path> ToDoList; + typedef std::map<std::string, const Glib::ustring> QueryParams; ConsoleEnvironment(int argc, char ** argv); virtual ~ConsoleEnvironment(); @@ -18,12 +19,15 @@ class ConsoleEnvironment : public Environment { Glib::ustring getParamQuery(const std::string & idx) const; std::string getServerName() const; std::string getScriptName() const; + const std::string & getPlatform() const; const ToDoList & todoList() const; private: boost::program_options::options_description addOptions(boost::program_options::positional_options_description &); void postinit(const boost::program_options::options_description &, const boost::program_options::variables_map &); std::string scriptname; + std::string platform; + QueryParams queryParams; ToDoList todolist; }; diff --git a/project2/environment.cpp b/project2/environment.cpp index 5510b1a..46ec6cf 100644 --- a/project2/environment.cpp +++ b/project2/environment.cpp @@ -64,13 +64,3 @@ Environment::~Environment() Logger()->clear(); } -Glib::ustring -Environment::getParamUri(unsigned int) const -{ - throw ParameterTypeNotSupported(); -} -Glib::ustring -Environment::getParamQuery(const std::string &) const -{ - throw ParameterTypeNotSupported(); -} diff --git a/project2/environment.h b/project2/environment.h index 60b5f66..246c525 100644 --- a/project2/environment.h +++ b/project2/environment.h @@ -8,9 +8,6 @@ class Environment { public: - class ParameterTypeNotSupported : public std::exception { }; - - Environment(int argc, char ** argv); virtual ~Environment() = 0; diff --git a/project2/exceptions.cpp b/project2/exceptions.cpp index 9aaeb07..ddf8e94 100644 --- a/project2/exceptions.cpp +++ b/project2/exceptions.cpp @@ -1,7 +1,26 @@ #include "exceptions.h" +#include <stdlib.h> +#include <stdio.h> -NotSupported::NotSupported(const std::string & what) : - std::runtime_error(what) +numeric_error::numeric_error(int e) : + err(e), + buf(NULL) { } +numeric_error::~numeric_error() throw() +{ + free(buf); +} + +const char * +numeric_error::what() const throw() +{ + if (!buf) { + if (asprintf(&buf, "%d", err) < 1) { + throw std::bad_alloc(); + } + } + return buf; +} + diff --git a/project2/exceptions.h b/project2/exceptions.h index d156636..b6c64ae 100644 --- a/project2/exceptions.h +++ b/project2/exceptions.h @@ -3,15 +3,32 @@ #include <stdexcept> -class UriElementOutOfRange : public std::exception { }; -class ParamNotFound : public std::exception { }; -class NotSupported : public std::runtime_error { +class numeric_error : public std::exception { public: - NotSupported(const std::string & what); + numeric_error(int); + ~numeric_error() throw(); + const char * what() const throw(); + private: + int err; + mutable char * buf; }; -class FileNotReadable : public std::exception { }; -class FileNotWritable : public std::exception { }; -class FilterNotFound : public std::exception { }; +#define SimpleMessageException(Name) \ +class Name : public std::runtime_error { \ + public: \ + Name(const std::string & what) : std::runtime_error(what) { } \ +} +#define SimpleNumericException(Name) \ +class Name : public numeric_error { \ + public: \ + Name(int e) : numeric_error(e) { } \ +} + +SimpleNumericException(UriElementOutOfRange); +SimpleMessageException(ParamNotFound); +SimpleMessageException(NotSupported); +SimpleMessageException(FileNotReadable); +SimpleMessageException(FileNotWritable); +SimpleMessageException(FilterNotFound); #endif diff --git a/project2/fileRows.cpp b/project2/fileRows.cpp index 950bb39..487c2ef 100644 --- a/project2/fileRows.cpp +++ b/project2/fileRows.cpp @@ -48,7 +48,7 @@ FileRows::doOpen() const { FILE * f = fopen(path(), "r"); if (!f) { - throw FileNotReadable(); + throw FileNotReadable(path()); } return FileStarChannel(f, true, fclose); } diff --git a/project2/fileStrmVarWriter.cpp b/project2/fileStrmVarWriter.cpp index f3812ce..8b5b2ec 100644 --- a/project2/fileStrmVarWriter.cpp +++ b/project2/fileStrmVarWriter.cpp @@ -46,10 +46,10 @@ void FileStreamVariableWriter::operator()(const double & i) const { fprintf(out, "%g", i); } void FileStreamVariableWriter::operator()(const Glib::ustring & i) const { - fprintf(out, "'%.*s'", i.length(), i.c_str()); + fprintf(out, "'%.*s'", i.bytes(), i.c_str()); } void FileStreamVariableWriter::operator()(const boost::shared_ptr<const Glib::ustring> & i) const { - fprintf(out, "'%.*s'", i->length(), i->c_str()); + fprintf(out, "'%.*s'", i->bytes(), i->c_str()); } void FileStreamVariableWriter::operator()(const boost::posix_time::ptime & i) const { fprintf(out, "[%s]", boost::posix_time::to_iso_extended_string(i).c_str()); diff --git a/project2/iHaveParameters.cpp b/project2/iHaveParameters.cpp index 84adee5..6431fc6 100644 --- a/project2/iHaveParameters.cpp +++ b/project2/iHaveParameters.cpp @@ -32,6 +32,6 @@ IHaveParameters::getParameter(const Glib::ustring & name) const if (i != parameters.end()) { return i->second->value; } - throw ParamNotFound(); + throw ParamNotFound(name); } diff --git a/project2/if.cpp b/project2/if.cpp index 8fc210d..4531b89 100644 --- a/project2/if.cpp +++ b/project2/if.cpp @@ -4,7 +4,7 @@ DECLARE_LOADER("if", If); -class IfModeIsNonsense : public std::exception { }; +SimpleMessageException(IfModeIsNonsense); IfSet::IfSet(const xmlpp::Element * e) : mode(e->get_attribute_value("mode") == "or" ? Or : And) @@ -33,7 +33,7 @@ IfSet::passes() const } return false; } - throw IfModeIsNonsense(); + throw IfModeIsNonsense(getName()); } If::If(const xmlpp::Element * e) : @@ -44,11 +44,13 @@ If::If(const xmlpp::Element * e) : { } -void If::loadComplete(const CommonObjects*) +void +If::loadComplete(const CommonObjects*) { } -void If::execute(const Presenter * presenter) const +void +If::execute(const Presenter * presenter) const { if (passes()) { Logger()->messagef(LOG_DEBUG, "IfSet passed, showing %zu views", subViews.size()); @@ -58,7 +60,8 @@ void If::execute(const Presenter * presenter) const } } -void If::execute() const +void +If::execute() const { if (passes()) { Logger()->message(LOG_DEBUG, "IfSet passed"); @@ -68,4 +71,9 @@ void If::execute() const } } +const std::string & +If::getName() const +{ + return name; +} diff --git a/project2/if.h b/project2/if.h index 8ce08fb..26aef1a 100644 --- a/project2/if.h +++ b/project2/if.h @@ -11,6 +11,7 @@ class IfSet : public virtual IntrusivePtrBase { bool passes() const; private: + virtual const std::string & getName() const = 0; enum Mode { And, Or }; Mode mode; ParamCheckers checks; @@ -23,6 +24,8 @@ class If : public Iterate, public RowView, public IfSet { virtual void loadComplete(const CommonObjects*); virtual void execute(const Presenter*) const; virtual void execute() const; + private: + const std::string & getName() const; }; #endif diff --git a/project2/procRows.cpp b/project2/procRows.cpp index 11ae35e..54b6d99 100644 --- a/project2/procRows.cpp +++ b/project2/procRows.cpp @@ -1,11 +1,11 @@ #include "procRows.h" #include "xmlObjectLoader.h" -#include <stdexcept> +#include <exception> DECLARE_LOADER("procrows", ProcRows); -class SubProcessFailedToStart : public std::exception { }; -class SubProcessFailed : public std::exception { }; +SimpleMessageException(SubProcessFailedToStart); +SimpleNumericException(SubProcessFailed); ProcRows::ProcRows(const xmlpp::Element * p) : SourceObject(p), @@ -27,7 +27,7 @@ ProcRows::doOpen() const { FILE * f = popen(path(), "re"); if (!f) { - throw SubProcessFailedToStart(); + throw SubProcessFailedToStart(path()); } return FileStarChannel(f, false, doClose); } @@ -36,8 +36,11 @@ int ProcRows::doClose(FILE * f) { int pclo = pclose(f); - if (pclo != 0) { - throw SubProcessFailed(); + // pclose returns an error if the application is still running, + // but if there is already an exception being thrown, we don't + // want to throw another. + if (pclo != 0 && !std::uncaught_exception()) { + throw SubProcessFailed(pclo); } return 0; } diff --git a/project2/rdbmsDataSource.cpp b/project2/rdbmsDataSource.cpp index ac63042..d7d77d3 100644 --- a/project2/rdbmsDataSource.cpp +++ b/project2/rdbmsDataSource.cpp @@ -16,7 +16,7 @@ static const int PQ_TYPEID = 1; static const int ODBC_TYPEID = 2; #endif -class UnknownConnectionProvider : public std::exception { }; +SimpleMessageException(UnknownConnectionProvider); class RdbmsDataSourceLoader : public ElementLoaderImpl<RdbmsDataSource> { public: @@ -103,7 +103,7 @@ RdbmsDataSource::getReadonly() const ReadonlyDSNs::const_iterator ro = roDSNs.find(localhost); try { if (ro == roDSNs.end()) { - Logger()->messagef(LOG_WARNING, "%s: No database host matches local host name (%s) Will use master DSN", + Logger()->messagef(LOG_INFO, "%s: No database host matches local host name (%s) Will use master DSN", __PRETTY_FUNCTION__, localhost.c_str()); return *connectTo(masterDsn)->connection; } @@ -219,7 +219,7 @@ RdbmsDataSource::ConnectionInfo::ConnectionInfo(const xmlpp::Element * n) : } #endif if (typeId == NOTSET || dsn.empty()) { - throw UnknownConnectionProvider(); + throw UnknownConnectionProvider(n->get_path()); } } @@ -236,7 +236,8 @@ RdbmsDataSource::ConnectionInfo::connect() const return new PQ::Connection(dsn); } #endif - throw UnknownConnectionProvider(); + // This should never happen if the object was constructed correctly + throw UnknownConnectionProvider(__PRETTY_FUNCTION__); } bool diff --git a/project2/rowSet.cpp b/project2/rowSet.cpp index 2dd4663..1be3547 100644 --- a/project2/rowSet.cpp +++ b/project2/rowSet.cpp @@ -66,6 +66,6 @@ RowSet::resolveAttr(const Glib::ustring & attrName) const if (attrName == "rownum") { return boost::bind(&RowSet::getRowNum, this); } - throw FieldDoesNotExist(); + throw AttributeDoesNotExist(attrName); } diff --git a/project2/rowSet.h b/project2/rowSet.h index bd17412..9a74719 100644 --- a/project2/rowSet.h +++ b/project2/rowSet.h @@ -20,8 +20,10 @@ typedef Storage<RowSet>::Objects RowSets; class RowSet : public virtual SourceObject { public: typedef boost::function0<VariableType> RowAttribute; - class ParentOutOfRange : public std::exception { }; - class FieldDoesNotExist : public std::exception { }; + SimpleNumericException(ParentOutOfRange); + SimpleMessageException(AttributeDoesNotExist); + SimpleMessageException(FieldDoesNotExist); + SimpleNumericException(FieldOutOfRange); typedef std::vector<const RowSet *> RowValuesStack; RowSet(const xmlpp::Element *); virtual ~RowSet() = 0; diff --git a/project2/session.h b/project2/session.h index 93b0303..2227b5b 100644 --- a/project2/session.h +++ b/project2/session.h @@ -6,10 +6,11 @@ #include <boost/intrusive_ptr.hpp> #include "intrusivePtrBase.h" #include "variables.h" +#include "exceptions.h" class Session : public virtual IntrusivePtrBase { public: - class VariableNotFound : public std::exception { }; + SimpleMessageException(VariableNotFound); typedef std::map<Glib::ustring, VariableType> Values; Session(); diff --git a/project2/sessionXml.cpp b/project2/sessionXml.cpp index 3281a81..41a2f1e 100644 --- a/project2/sessionXml.cpp +++ b/project2/sessionXml.cpp @@ -144,7 +144,7 @@ SessionXml::GetValue(const Glib::ustring & name) const { Values::const_iterator i = vars.find(name); if (i == vars.end()) { - throw Session::VariableNotFound(); + throw Session::VariableNotFound(name); } return i->second; } diff --git a/project2/streamRows.cpp b/project2/streamRows.cpp index 21ea391..d214e01 100644 --- a/project2/streamRows.cpp +++ b/project2/streamRows.cpp @@ -38,7 +38,7 @@ StreamRows::getColumnName(unsigned int col) const if (i != columns.get<byColIdx>().end()) { return i->col; } - throw RowSet::FieldDoesNotExist(); + throw RowSet::FieldOutOfRange(col); } unsigned int @@ -54,7 +54,7 @@ StreamRows::getCurrentValue(unsigned int col) const if (i != columns.get<byColIdx>().end()) { return i->value; } - throw RowSet::FieldDoesNotExist(); + throw RowSet::FieldOutOfRange(col); } bool @@ -76,7 +76,7 @@ StreamRows::getCurrentValue(const Glib::ustring & col) const if (i != columns.end()) { return i->value; } - throw RowSet::FieldDoesNotExist(); + throw RowSet::FieldDoesNotExist(col); } void diff --git a/project2/variables.cpp b/project2/variables.cpp index 29e6353..5514638 100644 --- a/project2/variables.cpp +++ b/project2/variables.cpp @@ -12,9 +12,9 @@ #include <boost/bind.hpp> #include <boost/date_time/posix_time/posix_time.hpp> -class UnknownVariableType : public std::exception { }; -class UnknownVariableSource : public std::exception { }; -class NoVariableDefinition : public std::exception { }; +SimpleMessageException(UnknownVariableType); +SimpleMessageException(UnknownVariableSource); +SimpleMessageException(NoVariableDefinition); enum VT_typeID { DefaultType, @@ -49,13 +49,14 @@ getVariableTypeFromName(const std::string & src) if (src == "double") return Double; if (src == "datetime") return DateTime; if (src == "datetimeptr") return DateTimePtr; - throw UnknownVariableType(); + throw UnknownVariableType(src); } static VariableType makeVariableType(const Glib::ustring & src, const VT_typeID format = DefaultType) { switch (format) { + default: case DefaultType: case StringPtr: return boost::shared_ptr<Glib::ustring>(new Glib::ustring(src)); @@ -82,7 +83,6 @@ makeVariableType(const Glib::ustring & src, const VT_typeID format = DefaultType case DateTimePtr: return boost::shared_ptr<boost::posix_time::ptime>(new boost::posix_time::ptime(boost::posix_time::time_from_string(src))); } - throw UnknownVariableType(); } VariableType::VariableType() : @@ -268,7 +268,7 @@ class VariableParent : public VariableImplDyn, public RowUser { RowSet::RowValuesStack::const_reverse_iterator r = RowSet::Stack().rbegin(); for (size_t p = depth; p--; r++) ; if (r == RowSet::Stack().rend()) { - throw RowSet::ParentOutOfRange(); + throw RowSet::ParentOutOfRange(depth); } row = *r; row->use(this); @@ -377,7 +377,7 @@ Variable::Variable(const xmlpp::Element * e, const Glib::ustring & n, bool requi else if (source == "literal" || source.empty()) var = new VariableLiteral(c->get_attribute_value("value"), getVariableTypeFromName(c->get_attribute_value("type"))); else - throw UnknownVariableSource(); + throw UnknownVariableSource(source); return; } } @@ -385,7 +385,7 @@ Variable::Variable(const xmlpp::Element * e, const Glib::ustring & n, bool requi var = new VariableFixed(def); return; } - throw NoVariableDefinition(); + throw NoVariableDefinition(n); } Variable::Variable(VariableImpl * v) : diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h index 4d0346e..d1209c7 100644 --- a/project2/xmlObjectLoader.h +++ b/project2/xmlObjectLoader.h @@ -9,13 +9,14 @@ #include <boost/foreach.hpp> #include "intrusivePtrBase.h" #include "sourceObject.h" +#include "exceptions.h" #include <boost/multi_index_container.hpp> #include <boost/multi_index/member.hpp> #include <boost/multi_index/ordered_index.hpp> Glib::ustring xmlChildText(const xmlpp::Node * p, const Glib::ustring & n); -class StoreFailed : public std::exception { }; +SimpleMessageException(StoreFailed); struct bySOName { }; struct bySOOrder { }; diff --git a/project2/xmlRows.cpp b/project2/xmlRows.cpp index 965b8a3..0056084 100644 --- a/project2/xmlRows.cpp +++ b/project2/xmlRows.cpp @@ -66,7 +66,7 @@ XmlRows::getCurrentValue(const Glib::ustring & id) const { Values::const_iterator i = values.find(id); if (i == values.end()) { - throw FieldDoesNotExist(); + throw FieldDoesNotExist(id); } return i->second; } @@ -76,7 +76,7 @@ XmlRows::getCurrentValue(unsigned int col) const { Values::const_iterator i = values.find(fieldNames[col]); if (i == values.end()) { - throw FieldDoesNotExist(); + throw FieldDoesNotExist(""); } return i->second; } 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; |