diff options
author | Adrian Kummerlaender | 2014-08-23 00:19:09 +0200 |
---|---|---|
committer | Adrian Kummerlaender | 2014-08-23 00:19:09 +0200 |
commit | 5a54b5b8150d8bf1ac5db3ac688479b3aca6486d (patch) | |
tree | 08fe4ce82a6f0da1837504afaf9c0d27affa5513 /src/function | |
parent | 2c89112141530617b51af8c41211c2507ec8c738 (diff) | |
download | InputXSLT-5a54b5b8150d8bf1ac5db3ac688479b3aca6486d.tar InputXSLT-5a54b5b8150d8bf1ac5db3ac688479b3aca6486d.tar.gz InputXSLT-5a54b5b8150d8bf1ac5db3ac688479b3aca6486d.tar.bz2 InputXSLT-5a54b5b8150d8bf1ac5db3ac688479b3aca6486d.tar.lz InputXSLT-5a54b5b8150d8bf1ac5db3ac688479b3aca6486d.tar.xz InputXSLT-5a54b5b8150d8bf1ac5db3ac688479b3aca6486d.tar.zst InputXSLT-5a54b5b8150d8bf1ac5db3ac688479b3aca6486d.zip |
Replaced FunctionTransform by making the target of FunctionGenerate optional
* if the target parameter is not provided FunctionGenerate now performs exactly the same functionality as FunctionTransform
* added "boost::optional<boost::filesystem::path>" specialization to the XObjectValue class
* modified test cases accordingly
* modified README.md accordingly
Diffstat (limited to 'src/function')
-rw-r--r-- | src/function/generate.cc | 73 | ||||
-rw-r--r-- | src/function/generate.h | 4 | ||||
-rw-r--r-- | src/function/transform.cc | 57 | ||||
-rw-r--r-- | src/function/transform.h | 31 |
4 files changed, 47 insertions, 118 deletions
diff --git a/src/function/generate.cc b/src/function/generate.cc index f9cd449..b93c2f1 100644 --- a/src/function/generate.cc +++ b/src/function/generate.cc @@ -2,6 +2,7 @@ #include <xalanc/PlatformSupport/XalanOutputStreamPrintWriter.hpp> #include <xalanc/PlatformSupport/XalanStdOutputStream.hpp> +#include <xalanc/XercesParserLiaison/FormatterToXercesDOM.hpp> #include <xalanc/XMLSupport/FormatterToXML.hpp> #include <boost/filesystem.hpp> @@ -16,53 +17,69 @@ namespace InputXSLT { DomDocumentCache::document_ptr FunctionGenerate::constructDocument( const FilesystemContext&, - xalan::XSLTInputSource inputSource, - xalan::XSLTInputSource transformationSource, - boost::filesystem::path targetPath + xalan::XSLTInputSource inputSource, + xalan::XSLTInputSource transformationSource, + boost::optional<boost::filesystem::path> targetPath ) const { DomDocumentCache::document_ptr domDocument( DomDocumentCache::createDocument("content") ); - ResultNodeFacade result(domDocument.get(), "generation"); - result.setAttribute("path", targetPath.string()); + ResultNodeFacade result(domDocument.get(), "generation"); + TransformerFacade transformer(this->include_resolver_); - boost::filesystem::create_directories(targetPath.parent_path()); - boost::filesystem::ofstream file(targetPath); + try { + if ( targetPath ) { + result.setAttribute("path", (*targetPath).string()); - if ( file.is_open() ) { - TransformerFacade transformer(this->include_resolver_); + boost::filesystem::create_directories( + (*targetPath).parent_path() + ); + + boost::filesystem::ofstream file(*targetPath); - try { - xalan::XalanStdOutputStream output(file); - xalan::XalanOutputStreamPrintWriter writer(output); - xalan::FormatterToXML targetFormatter(writer); + if ( file.is_open() ) { + xalan::XalanStdOutputStream output(file); + xalan::XalanOutputStreamPrintWriter writer(output); + xalan::FormatterToXML targetFormatter(writer); + + transformer.generate( + inputSource, + transformationSource, + targetFormatter + ); + } else { + result.setAttribute("result", "error"); + } + } else { + xalan::FormatterToXercesDOM targetFormatter( + domDocument.get(), + result.getResultElement() + ); transformer.generate( inputSource, transformationSource, targetFormatter ); - - result.setAttribute("result", "success"); } - catch (const ErrorCapacitor::exception& exception) { - result.setAttribute("result", "error"); - for ( auto&& error : *exception ) { - result.setValueNode("error", error); - } + result.setAttribute("result", "success"); + } + catch (const ErrorCapacitor::exception& exception) { + result.setAttribute("result", "error"); + + for ( auto&& error : *exception ) { + result.setValueNode("error", error); } + } - WarningCapacitor::warning_cache_ptr warnings( - transformer.getCachedWarnings() - ); + WarningCapacitor::warning_cache_ptr warnings( + transformer.getCachedWarnings() + ); - for ( auto&& warning : *warnings ) { - result.setValueNode("warning", warning); - } - } else { - result.setAttribute("result", "error"); + for ( auto&& warning : *warnings ) { + result.setValueNode("warning", warning); } return domDocument; diff --git a/src/function/generate.h b/src/function/generate.h index 333ed37..fa38e3f 100644 --- a/src/function/generate.h +++ b/src/function/generate.h @@ -11,7 +11,7 @@ class FunctionGenerate : public FunctionBase< FunctionGenerate, xalan::XSLTInputSource, xalan::XSLTInputSource, - boost::filesystem::path + boost::optional<boost::filesystem::path> > { public: using FunctionBase::FunctionBase; @@ -23,7 +23,7 @@ class FunctionGenerate : public FunctionBase< const FilesystemContext&, xalan::XSLTInputSource, xalan::XSLTInputSource, - boost::filesystem::path + boost::optional<boost::filesystem::path> ) const; }; diff --git a/src/function/transform.cc b/src/function/transform.cc deleted file mode 100644 index 9bd2dae..0000000 --- a/src/function/transform.cc +++ /dev/null @@ -1,57 +0,0 @@ -#include "transform.h" - -#include <xalanc/XercesParserLiaison/FormatterToXercesDOM.hpp> - -#include "transformer_facade.h" -#include "support/xerces_string_guard.h" -#include "support/dom/result_node_facade.h" -#include "support/error/error_capacitor.h" - -namespace InputXSLT { - -DomDocumentCache::document_ptr FunctionTransform::constructDocument( - const FilesystemContext&, - xalan::XSLTInputSource inputSource, - xalan::XSLTInputSource transformationSource -) const { - DomDocumentCache::document_ptr domDocument( - DomDocumentCache::createDocument("content") - ); - - ResultNodeFacade result(domDocument.get(), "transformation"); - TransformerFacade transformer(this->include_resolver_); - - try { - xalan::FormatterToXercesDOM targetFormatter( - domDocument.get(), - result.getResultElement() - ); - - transformer.generate( - inputSource, - transformationSource, - targetFormatter - ); - - result.setAttribute("result", "success"); - } - catch (const ErrorCapacitor::exception& exception) { - result.setAttribute("result", "error"); - - for ( auto&& error : *exception ) { - result.setValueNode("error", error); - } - } - - WarningCapacitor::warning_cache_ptr warnings( - transformer.getCachedWarnings() - ); - - for ( auto&& warning : *warnings ) { - result.setValueNode("warning", warning); - } - - return domDocument; -} - -} diff --git a/src/function/transform.h b/src/function/transform.h deleted file mode 100644 index 6c8c05d..0000000 --- a/src/function/transform.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef INPUTXSLT_SRC_FUNCTION_TRANSFORM_H_ -#define INPUTXSLT_SRC_FUNCTION_TRANSFORM_H_ - -#include <xalanc/XSLT/XSLTInputSource.hpp> - -#include "base.h" - -namespace InputXSLT { - -class FunctionTransform : public FunctionBase< - FunctionTransform, - xalan::XSLTInputSource, - xalan::XSLTInputSource -> { - public: - using FunctionBase::FunctionBase; - - protected: - friend FunctionBase; - - DomDocumentCache::document_ptr constructDocument( - const FilesystemContext&, - xalan::XSLTInputSource, - xalan::XSLTInputSource - ) const; - -}; - -} - -#endif // INPUTXSLT_SRC_FUNCTION_TRANSFORM_H_ |