Ejemplo n.º 1
0
  public static void main(String[] args) throws IOException, TemplateException {
    Configuration cfg =
        FreeMarkerUtil.getFolderCfg(
            "D:/workspace/eopnew/eop/WebContent/WEB-INF/classes/com/enation/javashop/core/widget/goodscat");
    Template temp = cfg.getTemplate("GoodsCat.html");
    ByteOutputStream stream = new ByteOutputStream();

    Writer out = new OutputStreamWriter(stream, "UTF-8");
    temp.process(new HashMap(), out);

    out.flush();
    String html = stream.toString();
    System.out.println(html);
  }
Ejemplo n.º 2
0
  public static void test() {
    Configuration cfg;
    try {
      cfg =
          FreeMarkerUtil.getFolderCfg(
              "D:/workspace/eopnew/eop/WebContent/WEB-INF/classes/com/enation/javashop/core/widget/goodscat");
      Template temp = cfg.getTemplate("GoodsCat.html");
      ByteOutputStream stream = new ByteOutputStream();

      Writer out = new OutputStreamWriter(stream, "UTF-8");
      temp.process(new HashMap(), out);

      out.flush();
      String html = stream.toString();
      System.out.println("+++++++++" + html);
    } catch (IOException e) {
      e.printStackTrace();
    } catch (TemplateException e) {
      e.printStackTrace();
    }
  }
Ejemplo n.º 3
0
  private Configuration getCfg() {

    if (cfg == null) {
      cfg = FreeMarkerUtil.getCfg();
    }

    pathPrefix = pathPrefix == null ? "" : pathPrefix;

    if (pageFolder == null) { // 默认使用挂件所在文件夹
      // System.out.println(" folder null use "+ this.clazz.getName() );
      cfg.setClassForTemplateLoading(this.clazz, pathPrefix);
    } else {
      // System.out.println(" folder not null use "+ pageFolder);
      cfg.setServletContextForTemplateLoading(
          ThreadContextHolder.getHttpRequest().getSession().getServletContext(), pageFolder);
    }
    cfg.setObjectWrapper(new DefaultObjectWrapper());
    cfg.setDefaultEncoding("UTF-8");
    cfg.setLocale(java.util.Locale.CHINA);
    cfg.setEncoding(java.util.Locale.CHINA, "UTF-8");
    return cfg;
  }