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
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 Summary
ConstructorsConstructorDescriptionDefault constructor for FreemarkerProvider.FreemarkerProvider(freemarker.template.Configuration freemarkerCfg) Constructs a new FreemarkerProvider with an existing FreeMarkerConfigurationinstance.FreemarkerProvider(TemplateConfig config) Constructs a new FreemarkerProvider with the given template configuration. -
Method Summary
Modifier and TypeMethodDescriptionfreemarker.template.ConfigurationgetRaw()Provides a hook to access the raw FreeMarkerConfigurationengine.getTemplate(String resource) Retrieves aTemplateobject based on the provided resource.init(TemplateConfig config) Initializes the template engine with the specified configuration.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.miaixz.bus.core.lang.Wrapper
type
-
Constructor Details
-
FreemarkerProvider
public FreemarkerProvider()Default constructor for FreemarkerProvider. Checks if the FreeMarker library is available (viaConfigurationclass). -
FreemarkerProvider
Constructs a new FreemarkerProvider with the given template configuration.- Parameters:
config- TheTemplateConfigfor initializing the FreeMarker engine.
-
FreemarkerProvider
public FreemarkerProvider(freemarker.template.Configuration freemarkerCfg) Constructs a new FreemarkerProvider with an existing FreeMarkerConfigurationinstance.- Parameters:
freemarkerCfg- The pre-initializedConfigurationinstance.
-
-
Method Details
-
init
Description copied from interface:TemplateProviderInitializes the template engine with the specified configuration.- Specified by:
initin interfaceTemplateProvider- Parameters:
config- TheTemplateConfigcontaining initialization parameters for the template engine.- Returns:
- This
TemplateProviderinstance, initialized with the given configuration.
-
getTemplate
Description copied from interface:TemplateProviderRetrieves aTemplateobject 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:
getTemplatein interfaceTemplateProvider- Parameters:
resource- The resource identifier for the template.- Returns:
- A
Templateinstance ready for rendering.
-
getRaw
public freemarker.template.Configuration getRaw()Provides a hook to access the raw FreeMarkerConfigurationengine. This can be used for custom configurations or accessing specific FreeMarker functionalities, such as plugins.- Specified by:
getRawin interfaceorg.miaixz.bus.core.lang.Wrapper<Object>- Returns:
- The raw
Configurationinstance.
-