From 32c65970263c65022f5278b568c07b63c3d5d64b Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sun, 15 Jun 2014 15:14:46 +0200 Subject: Merged "read-xml-file" and "read-file" into "read-file" * FunctionReadFile is now able to distinguish between XML files and plain text files ** it selects the appropriate course of action automatically ** reading the file as XML into the DOM or reading it as a string * the current selection criteria is the file extension ** I am thinking about trying to import every file into the DOM and using the result state of that action as selection criteria * Updated README.md and test cases accordingly --- src/function/read_xml_file.cc | 86 ------------------------------------------- 1 file changed, 86 deletions(-) delete mode 100644 src/function/read_xml_file.cc (limited to 'src/function/read_xml_file.cc') diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc deleted file mode 100644 index e4d256d..0000000 --- a/src/function/read_xml_file.cc +++ /dev/null @@ -1,86 +0,0 @@ -#include "read_xml_file.h" - -#include -#include -#include -#include -#include - -#include "support/xerces_string_guard.h" -#include "support/dom/result_node_facade.h" - -namespace { - -inline xercesc::DOMNode* importDocumentElement( - const std::string& filePath, - xercesc::DOMDocument* const domDocument -) { - const xercesc::LocalFileInputSource file( - *InputXSLT::XercesStringGuard(filePath.data()) - ); - - xercesc::XercesDOMParser parser; - parser.parse(file); - - return domDocument->importNode( - parser.getDocument()->getDocumentElement(), - true - ); -} - -} - -namespace InputXSLT { - -xercesc::DOMDocument* FunctionReadXmlFile::constructDocument( - const FilesystemContext& fsContext, - std::string rawPath -) { - boost::filesystem::path filePath(fsContext.resolve(rawPath)); - - if ( !(boost::filesystem::exists(filePath) && - boost::filesystem::is_regular_file(filePath)) ) { - if ( auto resolvedPath = this->include_resolver_->resolve(rawPath) ) { - filePath = *resolvedPath; - } - } - - xercesc::DOMDocument* const domDocument( - xercesc::DOMImplementation::getImplementation()->createDocument( - nullptr, - *XercesStringGuard("content"), - nullptr - ) - ); - - xercesc::DOMNode* const rootNode( - domDocument->getDocumentElement() - ); - - ResultNodeFacade result(domDocument, rootNode, "file"); - result.setAttribute("path", filePath.string()); - - if ( boost::filesystem::is_regular_file(filePath) ) { - try { - result.setContent( - importDocumentElement(filePath.string(), domDocument) - ); - - result.setAttribute("result", "success"); - } - catch ( const xercesc::DOMException& exception ) { - result.setAttribute("result", "error"); - - result.setValueNode( - "error", - *XercesStringGuard(exception.msg) - ); - } - } else { - result.setAttribute("result", "error"); - } - - return domDocument; -} - -} -- cgit v1.2.3