freemarker.template.DefaultObjectWrapperBuilder Java Examples

The following examples show how to use freemarker.template.DefaultObjectWrapperBuilder. 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: MagicWebSiteGenerator.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public MagicWebSiteGenerator(String template, String dest) throws IOException {
	cfg = new Configuration(MTGConstants.FREEMARKER_VERSION);
	cfg.setDirectoryForTemplateLoading(new File(MTGConstants.MTG_TEMPLATES_DIR, template));
	cfg.setDefaultEncoding(MTGConstants.DEFAULT_ENCODING.displayName());
	cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
	cfg.setObjectWrapper(new DefaultObjectWrapperBuilder(MTGConstants.FREEMARKER_VERSION).build());

	this.dest = dest;
	FileUtils.copyDirectory(new File(MTGConstants.MTG_TEMPLATES_DIR, template), new File(dest), pathname -> {
		if (pathname.isDirectory())
			return true;

		return !pathname.getName().endsWith(".html");
	});
}
 
Example #2
Source File: AbstractHalProcessor.java    From core with GNU Lesser General Public License v2.1 5 votes vote down vote up
public AbstractHalProcessor() {

        Version version = new Version(2, 3, 22);
        config = new Configuration(version);
        config.setDefaultEncoding("UTF-8");
        config.setClassForTemplateLoading(getClass(), "templates");
        config.setObjectWrapper(new DefaultObjectWrapperBuilder(version).build());
    }
 
Example #3
Source File: FreeMarkerUtil.java    From windup with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Gets the default configuration for Freemarker within Windup.
 */
public static Configuration getDefaultFreemarkerConfiguration()
{
    freemarker.template.Configuration configuration = new freemarker.template.Configuration(Configuration.VERSION_2_3_26);
    DefaultObjectWrapperBuilder objectWrapperBuilder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_26);
    objectWrapperBuilder.setUseAdaptersForContainers(true);
    objectWrapperBuilder.setIterableSupport(true);
    configuration.setObjectWrapper(objectWrapperBuilder.build());
    configuration.setAPIBuiltinEnabled(true);

    configuration.setTemplateLoader(new FurnaceFreeMarkerTemplateLoader());
    configuration.setTemplateUpdateDelayMilliseconds(3600);
    return configuration;
}
 
Example #4
Source File: SpringController.java    From tutorials with MIT License 5 votes vote down vote up
@RequestMapping(value = "/commons", method = RequestMethod.GET)
public String showCommonsPage(Model model) {
    model.addAttribute("statuses", Arrays.asList("200 OK", "404 Not Found", "500 Internal Server Error"));
    model.addAttribute("lastChar", new LastCharMethod());
    model.addAttribute("random", new Random());
    model.addAttribute("statics", new DefaultObjectWrapperBuilder(new Version("2.3.28")).build().getStaticModels());
    return "commons";
}
 
Example #5
Source File: Environment.java    From hsac-fitnesse-fixtures with Apache License 2.0 5 votes vote down vote up
private Environment() {
    Configuration cfg = new Configuration(Configuration.VERSION_2_3_23);
    // Specify the data source where the template files come from.
    cfg.setClassForTemplateLoading(getClass(), "/templates/");
    DefaultObjectWrapperBuilder builder = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23);
    builder.setExposeFields(true);
    cfg.setObjectWrapper(builder.build());
    freemarkerConfig = cfg;

    fmHelper = new FreeMarkerHelper();
    templateCache = new ConcurrentHashMap<String, Template>();

    symbols = new ConcurrentHashMap<String, String>();

    textFormatter = new TextFormatter();

    xmlFormatter = new XMLFormatter();
    nsContext = new NamespaceContextImpl();
    fillNamespaceContext();
    xPathHelper = new XPathHelper();

    jsonPathHelper = new JsonPathHelper();
    jsonHelper = new JsonHelper();

    htmlCleaner = new HtmlCleaner();

    httpClient = new HttpClient();

    programHelper = new ProgramHelper();
    programHelper.setTimeoutHelper(timeoutHelper);
    configDatesHelper();

    driverManager = new DriverManager();
    cookieConverter = new CookieConverter();
}
 
Example #6
Source File: TextReporter.java    From revapi with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new FreeMarker configuration.
 * By default, it is configured as follows:
 * <ul>
 * <li>compatibility level is set to 2.3.23
 * <li>the object wrapper is configured to expose fields
 * <li>API builtins are enabled
 * <li>there are 2 template loaders - 1 for loading templates from /META-INF using a classloader and a second
 *     one to load templates from files.
 * </ul>
 * @return
 */
