aboutsummaryrefslogtreecommitdiff
path: root/src/function/read_xml_file.cc
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-04 20:49:37 +0200
committerAdrian Kummerländer2014-05-04 20:49:37 +0200
commitbd24e3fe6335bc776400be6bcb44a0701ecc4133 (patch)
tree748364b36990e1fe949a3826ff6e878c2f14f9fb /src/function/read_xml_file.cc
parenta0ddbb0ccba20123fc4e8243d962f86232282612 (diff)
downloadInputXSLT-bd24e3fe6335bc776400be6bcb44a0701ecc4133.tar
InputXSLT-bd24e3fe6335bc776400be6bcb44a0701ecc4133.tar.gz
InputXSLT-bd24e3fe6335bc776400be6bcb44a0701ecc4133.tar.bz2
InputXSLT-bd24e3fe6335bc776400be6bcb44a0701ecc4133.tar.lz
InputXSLT-bd24e3fe6335bc776400be6bcb44a0701ecc4133.tar.xz
InputXSLT-bd24e3fe6335bc776400be6bcb44a0701ecc4133.tar.zst
InputXSLT-bd24e3fe6335bc776400be6bcb44a0701ecc4133.zip
Moved DOM document construction logic into local functions
* this change makes the underlying similarity between all currently implemented external functions obvious * they more or less only differ in their document construction logic ** i.e. there is a possibility for a second layer of abstraction between the classes derived from xalan::Function and the actual functionality * added boost::filesystem::path taking overload of the _iterate_ member method to FilesystemGuard ** this overload functions as the _master_ overload that is called by all other overloads which merely perform type conversion and path resolution ** this overload doesn't perform path resolution
Diffstat (limited to 'src/function/read_xml_file.cc')
-rw-r--r--src/function/read_xml_file.cc86
1 files changed, 47 insertions, 39 deletions
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
index 0fa21fe..a4e3e3c 100644
--- a/src/function/read_xml_file.cc
+++ b/src/function/read_xml_file.cc
@@ -13,6 +13,8 @@
namespace {
+using InputXSLT::XercesStringGuard;
+
inline xercesc::DOMNode* importDocumentElement(
const boost::filesystem::path& filePath,
xercesc::DOMDocument* const domDocument
@@ -27,6 +29,48 @@ inline xercesc::DOMNode* importDocumentElement(
);
}
+xercesc::DOMDocument* constructDocument(
+ const boost::filesystem::path& filePath
+) {
+ xercesc::DOMDocument* const domDocument(
+ xercesc::DOMImplementation::getImplementation()->createDocument(
+ nullptr,
+ *XercesStringGuard<XMLCh>("content"),
+ nullptr
+ )
+ );
+
+ xercesc::DOMNode* const rootNode(
+ domDocument->getDocumentElement()
+ );
+
+ if ( boost::filesystem::is_regular_file(filePath) ) {
+ xercesc::DOMElement* const resultNode(
+ domDocument->createElement(*XercesStringGuard<XMLCh>("result"))
+ );
+
+ resultNode->setAttribute(
+ *XercesStringGuard<XMLCh>("name"),
+ *XercesStringGuard<XMLCh>(filePath.filename().string())
+ );
+
+ xercesc::DOMNode* const resultTreeNode(
+ importDocumentElement(filePath, domDocument)
+ );
+
+ resultNode->appendChild(resultTreeNode);
+ rootNode->appendChild(resultNode);
+ } else {
+ xercesc::DOMElement* const resultNode(
+ domDocument->createElement(*XercesStringGuard<XMLCh>("error"))
+ );
+
+ rootNode->appendChild(resultNode);
+ }
+
+ return domDocument;
+}
+
}
namespace InputXSLT {
@@ -40,10 +84,10 @@ xalan::XObjectPtr FunctionReadXmlFile::execute(
const xalan::XObjectPtr argument,
const xalan::Locator* locator
) const {
- const FilesystemContext fs_context(locator);
+ const FilesystemContext fsContext(locator);
const boost::filesystem::path filePath(
- fs_context.resolve(argument->str())
+ fsContext.resolve(argument->str())
);
DomDocumentCache::optional_item optionalCachedDocument(
@@ -51,45 +95,9 @@ xalan::XObjectPtr FunctionReadXmlFile::execute(
);
if ( !optionalCachedDocument.first ) {
- xercesc::DOMDocument* const domDocument(
- xercesc::DOMImplementation::getImplementation()->createDocument(
- nullptr,
- *XercesStringGuard<XMLCh>("content"),
- nullptr
- )
- );
-
- xercesc::DOMNode* const rootNode(
- domDocument->getDocumentElement()
- );
-
- if ( boost::filesystem::is_regular_file(filePath) ) {
- xercesc::DOMElement* const resultNode(
- domDocument->createElement(*XercesStringGuard<XMLCh>("result"))
- );
-
- resultNode->setAttribute(
- *XercesStringGuard<XMLCh>("name"),
- *XercesStringGuard<XMLCh>(filePath.filename().string())
- );
-
- xercesc::DOMNode* const resultTreeNode(
- importDocumentElement(filePath, domDocument)
- );
-
- resultNode->appendChild(resultTreeNode);
- rootNode->appendChild(resultNode);
- } else {
- xercesc::DOMElement* const resultNode(
- domDocument->createElement(*XercesStringGuard<XMLCh>("error"))
- );
-
- rootNode->appendChild(resultNode);
- }
-
optionalCachedDocument = this->document_cache_->create(
filePath.string(),
- domDocument
+ constructDocument(filePath)
);
}