diff options
author | Adrian Kummerländer | 2014-04-25 17:44:32 +0200 |
---|---|---|
committer | Adrian Kummerländer | 2014-04-25 17:44:32 +0200 |
commit | 938ed7622656c3494ae8fdb83bc2ad4b1f31d901 (patch) | |
tree | 75ef069d66ce3709139955cccaa05b531fa6f9a0 /src/function/read_xml_file.cc | |
parent | 78d3873061f1a974da4d0ccdcc1778c6a11139e8 (diff) | |
download | InputXSLT-938ed7622656c3494ae8fdb83bc2ad4b1f31d901.tar InputXSLT-938ed7622656c3494ae8fdb83bc2ad4b1f31d901.tar.gz InputXSLT-938ed7622656c3494ae8fdb83bc2ad4b1f31d901.tar.bz2 InputXSLT-938ed7622656c3494ae8fdb83bc2ad4b1f31d901.tar.lz InputXSLT-938ed7622656c3494ae8fdb83bc2ad4b1f31d901.tar.xz InputXSLT-938ed7622656c3494ae8fdb83bc2ad4b1f31d901.tar.zst InputXSLT-938ed7622656c3494ae8fdb83bc2ad4b1f31d901.zip |
Improved argument resolution and error handling
* execute member method internal argument count checks are not needed when using between one and two arguments
** xalan automatically generates the appropriate message containing the getError message when only offered fixed argument execute member overloads
* improved FunctionReadDirectory attribute element generation
* added additional validations to FunctionReadFile and FunctionReadXMLFile
* I plan to return errors inside a DOM tree alongside the function return values in the future
Diffstat (limited to 'src/function/read_xml_file.cc')
-rw-r--r-- | src/function/read_xml_file.cc | 40 |
1 files changed, 20 insertions, 20 deletions
diff --git a/src/function/read_xml_file.cc b/src/function/read_xml_file.cc index ac42288..d429f34 100644 --- a/src/function/read_xml_file.cc +++ b/src/function/read_xml_file.cc @@ -13,28 +13,28 @@ FunctionReadXmlFile::FunctionReadXmlFile(const FunctionReadXmlFile& src): parser_() { } xalan::XObjectPtr FunctionReadXmlFile::execute( - xalan::XPathExecutionContext& executionContext, - xalan::XalanNode* context, - const xalan::Function::XObjectArgVectorType& arguments, - const xalan::Locator* locator + xalan::XPathExecutionContext& executionContext, + xalan::XalanNode*, + const xalan::XObjectPtr argument, + const xalan::Locator* ) const { - if ( arguments.size() != 1 ) { - xalan::XPathExecutionContext::GetAndReleaseCachedString guard( - executionContext - ); - - this->generalError(executionContext, context, locator); - } - - boost::filesystem::ifstream file( - this->fs_context_.resolve(arguments[0]->str()) + const boost::filesystem::path filePath( + this->fs_context_.resolve(argument->str()) ); - return executionContext.getXObjectFactory().createNodeSet( - this->parser_.parseXMLStream( - xalan::XSLTInputSource(file) - ) - ); + if ( boost::filesystem::is_regular_file(filePath) ) { + boost::filesystem::ifstream file(filePath); + + return executionContext.getXObjectFactory().createNodeSet( + this->parser_.parseXMLStream( + xalan::XSLTInputSource(file) + ) + ); + } else { + return executionContext.getXObjectFactory().createString( + xalan::XalanDOMString("io error") + ); + } } FunctionReadXmlFile* FunctionReadXmlFile::clone( @@ -44,7 +44,7 @@ FunctionReadXmlFile* FunctionReadXmlFile::clone( const xalan::XalanDOMString& FunctionReadXmlFile::getError( xalan::XalanDOMString& result) const { - result.assign("The read-xml-file() function expects one argument."); + result.assign("The read-xml-file() function expects one argument of type string."); return result; } |