aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/function/read_directory.cc5
-rw-r--r--src/function/read_file.cc24
-rw-r--r--src/function/read_xml_file.cc27
-rw-r--r--src/support/filesystem_context.cc3
4 files changed, 39 insertions, 20 deletions
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc
index 686767d..f155029 100644
--- a/src/function/read_directory.cc
+++ b/src/function/read_directory.cc
@@ -62,6 +62,11 @@ xalan::XObjectPtr FunctionReadDirectory::execute(
break;
};
default: {
+ itemNode->setAttribute(
+ *XercesStringGuard("type"),
+ *XercesStringGuard("misc")
+ );
+
break;
};
}
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 83456c6..f531191 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -7,10 +7,21 @@
#include "boost/filesystem/fstream.hpp"
-#include <fstream>
-
#include "support/xerces_string_guard.h"
+namespace {
+
+inline std::string readFile(const boost::filesystem::path& filePath) {
+ boost::filesystem::ifstream file(filePath);
+
+ return std::string(
+ (std::istreambuf_iterator<char>(file)),
+ (std::istreambuf_iterator<char>())
+ );
+}
+
+}
+
namespace InputXSLT {
FunctionReadFile::FunctionReadFile(const FilesystemContext& context):
@@ -41,13 +52,6 @@ xalan::XObjectPtr FunctionReadFile::execute(
);
if ( boost::filesystem::is_regular_file(filePath) ) {
- boost::filesystem::ifstream file(filePath);
-
- const std::string fileContent(
- (std::istreambuf_iterator<char>(file)),
- (std::istreambuf_iterator<char>())
- );
-
xercesc::DOMElement* const resultNode(
domDocument->createElement(*XercesStringGuard("result"))
);
@@ -59,7 +63,7 @@ xalan::XObjectPtr FunctionReadFile::execute(
xercesc::DOMText* const resultTextNode(
domDocument->createTextNode(
- *XercesStringGuard(fileContent)
+ *XercesStringGuard(readFile(filePath))
)
);
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
index 7b54732..bf9ec2e 100644
--- a/src/function/read_xml_file.cc
+++ b/src/function/read_xml_file.cc
@@ -10,6 +10,24 @@
#include "support/xerces_string_guard.h"
+namespace {
+
+inline xercesc::DOMNode* importDocumentElement(
+ const boost::filesystem::path& filePath,
+ xercesc::DOMDocument* const domDocument
+) {
+ xercesc::XercesDOMParser parser;
+ boost::filesystem::ifstream file(filePath);
+ parser.parse(xalan::XSLTInputSource(file));
+
+ return domDocument->importNode(
+ parser.getDocument()->getDocumentElement(),
+ true
+ );
+}
+
+}
+
namespace InputXSLT {
FunctionReadXmlFile::FunctionReadXmlFile(const FilesystemContext& context):
@@ -49,15 +67,8 @@ xalan::XObjectPtr FunctionReadXmlFile::execute(
*XercesStringGuard(filePath.filename().string())
);
- xercesc::XercesDOMParser parser;
- boost::filesystem::ifstream file(filePath);
- parser.parse(xalan::XSLTInputSource(file));
-
xercesc::DOMNode* const resultTreeNode(
- domDocument->importNode(
- parser.getDocument()->getDocumentElement(),
- true
- )
+ importDocumentElement(filePath, domDocument)
);
resultNode->appendChild(resultTreeNode);
diff --git a/src/support/filesystem_context.cc b/src/support/filesystem_context.cc
index 6ad682f..d3caf88 100644
--- a/src/support/filesystem_context.cc
+++ b/src/support/filesystem_context.cc
@@ -35,8 +35,7 @@ void FilesystemContext::iterate(
) const {
const boost::filesystem::path directory(this->resolve(path));
- if ( boost::filesystem::exists(directory) &&
- boost::filesystem::is_directory(directory) ) {
+ if ( boost::filesystem::is_directory(directory) ) {
for ( boost::filesystem::directory_iterator iter(directory);
iter != boost::filesystem::directory_iterator();
++iter ) {