Package freemarker.cache
Class TemplateLookupContext
- java.lang.Object
-
- freemarker.cache.TemplateLookupContext
-
public abstract class TemplateLookupContext extends Object
Used as the parameter ofTemplateLookupStrategy.lookup(TemplateLookupContext). You can't create instances of this, only receive them from FreeMarker.- Since:
- 2.3.22
-
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description TemplateLookupResultcreateNegativeLookupResult()Creates a not-found lookup result that then can be used as the return value ofTemplateLookupStrategy.lookup(TemplateLookupContext).ObjectgetCustomLookupCondition()Returns the value of thecustomLookupConditionparameter ofConfiguration.getTemplate(String, Locale, Object, String, boolean, boolean); see requirements there, such as having a properObject.equals(Object)andObject.hashCode()method.LocalegetTemplateLocale()nullif localized lookup is disabled (seeConfiguration.getLocalizedLookup()), otherwise the locale requested.StringgetTemplateName()The normalized name (path) of the template (relatively to theTemplateLoader).abstract TemplateLookupResultlookupWithAcquisitionStrategy(String templateName)Finds the template source based on its normalized name; handles*steps (so called acquisition), otherwise it just callsTemplateLoader.findTemplateSource(String).abstract TemplateLookupResultlookupWithLocalizedThenAcquisitionStrategy(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 Detail
-
lookupWithAcquisitionStrategy
public abstract TemplateLookupResult lookupWithAcquisitionStrategy(String templateName) throws IOException
Finds 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..paths steps, or it uses backslash (\) instead of/. A normalized name might contains "*" steps.- 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 IOException
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). IftemplateLocaleisnull(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
public String getTemplateName()
The normalized name (path) of the template (relatively to theTemplateLoader). Notnull.
-
getTemplateLocale
public Locale getTemplateLocale()
nullif localized lookup is disabled (seeConfiguration.getLocalizedLookup()), otherwise the locale requested.
-
getCustomLookupCondition
public Object getCustomLookupCondition()
Returns the value of thecustomLookupConditionparameter 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
public TemplateLookupResult 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.)
-
-