summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrandomdan <randomdan@localhost>2013-08-19 00:17:30 +0000
committerrandomdan <randomdan@localhost>2013-08-19 00:17:30 +0000
commit9ca6c72c24121e375591f8a3f5921a5a25567c11 (patch)
treecc359df71c3e2f344a6db1f966617e98d940128d
parentFix the schoolboy error with buffer allocation in base exception classes (diff)
downloadproject2-9ca6c72c24121e375591f8a3f5921a5a25567c11.tar.bz2
project2-9ca6c72c24121e375591f8a3f5921a5a25567c11.tar.xz
project2-9ca6c72c24121e375591f8a3f5921a5a25567c11.zip
Allow specifying a custom date format in an XML presenter declaration, used to correct the date format used in GB RSS feeds
-rw-r--r--project2/xml/xmlPresenter.cpp18
-rw-r--r--project2/xml/xmlPresenter.h1
2 files changed, 13 insertions, 6 deletions
diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp
index 32960a1..d0281f7 100644
--- a/project2/xml/xmlPresenter.cpp
+++ b/project2/xml/xmlPresenter.cpp
@@ -45,19 +45,21 @@ DECLARE_GENERIC_LOADER("xml", PresenterLoader, XmlPresenter)
XmlPresenter::XmlPresenter(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle, const Glib::ustring & ct) :
Presenter(Default),
ContentPresenter(ct),
+ customDateFormat(Null()),
root(responseRootNodeName),
style(responseStyle.empty() ? Null() : VariableType(responseStyle))
{
}
-XmlPresenter::XmlPresenter(ScriptNodePtr e, ObjectSource os, ExecContext *) :
+XmlPresenter::XmlPresenter(ScriptNodePtr e, ObjectSource os, ExecContext * ec) :
TransformSource(e, os),
Presenter(os),
- ContentPresenter(e->value("contenttype", "application/xml", NULL)),
+ ContentPresenter(e->value("contenttype", "application/xml", ec)),
SourceOf<xmlpp::Document>(e, os),
SourceOf<_xmlDoc>(e, os),
SourceOf<boost::shared_ptr<xmlpp::Document> >(e, os),
SourceOf<WritableContent>(e, os),
+ customDateFormat(e->value("dateformat", XmlPresenter::customFormat ? VariableType(*XmlPresenter::customFormat) : Null(), ec)),
root(e, "root"),
style(e, "style", Null())
{
@@ -155,7 +157,10 @@ XmlPresenter::addNamedValue(const Glib::ustring & name, const Glib::ustring & ns
class XmlNodeWriter : public boost::static_visitor<bool> {
public:
- XmlNodeWriter(xmlpp::Element * n) : node(n) { }
+ XmlNodeWriter(xmlpp::Element * n, const VariableType & df) :
+ node(n),
+ dateFormat(df)
+ { }
bool operator()(const Null &) const {
addType(XmlPresenter::typeidNull, "null");
return false;
@@ -184,11 +189,11 @@ class XmlNodeWriter : public boost::static_visitor<bool> {
if (XmlPresenter::dateAttr) {
node->set_attribute("date", boost::gregorian::to_iso_extended_string(i.date()));
}
- if (!!XmlPresenter::customFormat) {
+ if (!dateFormat.isNull()) {
std::stringstream ss;
boost::date_time::time_facet<boost::posix_time::ptime, char> * ft = new boost::date_time::time_facet<boost::posix_time::ptime, char>();
ss.imbue(std::locale(ss.getloc(), ft));
- ft->format(XmlPresenter::customFormat->c_str());
+ ft->format(dateFormat);
ss << boost::get<boost::posix_time::ptime>(i);
node->set_attribute("custom", ss.str());
}
@@ -203,12 +208,13 @@ class XmlNodeWriter : public boost::static_visitor<bool> {
}
private:
xmlpp::Element * node;
+ const VariableType dateFormat;
};
void
XmlPresenter::addText(const VariableType & value) const
{
- if (boost::apply_visitor(XmlNodeWriter(nodeStack.back()), value)) {
+ if (boost::apply_visitor(XmlNodeWriter(nodeStack.back(), customDateFormat), value)) {
nodeStack.back()->add_child_text(value);
}
}
diff --git a/project2/xml/xmlPresenter.h b/project2/xml/xmlPresenter.h
index de3f65b..6dbee7e 100644
--- a/project2/xml/xmlPresenter.h
+++ b/project2/xml/xmlPresenter.h
@@ -53,6 +53,7 @@ class XmlPresenter : public Presenter, public ContentPresenter, public SourceOf<
void createDoc(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle) const;
XmlDocumentPtr responseDoc;
mutable std::vector<xmlpp::Element *> nodeStack;
+ const VariableType customDateFormat;
const Variable root;
const Variable style;