public class Resource extends Object
Used as result of a Resolver
. Next to the resolved URL it also stores the original
scope and path which was used to resolve the url.
Resolver
,
UserContext.getCurrentScope()
Modifier and Type | Method and Description |
---|---|
static Resource |
constantResource(String scopeId,
String path,
URL url)
Creates a new constant resource for the given scope, path and resulting url.
|
static Resource |
dynamicResource(String scopeId,
String path,
URL url)
Creates a new dynamic resource for the given scope, path and resulting url.
|
boolean |
equals(Object obj) |
byte[] |
getContent()
Returns the contents of the resource as byte array.
|
String |
getContentAsString()
Returns the contents of the resource as string.
|
long |
getLastModified()
Computes the last modified date.
|
String |
getPath()
Returns the path which was used to lookup the resource.
|
String |
getScopeId()
Returns the scope id which was set when resolving the resource.
|
URL |
getUrl()
Returns the effective URL pointing to the resolved content
|
int |
hashCode() |
InputStream |
openStream()
Returns the contents of the resource as
InputStream . |
String |
toString() |
public static Resource dynamicResource(String scopeId, String path, URL url)
A dynamic resource might change over time (like a customer specific file on disk). Therefore we frequently check for changes.
scopeId
- the scope which was used to resolve the resourcepath
- the local path pointing to the resourceurl
- the url pointing to the actual contentpublic static Resource constantResource(String scopeId, String path, URL url)
A constant resource will not change over time. An example might be a file in the classpath. Note that in
debug mode (Sirius.isDev()
) all resources are considered dynamic.
scopeId
- the scope which was used to resolve the resourcepath
- the local path pointing to the resourceurl
- the url pointing to the actual contentpublic String getScopeId()
public String getPath()
public URL getUrl()
public InputStream openStream()
InputStream
.public byte[] getContent()
public String getContentAsString()
public long getLastModified()
This value will be cached if the resource is considered constant. However, in development systems the resource will sill be checked in a regular interval.
Also note that the last modified timestamp is at least the timestamp when the resource was resolved. This is required to manage dynamic resources which suddenly are created or vanish.
Copyright © 2018. All rights reserved.