diff options
author | Adrian Kummerländer | 2014-04-24 20:14:14 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-24 20:14:14 +0200 |
commit | a31fc1169edb33126242eb035dc038cbdea407e8 (patch) | |
tree | bba9d219ad9fc8a0ea752f6d8025a4b614bdebdb | |
parent | 525aa8c4dc3e23f0369c7edb1fb507ecad5f43bf (diff) | |
download | InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.gz InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.bz2 InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.lz InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.xz InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.tar.zst InputXSLT-a31fc1169edb33126242eb035dc038cbdea407e8.zip |
Changed TransformerFacade into TransformationFacade for single XSLTs
* contains a single, compiled transformation as specified by its construction argument
* uses the transformation's location as the FilesystemContext
* allows generation of output documents using _generate_ member method
-rw-r--r-- | CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/function/read_directory.cc | 2 | ||||
-rw-r--r-- | src/transformation_facade.cc | 65 | ||||
-rw-r--r-- | src/transformation_facade.h | 31 | ||||
-rw-r--r-- | src/transformer_facade.cc | 74 | ||||
-rw-r--r-- | src/transformer_facade.h | 30 | ||||
-rw-r--r-- | test.cc | 9 |
7 files changed, 101 insertions, 112 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 94ade96..ee6e7e3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,7 @@ include_directories( add_executable( test test.cc - src/transformer_facade.cc + src/transformation_facade.cc src/function/read_file.cc src/function/read_xml_file.cc src/function/read_directory.cc diff --git a/src/function/read_directory.cc b/src/function/read_directory.cc index 6d643da..0ed33bc 100644 --- a/src/function/read_directory.cc +++ b/src/function/read_directory.cc @@ -10,7 +10,7 @@ namespace InputXSLT { FunctionReadDirectory::FunctionReadDirectory(const FilesystemContext& context): fs_context_(context), - documents_(new std::stack<DomDocumentGuard>()) { } + documents_(std::make_shared<std::stack<DomDocumentGuard>>()) { } xalan::XObjectPtr FunctionReadDirectory::execute( xalan::XPathExecutionContext& executionContext, diff --git a/src/transformation_facade.cc b/src/transformation_facade.cc new file mode 100644 index 0000000..58bdb52 --- /dev/null +++ b/src/transformation_facade.cc @@ -0,0 +1,65 @@ +#include "transformation_facade.h" + +#include <xalanc/XSLT/XSLTInputSource.hpp> +#include <xalanc/XalanTransformer/XalanCompiledStylesheet.hpp> + +#include <sstream> + +#include "function/read_file.h" +#include "function/read_xml_file.h" +#include "function/read_directory.h" + + +namespace InputXSLT { + +TransformationFacade::TransformationFacade(const std::string& transformation): + fs_context_(boost::filesystem::path(transformation).parent_path().string()), + transformation_{}, + transformer_() { + const xalan::XalanDOMString customNamespace( + "http://ExternalFunction.xalan-c++.xml.apache.org" + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-file"), + InputXSLT::FunctionReadFile(this->fs_context_) + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-xml-file"), + InputXSLT::FunctionReadXmlFile(this->fs_context_) + ); + + this->transformer_.installExternalFunction( + customNamespace, + xalan::XalanDOMString("read-directory"), + InputXSLT::FunctionReadDirectory(this->fs_context_) + ); + + this->transformer_.compileStylesheet( + xalan::XSLTInputSource(transformation.data()), + this->transformation_ + ); +} + +TransformationFacade::~TransformationFacade() { + this->transformer_.destroyStylesheet( + this->transformation_ + ); +} + +int TransformationFacade::generate(const std::string& target) { + std::stringstream emptyStream("<dummy/>"); + xalan::XSLTInputSource inputSource(emptyStream); + xalan::XSLTResultTarget outputTarget(target.data()); + + return this->transformer_.transform( + inputSource, + this->transformation_, + outputTarget + ); +} + +} diff --git a/src/transformation_facade.h b/src/transformation_facade.h new file mode 100644 index 0000000..715d72e --- /dev/null +++ b/src/transformation_facade.h @@ -0,0 +1,31 @@ +#ifndef INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_ +#define INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_ + +#include <string> + +#include <xalanc/XalanTransformer/XalanTransformer.hpp> +#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp> + +#include "common.h" +#include "support/filesystem_context.h" + +namespace InputXSLT { + +class TransformationFacade { + public: + TransformationFacade(const std::string&); + ~TransformationFacade(); + + int generate(const std::string&); + + private: + const FilesystemContext fs_context_; + const xalan::XalanCompiledStylesheet* transformation_; + + xalan::XalanTransformer transformer_; + +}; + +} + +#endif // INPUTXSLT_SRC_TRANSFORMATION_FACADE_H_ diff --git a/src/transformer_facade.cc b/src/transformer_facade.cc deleted file mode 100644 index fbf604c..0000000 --- a/src/transformer_facade.cc +++ /dev/null @@ -1,74 +0,0 @@ -#include "transformer_facade.h" - -#include <xalanc/XSLT/XSLTInputSource.hpp> -#include <xalanc/XalanTransformer/XalanTransformer.hpp> -#include <xalanc/XercesParserLiaison/XercesDOMSupport.hpp> -#include <xalanc/XalanTransformer/XercesDOMWrapperParsedSource.hpp> - -#include <xercesc/dom/DOMDocument.hpp> -#include <xercesc/dom/DOMImplementation.hpp> - -#include <iostream> - -#include "function/read_file.h" -#include "function/read_xml_file.h" -#include "function/read_directory.h" - - -namespace InputXSLT { - -TransformerFacade::TransformerFacade(const std::string& path): - fs_context_(path), - parser_(), - transformer_() { - const xalan::XalanDOMString customNamespace( - "http://ExternalFunction.xalan-c++.xml.apache.org" - ); - - this->transformer_.installExternalFunction( - customNamespace, - xalan::XalanDOMString("read-file"), - InputXSLT::FunctionReadFile(this->fs_context_) - ); - - this->transformer_.installExternalFunction( - customNamespace, - xalan::XalanDOMString("read-xml-file"), - InputXSLT::FunctionReadXmlFile(this->fs_context_) - ); - - this->transformer_.installExternalFunction( - customNamespace, - xalan::XalanDOMString("read-directory"), - InputXSLT::FunctionReadDirectory(this->fs_context_) - ); -} - -int TransformerFacade::execute( - const std::string& transformation, - const std::string& target -) { - xercesc::DOMDocument* inputDom( - xercesc::DOMImplementation::getImplementation()->createDocument() - ); - xalan::XercesDOMSupport domSupport(this->parser_); - - xalan::XercesDOMWrapperParsedSource parsedInput( - inputDom, - this->parser_, - domSupport - ); - - inputDom->release(); - - xalan::XSLTInputSource transform(transformation.data()); - xalan::XSLTResultTarget output(target.data()); - - return this->transformer_.transform( - parsedInput, - transform, - output - ); -} - -} diff --git a/src/transformer_facade.h b/src/transformer_facade.h deleted file mode 100644 index ed25edc..0000000 --- a/src/transformer_facade.h +++ /dev/null @@ -1,30 +0,0 @@ -#ifndef INPUTXSLT_SRC_TRANSFORMER_FACADE_H_ -#define INPUTXSLT_SRC_TRANSFORMER_FACADE_H_ - -#include <string> - -#include <xalanc/XalanTransformer/XalanTransformer.hpp> -#include <xalanc/XercesParserLiaison/XercesParserLiaison.hpp> - -#include "common.h" -#include "support/filesystem_context.h" - -namespace InputXSLT { - -class TransformerFacade { - public: - TransformerFacade(const std::string&); - - int execute(const std::string&, const std::string&); - - private: - const FilesystemContext fs_context_; - mutable xalan::XercesParserLiaison parser_; - - xalan::XalanTransformer transformer_; - -}; - -} - -#endif // INPUTXSLT_SRC_TRANSFORMER_FACADE_H_ @@ -1,12 +1,9 @@ #include "plattform_guard.h" -#include "transformer_facade.h" +#include "transformation_facade.h" int main() { InputXSLT::PlattformGuard plattform; - InputXSLT::TransformerFacade transformer("../dummy/"); + InputXSLT::TransformationFacade transformation("../dummy/transform.xsl"); - return transformer.execute( - "../dummy/transform.xsl", - "out.xml" - ); + return transformation.generate("out.xml"); } |