org.zkoss.web.util.resource
Class ResourceLoader

java.lang.Object
  extended by org.zkoss.web.util.resource.ResourceLoader
All Implemented Interfaces:
Loader

public abstract class ResourceLoader
extends java.lang.Object
implements Loader

A semi-implemented loader to used with ResourceCaches.get(org.zkoss.util.resource.ResourceCache, javax.servlet.ServletContext, java.lang.String, java.lang.Object) to retrieve servlet resources.

Author:
tomyeh

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.zkoss.util.resource.Loader
Loader.Resource
 
Constructor Summary
protected ResourceLoader()
           
 
Method Summary
 long getLastModified(java.lang.Object src)
          Returns the last modified time, or -1 if reload is required or not exists.
 java.lang.Object load(java.lang.Object src)
          Loads the resource.
protected abstract  java.lang.Object parse(java.lang.String path, java.io.File file, java.lang.Object extra)
          Parses the specified file and returns the result which will be stored into the cache (ResourceCaches.get(org.zkoss.util.resource.ResourceCache, javax.servlet.ServletContext, java.lang.String, java.lang.Object)).
protected abstract  java.lang.Object parse(java.lang.String path, java.net.URL url, java.lang.Object extra)
          Parses the specified URL and returns the result which will be stored into the cache (ResourceCaches.get(org.zkoss.util.resource.ResourceCache, javax.servlet.ServletContext, java.lang.String, java.lang.Object)).
 boolean shallCheck(java.lang.Object src, long expiredMillis)
          Returns whether to call Loader.getLastModified(java.lang.Object).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceLoader

protected ResourceLoader()
Method Detail

parse

protected abstract java.lang.Object parse(java.lang.String path,
                                          java.io.File file,
                                          java.lang.Object extra)
                                   throws java.lang.Exception
Parses the specified file and returns the result which will be stored into the cache (ResourceCaches.get(org.zkoss.util.resource.ResourceCache, javax.servlet.ServletContext, java.lang.String, java.lang.Object)).

Deriving must override this method.

Parameters:
extra - the extra paramter passed from ResourceCaches.get(org.zkoss.util.resource.ResourceCache, javax.servlet.ServletContext, java.lang.String, java.lang.Object).
Throws:
java.lang.Exception

parse

protected abstract java.lang.Object parse(java.lang.String path,
                                          java.net.URL url,
                                          java.lang.Object extra)
                                   throws java.lang.Exception
Parses the specified URL and returns the result which will be stored into the cache (ResourceCaches.get(org.zkoss.util.resource.ResourceCache, javax.servlet.ServletContext, java.lang.String, java.lang.Object)).

Deriving must override this method.

Parameters:
extra - the extra paramter passed from ResourceCaches.get(org.zkoss.util.resource.ResourceCache, javax.servlet.ServletContext, java.lang.String, java.lang.Object).
Throws:
java.lang.Exception

shallCheck

public boolean shallCheck(java.lang.Object src,
                          long expiredMillis)
Description copied from interface: Loader
Returns whether to call Loader.getLastModified(java.lang.Object). If false, it assumes the current cached content is up-to-date.

Specified by:
shallCheck in interface Loader
expiredMillis - how many milli-seconds are expired after the last check. In most cases, just return true if expiredMillis > 0

getLastModified

public long getLastModified(java.lang.Object src)
Description copied from interface: Loader
Returns the last modified time, or -1 if reload is required or not exists.

Specified by:
getLastModified in interface Loader

load

public java.lang.Object load(java.lang.Object src)
                      throws java.lang.Exception
Description copied from interface: Loader
Loads the resource.

The returned resource could be anything. It will be returned by ResourceCache.get(java.lang.Object). However, if you want to have more control (e.g., whether to cache), you can return an instance of Loader.Resource. Then, the return value of ResourceCache.get(java.lang.Object) will be Loader.Resource.resource.

Specified by:
load in interface Loader
Returns:
null if not found
Throws:
java.lang.Exception - you might throw any exception which will be passed back to the caller of ResourceCache.get(java.lang.Object)


Copyright © 2005-2009 Potix Corporation. All Rights Reserved. SourceForge.net Logo