Package freemarker.template

Examples of freemarker.template.Template$WrongEncodingException


    DataHandler merged = null;
    try {
      freemarker.template.Configuration cfg = new freemarker.template.Configuration();
      cfg.setObjectWrapper(new DefaultObjectWrapper());
      cfg.setTemplateUpdateDelay(0);
      Template temp = new Template(name, new InputStreamReader(src), cfg);
      final ByteArrayOutputStream bout = new ByteArrayOutputStream();
      Writer out = new OutputStreamWriter(bout);
      temp.process(renderContext, out);
      out.flush();
      merged = new DataHandler(new DataSource() {
        public InputStream getInputStream() throws IOException {
          return new ByteArrayInputStream(bout.toByteArray());
        }
View Full Code Here


  public void render(OutputStream out, PageFlow annotation, ServiceResult result,String charset)
      throws Exception {

    this.initFreemarker();
    //获取模板
    Template template = cfg.getTemplate(annotation.success().value(), "utf-8");
    StringWriter writer = new StringWriter();
    //往上下文中填入数据
    Map context = new HashMap();
    context.put("ctx", result);
    context.put("xctx",session.getAttribute(HtmlResponseWriter.OPTION_KEY));
    template.process(context, writer);

    //输出到用户端
    writer.toString();
    out.write(writer.toString().getBytes());
  }
View Full Code Here

        throws Exception
    {
        StringWriter writer = new StringWriter();

        // - create the template
        Template template = new Template("strTemplate", new StringReader("${test1}${test2}"), new Configuration());

        HashMap templateObjects = new HashMap();

        templateObjects.put(
            "test1",
            "@test1@");
        templateObjects.put(
            "test2",
            "@test2@");

        template.process(
            templateObjects,
            writer);
        assertEquals(
            "@test1@@test2@",
            writer.getBuffer().toString());
View Full Code Here

            // capabilities
            this.configuration.setObjectWrapper(ObjectWrapper.BEANS_WRAPPER);
        }

        // create the template
        final Template template = this.configuration.getTemplate(templateFile);

        if (templateObjects == null)
        {
            templateObjects = new HashMap();
        }

        // - merge data model with template
        template.process(templateObjects, output);
    }
View Full Code Here

    public String getEvaluatedExpression(final String expression, Map templateObjects)
    {
        try
        {
            // - create the template
            final Template template = new Template(STRING_TEMPLATE, new StringReader(expression), new Configuration());

            if (templateObjects == null)
            {
                templateObjects = new HashMap();
            }

            final StringWriter output = new StringWriter();

            // - merge data model with template
            template.process(templateObjects, output);

            return output.toString();
        }
        catch (final Throwable throwable)
        {
View Full Code Here

  }

  @Override
  public void out(String viewFileName) {
    try {
      Template template = config.getTemplate(viewFileName, defaultEncoding);

      if (template != null) {
        Writer writer = douyuContext.getHttpServletResponse().getWriter();

        //TODO
        //template.process内部会自动调用writer.flush,
        //如果在输出ftl文件后又接着输出jsp,那么jsp会出异常:
        //java.lang.IllegalStateException: Cannot create a session after the response has been committed
        //因为调用writer.flush会导致响应头会被提交
        template.process(root, writer);

        //writer.flush();
        //writer.close();
      }
    } catch (Throwable t) {
View Full Code Here

      }else{
        notifyMsg.setFrom("no-reply@localhost");
      }
    } 
   
    Template fmTemplate1 = null;
    String text1 = null;
    try{     
      fmTemplate1 = freemarkerEngine.getTemplate("login/welcome-template.ftl");     
      text1 = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate1,model);
    }catch(Exception e){
View Full Code Here

    }else{
      logger.error("RegisterUser: siteContactEmail is not defined. Can't sent approval emaili. Abort.");
      return false;
    }
       
    Template fmTemplate1 = null;
    Template fmTemplate2 = null;
    String text1 = null;
    String text2 = null;
    try{     
      fmTemplate1 = freemarkerEngine.getTemplate("login/notifyemail-template.ftl");
      fmTemplate2 = freemarkerEngine.getTemplate("login/approvalemail-template.ftl");
View Full Code Here

      }else{
        msg.setFrom("help@localhost");
      }
    }   
       
    Template fmTemplate = null;
    String text = null;
    try{     
      fmTemplate = freemarkerEngine.getTemplate("login/verifyemail-template.ftl");
      text = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate,model);
    }catch(Exception e){
View Full Code Here

      }else{
        msg.setFrom("help@localhost");
      }
    }   
       
    Template fmTemplate = null;
    String text = null;
    try{     
      fmTemplate = freemarkerEngine.getTemplate("login/notifyreset-template.ftl");
      text = FreeMarkerTemplateUtils.processTemplateIntoString(fmTemplate,model);
    }catch(Exception e){
View Full Code Here

TOP

Related Classes of freemarker.template.Template$WrongEncodingException

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.