freemarker.template.AdapterTemplateModel Java Examples

The following examples show how to use freemarker.template.AdapterTemplateModel. 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: LangFtlUtil.java    From scipio-erp with Apache License 2.0 5 votes vote down vote up
/**
 * Gets the wrapped hash's map OR adapts a hash model to a Map adapter if not a wrapper (SimpleHash).
 * <p>
 * NOTE: At current time (2019-01-28), this is best-effort and does not guarantee
 * copies won't be made - see implementation (incomplete). In other words,
 * avoid using anything but the Map.get method.
 */
@SuppressWarnings("unchecked")
public static <V extends TemplateModel> Map<String, V> getWrappedOrAdaptAsMap(TemplateHashModelEx hash) {
    if (hash instanceof AdapterTemplateModel) {
        return (Map<String, V>) ((AdapterTemplateModel) hash).getAdaptedObject(Map.class);
    }
    if (hash instanceof WrapperTemplateModel) {
        return (Map<String, V>) ((WrapperTemplateModel) hash).getWrappedObject();
    }
    return adaptAsMap(hash);
}
 
Example #2
Source File: FrontUtils.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 标签中获得站点
 * 
 * @param env
 * @return
 * @throws TemplateModelException
 */
public static CmsSite getSite(Environment env)
		throws TemplateModelException {
	TemplateModel model = env.getGlobalVariable(SITE);
	if (model instanceof AdapterTemplateModel) {
		return (CmsSite) ((AdapterTemplateModel) model)
				.getAdaptedObject(CmsSite.class);
	} else {
		throw new TemplateModelException("'" + SITE
				+ "' not found in DataModel");
	}
}
 
Example #3
Source File: DirectiveUtils.java    From Lottery with GNU General Public License v2.0 5 votes vote down vote up
/**
 * 获得RequestContext
 * 
 * ViewResolver中的exposeSpringMacroHelpers必须为true
 * 
 * @param env
 * @return
 * @throws TemplateException
 */
public static RequestContext getContext(Environment env)
		throws TemplateException {
	TemplateModel ctx = env
			.getGlobalVariable(SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE);
	if (ctx instanceof AdapterTemplateModel) {
		return (RequestContext) ((AdapterTemplateModel) ctx)
				.getAdaptedObject(RequestContext.class);
	} else {
		throw new TemplateModelException("RequestContext '"
				+ SPRING_MACRO_REQUEST_CONTEXT_ATTRIBUTE
				+ "' not found in DataModel.");
	}
}