Can Web Harvest support default parameters in function definition?
- or -
Can Web Harvest detect a parameter of a function is provided by its caller or not (If not provided, the function itself can choose a default value)?
For example, suppose a function "read_stream" having two parameters "istream_url" and "istream_charset". I want the first parameter (istream_url) being a mandatory one and the second parameter (istream_charset) being an optional one. When calling "read_stream", if the "istream_charset" is not provided, I want "read_stream" use the default settings. The following lines are the sample code:
<function name="read_stream">
<!-- detect if istream_charset is provided, if it is -->
<file action="read" path="${istream_url}" charset="${istream_charset}"/>
<!-- else
<file action="read" path="${istream_url}"/>
-->
</function>
Therefore I could call it in two ways:
Case #1. istream_charset provided
<call name="read_stream">
<call-param name="istream_url">C:\TEMP\input.htm</call-param>
<call-param name="istream_charset">GB2312</call-param>
</call>
Case #2. istream_charset not provided
<call name="read_stream">
<call-param name="istream_url">C:\TEMP\input.htm</call-param>
</call>
In this case, I expect "read_stream" use the default charset (e.g. UTF-8 which specified in <config> element
Case #3. istream_charset provided but is empty (abnormal test case)
<call name="read_stream">
<call-param name="istream_url">C:\TEMP\input.htm</call-param>
<call-param name="istream_charset"></call-param>
</call>
I used the following way to detect but all failed to do so.
${!sys.isVariableDefined("istream_charset")} ==> conditon#1
${istream_charset.toString() == ""} ===========> conditon#2
For condition#1, since the function calling point always follows the function body (otherwise, the function name can not be resolved), condition#1 will always report false.
For condition#2, unresolved problem will be reported in case#2 while false is returned in case#3.
Conclusion:
Case#2 could not be supported due to the name resolving, only case#3 can be used as an alternative way. Is it possible to have a "forward-reference-declaration" element to solve this problem in furture? ;-)
Test XXX.toString()=="" returns false when nothing specified in call-param (quite strang).
After many tries, I found the alternative testing solution in case#3:
${istream_charset.toString().length() == 0} ===> conditon#3
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can Web Harvest support default parameters in function definition?
- or -
Can Web Harvest detect a parameter of a function is provided by its caller or not (If not provided, the function itself can choose a default value)?
For example, suppose a function "read_stream" having two parameters "istream_url" and "istream_charset". I want the first parameter (istream_url) being a mandatory one and the second parameter (istream_charset) being an optional one. When calling "read_stream", if the "istream_charset" is not provided, I want "read_stream" use the default settings. The following lines are the sample code:
<function name="read_stream">
<!-- detect if istream_charset is provided, if it is -->
<file action="read" path="${istream_url}" charset="${istream_charset}"/>
<!-- else
<file action="read" path="${istream_url}"/>
-->
</function>
Therefore I could call it in two ways:
Case #1. istream_charset provided
<call name="read_stream">
<call-param name="istream_url">C:\TEMP\input.htm</call-param>
<call-param name="istream_charset">GB2312</call-param>
</call>
Case #2. istream_charset not provided
<call name="read_stream">
<call-param name="istream_url">C:\TEMP\input.htm</call-param>
</call>
In this case, I expect "read_stream" use the default charset (e.g. UTF-8 which specified in <config> element
Case #3. istream_charset provided but is empty (abnormal test case)
<call name="read_stream">
<call-param name="istream_url">C:\TEMP\input.htm</call-param>
<call-param name="istream_charset"></call-param>
</call>
I used the following way to detect but all failed to do so.
${!sys.isVariableDefined("istream_charset")} ==> conditon#1
${istream_charset.toString() == ""} ===========> conditon#2
For condition#1, since the function calling point always follows the function body (otherwise, the function name can not be resolved), condition#1 will always report false.
For condition#2, unresolved problem will be reported in case#2 while false is returned in case#3.
Conclusion:
Case#2 could not be supported due to the name resolving, only case#3 can be used as an alternative way. Is it possible to have a "forward-reference-declaration" element to solve this problem in furture? ;-)
Test XXX.toString()=="" returns false when nothing specified in call-param (quite strang).
After many tries, I found the alternative testing solution in case#3:
${istream_charset.toString().length() == 0} ===> conditon#3
XXX.toString()=="" should be XXX.toString().equal("")