I've been using rhino to allow the customization of some applications. Here is an example of JavaScript function that is called from Java:
function() {
var phone = this.telephoneNumber;
phone = phone.replace(/[^+0-9]/g,"");
if (phone.indexOf("+") == 0) {
phone = "00" + phone.substring(1);
}
if (phone.indexOf("0041") == 0) {
phone = "0" + phone.substring(4);
}
if (phone.indexOf("0") == 0) {
phone = "0" + phone;
}
return {
Name: this.sn + " " + this.givenName,
firstName: this.givenName || "",
lastName: this.sn || "",
phone: phone,
service: "",
info: ""
};
}
The java application can then get the values of the returned object for whatever it needs to do.
Now that rhino is part of the JVM, I would like to use the scripting API instead of the Rhino API, but I haven't found how to get the field values of a JavaScript object from Java code.