本文整理汇总了Java中freemarker.template.AdapterTemplateModel类的典型用法代码示例。如果您正苦于以下问题:Java AdapterTemplateModel类的具体用法?Java AdapterTemplateModel怎么用?Java AdapterTemplateModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
AdapterTemplateModel类属于freemarker.template包,在下文中一共展示了AdapterTemplateModel类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSectionWriter
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
public SectionWriter getSectionWriter()
{
try
{
AdapterTemplateModel model = (AdapterTemplateModel) Environment.getCurrentEnvironment().getGlobalVariable(
"_info");
if( model != null )
{
return (SectionWriter) model.getAdaptedObject(SectionWriter.class);
}
return null;
}
catch( TemplateModelException e )
{
throw new SectionsRuntimeException(e);
}
}
示例2: exec
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
@Override
public Object exec(@SuppressWarnings("rawtypes") List args) throws TemplateModelException
{
JSCallable function = (JSCallable) jsObject;
RenderContext context = getSectionWriter();
context.preRender(function);
Object[] exprArgs = new Object[args.size()];
int i = 0;
for( Object obj : args )
{
if( obj instanceof AdapterTemplateModel )
{
Object adapted = ((AdapterTemplateModel) obj).getAdaptedObject(Object.class);
exprArgs[i] = adapted;
}
else
{
exprArgs[i] = new ScriptExpression(obj.toString());
}
i++;
}
return function.getExpressionForCall(context, JSUtils.convertExpressions(exprArgs));
}
示例3: getSectionWriter
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
public SectionWriter getSectionWriter()
{
try
{
return (SectionWriter) ((AdapterTemplateModel) Environment.getCurrentEnvironment().getGlobalVariable(
"_info")) //$NON-NLS-1$
.getAdaptedObject(SectionWriter.class);
}
catch( TemplateModelException e )
{
throw new SectionsRuntimeException(e);
}
}
示例4: exec
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public Object exec(List list) throws TemplateModelException
{
RenderContext info = getSectionWriter();
Object section = list.get(0);
String tag = list.get(1).toString();
if( section instanceof AdapterTemplateModel )
{
Object wrapped = ((AdapterTemplateModel) section).getAdaptedObject(Object.class);
if( wrapped instanceof HtmlComponentState )
{
return new TagRenderer(tag, ((HtmlComponentState) wrapped));
}
if( wrapped instanceof SectionId )
{
SectionId sectionId = (SectionId) wrapped;
AbstractRenderedComponent<HtmlComponentState> component = (AbstractRenderedComponent<HtmlComponentState>) info
.getSectionForId(sectionId);
component.setRendererType(info, "null"); //$NON-NLS-1$
ResultListCollector results = new ResultListCollector(false);
try
{
info.processEvent(new RenderEvent(info, sectionId.getSectionId(), results));
}
catch( Exception e )
{
throw new RuntimeException(e);
}
HtmlComponentState state = component.getState(info);
TagRenderer renderer = new TagRenderer(tag, state);
state.fireRendererCallback(info, renderer);
return renderer;
}
}
throw new SectionsRuntimeException("Needs to be a HtmlComponentState or AbstractRenderedComponent"); //$NON-NLS-1$
}
示例5: exec
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Object exec(List args) throws TemplateModelException
{
UserBean user = null;
Object userModel = args.get(0);
if( userModel instanceof AdapterTemplateModel )
{
Object wrapped = ((AdapterTemplateModel) userModel).getAdaptedObject(Object.class);
if( wrapped instanceof UserBean )
{
user = (UserBean) wrapped;
}
}
if( user == null && userModel instanceof TemplateScalarModel )
{
String userId = ((TemplateScalarModel) userModel).getAsString();
if( userId.equals("$LoggedInUser") ) //$NON-NLS-1$
{
user = CurrentUser.getDetails();
}
else
{
user = userService.getInformationForUser(userId);
}
}
String format = Format.DEFAULT_USER_BEAN_FORMAT;
if( args.size() > 1 )
{
Object formatModel = args.get(1);
if( formatModel instanceof TemplateScalarModel )
{
format = ((TemplateScalarModel) formatModel).getAsString();
}
}
return new SimpleScalar(Utils.ent(Format.format(user, format)));
}
示例6: execute
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
@Override
public void execute(Environment env, Map params, TemplateModel[] loopVars,
TemplateDirectiveBody body) throws TemplateException, IOException
{
String name = Directives.getStringParam(env, params, "name");
name = Overrides.BLOCK_NAME_PRE+name;
TemplateModel tm = env.getCurrentNamespace().get(name);
if(tm instanceof AdapterTemplateModel)
{
Object o = ((AdapterTemplateModel)tm).getAdaptedObject(null);
if(o instanceof TemplateDirectiveBody)
{
((TemplateDirectiveBody)o).render(env.getOut());
return;
}
}
else if(tm instanceof TemplateDirectiveBody)
{
((TemplateDirectiveBody)tm).render(env.getOut());
return;
}
else if(tm instanceof TemplateScalarModel)
{
String tpl = ((TemplateScalarModel)tm).getAsString();
if(tpl!=null)
{
env.getOut().append(tpl);
return;
}
}
if(body!=null) body.render(env.getOut());
}
示例7: getContext
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
/**
* 获得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.");
}
}
示例8: getSite
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
/**
* 标签中获得站点
*
* @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");
}
}
示例9: exec
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
/**
* Tells whether an object is instance of a class.
* <p>
* {@inheritDoc}
*/
@Override
public TemplateModel exec(List arguments)
throws TemplateModelException {
try {
Object target = ((AdapterTemplateModel) arguments.get(0))
.getAdaptedObject(Object.class);
Class<?> clazz = Class.forName(((TemplateScalarModel) arguments.get(1))
.getAsString());
return new BooleanModel(clazz.isAssignableFrom(target
.getClass()), wrapper);
} catch (Exception ex) {
throw new TemplateModelException("Could execute instanceof method.", ex);
}
}
示例10: execute
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public void execute(Environment env, @SuppressWarnings("rawtypes") Map params, TemplateModel[] loopVars,
TemplateDirectiveBody body) throws TemplateException, IOException
{
Object section = params.get("section"); //$NON-NLS-1$
if( section == null )
{
throw new SectionsRuntimeException("Section is null"); //$NON-NLS-1$
}
if( section instanceof AdapterTemplateModel )
{
Object wrapped = ((AdapterTemplateModel) section).getAdaptedObject(Object.class);
if( wrapped instanceof SectionId )
{
SectionId sectionId = (SectionId) wrapped;
RenderContext context = getSectionWriter();
AbstractRenderedComponent<HtmlComponentState> component = (AbstractRenderedComponent<HtmlComponentState>) context
.getSectionForId(sectionId);
component.setRendererType(context, "null"); //$NON-NLS-1$
ResultListCollector results = new ResultListCollector(false);
try
{
context.processEvent(new RenderEvent(context, sectionId.getSectionId(), results));
}
catch( Exception e )
{
throw new RuntimeException(e);
}
HtmlComponentState state = component.getState(context);
TagRenderer renderer = createTagRenderer((HtmlMutableListState) state, env, params, body, loopVars);
state.setBeenRendered(true);
state.fireRendererCallback(context, renderer);
setupStyles(renderer, params);
try( SectionWriter writer = new SectionWriter(env.getOut(), context) )
{
writer.render(renderer);
}
}
else
{
throw new SectionsRuntimeException("Need a sectionId"); //$NON-NLS-1$
}
}
}
示例11: execute
import freemarker.template.AdapterTemplateModel; //导入依赖的package包/类
@NonNullByDefault(false)
@SuppressWarnings({"unchecked", "nls", "rawtypes"})
@Override
public void execute(Environment env, Map params, TemplateModel[] arg2, TemplateDirectiveBody body)
throws TemplateException, IOException
{
RenderContext info = getSectionWriter();
try
{
Object model = params.get("section"); //$NON-NLS-1$
if( model instanceof AdapterTemplateModel )
{
Object wrapped = ((AdapterTemplateModel) model).getAdaptedObject(Object.class);
if( wrapped != null )
{
SectionRenderable renderable = getRenderable(wrapped, params);
if( renderable == null )
{
return;
}
if( renderable instanceof StyleableRenderer )
{
((StyleableRenderer) renderable).setStyles(getParam("style", params),
getParam("class", params), getParam("id", params));
}
if( renderable instanceof NestedRenderable && body != null && getBodyField(env) != null )
{
((NestedRenderable) renderable).setNestedRenderable(new BodyDirectiveRenderable(body));
}
SectionWriter writer = new SectionWriter(env.getOut(), info);
writer.preRender(renderable);
renderable.realRender(writer);
}
}
else
{
throw new RuntimeException("'section' parameter to render macro was not of the appropriate type (was "
+ model.getClass() + "). Perhaps you named your section property the same as a method name?");
}
}
catch( Exception e )
{
throw Throwables.propagate(e);
}
}