|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface Resource
Abstraction of a file with a name, bytes and last modified date. Resources can either be a direct representation of a
file or be produced by name other resources. Resource instances exist also for non-existant files, in which case
getBytes()
returns an empty array, and getLastModified()
returns -1.
Resources are cached in memory.
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). |
List<String> |
findRequiresTags()
Scans the resource for the sequence " * @requires " which makes this resource depend on others. |
String |
getBasePath()
Base path is the fist half of a 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 getBasePath() + 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. |
Method Detail |
---|
String getBasePath()
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 |
|
getBasePath() |
/my/bundle/ |
getPath() |
path/to/resource.js |
getFullPath() |
/my/bundle/path/to/resource.js |
String getPath()
A path never starts with a /.
See getBasePath()
for full example.
String getFullPath()
getBasePath()
+ getPath()
.
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).
boolean isJs()
getContentType()
.
boolean isCss()
getContentType()
.
byte[] getBytes()
checkModified()
.
Notice that for resources pointing to non-existant files getBytes()
return an empty array, never null
(but getLastModified()
returns -1).
getBytes
in interface HasLastModifiedBytes
long getLastModified()
checkModified()
.
For non-existing resource, getLastModified()
returns -1.
getLastModified
in interface HasLastModifiedBytes
HasLastModifiedBytes.getBytes()
.boolean checkModified()
getBytes()
or getLastModified()
.
List<String> findRequiresTags()
* @requires
" which makes this resource depend on others. This
will only happen if the resource is found to be text, that is getContentType()
must be
text/xxx
, such as text/javascript
.
Example:
/**
* @requires some/other/javascript.js
* @requires some/other/styles.css
*/
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |