From a02dce3c8e6086acbfe9c57c3ee4bb386bfbebc2 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Sat, 5 Jul 2014 21:55:48 +0200 Subject: Revamped implementation to support FunctionTransform XalanNode input * FunctionTransform now accepts xalan::XalanNode base xalan::XSLTInputSource instances as input parameter ** such xalan::XSLTInputSource instances were already supported for the stylesheet parameter but not for the input parameter ** e.g. it is now possible to generate a DOM inside a transformation, pass the DOM into a embedded transformation as input, modifiy the output of that transformation, pass this modified DOM into another transformation and so on... you get the point * this required a revamp of TransformationFacade ** it is now a transformation independent wrapper for xalan::XalanTransformer *** as such is was renamed to TransformerFacade ** removed error catching template factory method "try_create" as it is not needed anymore ** "std::basic_ostream&" taking "generate" member method overloads were removed ** the set of "generate" member overloads was reduced to two methods accepting xalan::XSLTInputSource and xalan::FormatterListener as parameters * the core problem first documented in 299d0f6 was solved by transforming the input parameter into a xerces DOM and wrapping this DOM inside a xalan::XercesDOMWrapperParsedSource instance * serialization of the transformation result for file / std::cout output is now performed directly by the ixslt frontend * removed 'stylesheet parameter' parameter from FunctionTransform ** the functionality provided by this is easily replicated using the now possible DOM input parameter ** this was done to simplify the interface and reduce unnecessary feature duplication * updated FunctionTransform test case accordingly * added "generate" template function to ixslt frontend ** wraps TransformerFacade and manages ist input arguments ** handles serialization to stream * this commit marks a important milestone towards the goals defined in 741a70f --- src/transformer_facade.cc | 129 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 src/transformer_facade.cc (limited to 'src/transformer_facade.cc') diff --git a/src/transformer_facade.cc b/src/transformer_facade.cc new file mode 100644 index 0000000..10c8c7a --- /dev/null +++ b/src/transformer_facade.cc @@ -0,0 +1,129 @@ +#include "transformer_facade.h" + +#include +#include + +#include +#include +#include + +#include +#include +#include + +#include +#include + +#include "support/xerces_string_guard.h" + +namespace InputXSLT { + +TransformerFacade::TransformerFacade(IncludeEntityResolver* resolver): + transformer_(), + error_multiplexer_(&transformer_), + warning_capacitor_(&error_multiplexer_) { + this->transformer_.setEntityResolver(resolver); +} + +WarningCapacitor::warning_cache_ptr TransformerFacade::getCachedWarnings() { + return this->warning_capacitor_.discharge(); +} + +void TransformerFacade::generate( + const xalan::XSLTInputSource& source, + const xalan::XSLTInputSource& transformation, + xalan::FormatterListener& target +) { + if ( source.getNode() == nullptr ) { + ErrorCapacitor errorCapacitor(&this->error_multiplexer_); + + this->transformer_.transform( + source, + transformation, + target + ); + + errorCapacitor.discharge(); + } else { + this->generate( + source.getNode(), + transformation, + target + ); + } +} + +void TransformerFacade::generate( + const xalan::XSLTInputSource& transformation, + xalan::FormatterListener& target +) { + ErrorCapacitor errorCapacitor(&this->error_multiplexer_); + + xercesc::DOMDocument* const inputDocument( + xercesc::DOMImplementation::getImplementation()->createDocument( + nullptr, + *XercesStringGuard("dummy"), + nullptr + ) + ); + + xalan::XercesParserLiaison parserLiaison; + xalan::XercesDOMSupport domSupport(parserLiaison); + + xalan::XercesDOMWrapperParsedSource inputParsedSource( + inputDocument, + parserLiaison, + domSupport + ); + + this->transformer_.transform( + inputParsedSource, + transformation, + target + ); + + inputDocument->release(); + + errorCapacitor.discharge(); +} + +void TransformerFacade::generate( + xalan::XalanNode* const source, + const xalan::XSLTInputSource& transformation, + xalan::FormatterListener& target +) { + ErrorCapacitor errorCapacitor(&this->error_multiplexer_); + + xercesc::DOMDocument* const inputDocument( + xercesc::DOMImplementation::getImplementation()->createDocument() + ); + + xalan::FormatterToXercesDOM inputFormatter( + inputDocument, + inputDocument->getDocumentElement() + ); + + xalan::FormatterTreeWalker walker(inputFormatter); + walker.traverseSubtree(source); + + xalan::XercesParserLiaison parserLiaison; + xalan::XercesDOMSupport domSupport(parserLiaison); + + xalan::XercesDOMWrapperParsedSource inputParsedSource( + inputFormatter.getDocument(), + parserLiaison, + domSupport + ); + + this->transformer_.transform( + inputParsedSource, + transformation, + target + ); + + inputDocument->release(); + + errorCapacitor.discharge(); +} + +} -- cgit v1.2.3