From 30ae1cc66daf8acbb556ec761f96690a2fa74637 Mon Sep 17 00:00:00 2001 From: Adrian Kummerländer Date: Wed, 23 Apr 2014 14:00:36 +0200 Subject: Switched read-directory nodeSet generation to a xerces DOM document * replacement for manual XML construction * currently leaks memory as the objects have to exist out of scope and I have not yet thought of how to best manage their lifetime --- src/function/read_directory.cc | 47 +++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 8 deletions(-) (limited to 'src/function') diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 213ef68..a4284c0 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -1,5 +1,14 @@ #include "read_directory.h" +#include +#include + +#include +#include +#include +#include +#include + #include namespace InputXSLT { @@ -26,22 +35,44 @@ xalan::XObjectPtr FunctionReadDirectory::execute( this->generalError(executionContext, context, locator); } - std::stringstream stream; - stream << ""; + xercesc::DOMDocument* const inputDom( + xercesc::DOMImplementation::getImplementation()->createDocument( + nullptr, xercesc::XMLString::transcode("content"), nullptr + ) + ); + + xercesc::DOMNode* const rootNode = inputDom->getDocumentElement(); this->fs_context_.iterate( arguments[0]->str(), - [&stream](const boost::filesystem::path& p) { - stream << "" << p.filename().string() << ""; + [&inputDom, &rootNode](const boost::filesystem::path& p) { + xercesc::DOMNode* const fileNode = inputDom->createElement( + xercesc::XMLString::transcode("file") + ); + + xercesc::DOMText* const textNode = inputDom->createTextNode( + xercesc::XMLString::transcode(p.filename().string().data()) + ); + + fileNode->appendChild(textNode); + rootNode->appendChild(fileNode); }); - stream << ""; - return executionContext.getXObjectFactory().createNodeSet( - this->parser_.parseXMLStream( - xalan::XSLTInputSource(stream) + xalan::XercesDOMSupport domSupport(this->parser_); + + xalan::XercesDOMWrapperParsedSource* const parsedSource( + new xalan::XercesDOMWrapperParsedSource( + inputDom, + this->parser_, + domSupport ) ); + + return executionContext.getXObjectFactory().createNodeSet( + parsedSource->getDocument() + ); + } FunctionReadDirectory* FunctionReadDirectory::clone( -- cgit v1.2.3