Class DirectiveHelper
java.lang.Object
ch.tocco.nice2.templating.api.freemarker.directives.DirectiveHelper
Helper class for Directives providing some basic functions
-
Method Summary
Modifier and TypeMethodDescriptionstatic EntitygetBaseData(freemarker.core.Environment env) static StringgetBaseUrl(freemarker.core.Environment env) static <T> Optional<T> getBeanVariable(freemarker.core.Environment env, String name, Class<T> expectedClass) Get a bean wrapped in a BeanModel.static @Nullable TypedValue<?> getFieldValue(String path, Entity baseEntity) static org.joda.time.format.DateTimeFormattergetFormatterForPattern(String pattern, Locale locale) static freemarker.template.TemplateModelgetSequence(EntityList list, freemarker.core.Environment env) static freemarker.template.TemplateModelgetTemplateModelForObject(Object object, freemarker.core.Environment environment) static @Nullable BooleanreadBooleanParameter(String name, Map params) static BooleanreadBooleanParameter(String name, Map params, boolean notNull) static EntityreadEntityFromParams(String name, Map params) static EntityreadEntityFromParams(String name, Map params, boolean notNull) static EntityreadEntityFromParamsIfAbsentGetBaseData(String name, Map params, freemarker.core.Environment env) static EntityreadEntityFromVariables(String name, freemarker.core.Environment env) readEntityListFromVariables(String name, freemarker.core.Environment env) static @Nullable NumberreadNumberParameter(String name, Map params) static NumberreadNumberParameter(String name, Map params, boolean notNull) readOptionalEntityFromParams(String name, Map params) readOptionalEntityFromVariables(String name, freemarker.core.Environment env) static <T> TreadParameter(String name, Map params) static <T> TreadParameter(String name, Map params, boolean notNull) static TemplateIdentifiers.ScopereadScopeParameter(Map params) static StringreadStringFromEnvironment(freemarker.core.Environment env, String name) static @Nullable StringreadStringParameter(String name, Map params) static StringreadStringParameter(String name, Map params, boolean notNull) static StringreadStringParameter(String name, Map params, String defaultValue) static voidsetVariable(freemarker.core.Environment env, TemplateIdentifiers.Scope scope, String name, freemarker.template.TemplateModel model)
-
Method Details
-
readStringParameter
public static String readStringParameter(String name, Map params, boolean notNull) throws ParameterException - Parameters:
name- name of the parameterparams- the parametermapnotNull- set to true, if the parameter cannot be left out- Returns:
- parameter value as string or null if parameter is not available
- Throws:
ParameterException
-
readNumberParameter
public static Number readNumberParameter(String name, Map params, boolean notNull) throws ParameterException - Throws:
ParameterException
-
readBooleanParameter
public static Boolean readBooleanParameter(String name, Map params, boolean notNull) throws ParameterException - Throws:
ParameterException
-
readParameter
public static <T> T readParameter(String name, Map params, boolean notNull) throws ParameterException - Parameters:
name- name of the parameterparams- the parametermapnotNull- set to true, if the parameter cannot be left out- Returns:
- parameter value as string or null if parameter is not available
- Throws:
ParameterException
-
getBaseData
public static Entity getBaseData(freemarker.core.Environment env) throws freemarker.template.TemplateException, ParameterException - Throws:
freemarker.template.TemplateExceptionParameterException
-
readEntityFromParams
- Throws:
ParameterException
-
readEntityFromParams
public static Entity readEntityFromParams(String name, Map params, boolean notNull) throws ParameterException - Throws:
ParameterException
-
readOptionalEntityFromParams
public static Optional<Entity> readOptionalEntityFromParams(String name, Map params) throws ParameterException - Throws:
ParameterException
-
readEntityFromParamsIfAbsentGetBaseData
public static Entity readEntityFromParamsIfAbsentGetBaseData(String name, Map params, freemarker.core.Environment env) throws ParameterException, freemarker.template.TemplateException - Throws:
ParameterExceptionfreemarker.template.TemplateException
-
readEntityListFromVariables
public static List<Entity> readEntityListFromVariables(String name, freemarker.core.Environment env) throws freemarker.template.TemplateModelException, ParameterException - Throws:
freemarker.template.TemplateModelExceptionParameterException
-
readEntityFromVariables
public static Entity readEntityFromVariables(String name, freemarker.core.Environment env) throws freemarker.template.TemplateModelException, ParameterException - Throws:
freemarker.template.TemplateModelExceptionParameterException
-
readOptionalEntityFromVariables
public static Optional<Entity> readOptionalEntityFromVariables(String name, freemarker.core.Environment env) throws freemarker.template.TemplateModelException, ParameterException - Throws:
freemarker.template.TemplateModelExceptionParameterException
-
readStringParameter
@Nullable public static @Nullable String readStringParameter(String name, Map params) throws ParameterException - Throws:
ParameterException
-
readStringParameter
public static String readStringParameter(String name, Map params, String defaultValue) throws ParameterException - Throws:
ParameterException
-
readNumberParameter
@Nullable public static @Nullable Number readNumberParameter(String name, Map params) throws ParameterException - Throws:
ParameterException
-
readBooleanParameter
@Nullable public static @Nullable Boolean readBooleanParameter(String name, Map params) throws ParameterException - Throws:
ParameterException
-
readScopeParameter
- Throws:
ParameterException
-
setVariable
public static void setVariable(freemarker.core.Environment env, TemplateIdentifiers.Scope scope, String name, freemarker.template.TemplateModel model) -
readParameter
- Throws:
ParameterException
-
getFieldValue
-
getTemplateModelForObject
public static freemarker.template.TemplateModel getTemplateModelForObject(Object object, freemarker.core.Environment environment) throws freemarker.template.TemplateModelException - Parameters:
object- an objectenvironment- the template's environment- Returns:
- the template model representation for the provided object. it can be used to e.g. insert the object as a variable
- Throws:
freemarker.template.TemplateModelException
-
getSequence
public static freemarker.template.TemplateModel getSequence(EntityList list, freemarker.core.Environment env) throws freemarker.template.TemplateException - Throws:
freemarker.template.TemplateException
-
getFormatterForPattern
-
getBeanVariable
public static <T> Optional<T> getBeanVariable(freemarker.core.Environment env, String name, Class<T> expectedClass) throws freemarker.template.TemplateModelException Get a bean wrapped in a BeanModel.- Parameters:
env- The freemarker environment.name- The name of the variable to fetch.expectedClass- The expected class for the bean.- Throws:
freemarker.template.TemplateModelException
-
getBaseUrl
public static String getBaseUrl(freemarker.core.Environment env) throws freemarker.template.TemplateModelException - Throws:
freemarker.template.TemplateModelException
-
readStringFromEnvironment
public static String readStringFromEnvironment(freemarker.core.Environment env, String name) throws freemarker.template.TemplateModelException - Throws:
freemarker.template.TemplateModelException
-