/**
* 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.
if (node.getNodeKind() == Type.DOCUMENT) {
DocumentPool pool = c.getController().getDocumentPool();
String docURI = pool.getDocumentURI(node);
if (docURI == null) {
docURI = node.getSystemId();
}
if (docURI == null) {
return null;
} else if ("".equals(docURI)) {
return null;
} else {
return new AnyURIValue(docURI);
}
} else {
return null;
}
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);
}