#include "xobject_value.h" #include #include #include #include #include #include #include "support/xalan_string.h" #include "support/xerces_string_guard.h" namespace InputXSLT { XObjectValue::XObjectValue( const boost::filesystem::path& path, const IncludeEntityResolver* resolver ): filesystem_context_(path), include_resolver_(resolver) { } template <> std::string XObjectValue::get( const xalan::XObjectPtr& ptr) const { return boost::trim_copy(toString(ptr->str())); } template <> boost::optional XObjectValue::get>( const xalan::XObjectPtr& ptr) const { if ( ptr.null() ) { return boost::optional(); } else { return this->get(ptr); } } template <> boost::filesystem::path XObjectValue::get( const xalan::XObjectPtr& ptr) const { const std::string rawPath( this->get(ptr) ); if ( auto resolvedPath = this->include_resolver_->resolve(rawPath) ) { return *resolvedPath; } else { return this->filesystem_context_.resolve(rawPath); } } template <> xalan::XObjectPtr XObjectValue::get( const xalan::XObjectPtr& ptr) const { return ptr; } template <> xalan::XalanNode* XObjectValue::get( const xalan::XObjectPtr& ptr) const { switch ( ptr->getType() ) { case xalan::XObject::eObjectType::eTypeNodeSet: { return ptr->nodeset().item(0); } case xalan::XObject::eObjectType::eTypeResultTreeFrag: { return ptr->rtree().getFirstChild(); } default: { return nullptr; } } } template <> xalan::XSLTInputSource XObjectValue::get( const xalan::XObjectPtr& ptr) const { xalan::XalanNode* const node( this->get(ptr) ); if ( node == nullptr ) { return xalan::XSLTInputSource( this->get(ptr).string().data() ); } else { xalan::XSLTInputSource source(node); source.setSystemId( *XercesStringGuard( this->filesystem_context_.getBase().string() ) ); return source; } } }