private void initJsProcessor() {
this.cx = org.mozilla.javascript.Context.enter();
this.scope = new ImporterTopLevel(cx);
if (jsFunctions != null) {
scope.defineProperty("count", new BaseFunction() {
@Override
public Object call(org.mozilla.javascript.Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
if (args.length == 0 || !(args[0] instanceof String)) {
throw new IllegalArgumentException("Should take string argument");
}
return jsFunctions.count((String)args[0]);
}
}, ScriptableObject.DONTENUM);
scope.defineProperty("find", new BaseFunction() {
@Override
public Object call(org.mozilla.javascript.Context cx, Scriptable scope, Scriptable thisObj, Object[] args) {
if (args.length == 0 || !(args[0] instanceof String)) {
throw new IllegalArgumentException("Should take string argument");
}