diff options
Diffstat (limited to 'project2/xml/rawView.cpp')
-rw-r--r-- | project2/xml/rawView.cpp | 111 |
1 files changed, 73 insertions, 38 deletions
diff --git a/project2/xml/rawView.cpp b/project2/xml/rawView.cpp index cd65cfa..5226caf 100644 --- a/project2/xml/rawView.cpp +++ b/project2/xml/rawView.cpp @@ -1,55 +1,90 @@ #include <pch.hpp> #include "exceptions.h" -#include "rawView.h" #include "xml.h" #include "presenter.h" #include "scriptLoader.h" -#include "environment.h" -#include "appEngine.h" +#include "xmlDocumentCache.h" #include "xmlScriptParser.h" #include <boost/foreach.hpp> #include <libxml++/nodes/textnode.h> -DECLARE_LOADER("rawview", RawView); +class RawViewBase : public View { + public: + RawViewBase(ScriptNodePtr p) : + SourceObject(p), + View(p) { } + void execute(const MultiRowSetPresenter * mp) const + { + if (const Presenter * p = dynamic_cast<const Presenter *>(mp)) { + BOOST_FOREACH(const auto * node, getCopyRoot()->get_children()) { + const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(node); + if (e) { + copyNode(p, e); + } + } + } + } -RawView::RawView(ScriptNodePtr p) : - SourceObject(p), - View(p), - copyRoot(boost::dynamic_pointer_cast<const XmlScriptNode>(p)->xmlElement()) -{ -} + protected: + virtual const xmlpp::Element * getCopyRoot() const = 0; -void -RawView::execute(const MultiRowSetPresenter * mp) const -{ - if (const Presenter * p = dynamic_cast<const Presenter *>(mp)) { - BOOST_FOREACH(xmlpp::Node * node, copyRoot->get_children()) { - const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(node); - if (e) { - copyNode(p, e); + private: + void copyNode(const Presenter * p, const xmlpp::Element * n) const + { + p->pushSub(n->get_name()); + p->setNamespace(n->get_namespace_prefix(), n->get_namespace_uri()); + xmlpp::Element::AttributeList al = n->get_attributes(); + BOOST_FOREACH(const xmlpp::Attribute * a, al) { + p->addAttribute(a->get_name(), a->get_value()); + } + const xmlpp::Node::NodeList ch = n->get_children(); + BOOST_FOREACH(const xmlpp::Node * c, ch) { + if (const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(c)) { + copyNode(p, e); + } + else if (const xmlpp::TextNode * t = dynamic_cast<const xmlpp::TextNode *>(c)) { + p->addText(t->get_content()); + } } + p->popSub(); } - } -} +}; -void -RawView::copyNode(const Presenter * p, const xmlpp::Element * n) const -{ - p->pushSub(n->get_name()); - p->setNamespace(n->get_namespace_prefix(), n->get_namespace_uri()); - xmlpp::Element::AttributeList al = n->get_attributes(); - BOOST_FOREACH(const xmlpp::Attribute * a, al) { - p->addAttribute(a->get_name(), a->get_value()); - } - const xmlpp::Node::NodeList ch = n->get_children(); - BOOST_FOREACH(const xmlpp::Node * c, ch) { - if (const xmlpp::Element * e = dynamic_cast<const xmlpp::Element *>(c)) { - copyNode(p, e); +class RawView : public RawViewBase { + public: + RawView(ScriptNodePtr p) : + SourceObject(p), + RawViewBase(p), + copyRoot(boost::dynamic_pointer_cast<const XmlScriptNode>(p)->xmlElement()) + { } - else if (const xmlpp::TextNode * t = dynamic_cast<const xmlpp::TextNode *>(c)) { - p->addText(t->get_content()); + protected: + const xmlpp::Element * getCopyRoot() const { return copyRoot; } + private: + const xmlpp::Element * copyRoot; +}; +DECLARE_LOADER("rawview", RawView); + +class XmlResourceView : public RawViewBase, XmlDocumentCache, VariableCurlHelper { + public: + XmlResourceView(ScriptNodePtr p) : + SourceObject(p), + RawViewBase(p), + VariableCurlHelper(p), + encoding(p, "encoding", Null()) + { } - } - p->popSub(); -} + protected: + const xmlpp::Element * getCopyRoot() const + { + return getDocument(url(), encoding())->get_root_node(); + } + bool asHtml() const { return false; } + bool withWarnings() const { return true; } + CurlPtr newCurl() const { return VariableCurlHelper::newCurl(); } + + private: + Variable encoding; +}; +DECLARE_LOADER("xmlresourceview", XmlResourceView); |