public final class FreeMarkerUtil extends Object
Modifier and Type | Field and Description |
---|---|
static String |
COMPOSE_STACK_ATTRIBUTE_NAME
The name of the attribute that holds the compose stack.
|
Modifier and Type | Method and Description |
---|---|
static void |
evaluateBody(freemarker.template.TemplateDirectiveBody body)
Evaluates the body without rendering it.
|
static boolean |
getAsBoolean(freemarker.template.TemplateModel model,
boolean defaultValue)
Unwraps a TemplateModel to extract a boolean.
|
static Object |
getAsObject(freemarker.template.TemplateModel model)
Unwraps a TemplateModel to extract an object.
|
static String |
getAsString(freemarker.template.TemplateModel model)
Unwraps a TemplateModel to extract a string.
|
static ArrayStack<Object> |
getComposeStack(freemarker.core.Environment env)
Returns the current compose stack, or creates a new one if not present.
|
static TilesContainer |
getContainer(freemarker.core.Environment env,
String key)
Returns a specific Tiles container.
|
static TilesContainer |
getCurrentContainer(freemarker.core.Environment env)
Returns the current container that has been set, or the default one.
|
static freemarker.ext.servlet.HttpRequestHashModel |
getRequestHashModel(freemarker.core.Environment env)
Returns the HTTP request hash model.
|
static freemarker.ext.servlet.ServletContextHashModel |
getServletContextHashModel(freemarker.core.Environment env)
Returns the servlet context hash model.
|
static boolean |
isForceInclude(freemarker.core.Environment env)
Returns true if forced include of the result is needed.
|
static String |
renderAsString(freemarker.template.TemplateDirectiveBody body)
Renders the body as a string.
|
static void |
setAttribute(freemarker.core.Environment env,
String name,
Object obj,
String scope)
Sets an attribute in the desired scope.
|
static void |
setCurrentContainer(freemarker.core.Environment env,
String key)
Sets the current container to use in web pages.
|
static void |
setCurrentContainer(freemarker.core.Environment env,
TilesContainer container)
Sets the current container to use in web pages.
|
static void |
setForceInclude(freemarker.core.Environment env,
boolean forceInclude)
Sets the option that enables the forced include of the response.
|
public static final String COMPOSE_STACK_ATTRIBUTE_NAME
public static boolean isForceInclude(freemarker.core.Environment env)
env
- The current FreeMarker environment.true
the include operation must be forced.public static void setForceInclude(freemarker.core.Environment env, boolean forceInclude)
env
- The current FreeMarker environment.forceInclude
- If true
the include operation must be
forced.public static TilesContainer getContainer(freemarker.core.Environment env, String key)
env
- The current FreeMarker environment.key
- The key under which the container is stored. If null, the
default container will be returned.public static void setCurrentContainer(freemarker.core.Environment env, String key)
env
- The current FreeMarker environment.key
- The key under which the container is stored.public static void setCurrentContainer(freemarker.core.Environment env, TilesContainer container)
env
- The current FreeMarker environment.container
- The container to use as the current container.public static TilesContainer getCurrentContainer(freemarker.core.Environment env)
env
- The current FreeMarker environment.public static freemarker.ext.servlet.HttpRequestHashModel getRequestHashModel(freemarker.core.Environment env)
env
- The current FreeMarker environment.public static freemarker.ext.servlet.ServletContextHashModel getServletContextHashModel(freemarker.core.Environment env)
env
- The current FreeMarker environment.public static String getAsString(freemarker.template.TemplateModel model)
model
- The TemplateModel to unwrap.public static boolean getAsBoolean(freemarker.template.TemplateModel model, boolean defaultValue)
model
- The TemplateModel to unwrap.defaultValue
- If the value is null, this value will be returned.public static Object getAsObject(freemarker.template.TemplateModel model)
model
- The TemplateModel to unwrap.public static void setAttribute(freemarker.core.Environment env, String name, Object obj, String scope)
env
- The FreeMarker current environment.name
- The name of the attribute.obj
- The value of the attribute.scope
- The scope. It can be page
, request
, session
, application
.public static ArrayStack<Object> getComposeStack(freemarker.core.Environment env)
env
- The current FreeMarker environment.public static void evaluateBody(freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException
body
- The body to evaluate.freemarker.template.TemplateException
- If something goes wrong during evaluation.IOException
- If something goes wrong during writing the result.public static String renderAsString(freemarker.template.TemplateDirectiveBody body) throws freemarker.template.TemplateException, IOException
body
- The body to render.freemarker.template.TemplateException
- If something goes wrong during evaluation.IOException
- If something goes wrong during writing the result.Copyright © 2017. All rights reserved.