diff options
author | randomdan <randomdan@localhost> | 2010-06-10 18:18:39 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2010-06-10 18:18:39 +0000 |
commit | b91a4a2cb097b62daf8a3f74566b4d0b6b42258d (patch) | |
tree | 4b90718a96e8c22b796c0158178a4173fe32c3a5 /project2/envproc.cpp | |
parent | Initial workings of project2 - renders gentoobrowse homepage (diff) | |
download | project2-b91a4a2cb097b62daf8a3f74566b4d0b6b42258d.tar.bz2 project2-b91a4a2cb097b62daf8a3f74566b4d0b6b42258d.tar.xz project2-b91a4a2cb097b62daf8a3f74566b4d0b6b42258d.zip |
Use xml++ with glib utf8
Diffstat (limited to 'project2/envproc.cpp')
-rw-r--r-- | project2/envproc.cpp | 50 |
1 files changed, 29 insertions, 21 deletions
diff --git a/project2/envproc.cpp b/project2/envproc.cpp index 0313c0f..f280aa0 100644 --- a/project2/envproc.cpp +++ b/project2/envproc.cpp @@ -2,7 +2,7 @@ #include "rdbmsDataSource.h" #include "sqlView.h" #include <map> -#include <libxml/tree.h> +#include <libxml++/parsers/domparser.h> #include <libxml/xinclude.h> #include <boost/shared_ptr.hpp> #include <boost/any.hpp> @@ -18,12 +18,15 @@ EnvironmentProcessor::init() template <class X, class Y> void -collectAll(std::map<ustring, Y> & objs, xmlNodePtr node, const ustring & name) +collectAll(std::map<std::string, Y> & objs, const xmlpp::Element * node, const Glib::ustring & name) { - if (name == node->name) { + if (!node) { + return; + } + if (name == node->get_name()) { fprintf(stderr, "Found a %s\n", name.c_str()); try { - objs[xmlGetProp(node, BAD_CAST "name")] = Y(new X(node)); + objs[node->get_attribute_value("name").raw()] = Y(new X(node)); fprintf(stderr, "Load succeeded\n"); } catch (const std::exception & e) { @@ -36,43 +39,48 @@ collectAll(std::map<ustring, Y> & objs, xmlNodePtr node, const ustring & name) } } else { - for (xmlNodePtr child = node->children; child; child = child->next) { - collectAll<X, Y>(objs, child, name); + BOOST_FOREACH(xmlpp::Node * child, node->get_children()) { + collectAll<X, Y>(objs, dynamic_cast<const xmlpp::Element *>(child), name); } } } -xmlDocPtr +boost::shared_ptr<xmlpp::Document> EnvironmentProcessor::process() { - xmlDocPtr doc = xmlNewDoc(BAD_CAST "1.0"); - xmlDocPtr pageXDoc = xmlReadFile(("present/" + page + ".xml").c_str(), NULL, XML_PARSE_XINCLUDE); - while (xmlXIncludeProcess(pageXDoc) > 0); - xmlNodePtr root = xmlDocGetRootElement(pageXDoc); + fprintf(stderr, "parsing present .xml\n"); + xmlpp::DomParser present("present/" + page + ".xml"); + fprintf(stderr, "performing xincludes\n"); + while (xmlXIncludeProcessFlags(present.get_document()->cobj(), XML_PARSE_NOXINCNODE) > 0); + fprintf(stderr, "getting root\n"); + xmlpp::Element * presentRoot = present.get_document()->get_root_node(); // Collect datasources + fprintf(stderr, "collecting datasources\n"); RdbmsDataSources rdbmsDataSources; - collectAll<_RdbmsDataSource>(rdbmsDataSources, root, BAD_CAST "rdbmsdatasource"); + collectAll<_RdbmsDataSource>(rdbmsDataSources, presentRoot, "rdbmsdatasource"); // Collect views + fprintf(stderr, "collecting sqlviews\n"); SqlViews sqlViews; - collectAll<_SqlView>(sqlViews, root, BAD_CAST "sqlview"); + collectAll<_SqlView>(sqlViews, presentRoot, "sqlview"); // - xmlNodePtr root_node = xmlNewNode(NULL, xmlGetProp(root, BAD_CAST "root")); + 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, root_node); + s.second->execute(rdbmsDataSources, responseRoot); } } catch (...) { } - xmlDocSetRootElement(doc, root_node); + fprintf(stderr, "done views\n"); char * buf; if (asprintf(&buf, "type=\"text/xsl\" href=\"%s\"", - xmlGetProp(root, BAD_CAST "style")) > 0) { - xmlAddPrevSibling(root_node, - xmlNewDocPI(doc, BAD_CAST "xml-stylesheet", BAD_CAST buf)); + presentRoot->get_attribute_value("style").c_str()) > 0) { + xmlAddPrevSibling(responseRoot->cobj(), + xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf)); } free(buf); - xmlFreeDoc(pageXDoc); - return doc; + fprintf(stderr, "done style pi\n"); + return responseDoc; } |