aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-14 20:55:51 +0200
committerAdrian Kummerländer2014-05-14 20:55:51 +0200
commit5fbca0993146982ab1dbb0d352c1e15e40b3de22 (patch)
tree7f47a339fb61d5c8423162482494eafd95cc654d
parent943768ad437011756395b86958399992e6822604 (diff)
downloadInputXSLT-5fbca0993146982ab1dbb0d352c1e15e40b3de22.tar
InputXSLT-5fbca0993146982ab1dbb0d352c1e15e40b3de22.tar.gz
InputXSLT-5fbca0993146982ab1dbb0d352c1e15e40b3de22.tar.bz2
InputXSLT-5fbca0993146982ab1dbb0d352c1e15e40b3de22.tar.lz
InputXSLT-5fbca0993146982ab1dbb0d352c1e15e40b3de22.tar.xz
InputXSLT-5fbca0993146982ab1dbb0d352c1e15e40b3de22.tar.zst
InputXSLT-5fbca0993146982ab1dbb0d352c1e15e40b3de22.zip
Moved responsibility for argument conversion to FunctionBase descendants
* external functions may expect arguments with a type different from boost::filesystem::path so they are only provided raw string values * moved xalan string conversion logic into separate compilation unit
-rw-r--r--CMakeLists.txt1
-rw-r--r--src/function/base.h17
-rw-r--r--src/function/read_directory.cc4
-rw-r--r--src/function/read_file.cc6
-rw-r--r--src/function/read_xml_file.cc6
-rw-r--r--src/function/transform.cc11
-rw-r--r--src/support/filesystem_context.cc19
-rw-r--r--src/support/xalan_string.cc19
-rw-r--r--src/support/xalan_string.h17
9 files changed, 66 insertions, 34 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index da44f2b..73443c6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,6 +30,7 @@ set(
src/function/transform.cc
src/support/filesystem_context.cc
src/support/stylesheet_parameter_guard.cc
+ src/support/xalan_string.cc
src/support/dom/document_cache.cc
src/support/dom/document_cache_item.cc
)
diff --git a/src/function/base.h b/src/function/base.h
index 5604186..7fbd818 100644
--- a/src/function/base.h
+++ b/src/function/base.h
@@ -11,6 +11,7 @@
#include <array>
#include "common.h"
+#include "support/xalan_string.h"
#include "support/dom/document_cache.h"
#include "support/filesystem_context.h"
@@ -22,10 +23,7 @@ template <
>
class FunctionBase : public xalan::Function {
public:
- typedef std::array<
- boost::filesystem::path,
- ArgumentCount
- > argument_array;
+ typedef std::array<std::string, ArgumentCount> argument_array;
FunctionBase():
document_cache_(std::make_shared<DomDocumentCache>()) { }
@@ -43,15 +41,14 @@ class FunctionBase : public xalan::Function {
locator
);
- const FilesystemContext fsContext(locator);
argument_array pathArguments;
std::transform(
rawArguments.begin(),
rawArguments.end(),
pathArguments.begin(),
- [&fsContext](const xalan::XObjectPtr& ptr) -> boost::filesystem::path {
- return fsContext.resolve(ptr->str());
+ [](const xalan::XObjectPtr& ptr) -> std::string {
+ return toString(ptr->str());
}
);
@@ -60,7 +57,7 @@ class FunctionBase : public xalan::Function {
static_cast<Implementation*>(
const_cast<FunctionBase*>(this)
)->constructDocument(
- fsContext,
+ FilesystemContext(locator),
pathArguments
)
)
@@ -108,7 +105,7 @@ class FunctionBase : public xalan::Function {
xalan::XalanNode* context,
const xalan::Locator* locator
) const {
- const bool notNull = std::none_of(
+ const bool anyNull = std::any_of(
rawArguments.begin(),
rawArguments.end(),
[](const xalan::XObjectPtr& ptr) -> bool {
@@ -116,7 +113,7 @@ class FunctionBase : public xalan::Function {
}
);
- if ( rawArguments.size() != ArgumentCount && notNull ) {
+ if ( rawArguments.size() != ArgumentCount || anyNull ) {
xalan::XPathExecutionContext::GetAndReleaseCachedString guard(
executionContext
);
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc
index e030e33..54d3d0d 100644
--- a/src/function/read_directory.cc
+++ b/src/function/read_directory.cc
@@ -13,7 +13,9 @@ xercesc::DOMDocument* FunctionReadDirectory::constructDocument(
const InputXSLT::FilesystemContext& fsContext,
const FunctionBase::argument_array& arguments
) {
- const boost::filesystem::path& directoryPath = arguments[0];
+ const boost::filesystem::path directoryPath(
+ fsContext.resolve(arguments[0])
+ );
xercesc::DOMDocument* const domDocument(
xercesc::DOMImplementation::getImplementation()->createDocument(
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index da0e988..19ca296 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -25,10 +25,12 @@ inline std::string readFile(const boost::filesystem::path& filePath) {
namespace InputXSLT {
xercesc::DOMDocument* FunctionReadFile::constructDocument(
- const FilesystemContext&,
+ const FilesystemContext& fsContext,
const FunctionBase::argument_array& arguments
) {
- const boost::filesystem::path& filePath = arguments[0];
+ const boost::filesystem::path filePath(
+ fsContext.resolve(arguments[0])
+ );
xercesc::DOMDocument* const domDocument(
xercesc::DOMImplementation::getImplementation()->createDocument(
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
index b3bf3de..cf2cadd 100644
--- a/src/function/read_xml_file.cc
+++ b/src/function/read_xml_file.cc
@@ -33,10 +33,12 @@ inline xercesc::DOMNode* importDocumentElement(
namespace InputXSLT {
xercesc::DOMDocument* FunctionReadXmlFile::constructDocument(
- const FilesystemContext&,
+ const FilesystemContext& fsContext,
const FunctionBase::argument_array& arguments
) {
- const boost::filesystem::path& filePath = arguments[0];
+ const boost::filesystem::path filePath(
+ fsContext.resolve(arguments[0])
+ );
xercesc::DOMDocument* const domDocument(
xercesc::DOMImplementation::getImplementation()->createDocument(
diff --git a/src/function/transform.cc b/src/function/transform.cc
index 360b61d..5c53044 100644
--- a/src/function/transform.cc
+++ b/src/function/transform.cc
@@ -10,11 +10,16 @@
namespace InputXSLT {
xercesc::DOMDocument* FunctionTransform::constructDocument(
- const InputXSLT::FilesystemContext&,
+ const InputXSLT::FilesystemContext& fsContext,
const FunctionBase::argument_array& arguments
) {
- const boost::filesystem::path& transformationPath = arguments[0];
- const boost::filesystem::path& targetPath = arguments[1];
+ const boost::filesystem::path transformationPath(
+ fsContext.resolve(arguments[0])
+ );
+
+ const boost::filesystem::path targetPath(
+ fsContext.resolve(arguments[1])
+ );
xercesc::DOMDocument* const domDocument(
xercesc::DOMImplementation::getImplementation()->createDocument(
diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc
index 30502b3..8395046 100644
--- a/src/support/filesystem_context.cc
+++ b/src/support/filesystem_context.cc
@@ -3,22 +3,9 @@
#include <algorithm>
#include <iterator>
+#include "support/xalan_string.h"
#include "support/xerces_string_guard.h"
-namespace {
-
-inline std::string xalanToString(const xalan::XalanDOMString& text) {
- xalan::CharVectorType castHelper;
- text.transcode(castHelper);
-
- return std::string(
- castHelper.begin(),
- castHelper.end() - 1
- );
-}
-
-}
-
namespace InputXSLT {
FilesystemContext::FilesystemContext(const xalan::Locator* locator):
@@ -38,7 +25,7 @@ boost::filesystem::path FilesystemContext::resolve(
boost::filesystem::path FilesystemContext::resolve(
const xalan::XalanDOMString& path) const {
- return this->resolve(xalanToString(path));
+ return this->resolve(toString(path));
}
void FilesystemContext::iterate(
@@ -78,7 +65,7 @@ void FilesystemContext::iterate(
const xalan::XalanDOMString& path,
std::function<void(const boost::filesystem::path&)> func
) const {
- this->iterate(xalanToString(path), func);
+ this->iterate(toString(path), func);
}
}
diff --git a/src/support/xalan_string.cc b/src/support/xalan_string.cc
new file mode 100644
index 0000000..b89f08b
--- /dev/null
+++ b/src/support/xalan_string.cc
@@ -0,0 +1,19 @@
+#include "xalan_string.h"
+
+namespace InputXSLT {
+
+std::string toString(const xalan::XalanDOMString& text) {
+ xalan::CharVectorType castHelper;
+ text.transcode(castHelper);
+
+ return std::string(
+ castHelper.begin(),
+ castHelper.end() - 1
+ );
+}
+
+xalan::XalanDOMString toString(const std::string& text) {
+ return xalan::XalanDOMString(text.data());
+}
+
+}
diff --git a/src/support/xalan_string.h b/src/support/xalan_string.h
new file mode 100644
index 0000000..2220be5
--- /dev/null
+++ b/src/support/xalan_string.h
@@ -0,0 +1,17 @@
+#ifndef INPUTXSLT_SRC_SUPPORT_XALAN_STRING_H_
+#define INPUTXSLT_SRC_SUPPORT_XALAN_STRING_H_
+
+#include <xalanc/XalanDOM/XalanDOMString.hpp>
+
+#include <string>
+
+#include "common.h"
+
+namespace InputXSLT {
+
+std::string toString(const xalan::XalanDOMString&);
+xalan::XalanDOMString toString(const std::string&);
+
+}
+
+#endif // INPUTXSLT_SRC_SUPPORT_XALAN_STRING_H_