Java 8 ScriptContext - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 ScriptContext class.

This code example shows how to use the following methods:getAttribute, setAttribute
    } 
  } 
 
  private ELContext createElContext(final ScriptContext scriptCtx) {
    // Check if the ELContext is already stored on the ScriptContext 
    Object existingELCtx = scriptCtx.getAttribute("elcontext");
    if (existingELCtx instanceof ELContext) { 
      return (ELContext) existingELCtx; 
    } 
 
    scriptCtx.setAttribute("context", scriptCtx, ScriptContext.ENGINE_SCOPE);
 
    // Built-in function are added to ScriptCtx 
    scriptCtx.setAttribute("out:print", getPrintMethod(), ScriptContext.ENGINE_SCOPE);
 
    SecurityManager securityManager = System.getSecurityManager();
    if (securityManager == null) {
      scriptCtx.setAttribute("lang:import", getImportMethod(), ScriptContext.ENGINE_SCOPE);
    } 
 

7
CodeRank
This code example shows how to use the following methods:getAttribute, setAttribute
    } 
  } 
 
  private ELContext createElContext(final ScriptContext scriptCtx) {
    // Check if the ELContext is already stored on the ScriptContext 
    Object existingELCtx = scriptCtx.getAttribute("elcontext");
    if (existingELCtx instanceof ELContext) { 
      return (ELContext) existingELCtx; 
    } 
 
    scriptCtx.setAttribute("context", scriptCtx, ScriptContext.ENGINE_SCOPE);
 
    // Built-in function are added to ScriptCtx 
    scriptCtx.setAttribute("out:print", getPrintMethod(), ScriptContext.ENGINE_SCOPE);
 
    SecurityManager securityManager = System.getSecurityManager();
    if (securityManager == null) {
      scriptCtx.setAttribute("lang:import", getImportMethod(), ScriptContext.ENGINE_SCOPE);
    } 
 

6
CodeRank
This code example shows how to use the following methods:getAttribute, setAttribute
     */ 
    private List<Block> highlight(String syntaxId, String code) throws ScriptException, ParseException
    { 
        BlocksGeneratorPygmentsListener listener = new BlocksGeneratorPygmentsListener(this.plainTextParser);
 
        ScriptContext scriptContext = new SimpleScriptContext();
 
        scriptContext.setAttribute(PY_LANGUAGE_VARNAME, syntaxId, ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute(PY_CODE_VARNAME, code, ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute(PY_STYLE_VARNAME, this.configuration.getStyle(), ScriptContext.ENGINE_SCOPE);
        scriptContext.setAttribute(PY_LISTENER_VARNAME, listener, ScriptContext.ENGINE_SCOPE);
 
        this.engine.eval(this.script, scriptContext);
 
        List<Block> blocks;
        if (scriptContext.getAttribute(PY_LEXER_VARNAME) != null) {
            blocks = listener.getBlocks();
        } else { 
            blocks = this.plainTextParser.parse(new StringReader(code)).getChildren().get(0).getChildren();
        } 
 
6
CodeRank
This code example shows how to use the following methods:getBindings, getWriter
            throw new ScriptException("Unable to compile GSP script: " + e.getMessage());
        } catch (ClassNotFoundException e) {
            throw new ScriptException("Unable to compile GSP script: " + e.getMessage());
        } 
 
        Bindings bindings = ctx.getBindings(ScriptContext.ENGINE_SCOPE);
 
        Writable result = template.make(bindings);
 
        try { 
            result.writeTo(ctx.getWriter());
        } catch (IOException e) {
            throw new ScriptException("Unable to write result of script execution: " + e.getMessage());
        } 
 
        return null; 
    } 
 
} 
5
CodeRank
This code example shows how to use the following methods:setBindings
 
    public Object run(Bindings args) throws Exception {
        if (args == null) {
            args = new SimpleBindings();
        } 
        ScriptContext ctx = new SimpleScriptContext();
        ctx.setBindings(args, ScriptContext.ENGINE_SCOPE);
        Object result = null; 
        if (!trackChanges && script != null) {
            result = script.eval(ctx);
        } else { 
            result = getCompiledScript().eval(ctx);
        } 
        return result; 
    } 
 
    public CompiledScript getCompiledScript() throws ScriptException {
        try { 
            Reader reader = script == null ? getReader() : getReaderIfModified();
            if (reader != null) {
5
CodeRank
This code example shows how to use the following methods:getAttributesScope
    public boolean hasProperty(ExecutionContext context, String name) {
        if ( super.hasProperty( context, name ) ) {
            return true; 
        } 
 
        return ( this.context.getAttributesScope( name ) >= 0 );
    } 
 
 
 
} 
5
CodeRank
This code example shows how to use the following methods:getWriter
   public Object eval(ScriptContext cxt)
           throws ScriptException {
      Env env = null;
 
      try { 
         Writer writer = cxt.getWriter();
 
         WriteStream out;
 
         if (writer != null) {
            ReaderWriterStream s = new ReaderWriterStream(null, writer);
            WriteStream os = new WriteStream(s);
 
            os.setNewlineString("\n");
 
            try { 
               os.setEncoding("utf-8");
            } catch (Exception e) {
            } 
 

5
CodeRank
This code example shows how to use the following methods:setErrorWriter, setWriter
This code example shows how to use the following methods:getAttribute, getAttributesScope
		}		 
	} 
 
	private static final String PARENTLOADER = "parentLoader";
	private static ClassLoader getParentLoader(ScriptContext ctx) {
		int scope = ctx.getAttributesScope(PARENTLOADER);
		if (scope != -1) {
			Object loader = ctx.getAttribute(PARENTLOADER);
			if (loader instanceof ClassLoader) {
				return (ClassLoader) loader;
			} // else fall through.. 
		} 
		return null;	    
	} 
 
	private static Object evalClass(Class clazz, ScriptContext ctx) 
							throws ScriptException {
		// JSR-223 requirement 
		ctx.setAttribute("context", ctx, ScriptContext.ENGINE_SCOPE);
		if (clazz == null) {
4
CodeRank
This code example shows how to use the following methods:getAttribute, getAttributesScope
		}		 
	} 
 
	private static final String PARENTLOADER = "parentLoader";
	private static ClassLoader getParentLoader(ScriptContext ctx) {
		int scope = ctx.getAttributesScope(PARENTLOADER);
		if (scope != -1) {
			Object loader = ctx.getAttribute(PARENTLOADER);
			if (loader instanceof ClassLoader) {
				return (ClassLoader) loader;
			} // else fall through.. 
		} 
		return null;	    
	} 
 
} 
4
CodeRank
See Code Examples for Java 8 ScriptContext Methods: