public static Configuration getConfiguration(String templateDir) throws IOException {
		if (null == cfg) {
			cfg = new Configuration();
	        File templateDirFile = new File(templateDir);
	        cfg.setDirectoryForTemplateLoading(templateDirFile);
	        cfg.setLocale(Locale.CHINA);
	        cfg.setDefaultEncoding("UTF-8");
		}
		return cfg;
	}
  FremarkParseUtils() {
    if (config == null) {
      config = new Configuration();
      config.setTemplateLoader(new StringTemplateLoader());

      try {
        config.setSetting("datetime_format", "yyyy-MM-dd HH:mm:ss");
        config.setLocale(Locale.CHINA);

      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }
  }
  public static Configuration getCfg() {
    if (cfg == null) {
      cfg = new Configuration();
      cfg.setTemplateUpdateDelay(6000);
      cfg.setCacheStorage(new freemarker.cache.MruCacheStorage(20, 250));

      DateFormateDirectiveModel df = new DateFormateDirectiveModel();
      cfg.setSharedVariable("dateFormat", df);

      cfg.setObjectWrapper(new DefaultObjectWrapper());
      cfg.setDefaultEncoding("UTF-8");
      cfg.setLocale(java.util.Locale.CHINA);
      cfg.setEncoding(java.util.Locale.CHINA, "UTF-8");
    }

    return cfg;
  }
  private void writeHtmlOverviewFile() {
    File benchmarkReportDirectory = plannerBenchmarkResult.getBenchmarkReportDirectory();
    WebsiteResourceUtils.copyResourcesTo(benchmarkReportDirectory);

    htmlOverviewFile = new File(benchmarkReportDirectory, "index.html");
    Configuration freemarkerCfg = new Configuration();
    freemarkerCfg.setDefaultEncoding("UTF-8");
    freemarkerCfg.setLocale(locale);
    freemarkerCfg.setClassForTemplateLoading(BenchmarkReport.class, "");

    String templateFilename = "benchmarkReport.html.ftl";
    Map<String, Object> model = new HashMap<String, Object>();
    model.put("benchmarkReport", this);
    model.put("reportHelper", new ReportHelper());

    Writer writer = null;
    try {
      Template template = freemarkerCfg.getTemplate(templateFilename);
      writer = new OutputStreamWriter(new FileOutputStream(htmlOverviewFile), "UTF-8");
      template.process(model, writer);
    } catch (IOException e) {
      throw new IllegalArgumentException(
          "Can not read templateFilename ("
              + templateFilename
              + ") or write htmlOverviewFile ("
              + htmlOverviewFile
              + ").",
          e);
    } catch (TemplateException e) {
      throw new IllegalArgumentException(
          "Can not process Freemarker templateFilename ("
              + templateFilename
              + ") to htmlOverviewFile ("
              + htmlOverviewFile
              + ").",
          e);
    } finally {
      IOUtils.closeQuietly(writer);
    }
  }
示例#5
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;
  }