summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--project2/Jamfile.jam1
-rw-r--r--project2/cgi/cgiEnvironment.cpp15
-rw-r--r--project2/cgi/cgiStageCustomError.cpp4
-rw-r--r--project2/cgi/cgiStageCustomNotFound.cpp4
-rw-r--r--project2/cgi/cgiStageInitial.cpp4
-rw-r--r--project2/cgi/cgiStagePresent.cpp12
-rw-r--r--project2/cgi/cgiStageRequest.cpp6
-rw-r--r--project2/checkHost.cpp8
-rw-r--r--project2/checkHost.h3
-rw-r--r--project2/commonObjects.cpp5
-rw-r--r--project2/console/consoleAppEngine.cpp8
-rw-r--r--project2/environment.cpp25
-rw-r--r--project2/environment.h5
-rw-r--r--project2/sendmailTask.cpp3
-rw-r--r--project2/taskHost.cpp9
-rw-r--r--project2/taskHost.h3
-rw-r--r--project2/viewHost.cpp10
-rw-r--r--project2/viewHost.h3
-rw-r--r--project2/xmlScriptParser.cpp24
-rw-r--r--project2/xmlScriptParser.h6
20 files changed, 81 insertions, 77 deletions
diff --git a/project2/Jamfile.jam b/project2/Jamfile.jam
index 6015b7e..af19cee 100644
--- a/project2/Jamfile.jam
+++ b/project2/Jamfile.jam
@@ -194,6 +194,7 @@ lib p2web :
<library>p2uuid
<library>boost_program_options
<library>boost_regex
+ <library>boost_filesystem
<library>p2xmlSession
: :
<library>p2parts
diff --git a/project2/cgi/cgiEnvironment.cpp b/project2/cgi/cgiEnvironment.cpp
index 2bc3b02..21799db 100644
--- a/project2/cgi/cgiEnvironment.cpp
+++ b/project2/cgi/cgiEnvironment.cpp
@@ -3,18 +3,23 @@
#include "../exceptions.h"
#include <map>
#include <cgicc/Cgicc.h>
-#include <boost/tokenizer.hpp>
-template <class X, class Y>
-std::vector<X>makeVector(const Y & y)
+std::vector<std::string>
+makeVector(const boost::filesystem::path & y)
{
- return std::vector<X>(y.begin(), y.end());
+ std::vector<std::string> r;
+ boost::filesystem::path::iterator p = y.begin();
+ p++;
+ while(p != y.end()) {
+ r.push_back((p++)->string());
+ }
+ return r;
}
CgiEnvironment::CgiEnvironment(cgicc::Cgicc * c) :
Environment(0, NULL),
cgicc::CgiEnvironment(c->getEnvironment()),
- elems(makeVector<std::string>(boost::tokenizer<boost::char_separator<char> >(getRedirectURL(), boost::char_separator<char>("/")))),
+ elems(makeVector(boost::filesystem::path(getRedirectURL()))),
cgi(c)
{
}
diff --git a/project2/cgi/cgiStageCustomError.cpp b/project2/cgi/cgiStageCustomError.cpp
index fb2f0de..26fdf51 100644
--- a/project2/cgi/cgiStageCustomError.cpp
+++ b/project2/cgi/cgiStageCustomError.cpp
@@ -5,8 +5,8 @@
CgiApplicationEngine::CustomErrorStage::CustomErrorStage(const CgiEnvironment * env, const std::exception & ex) :
CgiApplicationEngine::ResponseStage(env),
- ::XmlScriptParser(env->errorPresentRoot, env->onErrorPresent, false),
- ::CheckHost(env->errorPresentRoot, env->onErrorPresent),
+ ::XmlScriptParser(e->resolveScript(env->errorPresentRoot, env->onErrorPresent), false),
+ ::CheckHost(e->resolveScript(env->errorPresentRoot, env->onErrorPresent)),
CgiApplicationEngine::DefaultErrorStage(env, ex),
CgiApplicationEngine::PresentStage(env, env->errorPresentRoot, env->onErrorPresent)
{
diff --git a/project2/cgi/cgiStageCustomNotFound.cpp b/project2/cgi/cgiStageCustomNotFound.cpp
index 7c08a9f..4f06c2e 100644
--- a/project2/cgi/cgiStageCustomNotFound.cpp
+++ b/project2/cgi/cgiStageCustomNotFound.cpp
@@ -5,8 +5,8 @@
CgiApplicationEngine::CustomNotFoundStage::CustomNotFoundStage(const CgiEnvironment * env, const ::XmlScriptParser::NotFound & notfound) :
CgiApplicationEngine::ResponseStage(env),
- ::XmlScriptParser(env->errorPresentRoot, env->notFoundPresent, false),
- ::CheckHost(env->errorPresentRoot, env->notFoundPresent),
+ ::XmlScriptParser(e->resolveScript(env->errorPresentRoot, env->notFoundPresent), false),
+ ::CheckHost(e->resolveScript(env->errorPresentRoot, env->notFoundPresent)),
CgiApplicationEngine::DefaultNotFoundStage(env, notfound),
CgiApplicationEngine::PresentStage(env, env->errorPresentRoot, env->notFoundPresent)
{
diff --git a/project2/cgi/cgiStageInitial.cpp b/project2/cgi/cgiStageInitial.cpp
index 1db8f8f..7c7b198 100644
--- a/project2/cgi/cgiStageInitial.cpp
+++ b/project2/cgi/cgiStageInitial.cpp
@@ -16,10 +16,10 @@ CgiApplicationEngine::InitialStage::run()
if (e->elems.empty()) {
throw EmptyRequestURL();
}
- return NextStage(new RequestStage(e, e->elems[0]));
+ return NextStage(new RequestStage(e, e->getRedirectURL()));
}
else {
- return NextStage(new PresentStage(e, e->elems.empty() ? e->defaultPresent : e->elems[0]));
+ return NextStage(new PresentStage(e, e->elems.empty() ? e->defaultPresent : e->getRedirectURL()));
}
}
diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp
index 6091ed8..4920623 100644
--- a/project2/cgi/cgiStagePresent.cpp
+++ b/project2/cgi/cgiStagePresent.cpp
@@ -6,17 +6,17 @@
CgiApplicationEngine::PresentStage::PresentStage(const CgiEnvironment * e, const std::string & id) :
CgiApplicationEngine::ResponseStage(e),
- XmlScriptParser(e->presentRoot, id, false),
- CheckHost(e->presentRoot, id),
- ViewHost(e->presentRoot, id)
+ XmlScriptParser(e->resolveScript(e->presentRoot, id), false),
+ CheckHost(e->resolveScript(e->presentRoot, id)),
+ ViewHost(e->resolveScript(e->presentRoot, id))
{
}
CgiApplicationEngine::PresentStage::PresentStage(const CgiEnvironment * e, const std::string & group, const std::string & id) :
CgiApplicationEngine::ResponseStage(e),
- XmlScriptParser(group, id, false),
- CheckHost(group, id),
- ViewHost(group, id)
+ XmlScriptParser(e->resolveScript(group, id), false),
+ CheckHost(e->resolveScript(group, id)),
+ ViewHost(e->resolveScript(group, id))
{
}
diff --git a/project2/cgi/cgiStageRequest.cpp b/project2/cgi/cgiStageRequest.cpp
index ee72b81..c53a172 100644
--- a/project2/cgi/cgiStageRequest.cpp
+++ b/project2/cgi/cgiStageRequest.cpp
@@ -5,10 +5,10 @@
#include <boost/foreach.hpp>
CgiApplicationEngine::RequestStage::RequestStage(const CgiEnvironment * e, const std::string & id) :
- XmlScriptParser(e->requestRoot, id, false),
- ::CheckHost(e->requestRoot, id),
+ XmlScriptParser(e->resolveScript(e->requestRoot, id), false),
+ ::CheckHost(e->resolveScript(e->requestRoot, id)),
CgiApplicationEngine::ResponseStage(e),
- ::TaskHost(e->requestRoot, id)
+ ::TaskHost(e->resolveScript(e->requestRoot, id))
{
xmlpp::Element * requestRoot = get_document()->get_root_node();
present = requestRoot->get_attribute_value("present");
diff --git a/project2/checkHost.cpp b/project2/checkHost.cpp
index cda07fc..a39c176 100644
--- a/project2/checkHost.cpp
+++ b/project2/checkHost.cpp
@@ -2,13 +2,7 @@
#include "appEngine.h"
#include <boost/foreach.hpp>
-CheckHost::CheckHost(const std::string & group, const std::string & name) :
- XmlScriptParser(group, name, false)
-{
- loader.supportedStorers.insert(Storer::into(&parameterChecks));
-}
-
-CheckHost::CheckHost(const std::string & file) :
+CheckHost::CheckHost(const boost::filesystem::path & file) :
XmlScriptParser(file, false)
{
loader.supportedStorers.insert(Storer::into(&parameterChecks));
diff --git a/project2/checkHost.h b/project2/checkHost.h
index 759c7a0..54fc96d 100644
--- a/project2/checkHost.h
+++ b/project2/checkHost.h
@@ -15,8 +15,7 @@ class CheckHost : public virtual XmlScriptParser {
~CheckFailure() throw();
const ParamCheckerCPtr failedCheck;
};
- CheckHost(const std::string & group, const std::string & file);
- CheckHost(const std::string & file);
+ CheckHost(const boost::filesystem::path & file);
~CheckHost();
void runChecks() const;
diff --git a/project2/commonObjects.cpp b/project2/commonObjects.cpp
index 1d0b13e..63d4d1d 100644
--- a/project2/commonObjects.cpp
+++ b/project2/commonObjects.cpp
@@ -5,8 +5,6 @@
CommonObjects::~CommonObjects()
{
- rowSets.clear();
- datasources.clear();
}
RowSetPtr
@@ -22,7 +20,8 @@ CommonObjects::getSource(const std::string & name) const
CommonObjects::DataSources::const_iterator
CommonObjects::loadDataSource(const std::string & name) const
{
- XmlScriptParser xml(ApplicationEngine::getCurrent()->env()->getDatasourceRoot(), name, true);
+ XmlScriptParser xml(Environment::getCurrent()->resolveScript(
+ Environment::getCurrent()->getDatasourceRoot(), name), true);
LoaderBase loader(true);
loader.supportedStorers.insert(Storer::into(&datasources));
diff --git a/project2/console/consoleAppEngine.cpp b/project2/console/consoleAppEngine.cpp
index dab1c46..49a5842 100644
--- a/project2/console/consoleAppEngine.cpp
+++ b/project2/console/consoleAppEngine.cpp
@@ -54,11 +54,11 @@ class ConsoleSession : public Session {
};
ConsoleApplicationEngine::ConsoleApplicationEngine(const ConsoleEnvironment * env, const boost::filesystem::path & f) :
- XmlScriptParser(f.string(), false),
- CheckHost(f.string()),
+ XmlScriptParser(f, false),
+ CheckHost(f),
ApplicationEngine("console/environment"),
- TaskHost(f.string()),
- ViewHost(f.string()),
+ TaskHost(f),
+ ViewHost(f),
_env(env),
runtime(new ConsoleSession())
{
diff --git a/project2/environment.cpp b/project2/environment.cpp
index 69cdde7..8a03af9 100644
--- a/project2/environment.cpp
+++ b/project2/environment.cpp
@@ -3,6 +3,7 @@
#include <stdio.h>
#include <fstream>
#include <boost/filesystem/convenience.hpp>
+#include <boost/foreach.hpp>
namespace po = boost::program_options;
@@ -91,3 +92,27 @@ Environment::getCurrent()
return currentEnv;
}
+boost::filesystem::path
+Environment::resolveScript(const std::string & group, const std::string & name) const
+{
+ boost::filesystem::path script(boost::filesystem::current_path() / group);
+ BOOST_FOREACH(const boost::filesystem::path & e, boost::filesystem::path(name)) {
+ if (boost::filesystem::is_directory(script / e)) {
+ script /= e;
+ }
+ else {
+ if (boost::filesystem::is_regular_file((script / e).replace_extension(".xml"))) {
+ return ((script / e).replace_extension(".xml"));
+ }
+ }
+ }
+ return script;
+}
+
+boost::filesystem::path
+Environment::resolveScript(const std::string & path) const
+{
+ boost::filesystem::path script(boost::filesystem::current_path());
+ return script / path;
+}
+
diff --git a/project2/environment.h b/project2/environment.h
index e515741..6a822c7 100644
--- a/project2/environment.h
+++ b/project2/environment.h
@@ -5,6 +5,7 @@
#include <glibmm/ustring.h>
#include <boost/program_options.hpp>
#include <boost/function.hpp>
+#include <boost/filesystem/path.hpp>
class Environment {
public:
@@ -24,6 +25,10 @@ class Environment {
virtual std::string getServerName() const = 0;
virtual std::string getScriptName() const = 0;
+
+ boost::filesystem::path resolveScript(const std::string & group, const std::string & name) const;
+ boost::filesystem::path resolveScript(const std::string & path) const;
+
private:
static const Environment * currentEnv;
diff --git a/project2/sendmailTask.cpp b/project2/sendmailTask.cpp
index 073022f..fa9a4a3 100644
--- a/project2/sendmailTask.cpp
+++ b/project2/sendmailTask.cpp
@@ -4,6 +4,7 @@
#include <boost/bind.hpp>
#include "xmlObjectLoader.h"
#include "viewHost.h"
+#include "environment.h"
#include <stdexcept>
#include <libesmtp.h>
#include "xmlPresenter.h"
@@ -198,7 +199,7 @@ SendMailTask::execute() const
parts->parts.insert(new Header("Content-Transfer-Encoding", "binary"));
parts->parts.insert(new BoundaryEnd());
- ViewHostPtr vsp = new ViewHost("emails", present);
+ ViewHostPtr vsp = new ViewHost(Environment::getCurrent()->resolveScript("emails", present));
vsp->executeViews(boost::bind(&SendMailTask::createDefaultPresenter, this, _1));
vsp->doTransforms();
part = parts->parts.begin();
diff --git a/project2/taskHost.cpp b/project2/taskHost.cpp
index 20595f9..0fc1453 100644
--- a/project2/taskHost.cpp
+++ b/project2/taskHost.cpp
@@ -3,14 +3,7 @@
#include "dataSource.h"
#include <boost/foreach.hpp>
-TaskHost::TaskHost(const std::string & group, const std::string & name) :
- XmlScriptParser(group, name, false),
- CheckHost(group, name)
-{
- loader.supportedStorers.insert(new NOEErrorStorer(&normTasks, &errorTasks));
-}
-
-TaskHost::TaskHost(const std::string & file) :
+TaskHost::TaskHost(const boost::filesystem::path & file) :
XmlScriptParser(file, false),
CheckHost(file)
{
diff --git a/project2/taskHost.h b/project2/taskHost.h
index 812760c..290c841 100644
--- a/project2/taskHost.h
+++ b/project2/taskHost.h
@@ -12,8 +12,7 @@ class TaskHost : virtual public XmlScriptParser, virtual public CheckHost {
protected:
typedef ANONORDEREDSTORAGEOF(NoOutputExecute) Tasks;
- TaskHost(const std::string & group, const std::string & name);
- TaskHost(const std::string & file);
+ TaskHost(const boost::filesystem::path & file);
virtual ~TaskHost();
void executeTasks() const;
diff --git a/project2/viewHost.cpp b/project2/viewHost.cpp
index 6bdbe34..c240f76 100644
--- a/project2/viewHost.cpp
+++ b/project2/viewHost.cpp
@@ -5,15 +5,7 @@
#define FOREACH_PRESENTER BOOST_FOREACH (const PresenterPtr & p, presenters)
-ViewHost::ViewHost(const std::string & group, const std::string & name) :
- XmlScriptParser(group, name, false),
- CheckHost(group, name)
-{
- loader.supportedStorers.insert(Storer::into(&views));
- loader.supportedStorers.insert(Storer::into(&pmp.presenters));
-}
-
-ViewHost::ViewHost(const std::string & file) :
+ViewHost::ViewHost(const boost::filesystem::path & file) :
XmlScriptParser(file, false),
CheckHost(file)
{
diff --git a/project2/viewHost.h b/project2/viewHost.h
index 19ff65f..1428a0e 100644
--- a/project2/viewHost.h
+++ b/project2/viewHost.h
@@ -28,8 +28,7 @@ class ViewHost : virtual public XmlScriptParser, virtual public CheckHost {
};
typedef boost::function1<PresenterPtr, const xmlpp::Element *> DefaultPresenterProvider;
- ViewHost(const std::string & group, const std::string & file);
- ViewHost(const std::string & file);
+ ViewHost(const boost::filesystem::path & file);
~ViewHost();
void executeViews(const DefaultPresenterProvider &) const;
diff --git a/project2/xmlScriptParser.cpp b/project2/xmlScriptParser.cpp
index 6d30d67..9b76316 100644
--- a/project2/xmlScriptParser.cpp
+++ b/project2/xmlScriptParser.cpp
@@ -2,15 +2,7 @@
#include <libxml/xinclude.h>
#include <boost/filesystem/convenience.hpp>
-XmlScriptParser::XmlScriptParser(const std::string & group, const std::string & name, bool ii) :
- IsInclusion(ii),
- loader(true),
- documentParsed(false)
-{
- loadDocument(group + "/" + name + ".xml");
-}
-
-XmlScriptParser::XmlScriptParser(const std::string & file, bool ii) :
+XmlScriptParser::XmlScriptParser(const boost::filesystem::path & file, bool ii) :
IsInclusion(ii),
loader(true),
documentParsed(false)
@@ -19,28 +11,28 @@ XmlScriptParser::XmlScriptParser(const std::string & file, bool ii) :
}
void
-XmlScriptParser::loadDocument(const std::string & file)
+XmlScriptParser::loadDocument(const boost::filesystem::path & file)
{
- loader.supportedStorers.insert(Storer::into(&rowSets));
if (!boost::filesystem::exists(file)) {
if (IsInclusion) {
- throw DependencyNotFound(file);
+ throw DependencyNotFound(file.string());
}
else {
- throw NotFound(file);
+ throw NotFound(file.string());
}
}
try {
- parse_file(file);
+ parse_file(file.string());
}
catch (const xmlpp::internal_error &) {
- throw NotReadable(file);
+ throw NotReadable(file.string());
}
for (int x; (x = xmlXIncludeProcessFlags(get_document()->cobj(), XML_PARSE_NOXINCNODE)); ) {
if (x < 0) {
- throw IncludesError(file);
+ throw IncludesError(file.string());
}
}
+ loader.supportedStorers.insert(Storer::into(&rowSets));
}
void
diff --git a/project2/xmlScriptParser.h b/project2/xmlScriptParser.h
index 72d6938..9f1406d 100644
--- a/project2/xmlScriptParser.h
+++ b/project2/xmlScriptParser.h
@@ -7,6 +7,7 @@
#include "xmlObjectLoader.h"
#include <intrusivePtrBase.h>
#include "commonObjects.h"
+#include <boost/filesystem/path.hpp>
class XmlScriptParser : public xmlpp::DomParser, virtual public CommonObjects, virtual public IntrusivePtrBase {
public:
@@ -16,8 +17,7 @@ class XmlScriptParser : public xmlpp::DomParser, virtual public CommonObjects, v
SimpleMessageExceptionBase(NotReadable, ParseError);
SimpleMessageExceptionBase(IncludesError, ParseError);
- XmlScriptParser(const std::string & group, const std::string & name, bool isInclusion);
- XmlScriptParser(const std::string & file, bool isInclusion);
+ XmlScriptParser(const boost::filesystem::path & file, bool isInclusion);
const bool IsInclusion;
@@ -27,7 +27,7 @@ class XmlScriptParser : public xmlpp::DomParser, virtual public CommonObjects, v
void parseDocument() const;
private:
- void loadDocument(const std::string & file);
+ void loadDocument(const boost::filesystem::path & file);
};