From 214516288993a6e51147810f3c9311f14245e050 Mon Sep 17 00:00:00 2001 From: randomdan Date: Sun, 22 Jul 2012 13:38:12 +0000 Subject: 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) --- project2/cgi/cgiStagePresent.cpp | 4 ++-- project2/common/commonObjects.cpp | 3 --- project2/common/presenter.cpp | 5 +++-- project2/common/presenter.h | 6 +++--- project2/common/scriptLoader.cpp | 8 ++++---- project2/common/scriptLoader.h | 2 +- project2/common/sourceObject.cpp | 1 + project2/common/sourceObject.h | 4 ++++ project2/common/transform.cpp | 8 +++++--- project2/common/transform.h | 6 +++--- project2/console/consolePresenter.cpp | 1 + project2/json/presenter-p.cpp | 4 ++-- project2/json/presenter.cpp | 18 ++++++++++-------- project2/json/presenter.h | 4 ++-- project2/mail/sendmailTask.cpp | 6 +++--- project2/streams/viewStream.cpp | 2 +- project2/xml/transformHtml.cpp | 8 ++++---- project2/xml/transformHtml.h | 2 +- project2/xml/transformText.cpp | 8 ++++---- project2/xml/transformText.h | 2 +- project2/xml/xmlPresenter.cpp | 20 ++++++++++++-------- 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(&outputOptions)); - s->loader.addLoadTarget(s->root(), Storer::into(&presenter)); + s->loader.addLoadTarget(s->root(), Storer::into(&presenter, Scripted)); s->loader.addLoadTarget(s->root(), Storer::into(&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 RowSetPresenterPtr; typedef boost::intrusive_ptr MultiRowSetPresenterPtr; typedef boost::intrusive_ptr NameValuePairPresenterPtr; -typedef GenLoader PresenterLoader; +typedef GenLoader 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 @@ -11,7 +10,7 @@ #include unsigned int LoaderBase::depth = 0; -std::set LoaderBase::loadedObjects; +std::set 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(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::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 loadedObjects; + static std::set 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 create(ScriptNodePtr p) const { - return LoaderBase::getLoader(p->get_name())->create(p); + return LoaderBase::getLoader(p->get_name())->create(p, Scripted); } bool save(boost::intrusive_ptr 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 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 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 TransformLoader; #define DECLARE_TRANSFORM(T) DECLARE_COMPONENT_LOADER(#T, T, TransformLoader) -typedef GenLoader TransformTargetLoader; +typedef GenLoader TransformTargetLoader; #define DECLARE_TRANSFORMTARGET(N, T) DECLARE_COMPONENT_LOADER(N, T, TransformTargetLoader) template 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 -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(s), - SourceOf(s), + SourceOf(s, os), + SourceOf(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(s), - SourceOf(s), + SourceOf(s, os), + SourceOf(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, public WritableContent, public SourceOf { 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 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(&presenter)); + p->script->loader.addLoadTarget(p, Storer::into(&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 #include -HtmlDocument::HtmlDocument(ScriptNodePtr s) : - TransformSource(s), - SourceOf(s), - SourceOf(s), +HtmlDocument::HtmlDocument(ScriptNodePtr s, ObjectSource os) : + TransformSource(s, os), + SourceOf(s, os), + SourceOf(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, public WritableContent, public SourceOf { 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 #include -TextDocument::TextDocument(ScriptNodePtr s) : - TransformSource(s), - SourceOf(s), - SourceOf(s), +TextDocument::TextDocument(ScriptNodePtr s, ObjectSource os) : + TransformSource(s, os), + SourceOf(s, os), + SourceOf(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, public WritableContent, public SourceOf { 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(e), - SourceOf<_xmlDoc>(e), - SourceOf >(e), - SourceOf(e), + SourceOf(e, os), + SourceOf<_xmlDoc>(e, os), + SourceOf >(e, os), + SourceOf(e, os), root(e, "root"), style(e, "style", Null()) { - e->script->loader.addLoadTarget(e, Storer::into(&mutators)); + if (os == Scripted) { + e->script->loader.addLoadTarget(e, Storer::into(&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 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; -- cgit v1.2.3