summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2010-11-01 20:18:43 +0000
committerrandomdan <randomdan@localhost>2010-11-01 20:18:43 +0000
commit4dce603e8400ef352ec84382b7e79ab4379115d8 (patch)
tree0e414072081bdca167231043f0fcbf5bd14b91ee
parentSplit up libs even more (diff)
downloadproject2-4dce603e8400ef352ec84382b7e79ab4379115d8.tar.bz2
project2-4dce603e8400ef352ec84382b7e79ab4379115d8.tar.xz
project2-4dce603e8400ef352ec84382b7e79ab4379115d8.zip
Improve XML usage correctness
-rw-r--r--project2/cgi/cgiAppEngine.cpp4
-rw-r--r--project2/console/consoleAppEngine.cpp5
-rw-r--r--project2/iHaveParameters.cpp11
-rw-r--r--project2/iterate.cpp4
-rw-r--r--project2/presenter.cpp6
-rw-r--r--project2/sqlMergeTask.cpp4
-rw-r--r--project2/view.cpp4
-rw-r--r--project2/xmlObjectLoader.cpp46
-rw-r--r--project2/xmlObjectLoader.h12
9 files changed, 62 insertions, 34 deletions
diff --git a/project2/cgi/cgiAppEngine.cpp b/project2/cgi/cgiAppEngine.cpp
index e419ddf..94de818 100644
--- a/project2/cgi/cgiAppEngine.cpp
+++ b/project2/cgi/cgiAppEngine.cpp
@@ -147,11 +147,11 @@ CgiApplicationEngine::RequestStage::RequestStage(const CgiApplicationEngine * e,
xmlpp::Element * requestRoot = request.get_document()->get_root_node();
present = requestRoot->get_attribute_value("present");
- LoaderBase loader;
+ LoaderBase loader("http://project2.randomdan.homeip.net", true);
loader.supportedStorers.insert(Storer::into(&appEngine->datasources));
loader.supportedStorers.insert(Storer::into(&parameterChecks));
loader.supportedStorers.insert(Storer::into(&tasks));
- loader.collectAll("project2", requestRoot, true, true);
+ loader.collectAll(requestRoot, true);
}
CgiApplicationEngine::RequestStage::~RequestStage()
{
diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp
index d46d091..98d280d 100644
--- a/project2/console/consoleAppEngine.cpp
+++ b/project2/console/consoleAppEngine.cpp
@@ -55,13 +55,12 @@ ConsoleApplicationEngine::ConsoleApplicationEngine(const ConsoleEnvironment * en
{
xmlpp::DomParser request(f.string());
while (xmlXIncludeProcessFlags(request.get_document()->cobj(), XML_PARSE_NOXINCNODE) > 0);
- xmlpp::Element * requestRoot = request.get_document()->get_root_node();
- LoaderBase loader;
+ LoaderBase loader("http://project2.randomdan.homeip.net", true);
loader.supportedStorers.insert(Storer::into(&this->datasources));
loader.supportedStorers.insert(Storer::into(&parameterChecks));
loader.supportedStorers.insert(Storer::into(&tasks));
- loader.collectAll("project2", requestRoot, true, true);
+ loader.collectAll(request.get_document()->get_root_node(), true);
}
ConsoleApplicationEngine::~ConsoleApplicationEngine()
diff --git a/project2/iHaveParameters.cpp b/project2/iHaveParameters.cpp
index c4006b9..9ba917d 100644
--- a/project2/iHaveParameters.cpp
+++ b/project2/iHaveParameters.cpp
@@ -4,11 +4,12 @@
IHaveParameters::IHaveParameters(const xmlpp::Element * p)
{
- xmlpp::NodeSet ps = p->find("parameters");
- BOOST_FOREACH(xmlpp::Node * psi, ps) {
- LoaderBase loader;
- loader.supportedStorers.insert(Storer::into(&parameters));
- loader.collectAll("", dynamic_cast<const xmlpp::Element *>(psi), false, true);
+ BOOST_FOREACH(xmlpp::Node * node, p->find("parameters/param")) {
+ const xmlpp::Element * elem = dynamic_cast<const xmlpp::Element *>(node);
+ if (elem) {
+ Parameter p = new _Parameter(elem);
+ parameters[p->bind] = p;
+ }
}
}
diff --git a/project2/iterate.cpp b/project2/iterate.cpp
index d245536..d114acb 100644
--- a/project2/iterate.cpp
+++ b/project2/iterate.cpp
@@ -7,9 +7,9 @@ _Iterate::_Iterate(const xmlpp::Element * p) :
_SourceObject(p),
_NoOutputExecute(p)
{
- LoaderBase loader;
+ LoaderBase loader("http://project2.randomdan.homeip.net", true);
loader.supportedStorers.insert(Storer::into(&subNOEs));
- loader.collectAll("project2", p, true, true);
+ loader.collectAll(p, true);
}
_Iterate::~_Iterate()
diff --git a/project2/presenter.cpp b/project2/presenter.cpp
index 3743e68..71ed45b 100644
--- a/project2/presenter.cpp
+++ b/project2/presenter.cpp
@@ -10,11 +10,11 @@ Presenter::Presenter(const std::string & group, const std::string & file) :
{
while (xmlXIncludeProcessFlags(present.get_document()->cobj(), XML_PARSE_NOXINCNODE) > 0);
- LoaderBase loader;
+ LoaderBase loader("http://project2.randomdan.homeip.net", true);
loader.supportedStorers.insert(Storer::into(&ApplicationEngine::getCurrent()->datasources));
loader.supportedStorers.insert(Storer::into(&views));
loader.supportedStorers.insert(Storer::into(&parameterChecks));
- loader.collectAll("project2", present.get_document()->get_root_node(), true, true);
+ loader.collectAll(present.get_document()->get_root_node(), true);
}
Presenter::~Presenter()
@@ -31,7 +31,7 @@ Presenter::getDataDocument() const
s.second->execute(responseRoot);
}
// These were for debug... but why not pass them on?
- xmlNewNs(responseRoot->cobj(), BAD_CAST "http://project2.randomdan.homeip.net/", BAD_CAST "project2");
+ xmlNewNs(responseRoot->cobj(), BAD_CAST "http://project2.randomdan.homeip.net", BAD_CAST "project2");
responseRoot->add_child("servername", "project2")->set_child_text(appEngine->env()->getServerName());
responseRoot->add_child("scriptname", "project2")->set_child_text(appEngine->env()->getScriptName());
return responseDoc;
diff --git a/project2/sqlMergeTask.cpp b/project2/sqlMergeTask.cpp
index f8177d5..318ab4f 100644
--- a/project2/sqlMergeTask.cpp
+++ b/project2/sqlMergeTask.cpp
@@ -26,9 +26,9 @@ _SqlMergeTask::_SqlMergeTask(const xmlpp::Element * p) :
dtable(p->get_attribute_value("targettable")),
dtablet(stringf("tmp_%s_%d", dtable.c_str(), getpid()))
{
- LoaderBase loader;
+ LoaderBase loader("http://project2.randomdan.homeip.net", true);
loader.supportedStorers.insert(Storer::into(&sources));
- loader.collectAll("project2", p, true, true);
+ loader.collectAll(p, true);
if (!sources.empty() && useView) {
throw std::runtime_error("useview not supported with iterate fillers");
diff --git a/project2/view.cpp b/project2/view.cpp
index 8ed5f65..44a162a 100644
--- a/project2/view.cpp
+++ b/project2/view.cpp
@@ -5,9 +5,9 @@ _View::_View(const xmlpp::Element * p) :
_SourceObject(p),
recordName(p->get_attribute_value("recordname"))
{
- LoaderBase loader;
+ LoaderBase loader("http://project2.randomdan.homeip.net", true);
loader.supportedStorers.insert(Storer::into(&subViews));
- loader.collectAll("project2", p, true, true);
+ loader.collectAll(p, true);
}
_View::~_View()
diff --git a/project2/xmlObjectLoader.cpp b/project2/xmlObjectLoader.cpp
index 9b4b24b..e789275 100644
--- a/project2/xmlObjectLoader.cpp
+++ b/project2/xmlObjectLoader.cpp
@@ -12,16 +12,26 @@ LoaderBase::getMap()
return loaders;
}
+LoaderBase::LoaderBase(const Glib::ustring & n, bool r) :
+ recursive(r),
+ ns(n)
+{
+}
+
+LoaderBase::~LoaderBase()
+{
+}
+
void
-LoaderBase::collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) const
+LoaderBase::collectAll(const xmlpp::Element * node, bool childrenOnly) const
{
if (!node) {
return;
}
depth += 1;
- if (!childrenOnly && ns == node->get_namespace_prefix()) {
+ unsigned int created = 0;
+ if (!childrenOnly && node->get_namespace_uri() == ns) {
Glib::ustring name = node->get_name();
- unsigned int created = 0;
unsigned int stored = 0;
for(ElementLoaderMap::const_iterator i = getMap().lower_bound(name); i != getMap().upper_bound(name); i++) {
Project2SourceObject o = i->second->go(node);
@@ -33,17 +43,13 @@ LoaderBase::collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bo
}
}
}
- if (created < 1) {
- fprintf(stderr, "Didn't create any objects for %s:%s\n", ns.c_str(), name.c_str());
- throw std::runtime_error("Unknown object");
- }
- if (stored < 1) {
- throw std::runtime_error("Unsupported object");
+ if (stored < created) {
+ throw std::runtime_error("Unexpected object");
}
}
- else if (recursive || childrenOnly) {
- BOOST_FOREACH(xmlpp::Node * child, node->get_children()) {
- collectAll(ns, dynamic_cast<const xmlpp::Element *>(child), recursive, false);
+ if (created == 0 && (recursive || childrenOnly)) {
+ BOOST_FOREACH(const xmlpp::Node * child, node->get_children()) {
+ collectAll(dynamic_cast<const xmlpp::Element *>(child), false);
}
}
depth -= 1;
@@ -84,6 +90,22 @@ ElementLoader::onIdle()
{
}
+Glib::ustring
+xmlChildText(const xmlpp::Node * p, const Glib::ustring & t)
+{
+ Glib::ustring rtn;
+ BOOST_FOREACH(const xmlpp::Node * child, p->get_children(t)) {
+ const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(child);
+ if (e) {
+ const xmlpp::ContentNode * cn = e->get_child_text();
+ if (cn) {
+ rtn += cn->get_content();
+ }
+ }
+ }
+ return rtn;
+}
+
void
ElementLoader::onIteration()
{
diff --git a/project2/xmlObjectLoader.h b/project2/xmlObjectLoader.h
index 56cdfac..8b71561 100644
--- a/project2/xmlObjectLoader.h
+++ b/project2/xmlObjectLoader.h
@@ -12,7 +12,7 @@
#include "intrusivePtrBase.h"
#include "sourceObject.h"
-#define xmlChildText(p, t) dynamic_cast<const xmlpp::Element&>(*p->get_children(t).front()).get_child_text()->get_content()
+Glib::ustring xmlChildText(const xmlpp::Node * p, const Glib::ustring & n);
class ElementLoader;
@@ -85,7 +85,9 @@ class LoaderBase {
public:
typedef std::map<std::string, ElementLoader *> ElementLoaderMap;
- void collectAll(const Glib::ustring & ns, const xmlpp::Element * node, bool recursive, bool childrenOnly) const;
+ LoaderBase(const Glib::ustring & ns, bool recursive);
+ virtual ~LoaderBase();
+ void collectAll(const xmlpp::Element * node, bool childrenOnly) const;
static ElementLoaderMap & getMap();
template<class Y>
@@ -101,6 +103,10 @@ class LoaderBase {
private:
static unsigned int depth;
static std::set<Project2SourceObject> loadedObjects;
+
+ const bool recursive;
+ public:
+ const Glib::ustring ns;
};
class ElementLoader {
@@ -128,7 +134,7 @@ class ElementLoaderImpl : ElementLoader {
return new X(xml);
}
- const std::string xmlName;
+ const Glib::ustring xmlName;
private:
};