Package jst

Examples of jst.ScriptRuntime.addVariable()


    private void writeScriptError(HttpServletRequest request, HttpServletResponse response, TemplateException ex) throws IOException {
        ScriptRuntime runtime = templateContext.load( "templates/exception.jst");
        runtime.addGlobalVariable( "request", request );
        runtime.addGlobalVariable( "response", response );
        runtime.addGlobalVariable( "servletContext", servletContext );
        runtime.addVariable("ex", ex );
        writeResponse( response, runtime.invoke() );
    }

    private ScriptRuntime initializeScript(String scriptName, HttpServletRequest request, HttpServletResponse response) throws IOException {
        ScriptRuntime runtime = templateContext.load( scriptName );
View Full Code Here


                runtime.mixin( mixinName, request.getAttribute( name ) );
            } else if( name.equalsIgnoreCase( TemplateDispatcher.JST_LAYOUT ) ) {
                runtime.setLayout( request.getAttribute( name ).toString() );
            } else if( name.startsWith(TemplateDispatcher.JST_VARIABLE) ) {
                String varName = name.substring( TemplateDispatcher.JST_VARIABLE.length() );
                runtime.addVariable( varName, request.getAttribute( name ) );
            } else if( name.startsWith( TemplateDispatcher.JST_SCRIPT_MIXIN ) ) {
                runtime.include( request.getAttribute( name ).toString() );
            }
        }
View Full Code Here

        initializeContext();

        ScriptRuntime runtime = context.load( url );

        for( String name : variables.keySet() ) {
            runtime.addVariable( name, variables.get( name ) );
        }

        for( String name : mixins.keySet() ) {
            runtime.mixin( name, mixins.get( name ) );
        }
View Full Code Here

    }

    public Object evaluate( String url, Map<String,Object> data ) throws IOException {
        ScriptRuntime runtime = load(url);
        for( String key : data.keySet() ) {
            runtime.addVariable( key, data.get(key) );
        }
        return runtime.invoke();
    }

    public void include(String url) throws IOException {
View Full Code Here

            runtime.addGlobalVariable( "request", httpServletRequest );
            runtime.addGlobalVariable( "response", httpServletResponse );
            runtime.addGlobalVariable( "servletContext", getServletContext() );

            for( String name : ((Map<String,Object>)objects).keySet() ) {
                runtime.addVariable( name, objects.get( name ) );
            }

            Object value = runtime.invoke();

            writeResponse(httpServletResponse, value);
View Full Code Here

            ScriptRuntime runtime = templates.load( "templates/exception.jst" );

            runtime.addGlobalVariable( "request", httpServletRequest);
            runtime.addGlobalVariable( "response", httpServletResponse );
            runtime.addGlobalVariable( "servletContext", getServletContext() );
            runtime.addVariable("ex", ex );

            writeResponse( httpServletResponse, runtime.invoke() );
        }
    }
View Full Code Here

    public static void main(String[] args) throws IOException {
        TemplateContextImpl context = new TemplateContextImpl();
        context.addLoader( new FileTemplateLoader( new File("./test") ) );
        ScriptRuntime runtime = context.load("/embedded-test.jst");
        Object output = runtime.addVariable("name", "Charlie").addVariable("age", 31).invoke();

        System.out.println( output );
    }
}
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.