本文整理匯總了Java中freemarker.core.Environment.getOut方法的典型用法代碼示例。如果您正苦於以下問題:Java Environment.getOut方法的具體用法?Java Environment.getOut怎麽用?Java Environment.getOut使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類freemarker.core.Environment
的用法示例。
在下文中一共展示了Environment.getOut方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings({ "unchecked", "rawtypes" })
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
AdPosition adPosition;
Long id = getId(params);
boolean useCache = useCache(env, params);
String cacheRegion = getCacheRegion(env, params);
if (useCache) {
adPosition = adPositionService.find(id, cacheRegion);
} else {
adPosition = adPositionService.find(id);
}
if (body != null) {
setLocalVariable(VARIABLE_NAME, adPosition, env, body);
} else {
if (adPosition != null && adPosition.getTemplate() != null) {
try {
Map<String, Object> model = new HashMap<String, Object>();
model.put(VARIABLE_NAME, adPosition);
Writer out = env.getOut();
new Template("adTemplate", new StringReader(adPosition.getTemplate()), freeMarkerConfigurer.getConfiguration()).process(model, out);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
示例2: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
/**
* @see freemarker.template.TemplateDirectiveModel#execute(freemarker.core.Environment,
* java.util.Map, freemarker.template.TemplateModel[],
* freemarker.template.TemplateDirectiveBody)
*/
@SuppressWarnings("rawtypes")
@Override
public void execute(Environment env, Map argsUntyped, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
String output = makeLinkFromFtl(env, UtilGenerics.<String, TemplateModel>checkMap(argsUntyped), loopVars, body);
Writer out = env.getOut();
if (output != null) out.write(output);
}
示例3: getWriterFromEnvironment
import freemarker.core.Environment; //導入方法依賴的package包/類
public static Appendable getWriterFromEnvironment(Environment env) {
if (env != null) {
Writer out = env.getOut();
if (out != null) {
return out;
}
}
return null;
}
示例4: executeTyped
import freemarker.core.Environment; //導入方法依賴的package包/類
protected void executeTyped(Environment env, Map<String, TemplateModel> params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
Writer writer = env.getOut();
// NOTE: this can only work if we already had a RenderWriter.
// if not, don't even bother trying.
if (writer instanceof RenderWriter) {
Map<String, Object> context = ContextFtlUtil.getContext(env);
WidgetRenderTargetState renderTargetState = WidgetRenderTargetExpr.getRenderTargetState(context);
if (renderTargetState.isEnabled()) {
String name = TransformUtil.getStringNonEscapingArg(params, "name");
String containsExpr = TransformUtil.getStringNonEscapingArg(params, "contains");
String location = "unknown-location"; // FIXME
ModelFtlWidget widget = new ModelVirtualSectionFtlWidget(name, location, containsExpr);
WidgetRenderTargetState.ExecutionInfo execInfo = renderTargetState.handleShouldExecute(widget, writer, context, null);
if (!execInfo.shouldExecute()) {
return;
}
try {
if (body != null) {
body.render((Writer) execInfo.getWriterForElementRender());
}
} finally {
execInfo.handleFinished(context); // SCIPIO: return logic
}
return;
}
}
body.render(writer);
}
示例5: executeGenerics
import freemarker.core.Environment; //導入方法依賴的package包/類
public void executeGenerics(Environment env, Map<String, TemplateModel> params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
List<String> args = params.entrySet().stream()
.map(this::mapArgKeys)
.collect(Collectors.toList());
final ViewFunctionParams vfParams = new ViewFunctionParams().name( name ).args( args ).portalRequest( this.portalRequest );
Writer out = env.getOut();
out.append(this.viewFunctionService.execute( vfParams ).toString());
out.close();
}
示例6: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
Member currentMember = memberService.getCurrent();
if (body != null) {
setLocalVariable(VARIABLE_NAME, currentMember, env, body);
} else {
if (currentMember != null) {
Writer out = env.getOut();
out.write(currentMember.getUsername());
}
}
}
示例7: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
if (requestAttributes != null) {
Message message = (Message) requestAttributes.getAttribute(FLASH_MESSAGE_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
if (body != null) {
setLocalVariable(VARIABLE_NAME, message, env, body);
} else {
if (message != null) {
Writer out = env.getOut();
out.write("$.message(\"" + message.getType() + "\", \"" + message.getContent() + "\");");
}
}
}
}
示例8: execute
import freemarker.core.Environment; //導入方法依賴的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$
}
}
}
示例9: execute
import freemarker.core.Environment; //導入方法依賴的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);
}
}
示例10: setEnv
import freemarker.core.Environment; //導入方法依賴的package包/類
public void setEnv(Environment env) {
this.env = env;
if (out == null && env != null) {
this.out = env.getOut();
}
}
示例11: executeTyped
import freemarker.core.Environment; //導入方法依賴的package包/類
protected void executeTyped(Environment env, Map<String, TemplateModel> params, TemplateModel[] loopVars, TemplateDirectiveBody body)
throws TemplateException, IOException {
Writer writer = env.getOut();
// NOTE: this can only work if we already had a RenderWriter.
// if not, don't even bother trying.
if (writer instanceof RenderWriter) {
Map<String, Object> context = ContextFtlUtil.getContext(env);
WidgetRenderTargetState renderTargetState = WidgetRenderTargetExpr.getRenderTargetState(context);
if (renderTargetState.isEnabled()) {
String dirName = TransformUtil.getStringArg(params, "dirName");
//TemplateHashModel dirArgs = (TemplateHashModel) params.get("dirArgs");
String id = null;
String name = null; // TODO?: this may not work as expected if we do this...
// TODO: review
// if (dirArgs != null) {
// TemplateScalarModel idModel = (TemplateScalarModel) dirArgs.get("id");
// if (idModel != null) {
// id = LangFtlUtil.getAsStringNonEscaping(idModel);
// if ("section".equals(dirName)) {
// TemplateScalarModel containerIdModel = (TemplateScalarModel) dirArgs.get("containerId");
// if (containerIdModel != null) {
// String containerId = LangFtlUtil.getAsStringNonEscaping(containerIdModel);
// if (UtilValidate.isNotEmpty(containerId)) {
// id = containerId;
// }
// }
// }
// }
// } else {
id = TransformUtil.getStringNonEscapingArg(params, "id");
name = TransformUtil.getStringNonEscapingArg(params, "name");
// }
String location = "unknown-location"; // FIXME
ModelFtlWidget widget = new ModelFtlWidget(name, dirName, location, id);
WidgetRenderTargetState.ExecutionInfo execInfo = renderTargetState.handleShouldExecute(widget, writer, context, null);
if (!execInfo.shouldExecute()) {
return;
}
try {
if (body != null) {
body.render((Writer) execInfo.getWriterForElementRender());
}
} finally {
execInfo.handleFinished(context); // SCIPIO: return logic
}
return;
}
}
body.render(writer);
}
示例12: execute
import freemarker.core.Environment; //導入方法依賴的package包/類
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body) throws TemplateException, IOException {
final String componentPath = (params.containsKey(PARAM_PATH) ? params.get(PARAM_PATH).toString() : "" );
Writer out = env.getOut();
out.append("<!--# COMPONENT " + componentPath + " -->");
}
示例13: FieldRender
import freemarker.core.Environment; //導入方法依賴的package包/類
public FieldRender(Environment env,Record r)
{
this.env = env;
this.out = env.getOut();
this.r = r;
}