diff options
author | Adrian Kummerländer | 2014-04-18 19:51:24 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-18 19:51:24 +0200 |
commit | 6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b (patch) | |
tree | f0a9709d7d09786585220ff0c27ceae97d7a4b87 /src | |
parent | e886ac3a4f2dacc79cf174b1257146fd91bf6b7c (diff) | |
download | InputXSLT-6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b.tar InputXSLT-6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b.tar.gz InputXSLT-6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b.tar.bz2 InputXSLT-6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b.tar.lz InputXSLT-6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b.tar.xz InputXSLT-6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b.tar.zst InputXSLT-6dd832dd0adb35f63148a0e7bd5bdcfb28516c3b.zip |
Implemented basic XML reading capabilities
* command "read-xml-file" reads a XML file and allows it to be transformed by the calling XSLT
* this will allow workflows like the following:
** a tranformation reads all the markdown files in a directory
** these markdown files are converted to a xml representation by a external function calling a appropriate C++ markdown parser
** the XML representation of each markdown file is converted to XHTML inside the XSL transformation
** ... and embedded into the output XHTML document
** => all inside a single XSL tranformation
*** i.e. it is provided with only a empty dummy XML input file and fetches the actual input by itself
* as all current code contained within this repository this is just a quick and dirty proof-of-concept and not in any way good code
Diffstat (limited to 'src')
-rw-r--r-- | src/read_file_command.h | 8 | ||||
-rw-r--r-- | src/read_xml_file_command.h | 57 | ||||
-rw-r--r-- | src/utility.h | 5 |
3 files changed, 66 insertions, 4 deletions
diff --git a/src/read_file_command.h b/src/read_file_command.h index 094bb3d..837ec04 100644 --- a/src/read_file_command.h +++ b/src/read_file_command.h @@ -9,7 +9,7 @@ namespace xalan = xalanc_1_11; -class FunctionFileRead : public xalan::Function { +class FunctionReadFile : public xalan::Function { public: virtual xalan::XObjectPtr execute( xalan::XPathExecutionContext& executionContext, @@ -43,7 +43,7 @@ class FunctionFileRead : public xalan::Function { ); } - virtual FunctionFileRead* clone(xalan::MemoryManager& manager) const { + virtual FunctionReadFile* clone(xalan::MemoryManager& manager) const { return xalan::XalanCopyConstruct(manager, *this); } @@ -55,7 +55,7 @@ class FunctionFileRead : public xalan::Function { } private: - FunctionFileRead& operator=(const FunctionFileRead&); - bool operator==(const FunctionFileRead&) const; + FunctionReadFile& operator=(const FunctionReadFile&); + bool operator==(const FunctionReadFile&) const; }; diff --git a/src/read_xml_file_command.h b/src/read_xml_file_command.h new file mode 100644 index 0000000..96b6c5d --- /dev/null +++ b/src/read_xml_file_command.h @@ -0,0 +1,57 @@ +#include <xalanc/Include/PlatformDefinitions.hpp> +#include <xercesc/util/PlatformUtils.hpp> +#include <xalanc/XalanTransformer/XalanTransformer.hpp> +#include <xalanc/XPath/XObjectFactory.hpp> +#include <xalanc/XPath/Function.hpp> +#include <xalanc/XPath/XObject.hpp> +#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp> + +#include "utility.h" + +namespace xalan = xalanc_1_11; + +class FunctionReadXmlFile : public xalan::Function { + public: + virtual xalan::XObjectPtr execute( + xalan::XPathExecutionContext& executionContext, + xalan::XalanNode* context, + const xalan::Function::XObjectArgVectorType& args, + const xalan::Locator* locator + ) const { + if ( args.size() != 1 ) { + xalan::XPathExecutionContext::GetAndReleaseCachedString guard( + executionContext + ); + + generalError(executionContext, context, locator); + } + + if ( this->liaison == nullptr ) { + const_cast<FunctionReadXmlFile*>(this)->liaison = new xalan::XercesParserLiaison(); + } + + xalan::XSLTInputSource file(args[0]->str()); + + return executionContext.getXObjectFactory().createNodeSet( + liaison->parseXMLStream(file) + ); + } + + virtual FunctionReadXmlFile* clone(xalan::MemoryManager& manager) const { + return xalan::XalanCopyConstruct(manager, *this); + } + + protected: + xalan::XercesParserLiaison* liaison = nullptr; + + const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const { + result.assign("The read-file() function expects one argument."); + + return result; + } + + private: + FunctionReadXmlFile& operator=(const FunctionReadXmlFile&); + bool operator==(const FunctionReadXmlFile&) const; + +}; diff --git a/src/utility.h b/src/utility.h index 7050cee..9c88b38 100644 --- a/src/utility.h +++ b/src/utility.h @@ -1,3 +1,6 @@ +#ifndef UTILITY_H_ +#define UTILITY_H_ + #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> @@ -46,3 +49,5 @@ std::string readFile(const std::string& path) { return content; } } + +#endif // UTILITY_H_ |