diff options
author | Adrian Kummerländer | 2014-04-23 14:00:36 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-23 14:00:36 +0200 |
commit | 30ae1cc66daf8acbb556ec761f96690a2fa74637 (patch) | |
tree | 5475226d75bde7785a29a2eb649b95e8c7a6cdd5 /src/function | |
parent | 34b2f97ac57489d7c9555a3cb0c92c808a4948ea (diff) | |
download | InputXSLT-30ae1cc66daf8acbb556ec761f96690a2fa74637.tar InputXSLT-30ae1cc66daf8acbb556ec761f96690a2fa74637.tar.gz InputXSLT-30ae1cc66daf8acbb556ec761f96690a2fa74637.tar.bz2 InputXSLT-30ae1cc66daf8acbb556ec761f96690a2fa74637.tar.lz InputXSLT-30ae1cc66daf8acbb556ec761f96690a2fa74637.tar.xz InputXSLT-30ae1cc66daf8acbb556ec761f96690a2fa74637.tar.zst InputXSLT-30ae1cc66daf8acbb556ec761f96690a2fa74637.zip |
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
Diffstat (limited to 'src/function')
-rw-r--r-- | src/function/read_directory.cc | 47 |
1 files changed, 39 insertions, 8 deletions
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 <xalanc/XercesParserLiaison/XercesDOMSupport.hpp> +#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp> + +#include <xercesc/dom/DOMDocument.hpp> +#include <xercesc/dom/DOMImplementation.hpp> +#include <xercesc/dom/DOMElement.hpp> +#include <xercesc/dom/DOMText.hpp> +#include <xercesc/util/XMLString.hpp> + #include <sstream> namespace InputXSLT { @@ -26,22 +35,44 @@ xalan::XObjectPtr FunctionReadDirectory::execute( this->generalError(executionContext, context, locator); } - std::stringstream stream; - stream << "<content>"; + 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 << "<file>" << p.filename().string() << "</file>"; + [&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 << "</content>"; - 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( |