/**
* Evaluate the function in a string context
*/
public Item evaluateItem(XPathContext c) throws XPathException {
NodeInfo node = (NodeInfo)argument[0].evaluateItem(c);
if (node==null) {
// Effect of supplying an empty sequence as the argument differs depending on the function
if (operation == NODE_NAME || operation == DOCUMENT_URI ) {
return null;
} else if (operation == NAMESPACE_URI) {
return AnyURIValue.EMPTY_URI;
} else {
return StringValue.EMPTY_STRING;
}
}
String s;
switch (operation) {
case NAME:
s = node.getDisplayName();
break;
case LOCAL_NAME:
s = node.getLocalPart();
break;
case NAMESPACE_URI:
String uri = node.getURI();
s = (uri==null ? "" : uri);
// null should no longer be returned, but the spec has changed, so it's
// better to be defensive
return new AnyURIValue(s);
case GENERATE_ID:
FastStringBuffer buffer = new FastStringBuffer(FastStringBuffer.TINY);
node.generateId(buffer);
buffer.condense();
return new StringValue(buffer);
case DOCUMENT_URI:
// If the node is in the document pool, get the URI under which it is registered.
// Otherwise, return its systemId.
return getDocumentURI(node, c);
case NODE_NAME:
int nc = node.getNameCode();
if (nc == -1) {
return null;
}
return new QNameValue(node.getNamePool(), nc);
default:
throw new UnsupportedOperationException("Unknown name operation");
}
return new StringValue(s);
}