public TypeValuePair evaluate(FormulaContext context, ParameterCallback parameters) throws EvaluationException
{
final int parameterCount = parameters.getParameterCount();
if (parameterCount < 1)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_ARGUMENTS_VALUE);
}
final Type textType = parameters.getType(0);
final Object textValue = parameters.getValue(0);
final String textResult =
context.getTypeRegistry().convertToText(textType, textValue);
if(textResult == null)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
String encodingResult = null;
if(parameterCount == 2)
{
final Type encodingType = parameters.getType(1);
final Object encodingValue = parameters.getValue(1);
encodingResult = context.getTypeRegistry().convertToText(encodingType, encodingValue);
if(encodingResult == null)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
}
try
{
if (encodingResult == null)
{
return new TypeValuePair
(TextType.TYPE, URLEncoder.encode(textResult, "ISO-8859-1"));
}
return new TypeValuePair
(TextType.TYPE, URLEncoder.encode(textResult, encodingResult));
}
catch(UnsupportedEncodingException use)
{
throw new EvaluationException(LibFormulaErrorValue.ERROR_INVALID_ARGUMENT_VALUE);
}
}