throws XPathException {
final ResponseModule myModule = (ResponseModule)context.getModule(ResponseModule.NAMESPACE_URI);
// request object is read from global variable $response
final Variable var = myModule.resolveVariable(ResponseModule.RESPONSE_VAR);
if(var == null || var.getValue() == null) {
throw new XPathException(this, "No request object found in the current XQuery context.");
}
if(var.getValue().getItemType() != Type.JAVA_OBJECT) {
throw new XPathException(this, "Variable $response is not bound to an Java object.");
}
// get parameters
final String url = args[0].getStringValue();
final JavaObjectValue value = (JavaObjectValue)
var.getValue().itemAt(0);
if(value.getObject() instanceof ResponseWrapper) {
return new AnyURIValue(((ResponseWrapper)value.getObject()).encodeURL(url));
} else {
throw new XPathException(this, "Variable $response is not bound to a Response object.");
}