#include "xobject_value.h" #include #include #include #include "boost/filesystem.hpp" #include #include "support/xalan_string.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::filesystem::path XObjectValue::get( const xalan::XObjectPtr& ptr) const { const boost::filesystem::path rawPath( toString(ptr->str()) ); const boost::filesystem::path filePath( this->filesystem_context_.resolve(rawPath) ); if ( !(boost::filesystem::exists(filePath) && boost::filesystem::is_regular_file(filePath)) ) { if ( auto resolvedPath = this->include_resolver_->resolve(rawPath) ) { return *resolvedPath; } else { return filePath; } } else { return filePath; } } template <> xalan::XObjectPtr XObjectValue::get( const xalan::XObjectPtr& ptr) const { return ptr; } template <> xalan::XSLTInputSource XObjectValue::get( const xalan::XObjectPtr& ptr) const { switch ( ptr->getType() ) { case xalan::XObject::eObjectType::eTypeNodeSet: { return xalan::XSLTInputSource( ptr->nodeset().item(0) ); } case xalan::XObject::eObjectType::eTypeResultTreeFrag: { return xalan::XSLTInputSource( ptr->rtree().getFirstChild() ); } default: { return xalan::XSLTInputSource( this->get(ptr).string().data() ); } } } }