aboutsummaryrefslogtreecommitdiff
path: root/src/function/read_file.cc
diff options
context:
space:
mode:
authorAdrian Kummerländer2014-05-03 22:04:16 +0200
committerAdrian Kummerländer2014-05-03 22:04:16 +0200
commit261170cc5b6661106877dc2611dab281f4d91348 (patch)
tree8482f249c090af5ca462f7e36a4b87082185f027 /src/function/read_file.cc
parente5ed418907f09bf8905463f42a44593d51159bc9 (diff)
downloadInputXSLT-261170cc5b6661106877dc2611dab281f4d91348.tar
InputXSLT-261170cc5b6661106877dc2611dab281f4d91348.tar.gz
InputXSLT-261170cc5b6661106877dc2611dab281f4d91348.tar.bz2
InputXSLT-261170cc5b6661106877dc2611dab281f4d91348.tar.lz
InputXSLT-261170cc5b6661106877dc2611dab281f4d91348.tar.xz
InputXSLT-261170cc5b6661106877dc2611dab281f4d91348.tar.zst
InputXSLT-261170cc5b6661106877dc2611dab281f4d91348.zip
Revamped DomDocumentCache with regard to thread safety
* DomDocumentCache::item class now is _finalized_ by default and doesn't perform document instantiation, just lifetime management ** xercesc::DOMDocument is instantiated inside the external function implementations and committed to the document cache for conversion to a xalan document * added mutex with scoped lock to prevent concurrent write access to the std::unordered_map contained withing DomDocumentCache * functionality of the _get_ member method was split into _get_ and _create_ ** added typedef for std::pair specialization type "optional_item" that functions as the return value of _create_ and _get_ * "locator->getSystemId()" was leaking memory as xerces doesn't manage the lifetime of the returned heap-allocated char array ** analog to XMLCh* strings ** transformed XercesStringGuard into template class to be instantiated on either XMLCh or char
Diffstat (limited to 'src/function/read_file.cc')
-rw-r--r--src/function/read_file.cc35
1 files changed, 25 insertions, 10 deletions
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 7634d54..633559e 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -36,7 +36,11 @@ xalan::XObjectPtr FunctionReadFile::execute(
) const {
const FilesystemContext fs_context(
boost::filesystem::path(
- xercesc::XMLString::transcode(locator->getSystemId() + 7)
+ *XercesStringGuard<char>(
+ xercesc::XMLString::transcode(
+ locator->getSystemId() + 7
+ )
+ )
).parent_path().string()
);
@@ -44,13 +48,17 @@ xalan::XObjectPtr FunctionReadFile::execute(
fs_context.resolve(argument->str())
);
- DomDocumentCache::item* const cachedDocument(
+ DomDocumentCache::optional_item optionalCachedDocument(
this->document_cache_->get(filePath.string())
);
- if ( !cachedDocument->isFinalized() ) {
+ if ( !optionalCachedDocument.first ) {
xercesc::DOMDocument* const domDocument(
- cachedDocument->getXercesDocument()
+ xercesc::DOMImplementation::getImplementation()->createDocument(
+ nullptr,
+ *XercesStringGuard<XMLCh>("content"),
+ nullptr
+ )
);
xercesc::DOMNode* const rootNode(
@@ -59,17 +67,17 @@ xalan::XObjectPtr FunctionReadFile::execute(
if ( boost::filesystem::is_regular_file(filePath) ) {
xercesc::DOMElement* const resultNode(
- domDocument->createElement(*XercesStringGuard("result"))
+ domDocument->createElement(*XercesStringGuard<XMLCh>("result"))
);
resultNode->setAttribute(
- *XercesStringGuard("name"),
- *XercesStringGuard(filePath.filename().string())
+ *XercesStringGuard<XMLCh>("name"),
+ *XercesStringGuard<XMLCh>(filePath.filename().string())
);
xercesc::DOMText* const resultTextNode(
domDocument->createTextNode(
- *XercesStringGuard(readFile(filePath))
+ *XercesStringGuard<XMLCh>(readFile(filePath))
)
);
@@ -77,11 +85,16 @@ xalan::XObjectPtr FunctionReadFile::execute(
rootNode->appendChild(resultNode);
} else {
xercesc::DOMElement* const resultNode(
- domDocument->createElement(*XercesStringGuard("error"))
+ domDocument->createElement(*XercesStringGuard<XMLCh>("error"))
);
rootNode->appendChild(resultNode);
}
+
+ optionalCachedDocument = this->document_cache_->create(
+ filePath.string(),
+ domDocument
+ );
}
xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList(
@@ -89,7 +102,9 @@ xalan::XObjectPtr FunctionReadFile::execute(
);
nodeList->addNodes(
- *cachedDocument->getXalanDocument()->getDocumentElement()->getChildNodes()
+ *optionalCachedDocument.second->getXalanDocument()
+ ->getDocumentElement()
+ ->getChildNodes()
);
return executionContext.getXObjectFactory().createNodeSet(nodeList);