Package org.apache.velocity

Examples of org.apache.velocity.Template


    public void generateTagReports() throws Exception {
        for (TagObject tagObject : ri.getTags()) {
            VelocityEngine ve = new VelocityEngine();
            ve.init(getProperties());
            Template featureResult = ve.getTemplate("templates/tagReport.vm");
            VelocityContextMap contextMap = VelocityContextMap.of(new VelocityContext());
            contextMap.putAll(getGeneralParameters());
            contextMap.put("tag", tagObject);
            contextMap.put("time_stamp", ri.timeStamp());
            contextMap.put("report_status_colour", ri.getTagReportStatusColour(tagObject));
View Full Code Here


    }

    public void generateTagOverview() throws Exception {
        VelocityEngine ve = new VelocityEngine();
        ve.init(getProperties());
        Template featureOverview = ve.getTemplate("templates/tagOverview.vm");
        VelocityContextMap contextMap = VelocityContextMap.of(new VelocityContext());
        contextMap.putAll(getGeneralParameters());
        contextMap.put("tags", ri.getTags());
        contextMap.put("total_tags", ri.getTotalTags());
        contextMap.put("total_scenarios", ri.getTotalTagScenarios());
View Full Code Here

    }

    public void generateErrorPage(Exception exception) throws Exception {
        VelocityEngine ve = new VelocityEngine();
        ve.init(getProperties());
        Template errorPage = ve.getTemplate("templates/errorPage.vm");
        VelocityContextMap contextMap = VelocityContextMap.of(new VelocityContext());
        contextMap.putAll(getGeneralParameters());
        contextMap.put("error_message", exception);
        contextMap.put("time_stamp", new SimpleDateFormat("dd-MM-yyyy HH:mm:ss").format(new Date()));
        generateReport("feature-overview.html", errorPage, contextMap.getVelocityContext());
View Full Code Here

            }

            String target = URLDecoder.decode(request.getRequestLine().getUri(), "UTF-8");
            if(target.endsWith(".jhtml")) {
              if(velocityOK) {
                Template template = templateCache.get(target);
                if(template == null) {
                  try {
                    String vmFileName = target.replace(".jhtml", ".vm").replace("/", "\\").substring(1);
                    final File file = new File(this.docRoot, target.replace(".jhtml", ".vm"));
                    if(!file.exists()) {
                      response.setStatusCode(HttpStatus.SC_NOT_FOUND);
                          NStringEntity entity = new NStringEntity(
                                  "<html><body><h1>File" + file.getPath() +
                                  " not found</h1></body></html>",
                                  ContentType.create("text/html", "UTF-8"));
                          response.setEntity(entity);
                          System.out.println("File " + file.getPath() + " not found");
                    } else {
                      template = Velocity.getTemplate(vmFileName, templateEncode);
                      //
                      templateCache.putIfAbsent(target, template);
                    }
                  } catch (Exception e) {
                    logger.error("Exception: get template", e);
                  }
                }
               
                // 渲染VM
                VelocityContext cxt = new VelocityContext();
                monitor.getData(cxt);
                Writer writer = new StringWriter();
                template.merge(cxt, writer);
                response.setStatusCode(HttpStatus.SC_OK);
                NStringEntity entity = new NStringEntity(writer.toString(), ContentType.create("text/html", "UTF-8"));
                response.setEntity(entity);
              } else {
                response.setStatusCode(HttpStatus.SC_NOT_FOUND);
View Full Code Here

public class VMDemo {

    public static void main(final String[] args) throws Exception {
        Velocity.init();
        final Template t = Velocity.getTemplate("./templates/poc.vm");

        final VelocityContext ctx = new VelocityContext();

        final Writer writer = new StringWriter();
        t.merge(ctx, writer);

        System.out.println(writer);
    }
View Full Code Here

        try {
            final String templText = getTemplateFromJar(relative);
            StringResourceLoader.getRepository().putStringResource("my_template",
                    templText);
            final Template t = ve.getTemplate("my_template");

            final StringWriter writer = new StringWriter();
            t.merge(context, writer);

            return writer.toString();
        } catch (final Exception e) {
            ErlLogger.error(e);
            return null;
View Full Code Here

     * @since Velocity v1.1
     */
    public boolean mergeTemplate(String templateName, String encoding,
                                 Context context, Writer writer)
        throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception {
        Template template = ri.getTemplate(templateName, encoding);

        if (template == null) {
            getLog().error("Velocity.mergeTemplate() was unable to load template '"
                + templateName + "'");
            return false;
        } else {
            template.merge(context, writer);
            return true;
        }
    }
View Full Code Here

     * @since Velocity v1.1
     */
    public boolean mergeTemplate(String templateName, String encoding,
                                 Context context, Writer writer)
        throws ResourceNotFoundException, ParseErrorException, MethodInvocationException, Exception {
        Template template = ri.getTemplate(templateName, encoding);

        if (template == null) {
            getLog().error("Velocity.mergeTemplate() was unable to load template '"
                + templateName + "'");
            return false;
        } else {
            template.merge(context, writer);
            return true;
        }
    }
View Full Code Here

  public static String mergeTemplateIntoString(String templatePath, VelocityContext appData) {
      try
      {

        // Fetch Template to a StringWriter
        Template template = engine.getTemplate(templatePath);
        StringWriter writer = new StringWriter();
        template.merge(appData, writer);

        return writer.toString();
      }
      catch (Exception e)
      {
View Full Code Here

      VelocityContext context) {
    String templatePath = config.getTemplateFolder()+ System.getProperty("file.separator") +template;
    Writer writer = null;
    try {
      log.info("Writing " + file);
      Template velocityTemplate = engine.getTemplate(templatePath);
      writer = new FileWriter(file);
      velocityTemplate.merge(context, writer);
    } catch (IOException e) {
      log.error(e.getMessage(), e);
    } catch (ResourceNotFoundException e) {
      log.error(e.getMessage(), e);
    } catch (ParseErrorException e) {
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.