Package freemarker.template

Examples of freemarker.template.Template


            AppProperties properties)
            throws ServletException, IOException {

        Configuration config = (Configuration)properties.getProperty(CONFIG_PROPERTY);
       
        Template template = config.getTemplate(templateName);
       
        try {
           
            template.process(attributes, response.getWriter());
           
        } catch (TemplateException e) {
            throw new RuntimeException("error processing template : " + templateName, e);
        }
    }
View Full Code Here


    @Override
    public String render(ModelAndView modelAndView) {
        try {
            StringWriter stringWriter = new StringWriter();

            Template template = configuration.getTemplate(modelAndView.getViewName());
            template.process(modelAndView.getModel(), stringWriter);

            return stringWriter.toString();
        } catch (IOException e) {
            throw new IllegalArgumentException(e);
        } catch (TemplateException e) {
View Full Code Here

    }

    private Template getTemplate(String templateName) throws IOException {
        // Configuration does auto-caching of templates
        try {
            Template template = cfg.getTemplate(templateName);
            return template;
        } catch (FileNotFoundException fnf) {
            throw new IOException("Template not found: " + templateName);
        }
    }
View Full Code Here

            throw new IOException("Template not found: " + templateName);
        }
    }

    public void runTemplate(String templateName, Map<String, Object> model, Writer writer) throws MojoExecutionException, IOException {
        Template template;
        try {
            template = getTemplate(templateName);
        } catch (IOException e) {
            throw new MojoExecutionException("Error reading template: " + templateName, e);
        }

        try {
            template.process(model, writer);
        } catch (freemarker.template.TemplateException e) {
            throw new MojoExecutionException("Error running template: " + templateName, e);
        }

        writer.flush();
View Full Code Here

  }

  private Template getTemplate(String templateName) throws IOException {
    // Configuration does auto-caching of templates
    try {
      Template template = cfg.getTemplate(templateName);
      return template;
    } catch (FileNotFoundException fnf) {
      throw new IOException("Template not found: " + templateName);
    }
  }
View Full Code Here

  }

  @Override
  public void runTemplate(String templateName, Map<String, Object> model, Writer writer) throws TemplateException,
      IOException {
    Template template;
    try {
      template = getTemplate(templateName);
    } catch (IOException e) {
      throw new TemplateException("Error reading template: " + templateName, e);
    }

    try {
      template.process(model, writer);
    } catch (freemarker.template.TemplateException e) {
      throw new TemplateException("Error running template: " + templateName, e);
    }

    writer.flush();
View Full Code Here

    this.cfg = cfg;
   
  }

  public void writeHtml(Writer out) throws IOException, TemplateException {
    Template template = cfg.getTemplate("diff.html");
    template.process(this, out);
  }
View Full Code Here

    write(templateName, report, file);
  }

  public void write(String templateName, Object report, File file) {
    try {
      Template template = cfg.getTemplate(templateName);
      FileOutputStream os = new FileOutputStream(file);
      OutputStreamWriter out = new OutputStreamWriter(os);
      template.process(report, out);
      out.close();
    } catch (IOException e) {
      throw new RuntimeException(e);
    } catch (TemplateException e) {
      throw new RuntimeException(e);
View Full Code Here

        }
        else
            model.put("includeUserComments", false);

        // Create the template.
        Template template;
        try {
            template = Common.freemarkerConfiguration.getTemplate(reportInstance.getTemplateFile());
        }
        catch (IOException e) {
            // Couldn't load the template?
            throw new ShouldNeverHappenException(e);
        }

        // Create the content from the template.
        StringWriter writer = new StringWriter();
        try {
            template.process(model, writer);
        }
        catch (Exception e) {
            // Couldn't process the template?
            throw new ShouldNeverHappenException(e);
        }
View Full Code Here

        return configuration;
    }

    private void process(String resource, Map<String, Object> dataModel, Writer writer) throws TemplateException,
            IOException {
        Template template = configuration.getTemplate(resource);
        template.process(dataModel, writer);
    }
View Full Code Here

TOP

Related Classes of freemarker.template.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.