diff options
author | randomdan <randomdan@localhost> | 2012-07-22 13:38:12 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-07-22 13:38:12 +0000 |
commit | d2ea2950d7ba4df8bb3960ed1abd0c65d322a716 (patch) | |
tree | 945b6a3129b854f9e80a971878ab22a2de97d8ce | |
parent | Regig output flow in CGI app engine to serve cached content when first create... (diff) | |
download | project2-d2ea2950d7ba4df8bb3960ed1abd0c65d322a716.tar.bz2 project2-d2ea2950d7ba4df8bb3960ed1abd0c65d322a716.tar.xz project2-d2ea2950d7ba4df8bb3960ed1abd0c65d322a716.zip |
Fix creation of default error XML document style
Fix hack used in script tidy up by not creating a mess in the first place (pass default or scripted to objects on creation)
Fix bug where a cached script that failed on first run would succeed wrongly on subsequent runs due to excessive tidy up (above)
-rw-r--r-- | project2/cgi/cgiStagePresent.cpp | 4 | ||||
-rw-r--r-- | project2/common/commonObjects.cpp | 3 | ||||
-rw-r--r-- | project2/common/presenter.cpp | 5 | ||||
-rw-r--r-- | project2/common/presenter.h | 6 | ||||
-rw-r--r-- | project2/common/scriptLoader.cpp | 8 | ||||
-rw-r--r-- | project2/common/scriptLoader.h | 2 | ||||
-rw-r--r-- | project2/common/sourceObject.cpp | 1 | ||||
-rw-r--r-- | project2/common/sourceObject.h | 4 | ||||
-rw-r--r-- | project2/common/transform.cpp | 8 | ||||
-rw-r--r-- | project2/common/transform.h | 6 | ||||
-rw-r--r-- | project2/console/consolePresenter.cpp | 1 | ||||
-rw-r--r-- | project2/json/presenter-p.cpp | 4 | ||||
-rw-r--r-- | project2/json/presenter.cpp | 18 | ||||
-rw-r--r-- | project2/json/presenter.h | 4 | ||||
-rw-r--r-- | project2/mail/sendmailTask.cpp | 6 | ||||
-rw-r--r-- | project2/streams/viewStream.cpp | 2 | ||||
-rw-r--r-- | project2/xml/transformHtml.cpp | 8 | ||||
-rw-r--r-- | project2/xml/transformHtml.h | 2 | ||||
-rw-r--r-- | project2/xml/transformText.cpp | 8 | ||||
-rw-r--r-- | project2/xml/transformText.h | 2 | ||||
-rw-r--r-- | project2/xml/xmlPresenter.cpp | 20 | ||||
-rw-r--r-- | project2/xml/xmlPresenter.h | 2 |
22 files changed, 68 insertions, 56 deletions
diff --git a/project2/cgi/cgiStagePresent.cpp b/project2/cgi/cgiStagePresent.cpp index 7282def..8e4a6ff 100644 --- a/project2/cgi/cgiStagePresent.cpp +++ b/project2/cgi/cgiStagePresent.cpp @@ -11,10 +11,10 @@ CgiApplicationEngine::PresentStage::PresentStage(ScriptReaderPtr s) : CommonObjects(s->root()), CheckHost(s->root()), ViewHost(s->root()), - presenter([root,this] { return PresenterLoader::getFor(this->env()->defaultPresenter)->create(root); }) + presenter([root,this] { return PresenterLoader::getFor(this->env()->defaultPresenter)->create(root, Default); }) { s->loader.addLoadTarget(s->root(), Storer::into<OutputOptionsLoader>(&outputOptions)); - s->loader.addLoadTarget(s->root(), Storer::into<PresenterLoader>(&presenter)); + s->loader.addLoadTarget(s->root(), Storer::into<PresenterLoader>(&presenter, Scripted)); s->loader.addLoadTarget(s->root(), Storer::into<ElementLoader>(&caches)); } diff --git a/project2/common/commonObjects.cpp b/project2/common/commonObjects.cpp index f27696f..9b45baa 100644 --- a/project2/common/commonObjects.cpp +++ b/project2/common/commonObjects.cpp @@ -18,9 +18,6 @@ CommonObjects::CommonObjects(ScriptNodePtr s) : CommonObjects::~CommonObjects() { - if (script) { - script->loader.discardLoadTargets(); - } } RowSetPtr diff --git a/project2/common/presenter.cpp b/project2/common/presenter.cpp index becfb50..1e5bbf2 100644 --- a/project2/common/presenter.cpp +++ b/project2/common/presenter.cpp @@ -26,7 +26,7 @@ RowSetPresenter::~RowSetPresenter() { } -MultiRowSetPresenter::MultiRowSetPresenter() +MultiRowSetPresenter::MultiRowSetPresenter(ObjectSource) { } @@ -34,7 +34,8 @@ MultiRowSetPresenter::~MultiRowSetPresenter() { } -Presenter::Presenter() +Presenter::Presenter(ObjectSource os) : + MultiRowSetPresenter(os) { } diff --git a/project2/common/presenter.h b/project2/common/presenter.h index ebcbe93..f9069de 100644 --- a/project2/common/presenter.h +++ b/project2/common/presenter.h @@ -28,7 +28,7 @@ class RowSetPresenter : public NameValuePairPresenter { class MultiRowSetPresenter : public RowSetPresenter { public: - MultiRowSetPresenter(); + MultiRowSetPresenter(ObjectSource); virtual ~MultiRowSetPresenter() = 0; virtual void declareNamespace(const Glib::ustring & prefix, const Glib::ustring & ns) const; @@ -45,7 +45,7 @@ class MultiRowSetPresenter : public RowSetPresenter { class Presenter : public MultiRowSetPresenter { public: - Presenter(); + Presenter(ObjectSource); virtual ~Presenter() = 0; virtual void pushSub(const Glib::ustring & name) const; @@ -77,7 +77,7 @@ typedef boost::intrusive_ptr<RowSetPresenter> RowSetPresenterPtr; typedef boost::intrusive_ptr<MultiRowSetPresenter> MultiRowSetPresenterPtr; typedef boost::intrusive_ptr<NameValuePairPresenter> NameValuePairPresenterPtr; -typedef GenLoader<MultiRowSetPresenter, ScriptNodePtr> PresenterLoader; +typedef GenLoader<MultiRowSetPresenter, ScriptNodePtr, ObjectSource> PresenterLoader; #endif diff --git a/project2/common/scriptLoader.cpp b/project2/common/scriptLoader.cpp index b13b3de..7f02f9b 100644 --- a/project2/common/scriptLoader.cpp +++ b/project2/common/scriptLoader.cpp @@ -2,7 +2,6 @@ #include "scopeObject.h" #include "scriptLoader.h" #include "scriptStorage.h" -#include "logger.h" #include "library.h" #include "appEngine.h" #include <boost/shared_ptr.hpp> @@ -11,7 +10,7 @@ #include <boost/function_equal.hpp> unsigned int LoaderBase::depth = 0; -std::set<SourceObjectPtr> LoaderBase::loadedObjects; +std::set<SourceObject *> LoaderBase::loadedObjects; class DepthCounter { public: @@ -103,7 +102,7 @@ LoaderBase::collectAll(ScriptNodePtr node, bool childrenOnly, const StorerPtrs & } else { if (SourceObjectPtr p = boost::dynamic_pointer_cast<SourceObject>(node->obj)) { - LoaderBase::loadedObjects.insert(p); + LoaderBase::loadedObjects.insert(p.get()); } } if (!node->obj) { @@ -134,15 +133,16 @@ LoaderBase::collectAll(const CommonObjects * co, bool childrenOnly, ScriptNodePt throw std::logic_error("Cannot set CommonObjects in subloader"); } Targets::iterator i; + ScopeObject clr(NULL, NULL, [&loadedObjects] { loadedObjects.clear(); }); while ((i = targets.begin()) != targets.end()) { collectAll(i->first, childrenOnly, i->second); targets.erase(i); } if (co) { - ScopeObject clr(boost::bind(&std::set<SourceObjectPtr>::clear, &loadedObjects)); BOOST_FOREACH(SourceObjectPtr o, loadedObjects) { o->loadComplete(co); } + loadedObjects.clear(); } } diff --git a/project2/common/scriptLoader.h b/project2/common/scriptLoader.h index 9f0e9c6..feb958b 100644 --- a/project2/common/scriptLoader.h +++ b/project2/common/scriptLoader.h @@ -93,7 +93,7 @@ class LoaderBase { Targets targets; static unsigned int depth; friend class SourceObject; - static std::set<SourceObjectPtr> loadedObjects; + static std::set<SourceObject *> loadedObjects; const bool recursive; diff --git a/project2/common/sourceObject.cpp b/project2/common/sourceObject.cpp index e66e9ee..ef909b9 100644 --- a/project2/common/sourceObject.cpp +++ b/project2/common/sourceObject.cpp @@ -19,6 +19,7 @@ SourceObject::SourceObject(const std::string & n) : SourceObject::~SourceObject() { + LoaderBase::loadedObjects.erase(this); } void diff --git a/project2/common/sourceObject.h b/project2/common/sourceObject.h index 8cf75ad..f8963ea 100644 --- a/project2/common/sourceObject.h +++ b/project2/common/sourceObject.h @@ -7,6 +7,10 @@ #include "scriptLoader.h" #include "scripts_fwd.h" +enum ObjectSource { + Default, + Scripted +}; class CommonObjects; /// Base class for all Project2 components that can be placed in a Project2 script class SourceObject : public virtual IntrusivePtrBase { diff --git a/project2/common/transform.cpp b/project2/common/transform.cpp index 5c67bd7..fc68855 100644 --- a/project2/common/transform.cpp +++ b/project2/common/transform.cpp @@ -12,7 +12,7 @@ class TransformTargetStorer : public Storer { } boost::intrusive_ptr<IntrusivePtrBase> create(ScriptNodePtr p) const { - return LoaderBase::getLoader<TransformTargetLoader, NotSupported>(p->get_name())->create(p); + return LoaderBase::getLoader<TransformTargetLoader, NotSupported>(p->get_name())->create(p, Scripted); } bool save(boost::intrusive_ptr<IntrusivePtrBase> o, ScriptNodePtr s) { @@ -30,9 +30,11 @@ TransformSource::TransformSource() { } -TransformSource::TransformSource(ScriptNodePtr s) +TransformSource::TransformSource(ScriptNodePtr s, ObjectSource os) { - s->script->loader.addLoadTarget(s, new TransformTargetStorer(this)); + if (os == Scripted) { + s->script->loader.addLoadTarget(s, new TransformTargetStorer(this)); + } } TransformChainLink::~TransformChainLink() diff --git a/project2/common/transform.h b/project2/common/transform.h index ef8fe83..3ae1063 100644 --- a/project2/common/transform.h +++ b/project2/common/transform.h @@ -19,7 +19,7 @@ typedef std::map<TransformChainLinkPtr, TransformPtr> Targets; class TransformSource : public TransformChainLink { public: TransformSource(); - TransformSource(ScriptNodePtr); + TransformSource(ScriptNodePtr, ObjectSource); void clearTargets(); void removeTarget(TransformChainLinkPtr); void addTarget(TransformChainLinkPtr, ScriptNodePtr e = NULL); @@ -35,7 +35,7 @@ template <class X> class SourceOf : public virtual TransformSource { public: SourceOf() { } - SourceOf(ScriptNodePtr s) : TransformSource(s) { } + SourceOf(ScriptNodePtr s, ObjectSource os) : TransformSource(s, os) { } virtual operator const X * () const = 0; }; @@ -49,7 +49,7 @@ class Transform : public virtual IntrusivePtrBase { typedef GenLoader<Transform> TransformLoader; #define DECLARE_TRANSFORM(T) DECLARE_COMPONENT_LOADER(#T, T, TransformLoader) -typedef GenLoader<TransformChainLink, ScriptNodePtr> TransformTargetLoader; +typedef GenLoader<TransformChainLink, ScriptNodePtr, ObjectSource> TransformTargetLoader; #define DECLARE_TRANSFORMTARGET(N, T) DECLARE_COMPONENT_LOADER(N, T, TransformTargetLoader) template <class Source, class Destination> diff --git a/project2/console/consolePresenter.cpp b/project2/console/consolePresenter.cpp index c76f206..52bface 100644 --- a/project2/console/consolePresenter.cpp +++ b/project2/console/consolePresenter.cpp @@ -3,6 +3,7 @@ #include "consolePresenter.h" ConsolePresenter::ConsolePresenter() : + Presenter(Default), indent(0), out(stdout, true) { diff --git a/project2/json/presenter-p.cpp b/project2/json/presenter-p.cpp index 2cd7e09..3cb5bf8 100644 --- a/project2/json/presenter-p.cpp +++ b/project2/json/presenter-p.cpp @@ -3,8 +3,8 @@ class Json_P_Presenter : public JsonPresenter { public: - Json_P_Presenter(ScriptNodePtr s) : - JsonPresenter(s, "application/json-p"), + Json_P_Presenter(ScriptNodePtr s, ObjectSource os) : + JsonPresenter(s, os, "application/json-p"), Callback(s, "callback") { } diff --git a/project2/json/presenter.cpp b/project2/json/presenter.cpp index 06b9410..111ae5c 100644 --- a/project2/json/presenter.cpp +++ b/project2/json/presenter.cpp @@ -6,19 +6,21 @@ #include "presenter.h" #include <stack> -JsonPresenter::JsonPresenter(ScriptNodePtr s, const Glib::ustring & ct) : - TransformSource(s), +JsonPresenter::JsonPresenter(ScriptNodePtr s, ObjectSource os, const Glib::ustring & ct) : + TransformSource(s, os), + MultiRowSetPresenter(os), ContentPresenter(ct), - SourceOf<json::Object>(s), - SourceOf<WritableContent>(s), + SourceOf<json::Object>(s, os), + SourceOf<WritableContent>(s, os), returnObject(s, "object", Null()) { } -JsonPresenter::JsonPresenter(ScriptNodePtr s) : - TransformSource(s), +JsonPresenter::JsonPresenter(ScriptNodePtr s, ObjectSource os) : + TransformSource(s, os), + MultiRowSetPresenter(os), ContentPresenter("application/json"), - SourceOf<json::Object>(s), - SourceOf<WritableContent>(s), + SourceOf<json::Object>(s, os), + SourceOf<WritableContent>(s, os), returnObject(s, "object", Null()) { } diff --git a/project2/json/presenter.h b/project2/json/presenter.h index c085524..8d5af2a 100644 --- a/project2/json/presenter.h +++ b/project2/json/presenter.h @@ -9,8 +9,8 @@ class JsonPresenter : public MultiRowSetPresenter, public ContentPresenter, public SourceOf<json::Object>, public WritableContent, public SourceOf<WritableContent> { public: - JsonPresenter(ScriptNodePtr s); - JsonPresenter(ScriptNodePtr s, const Glib::ustring &); + JsonPresenter(ScriptNodePtr s, ObjectSource); + JsonPresenter(ScriptNodePtr s, ObjectSource, const Glib::ustring &); void init(); typedef void (JsonPresenter::*ValueAdder)(const Glib::ustring &, const VariableType &) const; typedef std::stack<ValueAdder> ValueAdderStack; diff --git a/project2/mail/sendmailTask.cpp b/project2/mail/sendmailTask.cpp index 3cc3a92..f798e45 100644 --- a/project2/mail/sendmailTask.cpp +++ b/project2/mail/sendmailTask.cpp @@ -179,9 +179,9 @@ class EmailViewHost : public ViewHost { MultiRowSetPresenterPtr getPresenter() const { if (!presenter) { Logger()->message(LOG_DEBUG, "Building default email transform chain"); - XmlPresenterPtr xpp = new XmlPresenter(n); - HtmlDocument * hd = new HtmlDocument(n); - TextDocument * td = new TextDocument(n); + XmlPresenterPtr xpp = new XmlPresenter(n, Default); + HtmlDocument * hd = new HtmlDocument(n, Default); + TextDocument * td = new TextDocument(n, Default); xpp->addTarget(hd, n); hd->addTarget(parts); hd->addTarget(td, n); diff --git a/project2/streams/viewStream.cpp b/project2/streams/viewStream.cpp index 77ecf45..fb40c0e 100644 --- a/project2/streams/viewStream.cpp +++ b/project2/streams/viewStream.cpp @@ -27,7 +27,7 @@ class ViewStream : public Stream, public ViewHost { Stream(p), ViewHost(p) { - p->script->loader.addLoadTarget(p, Storer::into<PresenterLoader>(&presenter)); + p->script->loader.addLoadTarget(p, Storer::into<PresenterLoader>(&presenter, Scripted)); } void runStream(const Stream::Sink & s) const { diff --git a/project2/xml/transformHtml.cpp b/project2/xml/transformHtml.cpp index f032945..1070ada 100644 --- a/project2/xml/transformHtml.cpp +++ b/project2/xml/transformHtml.cpp @@ -4,10 +4,10 @@ #include <libxslt/xsltutils.h> #include <libxslt/transform.h> -HtmlDocument::HtmlDocument(ScriptNodePtr s) : - TransformSource(s), - SourceOf<HtmlDocument>(s), - SourceOf<WritableContent>(s), +HtmlDocument::HtmlDocument(ScriptNodePtr s, ObjectSource os) : + TransformSource(s, os), + SourceOf<HtmlDocument>(s, os), + SourceOf<WritableContent>(s, os), doc(NULL), contentType(s, "contenttype", "text/html") { diff --git a/project2/xml/transformHtml.h b/project2/xml/transformHtml.h index 6ff5d91..7273bb0 100644 --- a/project2/xml/transformHtml.h +++ b/project2/xml/transformHtml.h @@ -6,7 +6,7 @@ class HtmlDocument : public SourceOf<HtmlDocument>, public WritableContent, public SourceOf<WritableContent> { public: - HtmlDocument(ScriptNodePtr); + HtmlDocument(ScriptNodePtr, ObjectSource); ~HtmlDocument(); htmlDocPtr doc; operator const HtmlDocument * () const; diff --git a/project2/xml/transformText.cpp b/project2/xml/transformText.cpp index 02c12e3..43dcab6 100644 --- a/project2/xml/transformText.cpp +++ b/project2/xml/transformText.cpp @@ -6,10 +6,10 @@ #include <misc.h> #include <glibmm/convert.h> -TextDocument::TextDocument(ScriptNodePtr s) : - TransformSource(s), - SourceOf<TextDocument>(s), - SourceOf<WritableContent>(s), +TextDocument::TextDocument(ScriptNodePtr s, ObjectSource os) : + TransformSource(s, os), + SourceOf<TextDocument>(s, os), + SourceOf<WritableContent>(s, os), contentType(s, "contenttype", "text/plain") { } diff --git a/project2/xml/transformText.h b/project2/xml/transformText.h index f1fcaaf..071eadf 100644 --- a/project2/xml/transformText.h +++ b/project2/xml/transformText.h @@ -6,7 +6,7 @@ class TextDocument : public SourceOf<TextDocument>, public WritableContent, public SourceOf<WritableContent> { public: - TextDocument(ScriptNodePtr); + TextDocument(ScriptNodePtr, ObjectSource); Glib::ustring doc; operator const TextDocument * () const; operator const WritableContent * () const; diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index 1d77959..9982a43 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -62,23 +62,27 @@ bool XmlPresenterLoader::timeAttr; DECLARE_CUSTOM_COMPONENT_LOADER("xml", XmlPresenter, XmlPresenterLoader, PresenterLoader) XmlPresenter::XmlPresenter(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle, const Glib::ustring & ct) : + Presenter(Default), ContentPresenter(ct), root(responseRootNodeName), - style(responseStyle) + style(responseStyle.empty() ? Null() : VariableType(responseStyle)) { } -XmlPresenter::XmlPresenter(ScriptNodePtr e) : - TransformSource(e), +XmlPresenter::XmlPresenter(ScriptNodePtr e, ObjectSource os) : + TransformSource(e, os), + Presenter(os), ContentPresenter(e->value("contenttype", "")), - SourceOf<xmlpp::Document>(e), - SourceOf<_xmlDoc>(e), - SourceOf<boost::shared_ptr<xmlpp::Document> >(e), - SourceOf<WritableContent>(e), + SourceOf<xmlpp::Document>(e, os), + SourceOf<_xmlDoc>(e, os), + SourceOf<boost::shared_ptr<xmlpp::Document> >(e, os), + SourceOf<WritableContent>(e, os), root(e, "root"), style(e, "style", Null()) { - e->script->loader.addLoadTarget(e, Storer::into<XmlDocMutatorLoader>(&mutators)); + if (os == Scripted) { + e->script->loader.addLoadTarget(e, Storer::into<XmlDocMutatorLoader>(&mutators)); + } } XmlPresenter::~XmlPresenter() diff --git a/project2/xml/xmlPresenter.h b/project2/xml/xmlPresenter.h index e2e0b84..744ef3d 100644 --- a/project2/xml/xmlPresenter.h +++ b/project2/xml/xmlPresenter.h @@ -22,7 +22,7 @@ class XmlPresenter : public Presenter, public ContentPresenter, public SourceOf< public: typedef boost::shared_ptr<xmlpp::Document> XmlDocumentPtr; XmlPresenter(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle, const Glib::ustring & contentType); - XmlPresenter(ScriptNodePtr e); + XmlPresenter(ScriptNodePtr e, ObjectSource); ~XmlPresenter(); void declareNamespace(const Glib::ustring & prefix, const Glib::ustring & ns) const; |