Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
   * Copyright 2014 Attila Szegedi, Daniel Dekany, Jonathan Revusky
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
 package freemarker.cache;
Used as the parameter of TemplateLookupStrategy.lookup(freemarker.cache.TemplateLookupContext). You can't create instances of this, only receive them from FreeMarker.

 public abstract class TemplateLookupContext {
     private final String templateName;
     private final Locale templateLocale;
     private final Object customLookupCondition;

Finds the template source based on its normalized name; handles * steps (so called acquisition), otherwise it just calls TemplateLoader.findTemplateSource(java.lang.String).

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.
The result of the lookup. Not null; check TemplateLookupResult.isPositive() to see if the lookup has found anything.
     public abstract TemplateLookupResult lookupWithAcquisitionStrategy(String templateNamethrows 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 to lookupWithAcquisitionStrategy(java.lang.String). If templateLocale is null (typically, because freemarker.template.Configuration.getLocalizedLookup() is false)), then it's the same as calling lookupWithAcquisitionStrategy(java.lang.String) directly. This is the default strategy of FreeMarker (at least in 2.3.x), so for more information, see TemplateLookupStrategy.DEFAULT_2_3_0.
             Locale templateLocalethrows IOException;
Default visibility to prevent extending the class from outside this package.
     TemplateLookupContext(String templateNameLocale templateLocaleObject customLookupCondition) {
         this. = templateName;
         this. = templateLocale;
         this. = customLookupCondition;

The normalized name (path) of the template (relatively to the TemplateLoader). Not null.
     public String getTemplateName() {
         return ;

null if localized lookup is disabled (see freemarker.template.Configuration.getLocalizedLookup()), otherwise the locale requested.
     public Locale getTemplateLocale() {
         return ;

Returns the value of the customLookupCondition parameter of freemarker.template.Configuration.getTemplate(java.lang.String,java.util.Locale,java.lang.Object,java.lang.String,boolean,boolean); see requirements there, such as having a proper java.lang.Object.equals(java.lang.Object) and java.lang.Object.hashCode() method. The interpretation of this value is up to the custom TemplateLookupStrategy. Usually, it's used similarly to as the default lookup strategy uses getTemplateLocale(), 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.
     public Object getCustomLookupCondition() {
         return ;

Creates a not-found lookup result that then can be used as the return value of TemplateLookupStrategy.lookup(freemarker.cache.TemplateLookupContext). (In the current implementation it just always returns the same static singleton, but that might need to change in the future.)
        return TemplateLookupResult.createNegativeResult();
New to GrepCode? Check out our FAQ X