Refine search
@Override public TemplateModel wrap(Object obj) throws TemplateModelException { // So our existence builtins work as expected. if (obj == UNDEFINED_INSTANCE || obj == UniqueTag.NOT_FOUND) { return null; } // UniqueTag.NULL_VALUE represents intentionally set null in Rhino, and // BeansWrapper#nullModel also represents intentionally returned null. // I [A.Sz.] am fairly certain that this value is never passed out of // any of the Rhino code back to clients, but is instead always being // converted back to null. However, since this object is available to // any 3rd party Scriptable implementations as well, they might return // it, so we'll just be on the safe side, and handle it. if (obj == UniqueTag.NULL_VALUE) { return super.wrap(null); } // So, say, a JavaAdapter for FreeMarker interfaces works if (obj instanceof Wrapper) { obj = ((Wrapper) obj).unwrap(); } return super.wrap(obj); }
public Object getProperty(Object obj, String propertyName) { Context cx = null; try { cx = Context.enter(); Scriptable s = (Scriptable)obj; Object result = ScriptableObject.getProperty(s, propertyName); result = ((Wrapper)result).unwrap(); } else if (result == Undefined.instance) { result = null; Context.exit();
Context cx = ContextFactory.getGlobal().enterContext(); try { Scriptable scope = cx.newObject(scriptScope); scope.setPrototype(scriptScope); scope.setParentScope(null); if (isE4X) { try { inDoc = Context.toObject(node, scope); Object[] args = {inDoc}; inDoc = cx.newObject(scope, "XML", args); } catch (Exception ex) { ex.printStackTrace(); Object jsResp = invokeFunc.call(cx, scope, scope, args); if (jsResp instanceof Wrapper) { jsResp = ((Wrapper)jsResp).unwrap();
/** * The bindings function takes a JavaScript scope object * of type ExternalScriptable and returns the underlying Bindings * instance. * * var page = scope(pageBindings); * with (page) { * // code that uses page scope * } * var b = bindings(page); * // operate on bindings here. */ public static Object bindings(Context cx, Scriptable thisObj, Object[] args, Function funObj) { if (args.length == 1) { Object arg = args[0]; if (arg instanceof Wrapper) { arg = ((Wrapper)arg).unwrap(); } if (arg instanceof ExternalScriptable) { ScriptContext ctx = ((ExternalScriptable)arg).getContext(); Bindings bind = ctx.getBindings(ScriptContext.ENGINE_SCOPE); return Context.javaToJS(bind, ScriptableObject.getTopLevelScope(thisObj)); } } return cx.getUndefinedValue(); }
@Override protected String doCall(Context cx, Scriptable scope) throws RuntimeException { if (obj == null) { return "null"; } else if (obj instanceof Wrapper) { Object unwrapped = ((Wrapper) obj).unwrap(); return unwrapped.toString(); } else if (obj instanceof Scriptable) { return (String) cx.evaluateString((Scriptable) obj, "(function(obj) { " + " try { " + " var str = JSON.stringify(obj); " + " if (typeof str === 'string') return str; " + " } catch (e) { } " + " return obj.toString(); " + "})(this)", "<toString>", 1, null); } else if (obj instanceof Undefined) { return "undefined"; } return obj.toString(); } });
private Locale getLocale() { if (locale == null) { try { // check whether we have a request object which has the locale Object reqObj = ScriptRuntime.name(Context.getCurrentContext(), this, SlingBindings.REQUEST); if (reqObj instanceof Wrapper) { Object wrapped = ((Wrapper) reqObj).unwrap(); if (wrapped instanceof HttpServletRequest) { locale = ((HttpServletRequest) wrapped).getLocale(); } } } catch (Exception e) { // ignore any exceptions resulting from this and use default } // default, if the no request locale or no request is available if (locale == null) { locale = Locale.getDefault(); } } return locale; } }
public Scriptable construct(Context cx, Scriptable scope, Object[] args) { ClassLoader loader = null; if (args.length != 0) { Object arg = args[0]; if (arg instanceof Wrapper) { arg = ((Wrapper)arg).unwrap(); } if (arg instanceof ClassLoader) { loader = (ClassLoader)arg; } } if (loader == null) { Context.reportRuntimeError0("msg.not.classloader"); return null; } return new NativeJavaPackage(true, "", loader); }
private static Class<?> getClass(Object[] args) { if (args.length == 0) { throw reportRuntimeError("msg.expected.string.arg"); } Object arg0 = args[0]; if (arg0 instanceof Wrapper) { Object wrapped = ((Wrapper)arg0).unwrap(); if (wrapped instanceof Class) return (Class<?>)wrapped; } String className = Context.toString(args[0]); try { return Class.forName(className); } catch (ClassNotFoundException cnfe) { throw reportRuntimeError("msg.class.not.found", className); } }
public Scriptable construct(Context cx, Scriptable scope, Object[] args) throws RhinoException { if (args.length == 2) { Class<?> clazz = null; Object obj1 = args[0]; if (obj1 instanceof Wrapper) { Object o = ((Wrapper)obj1).unwrap(); if (o instanceof Class && ((Class)o).isInterface()) { clazz = (Class) o; } } else if (obj1 instanceof Class) { if (((Class)obj1).isInterface()) { clazz = (Class) obj1; } } if (clazz == null) { throw Context.reportRuntimeError("JavaAdapter: first arg should be interface Class"); } Scriptable topLevel = ScriptableObject.getTopLevelScope(scope); return cx.toObject(engine.getInterface(args[1], clazz), topLevel); } else { throw Context.reportRuntimeError("JavaAdapter requires two arguments"); } }
return ((Wrapper)x).unwrap() == ((Wrapper)y).unwrap(); warnAboutNonJSObject(x); return x == y;
public Scriptable construct(Context cx, Scriptable scope, Object[] args) { ClassLoader loader = null; if (args.length != 0) { Object arg = args[0]; if (arg instanceof Wrapper) { arg = ((Wrapper)arg).unwrap(); } if (arg instanceof ClassLoader) { loader = (ClassLoader)arg; } } if (loader == null) { Context.reportRuntimeError0("msg.not.classloader"); return null; } NativeJavaPackage pkg = new NativeJavaPackage(true, "", loader); ScriptRuntime.setObjectProtoAndParent(pkg, scope); return pkg; }
Object arg = args[0]; if (arg instanceof Wrapper) { arg = ((Wrapper)arg).unwrap(); return Context.getUndefinedValue();
private static InputStream toInputStream(Object value) throws IOException { InputStream is = null; String s = null; if (value instanceof Wrapper) { Object unwrapped = ((Wrapper)value).unwrap(); if (unwrapped instanceof InputStream) { is = (InputStream)unwrapped; } else if (unwrapped instanceof byte[]) { is = new ByteArrayInputStream((byte[])unwrapped); } else if (unwrapped instanceof Reader) { s = readReader((Reader)unwrapped); } else if (unwrapped instanceof char[]) { s = new String((char[])unwrapped); } } if (is == null) { if (s == null) { s = ScriptRuntime.toString(value); } is = new ByteArrayInputStream(s.getBytes()); } return is; }
/** * Returns the named toplevel property converted to the requested * <code>type</code> or <code>null</code> if no such property exists or the * property is of the wrong type. */ @SuppressWarnings("unchecked") private <Type> Type getProperty(Context cx, Scriptable scope, String name, Class<Type> type) { Object prop = ScriptRuntime.name(cx, scope, name); if (prop instanceof Wrapper) { prop = ((Wrapper) prop).unwrap(); } if (type.isInstance(prop)) { return (Type) prop; // unchecked case } return null; } }
/** * The bindings function takes a JavaScript scope object * of type ExternalScriptable and returns the underlying Bindings * instance. * * var page = scope(pageBindings); * with (page) { * // code that uses page scope * } * var b = bindings(page); * // operate on bindings here. */ public static Object bindings(Context cx, Scriptable thisObj, Object[] args, Function funObj) { if (args.length == 1) { Object arg = args[0]; if (arg instanceof Wrapper) { arg = ((Wrapper)arg).unwrap(); } if (arg instanceof ExternalScriptable) { ScriptContext ctx = ((ExternalScriptable)arg).getContext(); Bindings bind = ctx.getBindings(ScriptContext.ENGINE_SCOPE); return Context.javaToJS(bind, ScriptableObject.getTopLevelScope(thisObj)); } } return cx.getUndefinedValue(); }
public Scriptable construct(Context cx, Scriptable scope, Object[] args) { ClassLoader loader = null; if (args.length != 0) { Object arg = args[0]; if (arg instanceof Wrapper) { arg = ((Wrapper)arg).unwrap(); } if (arg instanceof ClassLoader) { loader = (ClassLoader)arg; } } if (loader == null) { Context.reportRuntimeError0("msg.not.classloader"); return null; } return new NativeJavaPackage(true, "", loader); }
private static Class<?> getClass(Object[] args) { if (args.length == 0) { throw reportRuntimeError("msg.expected.string.arg"); } Object arg0 = args[0]; if (arg0 instanceof Wrapper) { Object wrapped = ((Wrapper)arg0).unwrap(); if (wrapped instanceof Class) return (Class<?>)wrapped; } String className = Context.toString(args[0]); try { return Class.forName(className); } catch (ClassNotFoundException cnfe) { throw reportRuntimeError("msg.class.not.found", className); } }
return ((Wrapper)x).unwrap() == ((Wrapper)y).unwrap(); warnAboutNonJSObject(x); return x == y;