Examples of ScriptableObject


Examples of org.mozilla.javascript.ScriptableObject

public class SlingContext extends Context {

    @Override
    public ScriptableObject initStandardObjects(ScriptableObject scope,
            boolean sealed) {
        ScriptableObject rootScope = super.initStandardObjects(scope, sealed);

        // add Sling global objects
        SlingGlobal.init(rootScope, sealed);

        return rootScope;
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

            for (Class<?> clazz : HOSTOBJECT_CLASSES) {
                try {

                    // register the host object
                    ScriptableObject.defineClass(rootScope, clazz);
                    final ScriptableObject host = (ScriptableObject) clazz.newInstance();

                    if (SlingWrapper.class.isAssignableFrom(clazz)) {
                        // SlingWrappers can map to several classes if needed
                        final SlingWrapper hostWrapper = (SlingWrapper) host;
                        for (Class<?> c : hostWrapper.getWrappedClasses()) {
                            SlingWrapFactory.INSTANCE.registerWrapper(c,
                                hostWrapper.getClassName());
                        }
                    } else {
                        // but other ScriptableObjects need to be registered as
                        // well
                        SlingWrapFactory.INSTANCE.registerWrapper(
                            host.getClass(), host.getClassName());
                    }
                } catch (Throwable t) {
                    log.warn("getRootScope: Cannot prepare host object " + clazz, t);
                }
            }
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

        // create a rhino Context and execute the script
        try {
           
            final Context rhinoContext = Context.enter();
            final ScriptableObject scope = new NativeObject();

            // Set the global scope to be our prototype
            scope.setPrototype(rootScope);

            // We want "scope" to be a new top-level scope, so set its parent
            // scope to null. This means that any variables created by assignments
            // will be properties of "scope".
            scope.setParentScope(null);

            // setup the context for use
            rhinoContext.setWrapFactory(SlingWrapFactory.INSTANCE);

            // add initial properties to the scope
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

        // build the code, something like
        //  data = <jsonData> ;
        //  <code>
        final String jsCode = "data=" + jsonData + ";\n" + code;
        final Context rhinoContext = Context.enter();
        final ScriptableObject scope = rhinoContext.initStandardObjects();

        // execute the script, out script variable maps to sw
        final StringWriter sw = new StringWriter();
        final PrintWriter pw = new PrintWriter(sw, true);
        ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

        }

        public XLoper execute(IFunctionContext context, XLoper[] args) throws RequestException {
            Context ctx = Context.enter();
            Object[] oargs = converter.convert(args, BSFScript.createArgHints(args));
            ScriptableObject so = ctx.initStandardObjects();
            Scriptable argsObj = ctx.newArray(so, oargs);
            so.defineProperty("args", argsObj, ScriptableObject.DONTENUM);
            try {
                return converter.createFrom(script.exec(ctx, so));
            } catch (Throwable t) {
                throw new RequestException(t.getMessage());
            }
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

    @Override
    public Object evaluate(String script, String filename, Map<String, Object> args)
            throws ScriptException, Throwable {
        RhinoContextFactory factory = new RhinoContextFactory(timeLimit);
        Context cx = factory.enterContext();
        ScriptableObject scriptable = new ImporterTopLevel(cx);
        Scriptable scope = cx.initStandardObjects(scriptable);

        for (Map.Entry<String, Object> entry : args.entrySet()) {
            ScriptableObject.putProperty(scope, entry.getKey(),
                    Context.javaToJS(entry.getValue(), scope));
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

            return new RhinoScriptEngineFactory();
        }
    }

    private Scriptable setupScope(Context cx, ScriptContext context) {
        ScriptableObject scriptable = new ImporterTopLevel(cx);
        Scriptable scope = cx.initStandardObjects(scriptable);
        //ScriptableObject.putProperty(scope, "argv", Context.javaToJS(args, scope));
        return scope;
    }
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

                    @Override
                    public RhinoExecutor invoke()
                    {
                        final Context context = contextFactory.enterContext();

                        final ScriptableObject scope = context.initStandardObjects();

                        try
                        {
                            context.setOptimizationLevel(-1);

                            for (Resource script : scripts)
                            {
                                loadScript(context, scope, script);
                            }

                        } finally
                        {
                            Context.exit();
                        }

                        return new RhinoExecutor()
                        {
                            @Override
                            public ScriptableObject invokeFunction(String functionName, Object... arguments)
                            {
                                contextFactory.enterContext(context);

                                try
                                {
                                    NativeFunction function = (NativeFunction) scope.get(functionName, scope);

                                    return (ScriptableObject) function.call(context, scope, null, arguments);
                                } finally
                                {
                                    Context.exit();
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

                interpreter.callHandler(function,
                    new RhinoInterpreter.ArgumentsBuilder() {
                        public Object[] buildArguments() {
                            try {
                                Object[] arguments = new Object[1];
                                ScriptableObject so =
                                    (ScriptableObject)interpreter.evaluate
                                    (new StringReader("new Object()"));
                                so.put("success", so,
                                       (success) ?
                                       Boolean.TRUE : Boolean.FALSE);
                                if (mime != null) {
                                    so.put("contentType", so,
                                           Context.toObject(mime,
                                                            windowWrapper));
                                }
                                if (content != null) {
                                    so.put("content", so,
                                           Context.toObject(content,
                                                            windowWrapper));
                                }
                                arguments[0] = so;
                                return arguments;
View Full Code Here

Examples of org.mozilla.javascript.ScriptableObject

    long t = System.currentTimeMillis();
    try {
      return cx.evaluateString(scope, script, mnemonic, 1, null);
    } catch (JavaScriptException e) {
      Object obj = e.getValue();
      ScriptableObject so = (ScriptableObject) obj;

      throw e;
    } finally {
      log.info("EXECUTED SCRIPT '" + mnemonic +"' IN " + (System.currentTimeMillis()-t));
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.