Package org.apache.velocity.context

Examples of org.apache.velocity.context.Context


     * (releases the (non-global) tools in the context for reuse later)
     */
    protected void doPostBuild(RunData data)
        throws Exception
    {
        Context context = TurbineVelocity.getContext(data);
        TurbineVelocity.requestFinished(context);
    }
View Full Code Here


    public ConcreteElement buildTemplate(RunData data)
        throws Exception
    {
        String screenData = null;

        Context context = TurbineVelocity.getContext(data);

        String screenTemplate = data.getTemplateInfo().getScreenTemplate();
        String templateName
            = TurbineTemplate.getScreenTemplateName(screenTemplate);

        // The Template Service could not find the Screen
        if (StringUtils.isEmpty(templateName))
        {
            log.error("Screen " + screenTemplate + " not found!");
            throw new Exception("Could not find screen for " + screenTemplate);
        }

        try
        {
            // if a layout has been defined return the results, otherwise
            // send the results directly to the output stream.
            if (getLayout(data) == null)
            {
                TurbineVelocity.handleRequest(context,
                        prefix + templateName,
                        data.getResponse().getOutputStream());
            }
            else
            {
                screenData = TurbineVelocity
                        .handleRequest(context, prefix + templateName);
            }
        }
        catch (Exception e)
        {
            // If there is an error, build a $processingException and
            // attempt to call the error.vm template in the screens
            // directory.
            context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
            context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));

            templateName = Turbine.getConfiguration()
                .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
                           TurbineConstants.TEMPLATE_ERROR_VM);
View Full Code Here

     * @exception Exception, a generic exception.
     */
    public ConcreteElement buildTemplate(RunData data)
        throws Exception
    {
        Context context = TurbineVelocity.getContext(data);

        String screenTemplate = data.getTemplateInfo().getScreenTemplate();
        String templateName
            = TurbineTemplate.getScreenTemplateName(screenTemplate);

        // The Template Service could not find the Screen
        if (StringUtils.isEmpty(templateName))
        {
            log.error("Screen " + screenTemplate + " not found!");
            throw new Exception("Could not find screen for " + screenTemplate);
        }

        try
        {
            TurbineVelocity.handleRequest(context,
                                          prefix + templateName,
                                          data.getOut());

        }
        catch (Exception e)
        {
            // If there is an error, build a $processingException and
            // attempt to call the error.vm template in the screens
            // directory.
            context.put (TurbineConstants.PROCESSING_EXCEPTION_PLACEHOLDER, e.toString());
            context.put (TurbineConstants.STACK_TRACE_PLACEHOLDER, ExceptionUtils.getStackTrace(e));

            templateName = Turbine.getConfiguration()
                .getString(TurbineConstants.TEMPLATE_ERROR_KEY,
                           TurbineConstants.TEMPLATE_ERROR_VM);

View Full Code Here

     */
    public void doBuild(RunData data)
        throws Exception
    {
        // Get the context needed by Velocity.
        Context context = TurbineVelocity.getContext(data);

        data.getResponse().setContentType("text/html");

        String screenName = data.getScreen();

        log.debug("Loading Screen " + screenName);

        // First, generate the screen and put it in the context so
        // we can grab it the layout template.
        ConcreteElement results =
            ScreenLoader.getInstance().eval(data, screenName);

        String returnValue = (results == null) ? "" : results.toString();

        // variable for the screen in the layout template
        context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue);

        // variable to reference the navigation screen in the layout template
        context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
                    new TemplateNavigation(data));

        // Grab the layout template set in the VelocityPage.
        // If null, then use the default layout template
        // (done by the TemplateInfo object)
View Full Code Here

     */
    public void doBuild(RunData data)
        throws Exception
    {
        // Get the context needed by Velocity.
        Context context = TurbineVelocity.getContext(data);

        String screenName = data.getScreen();

        log.debug("Loading Screen " + screenName);

        // First, generate the screen and put it in the context so
        // we can grab it the layout template.
        ConcreteElement results =
            ScreenLoader.getInstance().eval(data, screenName);

        String returnValue = (results == null) ? "" : results.toString();

        // variable for the screen in the layout template
        context.put(TurbineConstants.SCREEN_PLACEHOLDER, returnValue);

        // variable to reference the navigation screen in the layout template
        context.put(TurbineConstants.NAVIGATION_PLACEHOLDER,
                    new TemplateNavigation(data));

        // Grab the layout template set in the VelocityPage.
        // If null, then use the default layout template
        // (done by the TemplateInfo object)
View Full Code Here

    private UIManager getTool()
    {
        PullService pullService = TurbinePull.getService();
        assertNotNull(pullService);

        Context globalContext = pullService.getGlobalContext();
        assertNotNull(globalContext);

        return (UIManager) globalContext.get("ui");
    }
View Full Code Here

    ResourceProperty property = new ResourceDescription(
        controller, descriptions, config).getProperty(predicate, isInverse);
    if (property == null) return false// Can happen if prefix is declared in URI space of a data source rather than in web space
   
    VelocityHelper template = new VelocityHelper(getServletContext(), response);
    Context context = template.getVelocityContext();
    context.put("project_name", config.getProjectName());
    context.put("project_link", config.getProjectLink());
    context.put("uri", resource.getURI());
    context.put("server_base", config.getWebApplicationBaseURI());
    context.put("title", resource.getTitle());
    context.put("head_title", resource.getTitle() + " \u00BB " + property.getCompleteLabel());
    context.put("property", property);
    context.put("back_uri", controller.getBrowsableURL());
    context.put("back_label", resource.getTitle());
    context.put("rdf_link", isInverse ? controller.getInverseValuesDataURL(predicate) : controller.getValuesDataURL(predicate));
    context.put("showLabels", config.showLabels());

    addPageMetadata(context, controller, resource.getModel());
   
    template.renderXHTML("valuespage.vm");
    return true;
View Full Code Here

  }
 
  protected void send404(HttpServletResponse response, String resourceURI) throws IOException {
    response.setStatus(404);
    VelocityHelper template = new VelocityHelper(getServletContext(), response);
    Context context = template.getVelocityContext();
    context.put("project_name", config.getProjectName());
    context.put("project_link", config.getProjectLink());
    context.put("server_base", config.getWebApplicationBaseURI());
    context.put("title", "404 Not Found");
    if (resourceURI != null) {
      context.put("uri", resourceURI);
    }
    template.renderXHTML("404.vm");
  }
View Full Code Here

  }
 
  protected void sendInitialization500(HttpServletResponse response, String message) throws IOException {
    response.setStatus(500);
    VelocityHelper template = new VelocityHelper(getServletContext(), response);
    Context context = template.getVelocityContext();
    context.put("message", message);
    context.put("title", "Configuration error");
    template.renderXHTML("500init.vm");
  }
View Full Code Here

    if (controller == null) return false;
    ResourceDescription description = controller.getResourceDescription();
    if (description == null) return false;
   
    VelocityHelper template = new VelocityHelper(getServletContext(), response);
    Context context = template.getVelocityContext();
    context.put("project_name", config.getProjectName());
    context.put("project_link", config.getProjectLink());
    context.put("uri", description.getURI());
    context.put("server_base", config.getWebApplicationBaseURI());
    context.put("rdf_link", controller.getDataURL());
    context.put("title", description.getTitle());
    context.put("comment", description.getComment());
    context.put("image", description.getImageURL());
    context.put("properties", description.getProperties());
    context.put("showLabels", config.showLabels());

    addPageMetadata(context, controller, description.getModel());
 
    template.renderXHTML("page.vm");
    return true;
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.