Examples of ScriptContext


Examples of javax.script.ScriptContext

    @Test
    public void testSetContext() {
        logger1.info("setContext");
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine instance = manager.getEngineByName("jruby");
        ScriptContext ctx = new SimpleScriptContext();
        StringWriter sw = new StringWriter();
        sw.write("Have a great summer!");
        ctx.setWriter(sw);
        instance.setContext(ctx);
        ScriptContext result = instance.getContext();
        Writer w = result.getWriter();
        Object expResult = "Have a great summer!";
        assertTrue(sw == result.getWriter());
        assertEquals(expResult, (result.getWriter()).toString());

        instance.getBindings(ScriptContext.ENGINE_SCOPE).clear();
        instance = null;
    }
View Full Code Here

Examples of javax.script.ScriptContext

            }
        }
    }

    public Object eval(String script, Bindings bindings) throws ScriptException {
        ScriptContext context = getScriptContext(bindings);
        return eval(script, context);
    }
View Full Code Here

Examples of javax.script.ScriptContext

        ScriptContext context = getScriptContext(bindings);
        return eval(script, context);
    }

    public Object eval(Reader reader, Bindings bindings) throws ScriptException {
        ScriptContext context = getScriptContext(bindings);
        return eval(reader, context);
    }
View Full Code Here

Examples of javax.script.ScriptContext

    protected ScriptContext getScriptContext(Bindings bindings) {
        if (bindings == null) {
            throw new NullPointerException("null bindings in engine scope");
        }

        ScriptContext newContext = new SimpleScriptContext();
        newContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
        Bindings global = getBindings(ScriptContext.GLOBAL_SCOPE);
        if (global != null) {
            newContext.setBindings(global, ScriptContext.GLOBAL_SCOPE);
        }
        newContext.setReader(context.getReader());
        newContext.setWriter(context.getWriter());
        newContext.setErrorWriter(context.getErrorWriter());

        return newContext;
    }
View Full Code Here

Examples of javax.script.ScriptContext

    @Override
    public Object eval(Bindings bindings) throws ScriptException {
        if (bindings == null) {
            throw new NullPointerException("bindings is null");
        }
        ScriptContext context = engine.getScriptContext(bindings);
        return eval(context);
    }
View Full Code Here

Examples of javax.script.ScriptContext

        ScriptEngine engine = createScriptEngine();

        Bindings bindings = engine.createBindings();
        populateBindings(bindings, container);

        ScriptContext context = new SimpleScriptContext();
        // Bug workaround
        context.setBindings(bindings, ScriptContext.GLOBAL_SCOPE);
        context.setBindings(bindings, ScriptContext.ENGINE_SCOPE);

        engine.setContext(context);

        try {
            engine.eval(new InputStreamReader(script.getInputStream()));
View Full Code Here

Examples of javax.script.ScriptContext

        Bindings bindings = null;
        Reader reader = null;
        try {
            bindings = verifySlingBindings(scriptName, props);

            ScriptContext ctx = new SimpleScriptContext();
            ctx.setBindings(bindings, ScriptContext.ENGINE_SCOPE);
            ctx.setReader((Reader) bindings.get(READER));
            ctx.setWriter((Writer) bindings.get(OUT));
            ctx.setErrorWriter(new LogWriter((Logger) bindings.get(LOG)));

            reader = getScriptReader();
            if ( method != null && !(this.scriptEngine instanceof Invocable)) {
                reader = getWrapperReader(reader, method, args);
            }

            // evaluate the script
            final Object result = scriptEngine.eval(reader, ctx);

            // call method - if supplied and script engine supports direct invocation
            if ( method != null && (this.scriptEngine instanceof Invocable)) {
                try {
                    ((Invocable)scriptEngine).invokeFunction(method, Arrays.asList(args).toArray());
                } catch (NoSuchMethodException e) {
                    throw new ScriptEvaluationException(scriptName, "Method " + method + " not found in script.", e);
                }
            }
            // optionall flush the output channel
            Object flushObject = bindings.get(SlingBindings.FLUSH);
            if (flushObject instanceof Boolean && (Boolean) flushObject) {
                ctx.getWriter().flush();
            }

            // allways flush the error channel
            ctx.getErrorWriter().flush();

            return result;

        } catch (IOException ioe) {
            throw new ScriptEvaluationException(scriptName, ioe.getMessage(),
View Full Code Here

Examples of javax.script.ScriptContext

    }

    public Object eval(String javascriptCode, Map<String, Object> data,
            final StringWriter sw) throws ScriptException {
        final PrintWriter pw = new PrintWriter(sw, true);
        ScriptContext ctx = new SimpleScriptContext();

        final Bindings b = new SimpleBindings();
        b.put("out", pw);
        if (data != null) {
            for (Map.Entry<String, Object> e : data.entrySet()) {
                b.put(e.getKey(), e.getValue());
            }
        }

        ctx.setBindings(b, ScriptContext.ENGINE_SCOPE);
        ctx.setWriter(sw);
        ctx.setErrorWriter(new OutputStreamWriter(System.err));
        Object result = getEngine().eval(javascriptCode, ctx);

        if (result instanceof Wrapper) {
            result = ((Wrapper) result).unwrap();
        }
View Full Code Here

Examples of org.apache.myfaces.shared.renderkit.html.HtmlRendererUtils.ScriptContext

   
    public static void appendAutoScrollAssignment(StringBuilder onClickValue,
            String formName)
    {
        appendAutoScrollAssignment(FacesContext.getCurrentInstance(),
                new ScriptContext(onClickValue, false), formName);
    }
View Full Code Here

Examples of org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlRendererUtils.ScriptContext

            writer.startElement(HTML.SCRIPT_ELEM, null);
            writer.writeAttribute(HTML.TYPE_ATTR, "text/javascript", null);

            boolean autoScroll = currentInstance.isAutoScroll();

            ScriptContext context = new ScriptContext(
                    currentInstance.isPrettyHtml());
            context.prettyLine();
            context.increaseIndent();

            prepareScript(facesContext, context, autoScroll);

            writer.writeText(context.toString(), null);

            writer.endElement(HTML.SCRIPT_ELEM);
        }
        else
        {
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.