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
   * 
   * http://www.apache.org/licenses/LICENSE-2.0
   * 
  * 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;
 
 import java.io.Reader;
 import java.net.URL;
 
This is an abstract template loader that can load templates whose location can be described by an URL. Subclasses only need to override the getURL(java.lang.String) method. Both ClassTemplateLoader and WebappTemplateLoader are (quite trivial) subclasses of this class.
 
 public abstract class URLTemplateLoader implements TemplateLoader
 {
     
     private Boolean urlConnectionUsesCaches;
     
     public Object findTemplateSource(String name)
     throws
     	IOException
     {
         URL url = getURL(name);
         return url == null ? null : new URLTemplateSource(urlgetURLConnectionUsesCaches());
     }
    
    
Given a template name (plus potential locale decorations) retrieves an URL that points the template source.

Parameters:
name the name of the sought template, including the locale decorations.
Returns:
an URL that points to the template source, or null if it can determine that the template source does not exist.
 
     protected abstract URL getURL(String name);
     
     public long getLastModified(Object templateSource)
     {
         return ((URLTemplateSourcetemplateSource).lastModified();
     }
     
     public Reader getReader(Object templateSourceString encoding)
     throws
         IOException
     {
         return new InputStreamReader(
                 ((URLTemplateSourcetemplateSource).getInputStream(),
                 encoding);
     }
     
     public void closeTemplateSource(Object templateSource)
     throws
     	IOException
     {
         ((URLTemplateSourcetemplateSource).close();
     }

    
Can be used by subclasses to canonicalize URL path prefixes.

Parameters:
prefix the path prefix to canonicalize
Returns:
the canonicalized prefix. All backslashes are replaced with forward slashes, and a trailing slash is appended if the original prefix wasn't empty and didn't already end with a slash.
 
     protected static String canonicalizePrefix(String prefix)
     {
         // make it foolproof
         prefix = prefix.replace('\\''/');
         // ensure there's a trailing slash
         if (prefix.length() > 0 && !prefix.endsWith("/"))
         {
             prefix += "/";
         }
         return prefix;
     }

    
Getter pair of setURLConnectionUsesCaches(java.lang.Boolean).

Since:
2.3.21
        return ;
    }

    
Sets if java.net.URLConnection.setUseCaches(boolean) will be called, and with what value. By default this is null; see the behavior then below. The recommended value is false, so that FreeMarker can always reliably detect when a template was changed. The default is null only for backward compatibility, and certainly will be changed to false in 2.4.0. As FreeMarker has its own template cache with its own update delay setting (freemarker.template.Configuration.setTemplateUpdateDelay(int)), setting this to false shouldn't cause performance problems.

Regarding null value: By default then java.net.URLConnection.setUseCaches(boolean) won't be called, and so the default of the java.net.URLConnection subclass will be in effect (usually true). That's the 2.3.0-compatible mode. However, if freemarker.template.Configuration.getIncompatibleImprovements() is at least 2.3.21, then when Configuration.getTemplate is used, null will mean false. Note that this 2.3.21 trick only works if the template is loaded through Configuration.getTemplate (or TemplateCache).

Since:
2.3.21
    public void setURLConnectionUsesCaches(Boolean urlConnectionUsesCaches) {
        this. = urlConnectionUsesCaches;
    }
    
New to GrepCode? Check out our FAQ X