diff options
Diffstat (limited to 'project2/xmlPresenter.cpp')
-rw-r--r-- | project2/xmlPresenter.cpp | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/project2/xmlPresenter.cpp b/project2/xmlPresenter.cpp index 244c96c..494a88e 100644 --- a/project2/xmlPresenter.cpp +++ b/project2/xmlPresenter.cpp @@ -1,6 +1,7 @@ #include "xmlPresenter.h" #include "xmlObjectLoader.h" #include "variables.h" +#include "appEngine.h" XmlPresenter::XmlPresenter() : responseDoc(XmlDocumentPtr(new xmlpp::Document("1.0"))) @@ -12,17 +13,21 @@ XmlPresenter::~XmlPresenter() } void -XmlPresenter::initDoc() +XmlPresenter::createDoc() const { - nodeStack.push_back(responseDoc->create_root_node(getResponseRootNodeName())); - xmlNewNs(nodeStack.back()->cobj(), BAD_CAST "http://project2.randomdan.homeip.net", BAD_CAST "project2"); - // 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); + if (nodeStack.empty()) { + nodeStack.push_back(responseDoc->create_root_node(getResponseRootNodeName())); + xmlNewNs(nodeStack.back()->cobj(), + BAD_CAST ApplicationEngine::getCurrent()->env()->getXmlNamespace().c_str(), + BAD_CAST ApplicationEngine::getCurrent()->env()->getXmlPrefix().c_str()); + // 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); + } } } @@ -32,12 +37,11 @@ XmlProcessPresenter::XmlProcessPresenter(const std::string & group, const std::s responseStyle(present.get_document()->get_root_node()->get_attribute_value("style")), contentType(present.get_document()->get_root_node()->get_attribute_value("contenttype")) { - LoaderBase loader("http://project2.randomdan.homeip.net", true); + LoaderBase loader(ApplicationEngine::getCurrent()->env()->getXmlNamespace(), true); loader.supportedStorers.insert(Storer::into(&rowSets)); loader.supportedStorers.insert(Storer::into(&views)); loader.supportedStorers.insert(Storer::into(¶meterChecks)); loader.collectAll(this, present.get_document()->get_root_node(), true); - initDoc(); } XmlProcessPresenter::~XmlProcessPresenter() @@ -65,6 +69,7 @@ XmlPresenter::getDataDocument() const void XmlPresenter::pushSub(const Glib::ustring & name, const Glib::ustring & ns) const { + createDoc(); nodeStack.push_back(nodeStack.back()->add_child(name, ns)); } @@ -72,6 +77,7 @@ void XmlPresenter::addAttr(const Glib::ustring & name, const Glib::ustring & ns, const VariableType & value) const { if (!boost::get<Null>(&value)) { + createDoc(); nodeStack.back()->set_attribute(name, value, ns); } } @@ -80,6 +86,7 @@ void XmlPresenter::setText(const VariableType & value) const { if (!boost::get<Null>(&value)) { + createDoc(); nodeStack.back()->set_child_text(value); } } |