aboutsummaryrefslogtreecommitdiff
path: root/src/function
diff options
context:
space:
mode:
Diffstat (limited to 'src/function')
-rw-r--r--src/function/read_file.cc49
-rw-r--r--src/function/read_file.h36
-rw-r--r--src/function/read_xml_file.cc44
-rw-r--r--src/function/read_xml_file.h42
4 files changed, 171 insertions, 0 deletions
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
new file mode 100644
index 0000000..efc1f61
--- /dev/null
+++ b/src/function/read_file.cc
@@ -0,0 +1,49 @@
+#include "read_file.h"
+
+namespace InputXSLT {
+
+xalan::XObjectPtr FunctionReadFile::execute(
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode* context,
+ const xalan::Function::XObjectArgVectorType& arguments,
+ const xalan::Locator* locator
+) const {
+ if ( arguments.size() != 1 ) {
+ xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
+ executionContext
+ );
+
+ generalError(executionContext, context, locator);
+ }
+
+ xalan::CharVectorType fileNameVector;
+ std::string fileNameString;
+
+ arguments[0]->str().transcode(fileNameVector);
+
+ std::move(
+ fileNameVector.begin(),
+ fileNameVector.end(),
+ fileNameString.begin()
+ );
+
+ return executionContext.getXObjectFactory().createString(
+ xalan::XalanDOMString(
+ InputXSLT::readFile(fileNameString).data()
+ )
+ );
+}
+
+FunctionReadFile* FunctionReadFile::clone(
+ xalan::MemoryManager& manager) const {
+ return xalan::XalanCopyConstruct(manager, *this);
+}
+
+const xalan::XalanDOMString& FunctionReadFile::getError(
+ xalan::XalanDOMString& result) const {
+ result.assign("The read-file() function expects one argument.");
+
+ return result;
+}
+
+}
diff --git a/src/function/read_file.h b/src/function/read_file.h
new file mode 100644
index 0000000..dbcf3d6
--- /dev/null
+++ b/src/function/read_file.h
@@ -0,0 +1,36 @@
+#ifndef INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
+#define INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
+
+#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 "utility.h"
+
+namespace InputXSLT {
+
+class FunctionReadFile : public xalan::Function {
+ public:
+ virtual xalan::XObjectPtr execute(
+ xalan::XPathExecutionContext&,
+ xalan::XalanNode*,
+ const xalan::Function::XObjectArgVectorType&,
+ const xalan::Locator*
+ ) const;
+
+ virtual FunctionReadFile* clone(xalan::MemoryManager&) const;
+
+ FunctionReadFile& operator=(const FunctionReadFile&) = delete;
+ bool operator==(const FunctionReadFile&) const = delete;
+
+ private:
+ const xalan::XalanDOMString& getError(xalan::XalanDOMString&) const;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_FUNCTION_READ_FILE_H_
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
new file mode 100644
index 0000000..616d189
--- /dev/null
+++ b/src/function/read_xml_file.cc
@@ -0,0 +1,44 @@
+#include "read_xml_file.h"
+
+namespace InputXSLT {
+
+FunctionReadXmlFile::FunctionReadXmlFile():
+ parser_() { }
+
+FunctionReadXmlFile::FunctionReadXmlFile(const FunctionReadXmlFile&):
+ parser_() { }
+
+xalan::XObjectPtr FunctionReadXmlFile::execute(
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode* context,
+ const xalan::Function::XObjectArgVectorType& arguments,
+ const xalan::Locator* locator
+) const {
+ if ( arguments.size() != 1 ) {
+ xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
+ executionContext
+ );
+
+ generalError(executionContext, context, locator);
+ }
+
+ return executionContext.getXObjectFactory().createNodeSet(
+ this->parser_.parseXMLStream(
+ xalan::XSLTInputSource(arguments[0]->str())
+ )
+ );
+}
+
+FunctionReadXmlFile* FunctionReadXmlFile::clone(
+ xalan::MemoryManager& manager) const {
+ return xalan::XalanCopyConstruct(manager, *this);
+}
+
+const xalan::XalanDOMString& FunctionReadXmlFile::getError(
+ xalan::XalanDOMString& result) const {
+ result.assign("The read-xml-file() function expects one argument.");
+
+ return result;
+}
+
+}
diff --git a/src/function/read_xml_file.h b/src/function/read_xml_file.h
new file mode 100644
index 0000000..1556764
--- /dev/null
+++ b/src/function/read_xml_file.h
@@ -0,0 +1,42 @@
+#ifndef INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_
+#define INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_
+
+#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 InputXSLT {
+
+class FunctionReadXmlFile : public xalan::Function {
+ public:
+ FunctionReadXmlFile();
+ FunctionReadXmlFile(const FunctionReadXmlFile&);
+
+ virtual xalan::XObjectPtr execute(
+ xalan::XPathExecutionContext& executionContext,
+ xalan::XalanNode* context,
+ const xalan::Function::XObjectArgVectorType& arguments,
+ const xalan::Locator* locator
+ ) const;
+
+ virtual FunctionReadXmlFile* clone(xalan::MemoryManager&) const;
+
+ FunctionReadXmlFile& operator=(const FunctionReadXmlFile&) = delete;
+ bool operator==(const FunctionReadXmlFile&) const = delete;
+
+ private:
+ mutable xalan::XercesParserLiaison parser_;
+
+ const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const;
+
+};
+
+}
+
+#endif // INPUTXSLT_SRC_FUNCTION_READ_XML_FILE_H_