org.webmacro.resource
Class UrlProvider
java.lang.Object
|
+--org.webmacro.resource.CachingProvider
|
+--org.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.
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 java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
AVG_TIMEOUT
public static final long AVG_TIMEOUT
MAX_TIMEOUT
public static final long MAX_TIMEOUT
MIN_TIMEOUT
public static final long MIN_TIMEOUT
UrlProvider
public UrlProvider()
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(...)
- Overrides:
init
in class CachingProvider
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.
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?