use of com.servoy.j2db.ExitScriptException in project servoy-client by Servoy.
the class InlineScriptExecutorBehavior method respond.
@Override
protected void respond(AjaxRequestTarget target) {
Page page = component.getPage();
String scriptName = RequestCycle.get().getRequest().getParameter("snenc");
ICrypt urlCrypt = Application.get().getSecuritySettings().getCryptFactory().newCrypt();
scriptName = urlCrypt.decryptUrlSafe(scriptName).replace("\\\"", "\"");
String argValue;
for (String browserArgument : getBrowserArguments(scriptName)) {
argValue = RequestCycle.get().getRequest().getParameter(browserArgument);
if (argValue == null)
argValue = "";
boolean isString = true;
try {
Double.parseDouble(argValue);
isString = false;
} catch (NumberFormatException ex) {
}
if (isString && ("true".equals(argValue) || "false".equals(argValue)))
isString = false;
String browserParamWithArgument = BROWSER_PARAM + browserArgument;
// make sure we ignore user quoting if isString
if (isString) {
scriptName = scriptName.replace("\"" + browserParamWithArgument + "\"", browserParamWithArgument);
scriptName = scriptName.replace("'" + browserParamWithArgument + "'", browserParamWithArgument);
}
scriptName = scriptName.replace(browserParamWithArgument, isString ? "'" + argValue + "'" : argValue);
}
WebForm wf = component.findParent(WebForm.class);
if (wf != null) {
try {
wf.getController().eval(scriptName);
} catch (Exception e) {
if (!(e instanceof ExitScriptException)) {
// $NON-NLS-1$
Debug.error("Exception evaluating: " + scriptName, e);
}
}
WebEventExecutor.generateResponse(target, page);
}
// $NON-NLS-1$ //$NON-NLS-2$
target.appendJavascript("clearDoubleClickId('" + component.getMarkupId() + "')");
}
use of com.servoy.j2db.ExitScriptException in project servoy-client by Servoy.
the class ScriptEngine method eval.
public Object eval(Scriptable scope, String eval_string) {
String userUidBefore = null;
if (Context.getCurrentContext() == null) {
userUidBefore = application.getClientInfo().getUserUid();
}
Context cx = Context.enter();
try {
Object o = null;
// $NON-NLS-1$ //$NON-NLS-2$
Function compileFunction = cx.compileFunction(scope, "function evalFunction(){}", "evalFunction", 0, null);
if (compileFunction instanceof FunctionWrapper)
compileFunction = ((FunctionWrapper) compileFunction).getWrappedFunction();
if (compileFunction instanceof NativeFunction) {
o = // $NON-NLS-1$
cx.evaluateString(// $NON-NLS-1$
ScriptRuntime.createFunctionActivation((NativeFunction) compileFunction, scope, null), // $NON-NLS-1$
eval_string, // $NON-NLS-1$
"internal_anon", // $NON-NLS-1$
1, null);
} else {
// $NON-NLS-1$
o = cx.evaluateString(scope, eval_string, "internal_anon", 1, null);
}
if (o instanceof Wrapper) {
o = ((Wrapper) o).unwrap();
}
if (o == Scriptable.NOT_FOUND || o == Undefined.instance) {
o = null;
}
return o;
} catch (Exception ex) {
if (ex instanceof ExitScriptException) {
throw (ExitScriptException) ex;
} else if (ex.getCause() instanceof ExitScriptException) {
throw (ExitScriptException) ex.getCause();
} else if (ex instanceof JavaScriptException && ((JavaScriptException) ex).getValue() instanceof ExitScriptException) {
throw (ExitScriptException) ((JavaScriptException) ex).getValue();
} else if (application.getSolution() != null) {
// $NON-NLS-1$//$NON-NLS-2$
application.reportError(application.getI18NMessage("servoy.formPanel.error.evalString") + eval_string + "'", ex);
} else {
// $NON-NLS-1$
Debug.trace("Solution already closed, ignoring exception", ex);
}
} finally {
Context.exit();
testClientUidChange(scope, userUidBefore);
}
return null;
}
use of com.servoy.j2db.ExitScriptException in project servoy-client by Servoy.
the class ServoyWrapFactory method wrap.
/**
* @see org.mozilla.javascript.WrapFactory#wrap(org.mozilla.javascript.Context, org.mozilla.javascript.Scriptable, java.lang.Object, java.lang.Class)
*/
@Override
public Object wrap(Context cx, Scriptable scope, Object obj, Class staticType) {
if (application.getSolution() == null) {
throw new ExitScriptException("killing current script, client/solution already terminated");
}
if (obj == null || obj == Undefined.instance || obj instanceof Scriptable || obj instanceof String || obj instanceof CharSequence || obj instanceof Number || obj instanceof Boolean) {
return obj;
}
if (obj instanceof Date) {
return cx.newObject(scope, "Date", new Object[] { new Double(NativeDate.convertToUTCMillisFromJava(((Date) obj).getTime())) });
}
if (obj instanceof DbIdentValue || obj instanceof UUID) {
return new NativeJavaObject(scope, obj, ScriptObjectRegistry.getJavaMembers(obj.getClass(), null));
}
if (cx != null) {
if (obj instanceof JSConvertedMap<?, ?>) {
Scriptable newObject = null;
JSConvertedMap<?, ?> map = (JSConvertedMap<?, ?>) obj;
if (map.getConstructorName() != null) {
newObject = cx.newObject(scope, map.getConstructorName());
} else {
newObject = cx.newObject(scope);
}
Iterator<?> iterator = map.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<?, ?> next = (Entry<?, ?>) iterator.next();
Object key = next.getKey();
Object value = next.getValue();
if (value != null) {
value = wrap(cx, newObject, value, value.getClass());
}
if (key instanceof Integer) {
newObject.put(((Integer) key).intValue(), newObject, value);
} else if (key instanceof String) {
newObject.put((String) key, newObject, value);
} else {
// $NON-NLS-1$ //$NON-NLS-2$
Debug.error("Try to create a JSConvertedMap->NativeObject with a key that isnt a string or integer:" + key + " for value: " + value);
}
}
return newObject;
}
if (obj.getClass() == JSONObject.class) {
JSONObject json = (JSONObject) obj;
Scriptable newObject = cx.newObject(scope);
Iterator<String> iterator = json.keys();
while (iterator.hasNext()) {
String key = iterator.next();
Object value = null;
try {
value = ServoyJSONObject.jsonNullToNull(json.get(key));
} catch (JSONException e) {
Debug.error(e);
}
if (value != null) {
value = wrap(cx, newObject, value, value.getClass());
}
newObject.put(key, newObject, value);
}
return newObject;
}
if (obj.getClass() == JSONArray.class) {
JSONArray array = (JSONArray) obj;
Scriptable newObject = cx.newObject(scope, "Array");
for (int i = 0; i < array.length(); i++) {
Object value = null;
try {
value = array.get(i);
} catch (JSONException e) {
Debug.error(e);
}
if (value != null) {
value = wrap(cx, newObject, value, value.getClass());
}
newObject.put(i, newObject, value);
}
return newObject;
}
}
if (obj instanceof IDataSet) {
return new JSDataSet(application, (IDataSet) obj);
}
if (obj instanceof FormController) {
throw new IllegalArgumentException(// $NON-NLS-1$
"Bad practice: FormController cant be wrapped to javascript (for example not usable as argument in Scheduler plugin)");
}
// if it is a none primitive array
if (obj.getClass().isArray() && !obj.getClass().getComponentType().isPrimitive()) {
// then convert the array to a NativeArray, first convert all the elements of the array itself.
Object[] source = (Object[]) obj;
Object[] array = new Object[source.length];
for (int i = 0; i < source.length; i++) {
Object src = source[i];
array[i] = wrap(cx, scope, src, src != null ? src.getClass() : null);
}
return cx.newArray(scope, array);
}
return super.wrap(cx, scope, obj, staticType);
}
use of com.servoy.j2db.ExitScriptException in project servoy-client by Servoy.
the class FormScope method get.
@Override
public Object get(String name, Scriptable start) {
if (_fp == null) {
Debug.warn("Error accessing a form " + formName + " that is already destroyed for getting: " + name);
throw new ExitScriptException("killing current script, client/solution already terminated");
}
_fp.touch();
if (// $NON-NLS-1$
"alldataproviders".equals(name)) {
List<String> al = new ArrayList<String>();
Table table = (Table) _fp.getTable();
if (table != null) {
al = getDataproviderIdList(table);
}
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
if (// $NON-NLS-1$
"allmethods".equals(name)) {
List<String> al = new ArrayList<String>();
Iterator<ScriptMethod> it = _fp.getForm().getScriptMethods(true);
while (it.hasNext()) {
ScriptMethod sm = it.next();
al.add(sm.getName());
}
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
if (// $NON-NLS-1$
"allrelations".equals(name)) {
List<String> al = getFormRelationsIdList(_fp.getForm());
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
if (// $NON-NLS-1$
"allvariables".equals(name)) {
List<String> al = getAllVariablesIdList(_fp.getForm());
return new NativeJavaArray(this, al.toArray(new String[al.size()]));
}
Object object = super.get(name, start);
if ((object == null || object == Scriptable.NOT_FOUND) && ("foundset".equals(name) || "elements".equals(name))) {
Debug.error(Thread.currentThread().getName() + ": For form " + _fp + " the foundset/elements were asked for but that was not (or was no longer) set. ", new RuntimeException());
if (name.equals("foundset"))
return _fp.getFormModel();
}
return object;
}
Aggregations