Java Reference
In-Depth Information
class Date implements XPathFunction
{
private final static ParsePosition POS = new ParsePosi-
tion(0);
private
SimpleDateFormat
sdf
=
new
SimpleDateFormat("yyyy-mm-dd");
@Override
public Object evaluate(List args) throws XPathFunc-
tionException
{
if (args.size() != 1)
throw new XPathFunctionException("Invalid number
of arguments");
String value;
Object o = args.get(0);
if (o instanceof NodeList)
{
NodeList list = (NodeList) o;
value = list.item(0).getTextContent();
}
else
if (o instanceof String)
value = (String) o;
else
throw new XPathFunctionException("Cannot convert
argument type");
POS.setIndex(0);
return sdf.parse(value, POS).getTime();
}
}
XPathFunction declaresasingle Object evaluate(List args) method
that XPath calls when it needs to execute the extension function. evaluate() is
passeda java.util.List ofobjectsthatdescribetheargumentsthatwerepassedto
theextensionfunctionbytheXPathevaluator.Furthermore,thismethodreturnsavalue
Search WWH ::




Custom Search