Package org.apache.velocity.context

Examples of org.apache.velocity.context.Context


        contentType = contentType + ";charset=" + encoding;
      }
      Template t = getTemplate(stack,
          velocityManager.getVelocityEngine(), invocation,
          finalLocation, encoding);
      Context context = createContext(velocityManager, stack, request,
          response, finalLocation);
      Writer screenWriter = new StringWriter();
      response.setContentType(contentType);
      t.merge(context, screenWriter);
      context.put(KEY_SCREEN_CONTENT, screenWriter.toString());

      // ------------- 2. render the layout template -------------

      initLayoutTemplateParameters();
View Full Code Here


                         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

                h = null;
                props = bi.getPropertyDescriptors();
            }
            final DynamicPropertyHandler handler = h;
           
            this.velocityContext = new Context() {
                    public Object put(String key, Object value) {
                        if (key.equals("flowContext")
                            || key.equals("continuation")) {
                            return value;
                        }
View Full Code Here

        PortletConfig portletConfig = (PortletConfig) request.getAttribute(PORTLET_CONFIG);
       
        if (renderRequest != null)
        {
            renderRequest.setAttribute(VELOCITY_CONTEXT_ATTR, ctx);
            Context portletContext = (Context)renderRequest.getAttribute(GenericVelocityPortlet.PORTLET_BRIDGE_CONTEXT);
            if (portletContext != null)
            {
                // merge in portletContext
                Object[] keys = portletContext.getKeys();
                for (int ix = 0; ix < keys.length; ix++)
                {
                    // is this api f'd in the head or what
                    ctx.put((String)keys[ix], portletContext.get((String)keys[ix]));
                }               
            }
           
        }
View Full Code Here

        super.render(request, response);
    }

    private Context createPortletVelocityContext(RenderRequest request, RenderResponse response)
    {
        Context ctx = new VelocityContext();
        request.setAttribute(PORTLET_BRIDGE_CONTEXT, ctx);
        // PLT.22
        ctx.put("renderRequest", request);
        ctx.put("renderResponse", response);
        ctx.put("portletConfig", getPortletConfig());
        // constants
        ctx.put("STATE_NORMAL", WindowState.NORMAL);
        ctx.put("STATE_MAX", WindowState.MAXIMIZED);
        ctx.put("STATE_MIN", WindowState.MINIMIZED);
        ctx.put("MODE_VIEW", PortletMode.VIEW);
        ctx.put("MODE_EDIT", PortletMode.EDIT);
        ctx.put("MODE_HELP", PortletMode.HELP);
        ctx.put("USER_INFO", PortletRequest.USER_INFO);
        return ctx;
    }
View Full Code Here

        return (Context) request.getAttribute(PORTLET_BRIDGE_CONTEXT);
    }

    public void setupPreferencesEdit(RenderRequest request, RenderResponse response)
    {
        Context context = getContext(request);
        PortletPreferences prefs = request.getPreferences();
        Map map = prefs.getMap();
        Iterator it = map.entrySet().iterator();
        context.put("prefs", it);
       
        Map result = new HashMap(map.size());
        Iterator f = map.entrySet().iterator();
        while(f.hasNext())
        {
            Map.Entry e = (Map.Entry)f.next();
            String []why = (String[])e.getValue();
            result.put(e.getKey(), why[0]);           
        }
        context.put("prefsMap", result);
    }
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

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.