diff options
author | randomdan <randomdan@localhost> | 2010-06-11 09:03:42 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-06-11 09:03:42 +0000 |
commit | 2e2223e48619d16bd39036a0d840ceb3ed195a9b (patch) | |
tree | f9ac70ea97c2ea99c525943aa76bd559de746396 /project2/envproc.cpp | |
parent | Use xml++ with glib utf8 (diff) | |
download | project2-2e2223e48619d16bd39036a0d840ceb3ed195a9b.tar.bz2 project2-2e2223e48619d16bd39036a0d840ceb3ed195a9b.tar.xz project2-2e2223e48619d16bd39036a0d840ceb3ed195a9b.zip |
Use Glib::ustring in libodbcpp for data and std::string for non-data
Add support for parameters in SqlViews
Uses parameters to implement category browse and search
Diffstat (limited to 'project2/envproc.cpp')
-rw-r--r-- | project2/envproc.cpp | 71 |
1 files changed, 39 insertions, 32 deletions
diff --git a/project2/envproc.cpp b/project2/envproc.cpp index f280aa0..e5c2a52 100644 --- a/project2/envproc.cpp +++ b/project2/envproc.cpp @@ -1,3 +1,4 @@ +#include "xmlObjectLoader.h" #include "envproc.h" #include "rdbmsDataSource.h" #include "sqlView.h" @@ -16,37 +17,9 @@ EnvironmentProcessor::init() page = elems.size() > 0 ? elems[0] : "index"; } -template <class X, class Y> -void -collectAll(std::map<std::string, Y> & objs, const xmlpp::Element * node, const Glib::ustring & name) -{ - if (!node) { - return; - } - if (name == node->get_name()) { - fprintf(stderr, "Found a %s\n", name.c_str()); - try { - objs[node->get_attribute_value("name").raw()] = Y(new X(node)); - fprintf(stderr, "Load succeeded\n"); - } - catch (const std::exception & e) { - // Assume the XML node is what we thought it was - fprintf(stderr, "Load failed (%s)\n", e.what()); - } - catch (...) { - // Assume the XML node is what we thought it was - fprintf(stderr, "Load failed\n"); - } - } - else { - BOOST_FOREACH(xmlpp::Node * child, node->get_children()) { - collectAll<X, Y>(objs, dynamic_cast<const xmlpp::Element *>(child), name); - } - } -} boost::shared_ptr<xmlpp::Document> -EnvironmentProcessor::process() +EnvironmentProcessor::process() const { fprintf(stderr, "parsing present .xml\n"); xmlpp::DomParser present("present/" + page + ".xml"); @@ -57,22 +30,39 @@ EnvironmentProcessor::process() // Collect datasources fprintf(stderr, "collecting datasources\n"); RdbmsDataSources rdbmsDataSources; - collectAll<_RdbmsDataSource>(rdbmsDataSources, presentRoot, "rdbmsdatasource"); + collectAll<_RdbmsDataSource>(rdbmsDataSources, presentRoot, "rdbmsdatasource", &_Project2SourceObject::name); // Collect views fprintf(stderr, "collecting sqlviews\n"); SqlViews sqlViews; - collectAll<_SqlView>(sqlViews, presentRoot, "sqlview"); + collectAll<_SqlView>(sqlViews, presentRoot, "sqlview", &_SqlView::name); // boost::shared_ptr<xmlpp::Document> responseDoc = boost::shared_ptr<xmlpp::Document>(new xmlpp::Document("1.0")); xmlpp::Element * responseRoot = responseDoc->create_root_node(presentRoot->get_attribute_value("root")); try { BOOST_FOREACH(SqlViews::value_type s, sqlViews) { - s.second->execute(rdbmsDataSources, responseRoot); + s.second->execute(rdbmsDataSources, responseRoot, this); } } catch (...) { } fprintf(stderr, "done views\n"); + // These were for debug... but why not pass them on? + xmlNewNs(responseRoot->cobj(), BAD_CAST "http://project2.randomdan.homeip.net/", BAD_CAST "project2"); + responseRoot->add_child("fqdn", "project2")->set_child_text(http_host); + responseRoot->add_child("requesturi", "project2")->set_child_text(request_uri); + // URL elements + xmlpp::Element * uriElems = responseRoot->add_child("uriElems", "project2"); + BOOST_FOREACH(std::string s, elems) { + uriElems->add_child("uriElem", "project2")->set_child_text(s); + } + // Parameters + xmlpp::Element * paramsXml = responseRoot->add_child("params", "project2"); + BOOST_FOREACH(RegMultiMatch::value_type u, params) { + xmlpp::Element * param = paramsXml->add_child("param", "project2"); + param->add_child_text(u[1]); + param->set_attribute("name", u[0]); + } + // XSLT Style char * buf; if (asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", presentRoot->get_attribute_value("style").c_str()) > 0) { @@ -84,3 +74,20 @@ EnvironmentProcessor::process() return responseDoc; } +Glib::ustring +EnvironmentProcessor::getParamUri(const std::string & p) const +{ + return elems[atoi(p.c_str())]; +} + +Glib::ustring +EnvironmentProcessor::getParamQuery(const std::string & p) const +{ + BOOST_FOREACH(RegMultiMatch::value_type u, params) { + if (u[0] == p) { + return u[1]; + } + } + return Glib::ustring(); +} + |