summaryrefslogtreecommitdiff
path: root/project2/xmlPresenter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlPresenter.cpp')
-rw-r--r--project2/xmlPresenter.cpp78
1 files changed, 30 insertions, 48 deletions
diff --git a/project2/xmlPresenter.cpp b/project2/xmlPresenter.cpp
index adf7860..c6bb04d 100644
--- a/project2/xmlPresenter.cpp
+++ b/project2/xmlPresenter.cpp
@@ -2,67 +2,52 @@
#include "xmlObjectLoader.h"
#include "variables.h"
#include "appEngine.h"
+#include <libxml++/document.h>
-XmlPresenter::XmlPresenter() :
- responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0")))
-{
-}
-
-XmlPresenter::~XmlPresenter()
-{
-}
+DECLARE_COMPONENT_LOADER("xml", XmlPresenter, PresenterLoader)
-void
-XmlPresenter::createDoc() const
+XmlPresenter::XmlPresenter(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle, const Glib::ustring & ct) :
+ ContentPresenter(ct),
+ responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0")))
{
- if (nodeStack.empty()) {
- nodeStack.push_back(responseDoc->create_root_node(getResponseRootNodeName()));
- declareNamespace(ApplicationEngine::getCurrent()->env()->getXmlPrefix(),
- ApplicationEngine::getCurrent()->env()->getXmlNamespace());
- // XSLT Style
- char * buf;
- if (!getResponseStyle().empty() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"",
- getResponseStyle().c_str()) > 0) {
- xmlAddPrevSibling(nodeStack.back()->cobj(),
- xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf));
- free(buf);
- }
- }
+ createDoc(responseRootNodeName, responseStyle);
}
-XmlProcessPresenter::XmlProcessPresenter(const std::string & group, const std::string & file, bool isInclusion) :
- present(group, file, isInclusion),
- responseRootNodeName(present.get_document()->get_root_node()->get_attribute_value("root")),
- responseStyle(present.get_document()->get_root_node()->get_attribute_value("style")),
- contentType(present.get_document()->get_root_node()->get_attribute_value("contenttype"))
+XmlPresenter::XmlPresenter(const xmlpp::Element * e) :
+ ContentPresenter(e->get_attribute_value("contenttype")),
+ responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0")))
{
- LoaderBase loader(true);
- loader.supportedStorers.insert(Storer::into(&rowSets));
- loader.supportedStorers.insert(Storer::into(&views));
- loader.supportedStorers.insert(Storer::into(&parameterChecks));
- loader.collectAll(this, present.get_document()->get_root_node(), true);
+ createDoc(e->get_attribute_value("root"), e->get_attribute_value("style"));
}
-XmlProcessPresenter::~XmlProcessPresenter()
+XmlPresenter::~XmlPresenter()
{
}
-const Glib::ustring &
-XmlProcessPresenter::getResponseRootNodeName() const
+void
+XmlPresenter::createDoc(const Glib::ustring & responseRootNodeName, const Glib::ustring & responseStyle) const
{
- return responseRootNodeName;
+ nodeStack.push_back(responseDoc->create_root_node(responseRootNodeName));
+ declareNamespace(Environment::getCurrent()->getXmlPrefix(),
+ Environment::getCurrent()->getXmlNamespace());
+ // XSLT Style
+ char * buf;
+ if (!responseStyle.empty() && asprintf(&buf, "type=\"text/xsl\" href=\"%s\"",
+ responseStyle.c_str()) > 0) {
+ xmlAddPrevSibling(nodeStack.back()->cobj(),
+ xmlNewDocPI(responseDoc->cobj(), BAD_CAST "xml-stylesheet", BAD_CAST buf));
+ free(buf);
+ }
}
-const Glib::ustring &
-XmlProcessPresenter::getResponseStyle() const
+XmlPresenter::operator const xmlpp::Document * () const
{
- return responseStyle;
+ return responseDoc.get();
}
-XmlPresenter::XmlDocumentPtr
-XmlPresenter::getDataDocument() const
+XmlPresenter::operator const xmlDoc * () const
{
- return responseDoc;
+ return responseDoc->cobj();
}
void
@@ -80,15 +65,13 @@ XmlPresenter::setNamespace(const Glib::ustring & prefix, const Glib::ustring & n
void
XmlPresenter::pushSub(const Glib::ustring & name, const Glib::ustring & ns) const
{
- createDoc();
nodeStack.push_back(nodeStack.back()->add_child(name, ns));
}
void
XmlPresenter::addAttr(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const
{
- if (!boost::get<Null>(&value)) {
- createDoc();
+ if (!value.get<Null>()) {
nodeStack.back()->set_attribute(name, value, ns);
}
}
@@ -96,8 +79,7 @@ XmlPresenter::addAttr(const Glib::ustring & name, const Glib::ustring & ns, cons
void
XmlPresenter::addText(const VariableType & value) const
{
- if (!boost::get<Null>(&value)) {
- createDoc();
+ if (!value.get<Null>()) {
nodeStack.back()->add_child_text(value);
}
}