summaryrefslogtreecommitdiff
path: root/project2/xmlPresenter.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'project2/xmlPresenter.cpp')
-rw-r--r--project2/xmlPresenter.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/project2/xmlPresenter.cpp b/project2/xmlPresenter.cpp
new file mode 100644
index 0000000..af870eb
--- /dev/null
+++ b/project2/xmlPresenter.cpp
@@ -0,0 +1,55 @@
+#include "xmlPresenter.h"
+
+XmlPresenter::~XmlPresenter()
+{
+}
+
+XmlPresenter::XmlPresenter(const std::string & group, const std::string & file) :
+ Presenter(group, file),
+ 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")),
+ responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0")))
+{
+ nodeStack.push_back(responseDoc->create_root_node(responseRootNodeName));
+ xmlNewNs(nodeStack.back()->cobj(), BAD_CAST "http://project2.randomdan.homeip.net", BAD_CAST "project2");
+ // XSLT Style
+ char * buf;
+ if (responseStyle.length() && 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);
+ }
+}
+
+XmlPresenter::XmlDocumentPtr
+XmlPresenter::getDataDocument() const
+{
+ return responseDoc;
+}
+
+void
+XmlPresenter::pushSub(const Glib::ustring & name, const Glib::ustring & ns) const
+{
+ nodeStack.push_back(nodeStack.back()->add_child(name, ns));
+}
+
+void
+XmlPresenter::addAttr(const Glib::ustring & name, const Glib::ustring & ns, const Glib::ustring & value) const
+{
+ nodeStack.back()->set_attribute(name, value, ns);
+}
+
+void
+XmlPresenter::setText(const Glib::ustring & value) const
+{
+ nodeStack.back()->set_child_text(value);
+}
+
+void
+XmlPresenter::popSub() const
+{
+ nodeStack.pop_back();
+}
+