java.lang.Object
ch.tocco.nice2.templating.api.freemarker.directives.DirectiveHelper

public final class DirectiveHelper extends Object
Helper class for Directives providing some basic functions
  • Method Details

    • readStringParameter

      public static String readStringParameter(String name, Map params, boolean notNull) throws ParameterException
      Parameters:
      name - name of the parameter
      params - the parametermap
      notNull - 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 parameter
      params - the parametermap
      notNull - 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

      public static Entity readEntityFromParams(String name, Map params) throws ParameterException
      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

      public static TemplateIdentifiers.Scope readScopeParameter(Map params) throws ParameterException
      Throws:
      ParameterException
    • setVariable

      public static void setVariable(freemarker.core.Environment env, TemplateIdentifiers.Scope scope, String name, freemarker.template.TemplateModel model)
    • readParameter

      @Nullable public static <T> T readParameter(String name, Map params) throws ParameterException
      Throws:
      ParameterException
    • getFieldValue

      @Nullable public static @Nullable TypedValue<?> getFieldValue(String path, Entity baseEntity)
    • getTemplateModelForObject

      public static freemarker.template.TemplateModel getTemplateModelForObject(Object object, freemarker.core.Environment environment) throws freemarker.template.TemplateModelException
      Parameters:
      object - an object
      environment - 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

      public static org.joda.time.format.DateTimeFormatter getFormatterForPattern(String pattern, Locale locale)
    • 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