|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectfnug.resource.AbstractResource
public abstract class AbstractResource
Abstract supertype for Resource
implementations. Reads a classpath resource /fnug/mime.types to get a
FileTypeMap
for getContentType()
.
Nested Class Summary | |
---|---|
protected class |
AbstractResource.Entry
Wrapper class for returning data from readEntry() . |
Field Summary | |
---|---|
static String |
CONTENT_TYPE_TEXT_CSS
Content type text/css . |
static String |
CONTENT_TYPE_TEXT_JAVASCRIPT
Content type text/javascript . |
Constructor Summary | |
---|---|
protected |
AbstractResource(String basePath,
String path)
Constructor setting necessary fields. |
Method Summary | |
---|---|
boolean |
checkModified()
Compares this resource in memory held last modified date with the one on disk (or for aggregated resource, all the aggregates are checked). |
protected boolean |
ensureReadEntry()
Ensures the bytes and lastmodified is read from the underlying resource (such as a file). |
String |
getBasePath()
Base path is the fist half of a Resource.getFullPath() . |
byte[] |
getBytes()
The bytes that is this resource data. |
String |
getContentType()
The mime type of the resource such as text/javascript or text/css . |
String |
getFullPath()
The full path, which is simply two strings concatenated as Resource.getBasePath() + Resource.getPath() . |
long |
getLastModified()
Tells this resource last modified date. |
String |
getPath()
The second part of a full path, that is the part after the base path. |
boolean |
isCss()
Shortcut to determine if this resource is css. |
boolean |
isJs()
Shortcut to determine if this resource is javascript. |
protected abstract AbstractResource.Entry |
readEntry()
Reads the actual entry providing the bytes and lastModified date back to the caller. |
protected abstract long |
readLastModified()
Reads just the last modified date from the actual data source. |
String |
toString()
Returns getPath() . |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface fnug.resource.Resource |
---|
findRequiresTags |
Field Detail |
---|
public static final String CONTENT_TYPE_TEXT_CSS
text/css
.
public static final String CONTENT_TYPE_TEXT_JAVASCRIPT
text/javascript
.
Constructor Detail |
---|
protected AbstractResource(String basePath, String path)
basePath
- The base path of the resource, see getBasePath()
.path
- The path of the resource, see getPath()
.Method Detail |
---|
public String getBasePath()
Resource.getFullPath()
. It is tightly connected to the concept of a
Bundle
, where the bundle is "rooted" at a base path and any resource is resolved from this directory.
A base path always ends with a /.
For example, a bundle may be BundleConfig.basePath()
to be rooted at /my/bundle/
. In this
case we get:
/my/bundle/path/to/resource.js |
|
Resource.getBasePath() |
/my/bundle/ |
Resource.getPath() |
path/to/resource.js |
Resource.getFullPath() |
/my/bundle/path/to/resource.js |
getBasePath
in interface Resource
public String getPath()
A path never starts with a /.
See Resource.getBasePath()
for full example.
getPath
in interface Resource
public String getFullPath()
Resource.getBasePath()
+ Resource.getPath()
.
getFullPath
in interface Resource
public String getContentType()
text/javascript
or text/css
. The implementation
uses a FileTypeMap
to map the file suffix to content type. Notice that this content type never includes
the encoding (which is assumed to be UTF-8).
getContentType
in interface Resource
public boolean isJs()
Resource.getContentType()
.
isJs
in interface Resource
public boolean isCss()
Resource.getContentType()
.
isCss
in interface Resource
public byte[] getBytes()
Resource.checkModified()
.
Notice that for resources pointing to non-existant files Resource.getBytes()
return an empty array, never null
(but Resource.getLastModified()
returns -1).
getBytes
in interface HasLastModifiedBytes
getBytes
in interface Resource
protected final boolean ensureReadEntry()
readEntry()
which needs to be implemented to do the actual reading.
public long getLastModified()
Resource.checkModified()
.
For non-existing resource, Resource.getLastModified()
returns -1.
getLastModified
in interface HasLastModifiedBytes
getLastModified
in interface Resource
HasLastModifiedBytes.getBytes()
.public boolean checkModified()
Resource.getBytes()
or Resource.getLastModified()
.
checkModified
in interface Resource
protected abstract AbstractResource.Entry readEntry()
protected abstract long readLastModified()
checkModified()
to
compare the stored last modified with the one on disk.
public String toString()
getPath()
.
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |