Java Code Examples for freemarker.template.Configuration#VERSION_2_3_25

The following examples show how to use freemarker.template.Configuration#VERSION_2_3_25 . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ResumeGenerator.java    From jresume with MIT License 6 votes vote down vote up
private String generateResumeHTML(String json, String theme) throws Exception {
    if (!isValidJSON(json)) {
        throw new InvalidJSONException();
    }

    Gson gson = new GsonBuilder().setPrettyPrinting().create();

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    cfg.setDirectoryForTemplateLoading(new File("themes"));
    cfg.setDefaultEncoding("UTF-8");
    Template temp = cfg.getTemplate(theme + ".html");
    //System.out.println(json);
    Resume resume = gson.fromJson(json, Resume.class);
    resume.getRidOfArraysWithEmptyElements();
    resume.setConfig(config);
    StringWriter htmlStringWriter = new StringWriter();
    temp.process(resume, htmlStringWriter);
    String html = htmlStringWriter.toString();
    return html;
}
 
Example 2
Source File: ResumeGenerator.java    From jresume with MIT License 6 votes vote down vote up
private String generateResumeHTML(String json, String theme) throws Exception {
    if (!isValidJSON(json)) {
        throw new InvalidJSONException();
    }

    Gson gson = new GsonBuilder().setPrettyPrinting().create();

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    cfg.setDirectoryForTemplateLoading(new File("themes"));
    cfg.setDefaultEncoding("UTF-8");
    Template temp = cfg.getTemplate(theme + ".html");
    //System.out.println(json);
    Resume resume = gson.fromJson(json, Resume.class);
    resume.getRidOfArraysWithEmptyElements();
    resume.setConfig(config);
    StringWriter htmlStringWriter = new StringWriter();
    temp.process(resume, htmlStringWriter);
    String html = htmlStringWriter.toString();
    return html;
}
 
Example 3
Source File: FreemarkerUtil.java    From SSMGenerator with MIT License 5 votes vote down vote up
public static void execute(String ftlNameWithPath, Map<String, Object> data, Writer out) throws IOException, TemplateException {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    int i = ftlNameWithPath.lastIndexOf("/") == -1 ? ftlNameWithPath.lastIndexOf("\\") : ftlNameWithPath.lastIndexOf("/");
    cfg.setDirectoryForTemplateLoading(new File(ftlNameWithPath.substring(0, i + 1)));
    cfg.setDefaultEncoding("UTF-8");
    Template t1 = cfg.getTemplate(ftlNameWithPath.substring(i + 1));
    t1.process(data, out);
    out.flush();
}
 
Example 4
Source File: FreeMarkerTemplateUtil.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * 获取模板信息
 *
 * @param name 模板名
 * @return
 */
public Template getTemplate(String name) {
    //通过freemarkerd Configuration读取相应的ftl
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    //设定去哪里读取相应的ftl模板文件,指定模板路径
    cfg.setClassLoaderForTemplateLoading(ClassLoader.getSystemClassLoader(), "ftl");
    try {
        //在模板文件目录中找到名称为name的文件
        Template template = cfg.getTemplate(name);
        return template;
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 5
Source File: FreeMarkerConfigFactory.java    From youran with Apache License 2.0 5 votes vote down vote up
/**
 * 构建freemarker配置
 *
 * @param templatePO
 * @return (freemarker配置 , 模板内部版本号 , 模板目录地址)
 */
private Triple<Configuration, Integer, String> buildTriple(CodeTemplatePO templatePO) {
    String templateDir = dataDirService.getTemplateRecentDir(templatePO);
    LOGGER.info("开始构建FreeMarker Configuration,templateId={},innerVersion={},模板文件输出目录:{}",
        templatePO.getTemplateId(), templatePO.getInnerVersion(), templateDir);
    // 把模板输出到目录
    templateFileOutputService.outputTemplateFiles(templatePO.getTemplateFiles(), templateDir);

    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);
    try {
        cfg.setDirectoryForTemplateLoading(new File(templateDir));
    } catch (IOException e) {
        LOGGER.error("模板目录设置异常", e);
        throw new BusinessException("模板目录设置异常");
    }
    cfg.setNumberFormat("#");
    // 设置可访问的静态工具类
    cfg.setSharedVariable("MetaConstType", metaConstTypeModel);
    cfg.setSharedVariable("JFieldType", jFieldTypeModel);
    cfg.setSharedVariable("QueryType", queryTypeModel);
    cfg.setSharedVariable("EditType", editTypeModel);
    cfg.setSharedVariable("MetaSpecialField", metaSpecialFieldModel);
    cfg.setSharedVariable("PrimaryKeyStrategy", primaryKeyStrategyModel);
    cfg.setSharedVariable("CommonTemplateFunction", commonTemplateFunctionModel);
    cfg.setSharedVariable("JavaTemplateFunction", javaTemplateFunctionModel);
    cfg.setSharedVariable("SqlTemplateFunction", sqlTemplateFunctionModel);
    return Triple.of(cfg, templatePO.getInnerVersion(), templateDir);
}
 
Example 6
Source File: Areaslist.java    From FlyCms with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
	// 获取页面的参数
	//指定父级id
	int parentId = 0;
	
	//处理标签变量
	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
	for(String str:paramWrap.keySet()){ 
		if("parentId".equals(str)){
			if(!NumberUtils.isNumber(paramWrap.get(str).toString())) {
				parentId=0;
			}else {
				if(!StringHelperUtils.checkInteger(paramWrap.get(str).toString())) {
					parentId=0;
				}else {
					parentId = Integer.parseInt(paramWrap.get(str).toString());
				}
			}
		}
	}
	// 获取文件的分页
	try {
		List<Areas> pageVo = areasService.selectAreasByPid(parentId);
		env.setVariable("areaslist", builder.build().wrap(pageVo));
	} catch (Exception e) {
		env.setVariable("areaslist", builder.build().wrap(null));
	}
	body.render(env.getOut());
}
 
