Module bus.extra

Class FreemarkerProvider

java.lang.Object
org.miaixz.bus.extra.template.provider.freemarker.FreemarkerProvider
All Implemented Interfaces:
Serializable, org.miaixz.bus.core.lang.Wrapper<Object>, org.miaixz.bus.core.Provider, TemplateProvider

public class FreemarkerProvider extends Object implements TemplateProvider
FreeMarker template engine encapsulation. This class provides an implementation of TemplateProvider for the FreeMarker template engine, allowing for configuration and retrieval of FreeMarker templates. For more information, see: https://freemarker.apache.org/
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Constructor Details

    • FreemarkerProvider

      public FreemarkerProvider()
      Default constructor for FreemarkerProvider. Checks if the FreeMarker library is available (via Configuration class).
    • FreemarkerProvider

      public FreemarkerProvider(TemplateConfig config)
      Constructs a new FreemarkerProvider with the given template configuration.
      Parameters:
      config - The TemplateConfig for initializing the FreeMarker engine.
    • FreemarkerProvider

      public FreemarkerProvider(freemarker.template.Configuration freemarkerCfg)
      Constructs a new FreemarkerProvider with an existing FreeMarker Configuration instance.
      Parameters:
      freemarkerCfg - The pre-initialized Configuration instance.
  • Method Details

    • init

      public TemplateProvider init(TemplateConfig config)
      Description copied from interface: TemplateProvider
      Initializes the template engine with the specified configuration.
      Specified by:
      init in interface TemplateProvider
      Parameters:
      config - The TemplateConfig containing initialization parameters for the template engine.
      Returns:
      This TemplateProvider instance, initialized with the given configuration.
    • getTemplate

      public Template getTemplate(String resource)
      Description copied from interface: TemplateProvider
      Retrieves a Template object based on the provided resource. The interpretation of the resource string depends on the specific template engine implementation; it could be the template content itself or a relative path to the template file.
      Specified by:
      getTemplate in interface TemplateProvider
      Parameters:
      resource - The resource identifier for the template.
      Returns:
      A Template instance ready for rendering.
    • getRaw

      public freemarker.template.Configuration getRaw()
      Provides a hook to access the raw FreeMarker Configuration engine. This can be used for custom configurations or accessing specific FreeMarker functionalities, such as plugins.
      Specified by:
      getRaw in interface org.miaixz.bus.core.lang.Wrapper<Object>
      Returns:
      The raw Configuration instance.