Package org.apache.velocity.context

Examples of org.apache.velocity.context.Context


                         Throwable e)
    {
        try
        {
            // get a velocity context
            Context ctx = createContext(request, response);

            Throwable cause = e;

            // if it's an MIE, i want the real cause and stack trace!
            if (cause instanceof MethodInvocationException)
            {
                // put the invocation exception in the context
                ctx.put(KEY_ERROR_INVOCATION_EXCEPTION, e);
                // get the real cause
                cause = ((MethodInvocationException)e).getWrappedThrowable();
            }

            // add the cause to the context
            ctx.put(KEY_ERROR_CAUSE, cause);

            // grab the cause's stack trace and put it in the context
            StringWriter sw = new StringWriter();
            cause.printStackTrace(new java.io.PrintWriter(sw));
            ctx.put(KEY_ERROR_STACKTRACE, sw.toString());

            // retrieve and render the error template
            Template et = getTemplate(errorTemplate);
            mergeTemplate(et, ctx, response);
View Full Code Here


     @param request  HttpServletRequest object containing client request
     *  @param response HttpServletResponse object for the response
     */
    protected void doRequest(HttpServletRequest request, HttpServletResponse response)
    {
        Context context = null;
        try
        {
            // then get a context
            context = createContext(request, response);

View Full Code Here

     */
    public Context render(HttpServletRequest request,
                          HttpServletResponse response) throws IOException
    {
        // then get a context
        Context context = getContext(request, response);

        // get the template
        Template template = getTemplate(request, response);

        // merge the template and context into the response
View Full Code Here

    public Context render(HttpServletRequest request, Writer out)
        throws IOException
    {
        // then get a context
        Context context = getContext(request);

        // get the template
        Template template = getTemplate(request);

        // merge the template and context into the writer
View Full Code Here

        {
            keys.addAll(tools.keySet());
        }

        // recurse down the velocity context collecting keys
        Context velctx = this.context.getVelocityContext();
        while (velctx != null)
        {
            Object[] ctxKeys = velctx.getKeys();
            keys.addAll(Arrays.asList(ctxKeys));
            if (velctx instanceof AbstractContext)
            {
                velctx = ((AbstractContext)velctx).getChainedContext();
            }
View Full Code Here

    }

    private String mergeTemplateIntoString(final String templateLocation, final Map<String, Object> model) {
        StringWriter result = new StringWriter();
        try {
            Context velocityContext = createVelocityContext(model);
            velocityEngine.mergeTemplate(templateLocation, SyncopeConstants.DEFAULT_ENCODING, velocityContext, result);
        } catch (VelocityException e) {
            LOG.error("Could not get mail body", e);
        } catch (RuntimeException e) {
            // ensure same behaviour as by using Spring VelocityEngineUtils.mergeTemplateIntoString()
View Full Code Here

     *
     * @param model Velocity model
     * @return Velocity context
     */
    protected Context createVelocityContext(Map<String, Object> model) {
        Context toolContext = velocityToolManager.createContext();
        return new VelocityContext(model, toolContext);
    }
View Full Code Here

        if (page == null || page.length() == 0) {
            throw new ViewHandlerException("Invalid template source");
        }

        Context context = new VelocityContext();

        context.put(REQUEST, request);
        context.put(RESPONSE, response);

        Template template = null;

        try {
            template = ve.getTemplate(page);
View Full Code Here

     * </ul>
     *
     * @return a new StrutsVelocityContext
     */
    public Context createContext(ValueStack stack, HttpServletRequest req, HttpServletResponse res) {
        Context result = null;
        VelocityContext[] chainedContexts = prepareChainedContexts(req, res, stack.getContext());
        StrutsVelocityContext context = new StrutsVelocityContext(chainedContexts, stack);
        Map standardMap = ContextUtil.getStandardContext(stack, req, res);
        for (Iterator iterator = standardMap.entrySet().iterator(); iterator.hasNext();) {
            Map.Entry entry = (Map.Entry) iterator.next();
View Full Code Here

        }

        for( int i = 0; i < contextList.size(); i++)
        {

            Context c = (Context) contextList.get( i );

            o = c.get( key );

            if ( o != null )
                return o;
        }
View Full Code Here

TOP

Related Classes of org.apache.velocity.context.Context

Copyright © 2018 www.massapicom. 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.