Example 7
Source File: Markrole.java    From FlyCms with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
	try {
		// 获取页面的参数
		Long roleId = 0L;
		// 获取文件的分页
		//审核设置,默认0
		Long permissionId = 0L;
		//处理标签变量
		@SuppressWarnings("unchecked")
		Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
		for(String str:paramWrap.keySet()){ 
			if("roleId".equals(str)){
				roleId = Long.parseLong(paramWrap.get(str).toString());
			}
			if("permissionId".equals(str)){
				permissionId = Long.parseLong(paramWrap.get(str).toString());
			}

		}
		boolean mark = srv.markAssignedPermissions(roleId,permissionId);
		env.setVariable("mark", builder.build().wrap(mark));
		body.render(env.getOut());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 8
Source File: Usergroup.java    From FlyCms with MIT License 5 votes vote down vote up
@Override
@SuppressWarnings({ "rawtypes", "unchecked" })
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
	// 获取页面的参数
	Long userId=0L;
	//处理标签变量
	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
	for(String str:paramWrap.keySet()){
		if("userId".equals(str)){
			if (!NumberUtils.isNumber(paramWrap.get(str).toString())) {
				userId = 0L;
			}else{
				userId = Long.parseLong(paramWrap.get(str).toString());
			}
		}
	}
	// 获取文章所有信息
	try {
		UserGroup group = userGroupService.findUuserGroupByUserId(userId);
		env.setVariable("group", builder.build().wrap(group));
		body.render(env.getOut());
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 9
Source File: FreemarkerTemplatingService.java    From blackduck-alert with Apache License 2.0 5 votes vote down vote up
private Configuration createDefaultConfiguration() {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_25);

    cfg.setDefaultEncoding("UTF-8");
    cfg.setTemplateExceptionHandler(TemplateExceptionHandler.HTML_DEBUG_HANDLER);
    cfg.setLogTemplateExceptions(false);

    return cfg;
}
 
Example 10
Source File: Templates.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private static Configuration createConfiguration() {
  Configuration configuration = new Configuration(Configuration.VERSION_2_3_25);
  configuration.setClassForTemplateLoading(Templates.class, "/templates/appengine");
  configuration.setDefaultEncoding(StandardCharsets.UTF_8.name());
  configuration.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
  configuration.setLogTemplateExceptions(false);
  return configuration;
}
 
Example 11
Source File: Questionpage.java    From FlyCms with MIT License 4 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars,
		TemplateDirectiveBody body) throws TemplateException, IOException {
	DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25);
	// 获取页面的参数
	//所属主信息类型,0是所有,1是文章,2是小组话题
	String title = null;

	Long userId = null;

	String createTime=null;
	
	Integer status=null;
	/**
	 *
	 * § orderby='hot' 或 orderby='click' 表示按点击数排列
	 * § orderby='sortrank' 或 orderby='pubdate' 按出版时间排列
	 * § orderby=='lastpost' 按最后评论时间
	 * § orderby=='scores' 按得分排序
	 * § orderby='id' 按文章ID排序
	 */
	String orderby=null;

	String order=null;

	//翻页页数
	Integer p = 1;
	//每页记录条数
	Integer rows = 10;
	//处理标签变量
	Map<String, TemplateModel> paramWrap = new HashMap<String, TemplateModel>(params);
	for(String str:paramWrap.keySet()){ 
		if("title".equals(str)){
			title = paramWrap.get(str).toString();
		}
		if("userId".equals(str)){
			userId = Long.parseLong(paramWrap.get(str).toString());
		}
		if("createTime".equals(str)){
			createTime = paramWrap.get(str).toString();
		}
           if("orderby".equals(str)){
               orderby = paramWrap.get(str).toString();
           }
           if("order".equals(str)){
               order = paramWrap.get(str).toString();
           }
		if("status".equals(str)){
			status = Integer.parseInt(paramWrap.get(str).toString());
		}
		if("p".equals(str)){
			p = Integer.parseInt(paramWrap.get(str).toString());
		}
		if("rows".equals(str)){
			rows = Integer.parseInt(paramWrap.get(str).toString());
		}
	}
	// 获取文件的分页
	try {
		PageVo<Question> pageVo = questionService.getQuestionListPage(title,userId,createTime,status,orderby,order,p,rows);
		env.setVariable("question_page", builder.build().wrap(pageVo));
	} catch (Exception e) {
		env.setVariable("question_page", builder.build().wrap(null));
	}
	body.render(env.getOut());
}