java.lang.Object
org.miaixz.bus.extra.template.TemplateConfig
- All Implemented Interfaces:
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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumEnumeration defining different modes for loading template resources. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final TemplateConfigDefault template configuration instance. -
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor.TemplateConfig(String path) Constructs a new TemplateConfig with the specified template path.TemplateConfig(String path, TemplateConfig.ResourceMode resourceMode) Constructs a new TemplateConfig with the specified template path and resource loading mode.TemplateConfig(Charset charset, String path, TemplateConfig.ResourceMode resourceMode) Constructs a new TemplateConfig with the specified character set, template path, and resource loading mode. -
Method Summary
Modifier and TypeMethodDescriptionbooleanRetrieves the character set used for template files.Retrieves the character set name as a string.getPath()Retrieves the path to the template files.Class<? extends TemplateProvider> Retrieves the custom template provider class.Retrieves the resource loading mode for templates.inthashCode()booleanChecks if template caching is enabled.voidsetCharset(Charset charset) Sets the character set for template files.voidSets the path to the template files.setProvider(Class<? extends TemplateProvider> provider) Sets the custom template provider class.voidsetResourceMode(TemplateConfig.ResourceMode resourceMode) Sets the resource loading mode for templates.setUseCache(boolean useCache) Sets whether template caching should be enabled.
-
Field Details
-
DEFAULT
Default template configuration instance. Uses UTF-8 encoding andTemplateConfig.ResourceMode.STRINGas the default resource loading mode.
-
-
Constructor Details
-
TemplateConfig
public TemplateConfig()Default constructor. Initializes with UTF-8 encoding andTemplateConfig.ResourceMode.STRINGas the default resource loading mode. -
TemplateConfig
Constructs a new TemplateConfig with the specified template path. Uses UTF-8 encoding andTemplateConfig.ResourceMode.STRINGas the default resource loading mode.- Parameters:
path- The path to the template files. Can be a relative path depending on the resource mode.
-
TemplateConfig
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
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
Retrieves the character set used for template files.- Returns:
- The character set.
-
setCharset
Sets the character set for template files.- Parameters:
charset- The character set to set.
-
getCharsetString
Retrieves the character set name as a string.- Returns:
- The name of the character set, or
nullif not set.
-
getPath
Retrieves the path to the template files. This can be a relative path depending on the configuredTemplateConfig.ResourceMode.- Returns:
- The template path.
-
setPath
Sets the path to the template files. This can be a relative path ifTemplateConfig.ResourceMode.CLASSPATHorTemplateConfig.ResourceMode.WEB_ROOTis used.- Parameters:
path- The template path to set.
-
getResourceMode
Retrieves the resource loading mode for templates.- Returns:
- The resource loading mode.
-
setResourceMode
Sets the resource loading mode for templates.- Parameters:
resourceMode- The resource loading mode to set.
-
getProvider
Retrieves the custom template provider class. Ifnull, the system will automatically determine the appropriate engine.- Returns:
- The custom template provider class, or
nullfor automatic detection.
-
setProvider
Sets the custom template provider class. Ifnull, the system will automatically determine the appropriate engine.- Parameters:
provider- The custom template provider class to set, ornullfor automatic detection.- Returns:
- This TemplateConfig instance for method chaining.
-
isUseCache
public boolean isUseCache()Checks if template caching is enabled.- Returns:
trueif caching is enabled,falseotherwise.
-
setUseCache
Sets whether template caching should be enabled.- Parameters:
useCache-trueto enable caching,falseto disable.- Returns:
- This TemplateConfig instance for method chaining.
-
equals
-
hashCode
public int hashCode()
-