aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dummy/transform.xsl22
-rw-r--r--src/function/read_directory.cc1
-rw-r--r--src/function/read_file.cc4
-rw-r--r--src/function/read_xml_file.cc88
-rw-r--r--src/function/read_xml_file.h6
5 files changed, 94 insertions, 27 deletions
diff --git a/dummy/transform.xsl b/dummy/transform.xsl
index fc6c15b..359db05 100644
--- a/dummy/transform.xsl
+++ b/dummy/transform.xsl
@@ -24,16 +24,26 @@
<xsl:value-of select="$testFile/self::content"/>
</xsl:when>
<xsl:otherwise>
- Could not read file.
+ Could not read text file.
</xsl:otherwise>
</xsl:choose>
</div>
- <ul id="xml">
- <xsl:for-each select="external:read-xml-file('test.txt')/tester/eintrag">
- <li><xsl:value-of select="."/></li>
- </xsl:for-each>
- </ul>
+ <div id="xml">
+ <xsl:variable name="testXml" select="external:read-xml-file('test.txt')"/>
+ <xsl:choose>
+ <xsl:when test="$testXml/self::status = 'successful'">
+ <ul id="xml">
+ <xsl:for-each select="$testXml/self::content/tester/eintrag">
+ <li><xsl:value-of select="."/></li>
+ </xsl:for-each>
+ </ul>
+ </xsl:when>
+ <xsl:otherwise>
+ Could not read XML file.
+ </xsl:otherwise>
+ </xsl:choose>
+ </div>
<div id="filelists">
<xsl:variable name="fileList" select="external:read-directory('../')"/>
diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc
index 1e7e7d7..6fcb447 100644
--- a/src/function/read_directory.cc
+++ b/src/function/read_directory.cc
@@ -4,7 +4,6 @@
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMText.hpp>
-#include <xercesc/util/XMLString.hpp>
#include "support/utility.h"
#include "support/xerces_string_guard.h"
diff --git a/src/function/read_file.cc b/src/function/read_file.cc
index 6f02702..cfbec59 100644
--- a/src/function/read_file.cc
+++ b/src/function/read_file.cc
@@ -4,14 +4,12 @@
#include <xercesc/dom/DOMImplementation.hpp>
#include <xercesc/dom/DOMElement.hpp>
#include <xercesc/dom/DOMText.hpp>
-#include <xercesc/util/XMLString.hpp>
#include "boost/filesystem/fstream.hpp"
#include <fstream>
#include "support/xerces_string_guard.h"
-#include "support/utility.h"
namespace InputXSLT {
@@ -30,7 +28,7 @@ xalan::XObjectPtr FunctionReadFile::execute(
);
DomDocumentCache::item* const cachedDocument(
- this->document_cache_->get(xalanToString(argument->str()))
+ this->document_cache_->get(filePath.string())
);
if ( !cachedDocument->isFinalized() ) {
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc
index d429f34..52f7735 100644
--- a/src/function/read_xml_file.cc
+++ b/src/function/read_xml_file.cc
@@ -1,16 +1,20 @@
#include "read_xml_file.h"
+#include <xercesc/dom/DOMDocument.hpp>
+#include <xercesc/dom/DOMImplementation.hpp>
+#include <xercesc/dom/DOMElement.hpp>
+#include <xercesc/dom/DOMText.hpp>
+#include <xercesc/parsers/XercesDOMParser.hpp>
+
#include "boost/filesystem/fstream.hpp"
+#include "support/xerces_string_guard.h"
+
namespace InputXSLT {
FunctionReadXmlFile::FunctionReadXmlFile(const FilesystemContext& context):
fs_context_(context),
- parser_() { }
-
-FunctionReadXmlFile::FunctionReadXmlFile(const FunctionReadXmlFile& src):
- fs_context_(src.fs_context_),
- parser_() { }
+ document_cache_(std::make_shared<DomDocumentCache>()) { }
xalan::XObjectPtr FunctionReadXmlFile::execute(
xalan::XPathExecutionContext& executionContext,
@@ -22,19 +26,75 @@ xalan::XObjectPtr FunctionReadXmlFile::execute(
this->fs_context_.resolve(argument->str())
);
- if ( boost::filesystem::is_regular_file(filePath) ) {
- boost::filesystem::ifstream file(filePath);
+ DomDocumentCache::item* const cachedDocument(
+ this->document_cache_->get(filePath.string())
+ );
- return executionContext.getXObjectFactory().createNodeSet(
- this->parser_.parseXMLStream(
- xalan::XSLTInputSource(file)
- )
+ if ( !cachedDocument->isFinalized() ) {
+ xercesc::DOMDocument* const domDocument(
+ cachedDocument->getXercesDocument()
);
- } else {
- return executionContext.getXObjectFactory().createString(
- xalan::XalanDOMString("io error")
+
+ xercesc::DOMNode* const rootNode(
+ domDocument->getDocumentElement()
);
+
+ if ( boost::filesystem::is_regular_file(filePath) ) {
+ xercesc::DOMElement* const contentNode(
+ domDocument->createElement(*XercesStringGuard("content"))
+ );
+
+ xercesc::XercesDOMParser parser;
+ boost::filesystem::ifstream file(filePath);
+ parser.parse(xalan::XSLTInputSource(file));
+
+ xercesc::DOMNode* const contentTreeNode(
+ domDocument->importNode(
+ parser.getDocument()->getDocumentElement(),
+ true
+ )
+ );
+
+ xercesc::DOMElement* const resultNode(
+ domDocument->createElement(*XercesStringGuard("status"))
+ );
+
+ xercesc::DOMText* const resultTextNode(
+ domDocument->createTextNode(
+ *XercesStringGuard("successful")
+ )
+ );
+
+ contentNode->appendChild(contentTreeNode);
+ resultNode->appendChild(resultTextNode);
+
+ rootNode->appendChild(contentNode);
+ rootNode->appendChild(resultNode);
+ } else {
+ xercesc::DOMElement* const resultNode(
+ domDocument->createElement(*XercesStringGuard("status"))
+ );
+
+ xercesc::DOMText* const resultTextNode(
+ domDocument->createTextNode(
+ *XercesStringGuard("error")
+ )
+ );
+
+ resultNode->appendChild(resultTextNode);
+ rootNode->appendChild(resultNode);
+ }
}
+
+ xalan::XPathExecutionContext::BorrowReturnMutableNodeRefList nodeList(
+ executionContext
+ );
+
+ nodeList->addNodes(
+ *cachedDocument->getXalanDocument()->getDocumentElement()->getChildNodes()
+ );
+
+ return executionContext.getXObjectFactory().createNodeSet(nodeList);
}
FunctionReadXmlFile* FunctionReadXmlFile::clone(
diff --git a/src/function/read_xml_file.h b/src/function/read_xml_file.h
index 775ec96..1df48fb 100644
--- a/src/function/read_xml_file.h
+++ b/src/function/read_xml_file.h
@@ -5,19 +5,19 @@
#include <xalanc/XPath/XObjectFactory.hpp>
#include <xalanc/XPath/Function.hpp>
#include <xalanc/XPath/XObject.hpp>
-#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp>
#include <string>
+#include <memory>
#include "common.h"
#include "support/filesystem_context.h"
+#include "support/dom/document_cache.h"
namespace InputXSLT {
class FunctionReadXmlFile : public xalan::Function {
public:
FunctionReadXmlFile(const FilesystemContext&);
- FunctionReadXmlFile(const FunctionReadXmlFile&);
virtual xalan::XObjectPtr execute(
xalan::XPathExecutionContext&,
@@ -33,7 +33,7 @@ class FunctionReadXmlFile : public xalan::Function {
private:
const FilesystemContext& fs_context_;
- mutable xalan::XercesParserLiaison parser_;
+ std::shared_ptr<DomDocumentCache> document_cache_;
const xalan::XalanDOMString& getError(xalan::XalanDOMString& result) const;