protected Configuration createFreeMarkerConfiguration() {
    DefaultObjectWrapperBuilder bld = new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23);
    bld.setExposeFields(true);

    Configuration freeMarker = new Configuration(Configuration.VERSION_2_3_23);

    freeMarker.setObjectWrapper(bld.build());
    freeMarker.setAPIBuiltinEnabled(true);
    freeMarker.setTemplateLoader(new MultiTemplateLoader(
            new TemplateLoader[]{new ClassTemplateLoader(getClass(), "/META-INF"),
                    new NaiveFileTemplateLoader()}));

    return freeMarker;
}
 
Example #7
Source File: ExportUtilities.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns an ObjectWrapper of sufficiently high version for pcgen
 */
public static ObjectWrapper getObjectWrapper()
{
	DefaultObjectWrapperBuilder defaultObjectWrapperBuilder = new DefaultObjectWrapperBuilder(
			new Version("2.3.28"));
	return defaultObjectWrapperBuilder.build();
}
 
Example #8
Source File: ExportUtilities.java    From pcgen with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns an ObjectWrapper of sufficiently high version for pcgen
 */
public static ObjectWrapper getObjectWrapper()
{
	DefaultObjectWrapperBuilder defaultObjectWrapperBuilder = new DefaultObjectWrapperBuilder(
			new Version("2.3.28"));
	return defaultObjectWrapperBuilder.build();
}
 
Example #9
Source File: ReportNotificationManager.java    From MtgDesktopCompanion with GNU General Public License v3.0 5 votes vote down vote up
public ReportNotificationManager() {
	  	cfg = new Configuration(MTGConstants.FREEMARKER_VERSION);
        try {
			cfg.setClassForTemplateLoading(ReportNotificationManager.class, MTGConstants.MTG_REPORTS_DIR);
			cfg.setDefaultEncoding(MTGConstants.DEFAULT_ENCODING.displayName());
			cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER);
			cfg.setObjectWrapper(new DefaultObjectWrapperBuilder(MTGConstants.FREEMARKER_VERSION).build());
		} catch (Exception e) {
			errorLoading=true;
			logger.error("error init Freemarker ",e);
		}
		
}
 
Example #10
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 #11
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 #12
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 #13
Source File: FreeMarkerView.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Return the configured FreeMarker {@link ObjectWrapper}, or the
 * {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
 * @see freemarker.template.Configuration#getObjectWrapper()
 */
protected ObjectWrapper getObjectWrapper() {
	ObjectWrapper ow = getConfiguration().getObjectWrapper();
	return (ow != null ? ow :
			new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build());
}
 
Example #14
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the configured FreeMarker {@link ObjectWrapper}, or the
 * {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
 * @see freemarker.template.Configuration#getObjectWrapper()
 */
protected ObjectWrapper getObjectWrapper() {
	ObjectWrapper ow = obtainConfiguration().getObjectWrapper();
	Version version = Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS;
	return (ow != null ? ow : new DefaultObjectWrapperBuilder(version).build());
}
 
Example #15
Source File: BaseTag.java    From OneBlog with GNU General Public License v3.0 4 votes vote down vote up
private DefaultObjectWrapper getBuilder() {
    return new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_25).build();
}
 
Example #16
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());
}
 
Example #17
Source File: NotificationServiceImpl.java    From studio with GNU General Public License v3.0 4 votes vote down vote up
public void init() {
    configuration = new Configuration(Configuration.VERSION_2_3_23);
    configuration.setTimeZone(TimeZone.getTimeZone(getTemplateTimezone()));
    configuration.setObjectWrapper(new DefaultObjectWrapperBuilder(Configuration.VERSION_2_3_23).build());
}
 
Example #18
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the configured FreeMarker {@link ObjectWrapper}, or the
 * {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
 * @see freemarker.template.Configuration#getObjectWrapper()
 */
protected ObjectWrapper getObjectWrapper() {
	ObjectWrapper ow = obtainConfiguration().getObjectWrapper();
	return (ow != null ? ow :
			new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build());
}
 
Example #19
Source File: FreeMarkerView.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Return the configured FreeMarker {@link ObjectWrapper}, or the
 * {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
 * @see freemarker.template.Configuration#getObjectWrapper()
 */
protected ObjectWrapper getObjectWrapper() {
	ObjectWrapper ow = obtainConfiguration().getObjectWrapper();
	Version version = Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS;
	return (ow != null ? ow : new DefaultObjectWrapperBuilder(version).build());
}
 
Example #20
Source File: FreeMarkerView.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Return the configured FreeMarker {@link ObjectWrapper}, or the
 * {@link ObjectWrapper#DEFAULT_WRAPPER default wrapper} if none specified.
 * @see freemarker.template.Configuration#getObjectWrapper()
 */
protected ObjectWrapper getObjectWrapper() {
	ObjectWrapper ow = obtainConfiguration().getObjectWrapper();
	return (ow != null ? ow :
			new DefaultObjectWrapperBuilder(Configuration.DEFAULT_INCOMPATIBLE_IMPROVEMENTS).build());
}