ScriptJavaAPI

last edited byusericonthelimit on 25-Nov-2009

Accessing the Java API through scripting

One of the strong points of SafiServer is scripting engine. Our scripting engine is based on Rhino javascript engine which offers access to most javascript functions. You can also access the entire Java API through our scripting engine.

Below is an example of accessing the Java API to use the startsWith function:

var a = "Test A B C D";
var b = new java.lang.String(a); // Converts javascript string to Java string
var c;

// String comparison with Java String API
if( b.startsWith("Test") ){
     c=true;
} else {
     c=false;
}
c; // Returned value

Once javascript string is converted to java string. Then you can access java string api. If you execute above code in script editor, it should return true value.

below is simple zip code validation which uses java regular expression.

var zip = new java.lang.String("90210");
var zipCodePattern = new java.lang.String("\\d{5}(-\\d{4})?");
var isValid = zip.matches(zipCodePattern);
isValid;


 
Download in other Formats:
markup Markup | pdf PDF | swf SWF | html HTML | word Word