You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@velocity.apache.org by jv...@locus.apache.org on 2000/11/16 03:01:52 UTC

cvs commit: jakarta-velocity/src/java/org/apache/velocity/runtime/loader TemplateLoader.java

jvanzyl     00/11/15 18:01:52

  Modified:    src/java/org/apache/velocity/runtime/loader
                        TemplateLoader.java
  Log:
  - New Template Loading Mechanism
    First these classes could probably use new names. What these loaders
    actually do now is locate an InputStream that is passed back to
    the Runtime, and the Runtime assembles the Template and caches it
    there. There is now a central cache for templates in the Runtime.
    This means that loader implementors only need be concerned with
  
    1. How to get the InputStream that the particular loader deals with.
    2. How to check the source of the stream for modification.
  
    The resultant template that is created by the Velocity Runtime will
    be cached in the Runtime. So the loaders can be very simple.
  
  Revision  Changes    Path
  1.3       +83 -8     jakarta-velocity/src/java/org/apache/velocity/runtime/loader/TemplateLoader.java
  
  Index: TemplateLoader.java
  ===================================================================
  RCS file: /home/cvs/jakarta-velocity/src/java/org/apache/velocity/runtime/loader/TemplateLoader.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- TemplateLoader.java	2000/09/30 22:21:05	1.2
  +++ TemplateLoader.java	2000/11/16 02:01:52	1.3
  @@ -54,22 +54,97 @@
    * <http://www.apache.org/>.
    */
   
  +import java.io.InputStream;
  +import java.util.Map;
  +
   import org.apache.velocity.Template;
   import org.apache.velocity.runtime.Runtime;
   
   /**
  - * Each loader should implement this class
  - * @author Dave Bryson
  - * $Revision: 1.2 $
  + * This is abstract class the all template loaders should
  + * extend.
  + * 
  + * @author <a href="mailto:daveb@miceda-data.com>Dave Bryson</a>
  + * @autor <a href="mailto:jvanzyl@periapt.com">Jason van Zyl</a>
  + * $Revision: 1.3 $
    */
   public abstract class TemplateLoader
   {
  -    /** Initialize the template loader */
  -    public abstract void init();
  +    /** 
  +     * Does this loader want templates produced with it
  +     * cached in the Runtime.
  +     */
  +    protected boolean cache = false;
  +    
  +    /**
  +     * This property will be passed on to the templates
  +     * that are created with this loader.
  +     */
  +    protected long modificationCheckInterval = 2;
  +
  +    /** 
  +     * Initialize the template loader with a
  +     * Map.
  +     */
  +    public abstract void init(Map initializer);
  +
  +    /** 
  +     * Get the InputStream that the Runtime will parse
  +     * to create a template.
  +     */
  +    public abstract InputStream getTemplateStream( String source ) throws Exception;
  +    
  +    /**
  +     * Given a template, check to see if the source of InputStream
  +     * has been modified.
  +     */
  +    public abstract boolean isSourceModified(Template template);
  +    
  +    /**
  +     * Get the last modified time of the InputStream source
  +     * that was used to create the template. We need the template
  +     * here because we have to extract the name of the template
  +     * in order to locate the InputStream source.
  +     */
  +    public abstract long getLastModified(Template template);
  +
  +    /**
  +     * Set the caching state. If true, then this loader
  +     * would like the Runtime to cache templates that
  +     * have been created with InputStreams provided
  +     * by this loader.
  +     */
  +    public void setCacheState(boolean state)
  +    {
  +        cache = state;
  +    }        
  +
  +    /**
  +     * The Runtime uses this to find out whether this
  +     * template loader wants the Runtime to cache
  +     * templates created with InputStreams provided
  +     * by this loader.
  +     */
  +    public boolean useCache()
  +    {
  +        return cache;
  +    }        
  +    
  +    /**
  +     * Set the interval at which the InputStream source
  +     * should be checked for modifications.
  +     */
  +    public void setModificationCheckInterval(long modificationCheckInterval)
  +    {
  +        this.modificationCheckInterval = modificationCheckInterval;
  +    }
       
       /**
  -     * Fetch the template
  -     * @return Template
  +     * Get the interval at which the InputStream source
  +     * should be checked for modifications.
        */
  -    public abstract Template getTemplate( String name ) throws Exception;
  +    public long getModificationCheckInterval()
  +    {
  +        return modificationCheckInterval;
  +    }        
   }