Class FreeMarkerWorker

java.lang.Object
org.apache.ofbiz.base.util.template.FreeMarkerWorker

public final class FreeMarkerWorker extends Object
FreeMarkerWorker - Freemarker Template Engine Utilities.
  • Field Details

    • VERSION

      public static final freemarker.template.Version VERSION
  • Method Details

    • getDefaultOfbizWrapper

      public static freemarker.ext.beans.BeansWrapper getDefaultOfbizWrapper()
    • newConfiguration

      public static freemarker.template.Configuration newConfiguration()
    • makeConfiguration

      public static freemarker.template.Configuration makeConfiguration(freemarker.ext.beans.BeansWrapper wrapper)
    • renderTemplate

      public static void renderTemplate(String templateLocation, Map<String,Object> context, Appendable outWriter) throws freemarker.template.TemplateException, IOException
      Renders a template from a Reader.
      Parameters:
      templateLocation - A unique ID for this template - used for caching
      context - The context Map
      outWriter - The Writer to render to
      Throws:
      freemarker.template.TemplateException
      IOException
    • renderTemplateFromString

      public static void renderTemplateFromString(String templateName, String templateString, Map<String,Object> context, Appendable outWriter, long lastModificationTime, boolean useCache) throws freemarker.template.TemplateException, IOException
      Throws:
      freemarker.template.TemplateException
      IOException
    • clearTemplateFromCache

      public static void clearTemplateFromCache(String templateLocation)
    • renderTemplate

      public static freemarker.core.Environment renderTemplate(freemarker.template.Template template, Map<String,Object> context, Appendable outWriter) throws freemarker.template.TemplateException, IOException
      Renders a Template instance.
      Parameters:
      template - A Template instance
      context - The context Map
      outWriter - The Writer to render to
      Throws:
      freemarker.template.TemplateException
      IOException
    • getDefaultOfbizConfig

      public static freemarker.template.Configuration getDefaultOfbizConfig()
      Returns a Configuration instance initialized to OFBiz defaults. Client code should call this method instead of creating its own Configuration instance. The instance returned by this method includes the component:// resolver and the OFBiz custom transformations.
      Returns:
      A Configuration instance.
    • getTemplate

      public static freemarker.template.Template getTemplate(String templateLocation) throws IOException
      Gets a Template instance from the template cache. If the Template instance isn't found in the cache, then one will be created.
      Parameters:
      templateLocation - Location of the template - file path or URL
      Throws:
      IOException
    • getTemplate

      public static freemarker.template.Template getTemplate(String templateLocation, UtilCache<String,freemarker.template.Template> cache, freemarker.template.Configuration config) throws IOException
      Throws:
      IOException
    • getArg

      public static String getArg(Map<String,? extends Object> args, String key, freemarker.core.Environment env)
    • getArg

      public static String getArg(Map<String,? extends Object> args, String key, Map<String,? extends Object> templateContext)
    • getWrappedObject

      public static <T> T getWrappedObject(String varName, freemarker.core.Environment env)
      Gets BeanModel from FreeMarker context and returns the object that it wraps.
      Parameters:
      varName - the name of the variable in the FreeMarker context.
      env - the FreeMarker Environment
    • get

      public static Object get(freemarker.template.SimpleHash args, String key)
    • unwrap

      public static <T> T unwrap(Object o)
    • createEnvironmentMap

      public static Map<String,Object> createEnvironmentMap(freemarker.core.Environment env)
    • saveContextValues

      public static void saveContextValues(Map<String,Object> context, String[] saveKeyNames, Map<String,Object> saveMap)
    • saveValues

      public static Map<String,Object> saveValues(Map<String,Object> context, String[] saveKeyNames)
    • reloadValues

      public static void reloadValues(Map<String,Object> context, Map<String,Object> saveValues, freemarker.core.Environment env)
    • removeValues

      public static void removeValues(Map<String,?> context, String... removeKeyNames)
    • overrideWithArgs

      public static void overrideWithArgs(Map<String,Object> ctx, Map<String,Object> args)
    • getSiteParameters

      public static void getSiteParameters(HttpServletRequest request, Map<String,Object> ctx)
    • autoWrap

      public static freemarker.template.TemplateModel autoWrap(Object obj, freemarker.core.Environment env)