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 Entity
getBaseData
(freemarker.core.Environment env) static String
getBaseUrl
(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.DateTimeFormatter
getFormatterForPattern
(String pattern, Locale locale) static freemarker.template.TemplateModel
getSequence
(EntityList list, freemarker.core.Environment env) static freemarker.template.TemplateModel
getTemplateModelForObject
(Object object, freemarker.core.Environment environment) static @Nullable Boolean
readBooleanParameter
(String name, Map params) static Boolean
readBooleanParameter
(String name, Map params, boolean notNull) static Entity
readEntityFromParams
(String name, Map params) static Entity
readEntityFromParams
(String name, Map params, boolean notNull) static Entity
readEntityFromParamsIfAbsentGetBaseData
(String name, Map params, freemarker.core.Environment env) static Entity
readEntityFromVariables
(String name, freemarker.core.Environment env) readEntityListFromVariables
(String name, freemarker.core.Environment env) static @Nullable Number
readNumberParameter
(String name, Map params) static Number
readNumberParameter
(String name, Map params, boolean notNull) readOptionalEntityFromParams
(String name, Map params) readOptionalEntityFromVariables
(String name, freemarker.core.Environment env) static <T> T
readParameter
(String name, Map params) static <T> T
readParameter
(String name, Map params, boolean notNull) static TemplateIdentifiers.Scope
readScopeParameter
(Map params) static String
readStringFromEnvironment
(freemarker.core.Environment env, String name) static @Nullable String
readStringParameter
(String name, Map params) static String
readStringParameter
(String name, Map params, boolean notNull) static String
readStringParameter
(String name, Map params, String defaultValue) static void
setVariable
(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.TemplateException
ParameterException
-
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:
ParameterException
freemarker.template.TemplateException
-
readEntityListFromVariables
public static List<Entity> readEntityListFromVariables(String name, freemarker.core.Environment env) throws freemarker.template.TemplateModelException, ParameterException - Throws:
freemarker.template.TemplateModelException
ParameterException
-
readEntityFromVariables
public static Entity readEntityFromVariables(String name, freemarker.core.Environment env) throws freemarker.template.TemplateModelException, ParameterException - Throws:
freemarker.template.TemplateModelException
ParameterException
-
readOptionalEntityFromVariables
public static Optional<Entity> readOptionalEntityFromVariables(String name, freemarker.core.Environment env) throws freemarker.template.TemplateModelException, ParameterException - Throws:
freemarker.template.TemplateModelException
ParameterException
-
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
-