aboutsummaryrefslogtreecommitdiff
path: root/src/read_file_command.h
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-04-17 21:51:20 +0200
committerAdrian Kummerländer2014-04-17 21:51:20 +0200
commit9648c804a23278fcdf66e0f78c350e2ddce492ee (patch)
tree3da73f21148ffaa3773abf5cd7a0d35cba76f8e5 /src/read_file_command.h
downloadInputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.gz
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.bz2
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.lz
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.xz
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.tar.zst
InputXSLT-9648c804a23278fcdf66e0f78c350e2ddce492ee.zip
First commit of _InputXSLT_
* quick and dirty proof-of-concept for adding plain-file access to XSLT ** based on Apache Xalan XSLT processor * The idea is to create something like a static counterpart to Symphony CMS * Adding functions to XSLT for file system, plain file and binary file (read)-access * This project aims to test how such functionality can be integrated into XSLT ** if it works it could be developed into a nice static content transformation system * Contrary to the popular opinion I actually like XML and XSLT when used responsibly
Diffstat (limited to 'src/read_file_command.h')
-rw-r--r--src/read_file_command.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/read_file_command.h b/src/read_file_command.h
new file mode 100644
index 0000000..88c20bf
--- /dev/null
+++ b/src/read_file_command.h
@@ -0,0 +1,60 @@
+#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 "utility.h"
+
+XALAN_USING_XALAN(Function)
+XALAN_USING_XALAN(Locator)
+XALAN_USING_XALAN(XPathExecutionContext)
+XALAN_USING_XALAN(XalanDOMString)
+XALAN_USING_XALAN(XalanNode)
+XALAN_USING_XALAN(XObjectPtr)
+XALAN_USING_XALAN(MemoryManager)
+XALAN_USING_XALAN(XalanCopyConstruct)
+
+class FunctionFileRead : public Function {
+ public:
+ virtual XObjectPtr execute(
+ XPathExecutionContext& executionContext,
+ XalanNode* context,
+ const XObjectArgVectorType& args,
+ const Locator* locator
+ ) const {
+ if ( args.size() != 1 ) {
+ XPathExecutionContext::GetAndReleaseCachedString guard(executionContext);
+
+ generalError(executionContext, context, locator);
+ }
+
+ xalanc_1_11::CharVectorType tmpFileName;
+ std::string fileName;
+
+ args[0]->str().transcode(tmpFileName);
+ std::move(tmpFileName.begin(), tmpFileName.end(), fileName.begin());
+
+ std::string content(readFile(fileName));
+
+ return executionContext.getXObjectFactory().createString(
+ XalanDOMString(content.data())
+ );
+ }
+
+ virtual FunctionFileRead* clone(MemoryManager& manager) const {
+ return XalanCopyConstruct(manager, *this);
+ }
+
+ protected:
+ const XalanDOMString& getError(XalanDOMString& result) const {
+ result.assign("The read-file() function expects one argument.");
+
+ return result;
+ }
+
+ private:
+ FunctionFileRead& operator=(const FunctionFileRead&);
+ bool operator==(const FunctionFileRead&) const;
+
+};