Package freemarker.cache
Class TemplateLookupContext
java.lang.Object
freemarker.cache.TemplateLookupContext
Used as the parameter of
TemplateLookupStrategy.lookup(TemplateLookupContext)
.
You can't create instances of this, only receive them from FreeMarker.- Since:
- 2.3.22
-
Method Summary
Modifier and TypeMethodDescriptionCreates a not-found lookup result that then can be used as the return value ofTemplateLookupStrategy.lookup(TemplateLookupContext)
.Returns the value of thecustomLookupCondition
parameter ofConfiguration.getTemplate(String, Locale, Object, String, boolean, boolean)
; see requirements there, such as having a properObject.equals(Object)
andObject.hashCode()
method.null
if localized lookup is disabled (seeConfiguration.getLocalizedLookup()
), otherwise the locale requested.The normalized name (path) of the template (relatively to theTemplateLoader
).abstract TemplateLookupResult
lookupWithAcquisitionStrategy(String templateName)
Finds the template source based on its normalized name; handles*
steps (so called acquisition), otherwise it just callsTemplateLoader.findTemplateSource(String)
.abstract TemplateLookupResult
lookupWithLocalizedThenAcquisitionStrategy(String templateName, Locale templateLocale)
Finds the template source based on its normalized name; tries localized variations going from most specific to less specific, and for each variation it delegates tolookupWithAcquisitionStrategy(String)
.
-
Method Details
-
lookupWithAcquisitionStrategy
public abstract TemplateLookupResult lookupWithAcquisitionStrategy(String templateName) throws IOExceptionFinds the template source based on its normalized name; handles*
steps (so called acquisition), otherwise it just callsTemplateLoader.findTemplateSource(String)
.- Parameters:
templateName
- Must be a normalized name, like"foo/bar/baaz.ftl"
. A name is not normalized when, among others, it starts with/
, or contains.
or..
path steps, or it uses backslash (\
) instead of/
. A normalized name might contains "*" path steps (acquisition).- Returns:
- The result of the lookup. Not
null
; checkTemplateLookupResult.isPositive()
to see if the lookup has found anything. - Throws:
IOException
-
lookupWithLocalizedThenAcquisitionStrategy
public abstract TemplateLookupResult lookupWithLocalizedThenAcquisitionStrategy(String templateName, Locale templateLocale) throws IOExceptionFinds the template source based on its normalized name; tries localized variations going from most specific to less specific, and for each variation it delegates tolookupWithAcquisitionStrategy(String)
. IftemplateLocale
isnull
(typically, becauseConfiguration.getLocalizedLookup()
isfalse
)), then it's the same as callinglookupWithAcquisitionStrategy(String)
directly. This is the default strategy of FreeMarker (at least in 2.3.x), so for more information, seeTemplateLookupStrategy.DEFAULT_2_3_0
.- Throws:
IOException
-
getTemplateName
The normalized name (path) of the template (relatively to theTemplateLoader
). Notnull
. -
getTemplateLocale
null
if localized lookup is disabled (seeConfiguration.getLocalizedLookup()
), otherwise the locale requested. -
getCustomLookupCondition
Returns the value of thecustomLookupCondition
parameter ofConfiguration.getTemplate(String, Locale, Object, String, boolean, boolean)
; see requirements there, such as having a properObject.equals(Object)
andObject.hashCode()
method. The interpretation of this value is up to the customTemplateLookupStrategy
. Usually, it's used similarly to as the default lookup strategy usesgetTemplateLocale()
, that is, to look for a template variation that satisfies the condition, and then maybe fall back to more generic template if that's missing. -
createNegativeLookupResult
Creates a not-found lookup result that then can be used as the return value ofTemplateLookupStrategy.lookup(TemplateLookupContext)
. (In the current implementation it just always returns the same static singleton, but that might need to change in the future.)
-