public class PortletContextResource extends AbstractFileResolvingResource implements ContextResource
Resource
implementation for
javax.portlet.PortletContext
resources, interpreting
relative paths within the portlet application root directory.
Always supports stream access and URL access, but only allows
java.io.File
access when the portlet application archive
is expanded.
javax.portlet.PortletContext#getResourceAsStream
,
javax.portlet.PortletContext#getRealPath
Modifier and Type | Field and Description |
---|---|
private java.lang.String |
path |
private PortletContext |
portletContext |
Constructor and Description |
---|
PortletContextResource(PortletContext portletContext,
java.lang.String path)
Create a new PortletContextResource.
|
Modifier and Type | Method and Description |
---|---|
Resource |
createRelative(java.lang.String relativePath)
This implementation throws a FileNotFoundException, assuming
that relative resources cannot be created for this resource.
|
boolean |
equals(java.lang.Object obj)
This implementation compares description strings.
|
boolean |
exists()
This implementation checks
PortletContext.getResource . |
java.lang.String |
getDescription()
Return a description for this resource,
to be used for error output when working with the resource.
|
java.io.File |
getFile()
This implementation resolves "file:" URLs or alternatively delegates to
PortletContext.getRealPath , throwing a FileNotFoundException
if not found or not resolvable. |
java.lang.String |
getFilename()
This implementation always returns
null ,
assuming that this resource type does not have a filename. |
java.io.InputStream |
getInputStream()
This implementation delegates to
PortletContext.getResourceAsStream ,
but throws a FileNotFoundException if not found. |
java.lang.String |
getPath()
Return the path for this resource.
|
java.lang.String |
getPathWithinContext()
Return the path within the enclosing 'context'.
|
PortletContext |
getPortletContext()
Return the PortletContext for this resource.
|
java.net.URL |
getURL()
This implementation delegates to
PortletContext.getResource ,
but throws a FileNotFoundException if no resource found. |
int |
hashCode()
This implementation returns the description's hash code.
|
boolean |
isReadable()
This implementation delegates to
PortletContext.getResourceAsStream ,
which returns null in case of a non-readable resource (e.g. |
contentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, lastModified
getURI, isOpen, toString
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
contentLength, getURI, isOpen, lastModified
private final PortletContext portletContext
private final java.lang.String path
public PortletContextResource(PortletContext portletContext, java.lang.String path)
The Portlet spec requires that resource paths start with a slash, even if many containers accept paths without leading slash too. Consequently, the given path will be prepended with a slash if it doesn't already start with one.
portletContext
- the PortletContext to load frompath
- the path of the resourcepublic final PortletContext getPortletContext()
public final java.lang.String getPath()
public boolean exists()
PortletContext.getResource
.exists
in interface Resource
exists
in class AbstractFileResolvingResource
javax.portlet.PortletContext#getResource(String)
public boolean isReadable()
PortletContext.getResourceAsStream
,
which returns null
in case of a non-readable resource (e.g. a directory).isReadable
in interface Resource
isReadable
in class AbstractFileResolvingResource
javax.portlet.PortletContext#getResourceAsStream(String)
public java.io.InputStream getInputStream() throws java.io.IOException
PortletContext.getResourceAsStream
,
but throws a FileNotFoundException if not found.getInputStream
in interface InputStreamSource
null
)java.io.FileNotFoundException
- if the underlying resource doesn't existjava.io.IOException
- if the content stream could not be openedjavax.portlet.PortletContext#getResourceAsStream(String)
public java.net.URL getURL() throws java.io.IOException
PortletContext.getResource
,
but throws a FileNotFoundException if no resource found.getURL
in interface Resource
getURL
in class AbstractResource
java.io.IOException
- if the resource cannot be resolved as URL,
i.e. if the resource is not available as descriptorjavax.portlet.PortletContext#getResource(String)
public java.io.File getFile() throws java.io.IOException
PortletContext.getRealPath
, throwing a FileNotFoundException
if not found or not resolvable.getFile
in interface Resource
getFile
in class AbstractFileResolvingResource
java.io.FileNotFoundException
- if the resource cannot be resolved as
absolute file path, i.e. if the resource is not available in a file systemjava.io.IOException
- in case of general resolution/reading failuresjavax.portlet.PortletContext#getResource(String)
,
javax.portlet.PortletContext#getRealPath(String)
public Resource createRelative(java.lang.String relativePath)
AbstractResource
createRelative
in interface Resource
createRelative
in class AbstractResource
relativePath
- the relative path (relative to this resource)public java.lang.String getFilename()
AbstractResource
null
,
assuming that this resource type does not have a filename.getFilename
in interface Resource
getFilename
in class AbstractResource
public java.lang.String getDescription()
Resource
Implementations are also encouraged to return this value
from their toString
method.
getDescription
in interface Resource
Object.toString()
public java.lang.String getPathWithinContext()
ContextResource
This is typically path relative to a context-specific root directory, e.g. a ServletContext root or a PortletContext root.
getPathWithinContext
in interface ContextResource
public boolean equals(java.lang.Object obj)
AbstractResource
equals
in class AbstractResource
Resource.getDescription()
public int hashCode()
AbstractResource
hashCode
in class AbstractResource
Resource.getDescription()