Module bus.extra

Class TemplateConfig

java.lang.Object
org.miaixz.bus.extra.template.TemplateConfig
All Implemented Interfaces:
Serializable

public class TemplateConfig extends Object implements Serializable
Configuration class for template engines. This class holds various settings required for initializing and using template engines, such as character encoding, template paths, resource loading mode, and custom template providers.
Since:
Java 17+
Author:
Kimi Liu
See Also:
  • Field Details

  • Constructor Details

    • TemplateConfig

      public TemplateConfig()
      Default constructor. Initializes with UTF-8 encoding and TemplateConfig.ResourceMode.STRING as the default resource loading mode.
    • TemplateConfig

      public TemplateConfig(String path)
      Constructs a new TemplateConfig with the specified template path. Uses UTF-8 encoding and TemplateConfig.ResourceMode.STRING as the default resource loading mode.
      Parameters:
      path - The path to the template files. Can be a relative path depending on the resource mode.
    • TemplateConfig

      public TemplateConfig(String path, TemplateConfig.ResourceMode resourceMode)
      Constructs a new TemplateConfig with the specified template path and resource loading mode. Uses UTF-8 encoding by default.
      Parameters:
      path - The path to the template files. Can be a relative path depending on the resource mode.
      resourceMode - The resource loading mode for templates.
    • TemplateConfig

      public TemplateConfig(Charset charset, String path, TemplateConfig.ResourceMode resourceMode)
      Constructs a new TemplateConfig with the specified character set, template path, and resource loading mode.
      Parameters:
      charset - The character set for template files.
      path - The path to the template files. Can be a relative path depending on the resource mode.
      resourceMode - The resource loading mode for templates.
  • Method Details

    • getCharset

      public Charset getCharset()
      Retrieves the character set used for template files.
      Returns:
      The character set.
    • setCharset

      public void setCharset(Charset charset)
      Sets the character set for template files.
      Parameters:
      charset - The character set to set.
    • getCharsetString

      public String getCharsetString()
      Retrieves the character set name as a string.
      Returns:
      The name of the character set, or null if not set.
    • getPath

      public String getPath()
      Retrieves the path to the template files. This can be a relative path depending on the configured TemplateConfig.ResourceMode.
      Returns:
      The template path.
    • setPath

      public void setPath(String path)
      Sets the path to the template files. This can be a relative path if TemplateConfig.ResourceMode.CLASSPATH or TemplateConfig.ResourceMode.WEB_ROOT is used.
      Parameters:
      path - The template path to set.
    • getResourceMode

      public TemplateConfig.ResourceMode getResourceMode()
      Retrieves the resource loading mode for templates.
      Returns:
      The resource loading mode.
    • setResourceMode

      public void setResourceMode(TemplateConfig.ResourceMode resourceMode)
      Sets the resource loading mode for templates.
      Parameters:
      resourceMode - The resource loading mode to set.
    • getProvider

      public Class<? extends TemplateProvider> getProvider()
      Retrieves the custom template provider class. If null, the system will automatically determine the appropriate engine.
      Returns:
      The custom template provider class, or null for automatic detection.
    • setProvider

      public TemplateConfig setProvider(Class<? extends TemplateProvider> provider)
      Sets the custom template provider class. If null, the system will automatically determine the appropriate engine.
      Parameters:
      provider - The custom template provider class to set, or null for automatic detection.
      Returns:
      This TemplateConfig instance for method chaining.
    • isUseCache

      public boolean isUseCache()
      Checks if template caching is enabled.
      Returns:
      true if caching is enabled, false otherwise.
    • setUseCache

      public TemplateConfig setUseCache(boolean useCache)
      Sets whether template caching should be enabled.
      Parameters:
      useCache - true to enable caching, false to disable.
      Returns:
      This TemplateConfig instance for method chaining.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object