summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2012-03-19 08:46:03 +0000
committerrandomdan <randomdan@localhost>2012-03-19 08:46:03 +0000
commit1701f57f5dd0a8c8ad1c987ff947f5294cdf29f2 (patch)
tree7c231fc79af0651c68575c064127ff88b3513d8b
parentIncreased control over nesting and output; allows cut down output suitable fo... (diff)
downloadproject2-1701f57f5dd0a8c8ad1c987ff947f5294cdf29f2.tar.bz2
project2-1701f57f5dd0a8c8ad1c987ff947f5294cdf29f2.tar.xz
project2-1701f57f5dd0a8c8ad1c987ff947f5294cdf29f2.zip
Add init function to presenter because none default ones get cached between runs and need resetting
-rw-r--r--project2/cgi/cgiStageDefaultError.cpp1
-rw-r--r--project2/cgi/cgiStageDefaultNotFound.cpp1
-rw-r--r--project2/common/presenter.h1
-rw-r--r--project2/common/viewHost.cpp1
-rw-r--r--project2/console/consolePresenter.cpp5
-rw-r--r--project2/console/consolePresenter.h1
-rw-r--r--project2/json/presenter.cpp10
-rw-r--r--project2/xml/xmlPresenter.cpp18
-rw-r--r--project2/xml/xmlPresenter.h3
9 files changed, 33 insertions, 8 deletions
diff --git a/project2/cgi/cgiStageDefaultError.cpp b/project2/cgi/cgiStageDefaultError.cpp
index 70efafc..c5642d5 100644
--- a/project2/cgi/cgiStageDefaultError.cpp
+++ b/project2/cgi/cgiStageDefaultError.cpp
@@ -29,6 +29,7 @@ CgiApplicationEngine::DefaultErrorStage::getHeader() const
CgiApplicationEngine::NextStage
CgiApplicationEngine::DefaultErrorStage::run()
{
+ pres->init();
pres->addNamedValue("error-type", env()->scriptNamespacePrefix, buf);
pres->addNamedValue("error-what", env()->scriptNamespacePrefix, what.c_str());
return NextStage(NULL, this, pres.get(), pres.get());
diff --git a/project2/cgi/cgiStageDefaultNotFound.cpp b/project2/cgi/cgiStageDefaultNotFound.cpp
index 8b3d6cc..5b68bc6 100644
--- a/project2/cgi/cgiStageDefaultNotFound.cpp
+++ b/project2/cgi/cgiStageDefaultNotFound.cpp
@@ -23,6 +23,7 @@ CgiApplicationEngine::DefaultNotFoundStage::getHeader() const
CgiApplicationEngine::NextStage
CgiApplicationEngine::DefaultNotFoundStage::run()
{
+ pres->init();
pres->addNamedValue("missing-resource", env()->scriptNamespacePrefix, nf.what());
return NextStage(NULL, this, pres.get(), pres.get());
}
diff --git a/project2/common/presenter.h b/project2/common/presenter.h
index 662af22..a16b32b 100644
--- a/project2/common/presenter.h
+++ b/project2/common/presenter.h
@@ -39,6 +39,7 @@ class MultiRowSetPresenter : public RowSetPresenter {
virtual void finishRowSet() const = 0;
virtual void addNewArray(const Glib::ustring & name, bool objects) const = 0;
virtual void finishArray(bool objects) const = 0;
+ virtual void init() = 0;
};
class Presenter : public MultiRowSetPresenter {
diff --git a/project2/common/viewHost.cpp b/project2/common/viewHost.cpp
index 64a8c8b..cbae417 100644
--- a/project2/common/viewHost.cpp
+++ b/project2/common/viewHost.cpp
@@ -22,6 +22,7 @@ ViewHost::executeViews() const
loadScriptComponents();
MultiRowSetPresenterPtr presenter = getPresenter();
+ presenter->init();
BOOST_FOREACH(const Views::value_type & s, views) {
s->execute(presenter.get());
}
diff --git a/project2/console/consolePresenter.cpp b/project2/console/consolePresenter.cpp
index 3979c4e..c76f206 100644
--- a/project2/console/consolePresenter.cpp
+++ b/project2/console/consolePresenter.cpp
@@ -9,6 +9,11 @@ ConsolePresenter::ConsolePresenter() :
}
void
+ConsolePresenter::init()
+{
+}
+
+void
ConsolePresenter::pushSub(const Glib::ustring & name, const Glib::ustring & ns) const
{
fprintf(stdout, "%*s", indent, "");
diff --git a/project2/console/consolePresenter.h b/project2/console/consolePresenter.h
index 0540248..f551063 100644
--- a/project2/console/consolePresenter.h
+++ b/project2/console/consolePresenter.h
@@ -15,6 +15,7 @@ class ConsolePresenter : public Presenter {
void addNewArray(const Glib::ustring&, bool objects) const;
void finishArray(bool objects) const;
void write(const boost::function1<std::ostream *, const std::string &> &) const;
+ void init();
private:
mutable unsigned int indent;
FileStreamVariableWriter out;
diff --git a/project2/json/presenter.cpp b/project2/json/presenter.cpp
index 01bb915..0eb484b 100644
--- a/project2/json/presenter.cpp
+++ b/project2/json/presenter.cpp
@@ -13,7 +13,17 @@ class JsonPresenter : public MultiRowSetPresenter, public ContentPresenter, publ
SourceOf<json::Object>(s),
SourceOf<WritableContent>(s),
returnObject(s, "object", Null()) {
+ }
+ void init()
+ {
+ while (!curRowSet.empty()) {
+ curRowSet.pop();
+ }
+ object.clear();
curRowSet.push(&object);
+ while (!vaStack.empty()) {
+ vaStack.pop();
+ }
vaStack.push(&JsonPresenter::addValueToObject);
}
typedef void (JsonPresenter::*ValueAdder)(const Glib::ustring &, const VariableType &) const;
diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp
index 2650186..02ec82d 100644
--- a/project2/xml/xmlPresenter.cpp
+++ b/project2/xml/xmlPresenter.cpp
@@ -62,9 +62,9 @@ DECLARE_CUSTOM_COMPONENT_LOADER("xml", XmlPresenter, XmlPresenterLoader, Present
XmlPresenter::XmlPresenter(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle, const Glib::ustring & ct) :
ContentPresenter(ct),
- responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0")))
+ root(responseRootNodeName),
+ style(responseStyle)
{
- createDoc(responseRootNodeName, responseStyle);
}
XmlPresenter::XmlPresenter(ScriptNodePtr e) :
@@ -74,9 +74,9 @@ XmlPresenter::XmlPresenter(ScriptNodePtr e) :
SourceOf<_xmlDoc>(e),
SourceOf<boost::shared_ptr<xmlpp::Document> >(e),
SourceOf<WritableContent>(e),
- responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0")))
+ root(e, "root"),
+ style(e, "style", Null())
{
- createDoc(e->value("root"), e->value("style", ""));
}
XmlPresenter::~XmlPresenter()
@@ -84,15 +84,17 @@ XmlPresenter::~XmlPresenter()
}
void
-XmlPresenter::createDoc(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle) const
+XmlPresenter::init()
{
- nodeStack.push_back(responseDoc->create_root_node(responseRootNodeName));
+ responseDoc = XmlDocumentPtr(new xmlpp::Document("1.0"));
+ nodeStack.clear();
+ nodeStack.push_back(responseDoc->create_root_node(root()));
declareNamespace(Environment::getCurrent()->scriptNamespacePrefix,
Environment::getCurrent()->scriptNamespace);
// XSLT Style
char * buf;
- if (!responseStyle.empty() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"",
- responseStyle.c_str()) > 0) {
+ if (!style().isNull() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"",
+ style().as<const char *>()) > 0) {
xmlAddPrevSibling(nodeStack.back()->cobj(),
xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf));
free(buf);
diff --git a/project2/xml/xmlPresenter.h b/project2/xml/xmlPresenter.h
index 1c4391a..dc88fa9 100644
--- a/project2/xml/xmlPresenter.h
+++ b/project2/xml/xmlPresenter.h
@@ -33,11 +33,14 @@ class XmlPresenter : public Presenter, public ContentPresenter, public SourceOf<
Class getContentClass() const;
Glib::ustring getContentType() const;
void writeTo(std::ostream &, const std::string & enc) const;
+ void init();
private:
void createDoc(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle) const;
XmlDocumentPtr responseDoc;
mutable std::vector<xmlpp::Element *> nodeStack;
+ const Variable root;
+ const Variable style;
};
typedef boost::intrusive_ptr<XmlPresenter> XmlPresenterPtr;