Package org.apache.velocity.context

Examples of org.apache.velocity.context.Context


        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();
            if (why == null || why[0] == null)
            {
                result.put(e.getKey(), "");               
            }
            else
            {
                result.put(e.getKey(), why[0]);
            }
        }
        context.put("prefsMap", result);
    }
View Full Code Here

            response.setContentType(contentType);
            Template t = getTemplate(stack,
                    velocityManager.getVelocityEngine(), invocation,
                    finalLocation, encoding);

            Context context = createContext(velocityManager, stack, request,
                    response, finalLocation);
            Writer writer = new OutputStreamWriter(response.getOutputStream(),
                    encoding);

            t.merge(context, writer);
View Full Code Here

        // getResourceAsInputStream also considers the content cache
        Reader reader = encoding != null ? new InputStreamReader(getResourceAsInputStream(), encoding) : new InputStreamReader(getResourceAsInputStream());
        StringWriter buffer = new StringWriter();
        String logTag = getClass().getName();
        Map variableMap = ExchangeHelper.createVariableMap(exchange);
        Context velocityContext = new VelocityContext(variableMap);

        // let velocity parse and generate the result in buffer
        VelocityEngine engine = getVelocityEngine();
        if (log.isDebugEnabled()) {
            log.debug("Velocity is evaluating using velocity context: " + variableMap);
        }
        engine.evaluate(velocityContext, buffer, logTag, reader);

        // now lets output the results to the exchange
        Message out = exchange.getOut(true);
        out.setBody(buffer.toString());
        out.setHeader("org.apache.camel.velocity.resource", resource);
        Map<String, Object> headers = (Map<String, Object>)velocityContext.get("headers");
        for (String key : headers.keySet()) {
            out.setHeader(key, headers.get(key));
        }
    }
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

        if (LOG.isDebugEnabled()) {
            LOG.debug("Rendering template " + templateName);
        }

        Context context = velocityManager.createContext(templateContext.getStack(), req, res);

        Writer outputWriter = templateContext.getWriter();
        context.put("tag", templateContext.getTag());
        context.put("parameters", templateContext.getParameters());

        template.merge(context, outputWriter);
    }
View Full Code Here

                contentType = contentType + ";charset=" + encoding;
            }

            Template t = getTemplate(stack, velocityManager.getVelocityEngine(), invocation, finalLocation, encoding);

            Context context = createContext(velocityManager, stack, request, response, finalLocation);
            Writer writer = new OutputStreamWriter(response.getOutputStream(), encoding);


            response.setContentType(contentType);
View Full Code Here

            throw new CannotRenderException("Cannot dispatch a null path");
        }

        ServletRequest servletRequest = ServletUtil.getServletRequest(request);
        // then get a context
        Context context = velocityView.createContext(servletRequest
                .getRequest(), servletRequest.getResponse());

        // get the template
        Template template = velocityView.getTemplate((String) path);
View Full Code Here

    public Context initControlContext()
    {
        /*
         * Create a new Velocity context.
         */
        Context context = new VelocityContext();

        /*
         * Transform the XML database schema into an
         * object that represents our model.
         */
        XmlToAppData xmlParser = new XmlToAppData();
        app = xmlParser.parseFile(xmlFile);

        /*
         * Place our model in the context.
         */
        context.put("appData", app);

        return context;
    }
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.