From 5a54b5b8150d8bf1ac5db3ac688479b3aca6486d Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 23 Aug 2014 00:19:09 +0200 Subject: 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" specialization to the XObjectValue class * modified test cases accordingly * modified README.md accordingly --- src/function/generate.cc | 73 +++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 28 deletions(-) (limited to 'src/function/generate.cc') 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 #include +#include #include #include @@ -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 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; -- cgit v1.2.3