Package org.apache.velocity

Examples of org.apache.velocity.Template


        }
      }
    }
   
    try {
      Template template = engine.getTemplate(templateName);
      getLog().info("Writing to " + outputFile.getAbsolutePath());
      outputFile.getParentFile().mkdirs();
      FileOutputStream fos = new FileOutputStream(outputFile);
      OutputStreamWriter osw = new OutputStreamWriter(fos, UTF8);
      template.merge(vc, osw);
      osw.close();
    } catch (Exception e) {
      getLog().error(e);
      throw new MojoExecutionException("Failed to expand template", e);
    }
View Full Code Here


        }
      }
    }
   
    try {
      Template template = engine.getTemplate(templateName);
      getLog().info("Writing to " + outputFile.getAbsolutePath());
      outputFile.getParentFile().mkdirs();
      FileOutputStream fos = new FileOutputStream(outputFile);
      OutputStreamWriter osw = new OutputStreamWriter(fos, UTF8);
      template.merge(vc, osw);
      osw.close();
    } catch (Exception e) {
      getLog().error(e);
      throw new MojoExecutionException("Failed to expand template", e);
    }
View Full Code Here

            VelocityEngine ve = new VelocityEngine();
            ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
            ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
            ve.init();
 
            Template t = ve.getTemplate( templateName );
            t.merge( vcontext, writer );
            System.out.println("================");
            System.out.println(writer.toString());
            System.out.println("================");
            return writer.toString();
        } catch (Exception e) {
View Full Code Here

   
      VelocityEngine ve = new VelocityEngine();
      ve.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
      ve.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
      ve.init();
      Template t = ve.getTemplate( "templates/default.vm" );
      t.merge( context, writer );
      System.out.println(writer);
  }
View Full Code Here

      if (encoding != null)
      {
        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();

      String layout = getLayoutTemplate(context);

      try
      {
        // load the layout template
        t = getTemplate(stack, velocityManager.getVelocityEngine(),
            invocation, layout, encoding);
      }
      catch (Exception e)
      {

        // if it was an alternate layout we couldn't get...
        if (!layout.equals(defaultLayout))
        {
          // try to get the default layout
          // if this also fails, let the exception go
          t = getTemplate(stack, velocityManager.getVelocityEngine(),
              invocation, defaultLayout, encoding);
        }
      }

      Writer writer = new OutputStreamWriter(response.getOutputStream(),
          encoding);
      // Render the layout template into the response
      t.merge(context, writer);

      // generator exec template time
      Date cur_time = Calendar.getInstance(
          invocation.getInvocationContext().getLocale()).getTime();
      writer.write("\r\n<!-- Generated by EATELE.NET (");
View Full Code Here

     */
    public String render(String template, HashMap<String, Object> m) {

        try {

            Template t = this.ve.getTemplate(template);
            VelocityContext context = new VelocityContext();
            context.put("data", m);
            StringWriter writer = new StringWriter();
            t.merge(context, writer);
            return writer.toString();

        } catch (ResourceNotFoundException ex) {
            return ex.getMessage();
        } catch (ParseErrorException ex) {
View Full Code Here

            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);

        }
        catch (Exception e2)
        {
View Full Code Here

            fillContext(context, request);

            setContentType(request, response);

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

            // merge the template and context into the response
            mergeTemplate(template, context, response);
        }
        catch (Throwable e)
View Full Code Here

      compileInterface(protocol).writeToDestination(src, dst);
    }
  }

  private String renderTemplate(String templateName, VelocityContext context) {
    Template template;
    try {
      template = this.velocityEngine.getTemplate(templateName);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }
    StringWriter writer = new StringWriter();
    template.merge(context, writer);
    return writer.toString();
  }
View Full Code Here

        if (getTemplate() != null)
        {
            ViewToolContext context = getViewToolContext();

            // get the actual Template
            Template template = view.getTemplate(getTemplate());

            if (getBodyContent() != null)
            {
                context.put(getBodyContentKey(), getRenderedBody());
            }

            // render the template into the writer
            template.merge(context, out);
        }
        else
        {
            // render the body into the writer
            renderBody(out);
View Full Code Here

TOP

Related Classes of org.apache.velocity.Template

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.