diff options
author | randomdan <randomdan@localhost> | 2012-02-18 15:10:20 +0000 |
---|---|---|
committer | randomdan <randomdan@localhost> | 2012-02-18 15:10:20 +0000 |
commit | c6ca14b87f2efa284aac31a73ca355b2da4d79a4 (patch) | |
tree | a7104c317aa503d00b500790de6a77fdbb6d2085 | |
parent | Finer control over output to presenters, addresses issues with JSON output an... (diff) | |
download | project2-c6ca14b87f2efa284aac31a73ca355b2da4d79a4.tar.bz2 project2-c6ca14b87f2efa284aac31a73ca355b2da4d79a4.tar.xz project2-c6ca14b87f2efa284aac31a73ca355b2da4d79a4.zip |
Add options for controlling the extra annotations in XML output
-rw-r--r-- | project2/xml/xmlPresenter.cpp | 79 |
1 files changed, 68 insertions, 11 deletions
diff --git a/project2/xml/xmlPresenter.cpp b/project2/xml/xmlPresenter.cpp index ba20eb2..37239fa 100644 --- a/project2/xml/xmlPresenter.cpp +++ b/project2/xml/xmlPresenter.cpp @@ -7,7 +7,58 @@ #include <boost/date_time/posix_time/time_formatters.hpp> #include <boost/date_time/gregorian/formatters.hpp> -DECLARE_COMPONENT_LOADER("xml", XmlPresenter, PresenterLoader) +class XmlPresenterLoader : public PresenterLoaderImpl<XmlPresenter> { + public: + XmlPresenterLoader() : + opts("XML Cache options") + { + opts + ("presenter.xml.typeid.null", Options::value(&typeidNull, false), + "Indicate the type of nulls on output") + ("presenter.xml.typeid.boolean", Options::value(&typeidBoolean, true), + "Indicate the type of booleans on output") + ("presenter.xml.typeid.string", Options::value(&typeidString, false), + "Indicate the type of strings on output") + ("presenter.xml.typeid.int", Options::value(&typeidInt, true), + "Indicate the type of integers on output") + ("presenter.xml.typeid.float", Options::value(&typeidFloat, true), + "Indicate the type of floating point numbers on output") + ("presenter.xml.typeid.datetime", Options::value(&typeidDateTime, true), + "Indicate the type of datetimes on output") + ("presenter.xml.datetime.dateattr", Options::value(&dateAttr, true), + "Output a date attribute in standard format") + ("presenter.xml.datetime.timeattr", Options::value(&timeAttr, true), + "Output a time attribute in standard format") + ; + } + + const Options * options() const + { + return &opts; + } + + static bool typeidNull; + static bool typeidBoolean; + static bool typeidString; + static bool typeidInt; + static bool typeidFloat; + static bool typeidDateTime; + static bool dateAttr; + static bool timeAttr; + private: + Options opts; +}; + +bool XmlPresenterLoader::typeidNull; +bool XmlPresenterLoader::typeidBoolean; +bool XmlPresenterLoader::typeidString; +bool XmlPresenterLoader::typeidInt; +bool XmlPresenterLoader::typeidFloat; +bool XmlPresenterLoader::typeidDateTime; +bool XmlPresenterLoader::dateAttr; +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) : ContentPresenter(ct), @@ -98,35 +149,41 @@ class XmlNodeWriter : public boost::static_visitor<bool> { public: XmlNodeWriter(xmlpp::Element * n) : node(n) { } bool operator()(const Null &) const { - addType("null"); + addType(XmlPresenterLoader::typeidNull, "null"); return false; } bool operator()(const Boolean &) const { - addType("bool"); + addType(XmlPresenterLoader::typeidBoolean, "bool"); return true; } bool operator()(const Glib::ustring &) const { - addType("string"); + addType(XmlPresenterLoader::typeidString, "string"); return true; } bool operator()(const int64_t &) const { - addType("int"); + addType(XmlPresenterLoader::typeidInt, "int"); return true; } bool operator()(const double &) const { - addType("float"); + addType(XmlPresenterLoader::typeidFloat, "float"); return true; } bool operator()(const boost::posix_time::ptime & i) const { - addType("datetime"); - node->set_attribute("time", boost::posix_time::to_simple_string(i.time_of_day())); - node->set_attribute("date", boost::gregorian::to_iso_extended_string(i.date())); + addType(XmlPresenterLoader::typeidDateTime, "datetime"); + if (XmlPresenterLoader::timeAttr) { + node->set_attribute("time", boost::posix_time::to_simple_string(i.time_of_day())); + } + if (XmlPresenterLoader::dateAttr) { + node->set_attribute("date", boost::gregorian::to_iso_extended_string(i.date())); + } return true; } protected: - void addType(const char * type) const { - node->set_attribute("type", type, Environment::getCurrent()->scriptNamespacePrefix); + void addType(bool condition, const char * type) const { + if (condition) { + node->set_attribute("type", type, Environment::getCurrent()->scriptNamespacePrefix); + } } private: xmlpp::Element * node; |