org.webmacro.resource
Class UrlProvider

java.lang.Object
  extended byorg.webmacro.resource.CachingProvider
      extended byorg.webmacro.resource.UrlProvider
All Implemented Interfaces:
Provider, ResourceLoader

public final class UrlProvider
extends CachingProvider

This is the canonical provider for mapping URLs to Handlers. The reactor will request that the "handler" provider return a Handler object when supplied with a URL.

You could implement your own version of this class to return handlers based on whatever criteria you wanted.


Field Summary
static long AVG_TIMEOUT
           
static long MAX_TIMEOUT
           
static long MIN_TIMEOUT
           
 
Fields inherited from class org.webmacro.resource.CachingProvider
_cacheSupportsReload
 
Constructor Summary
UrlProvider()
           
 
Method Summary
 java.lang.String getType()
          We serve up "url" type resources
static java.io.InputStream getUrlInputStream(java.net.URL u)
          Utility routine to get the input stream associated with a URL.
static long getUrlLastModified(java.net.URL u)
          Utility routine to get the last modification date for a URL.
 void init(Broker b, Settings config)
          If you override this method be sure and call super.init(...)
 java.lang.Object load(java.lang.String name, CacheElement ce)
          Load a URL from the specified name and return it.
 
Methods inherited from class org.webmacro.resource.CachingProvider
destroy, flush, get, load, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

AVG_TIMEOUT

public static final long AVG_TIMEOUT
See Also:
Constant Field Values

MAX_TIMEOUT

public static final long MAX_TIMEOUT
See Also:
Constant Field Values

MIN_TIMEOUT

public static final long MIN_TIMEOUT
See Also:
Constant Field Values
Constructor Detail

UrlProvider

public UrlProvider()
Method Detail

getType

public final java.lang.String getType()
We serve up "url" type resources


init

public void init(Broker b,
                 Settings config)
          throws InitException
Description copied from class: CachingProvider
If you override this method be sure and call super.init(...)

Specified by:
init in interface Provider
Overrides:
init in class CachingProvider
Throws:
InitException

load

public final java.lang.Object load(java.lang.String name,
                                   CacheElement ce)
                            throws ResourceException
Load a URL from the specified name and return it. The expire time for the SoftReference will be set to the expire time for the loaded URL.

Http expires information will be obeyed between the MIN_TIMEOUT and MAX_TIMEOUT bounds. URLs which do not specify a timeout, and files from the filesystem, will be cached for AVG_TIMEOUT milliseconds.

Throws:
ResourceException

getUrlLastModified

public static long getUrlLastModified(java.net.URL u)
Utility routine to get the last modification date for a URL. The standard implementation of .getLastModified() doesn't work for file or jar URLs, so we try to be a bit more clever (running the risk that we'll shoot ourselves in the foot, of course.) Also used by BrokerTemplateProvider; maybe this should go somewhere else?


getUrlInputStream

public static java.io.InputStream getUrlInputStream(java.net.URL u)
                                             throws java.io.IOException
Utility routine to get the input stream associated with a URL. It special-cases "file" URLs because this way is faster. If it doesn't work on some platforms (I could imagine some Windows JVM breaking) then we can back off to the standard implementation. Also used by BrokerTemplateProvider; maybe this should go somewhere else?

Throws:
java.io.IOException