Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## org.springframework.web.portlet.context
Class PortletContextResource

    java.lang.Object
      org.springframework.core.io.AbstractResource
          org.springframework.core.io.AbstractFileResolvingResource
              org.springframework.web.portlet.context.PortletContextResource

All Implemented Interfaces:
  ContextResource, InputStreamSource, Resource

    public class PortletContextResource

extends AbstractFileResolvingResource
implements ContextResource

`Resource` implementation for `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.

Since:
  2.0
Author:
  Juergen Hoeller, John A. Lewis
See Also:
  `PortletContext.getResourceAsStream(java.lang.String)`, `PortletContext.getRealPath(java.lang.String)`

Constructor Summary
`PortletContextResource(PortletContext portletContext, String path)` Create a new PortletContextResource.

Method Summary
`Resource` | `createRelative(String relativePath)` This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.
`boolean` | `equals(Object obj)` This implementation compares description strings.
`boolean` | `exists()` This implementation checks `PortletContext.getResource`.
`String` | `getDescription()` Return a description for this resource, to be used for error output when working with the resource.
`File` | `getFile()` This implementation resolves "file:" URLs or alternatively delegates to `PortletContext.getRealPath`, throwing a FileNotFoundException if not found or not resolvable.
`String` | `getFilename()` This implementation always returns `null`, assuming that this resource type does not have a filename.
`InputStream` | `getInputStream()` This implementation delegates to `PortletContext.getResourceAsStream`, but throws a FileNotFoundException if not found.
`String` | `getPath()` Return the path for this resource.
`String` | `getPathWithinContext()` Return the path within the enclosing 'context'.
`PortletContext` | `getPortletContext()` Return the PortletContext for this resource.
`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.

Methods inherited from class org.springframework.core.io.AbstractFileResolvingResource
`contentLength, getFile, getFileForLastModifiedCheck, lastModified`

Methods inherited from class org.springframework.core.io.AbstractResource
`getURI, isOpen, toString`

Methods inherited from class java.lang.Object
`clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

Methods inherited from interface org.springframework.core.io.Resource
`contentLength, getURI, isOpen, lastModified`

Constructor Detail

### PortletContextResource

    public PortletContextResource(PortletContext portletContext,
                                  String path)

  Create a new PortletContextResource.

  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.

  Parameters:
    `portletContext` - the PortletContext to load from
    `path` - the path of the resource

Method Detail

### getPortletContext

    public final PortletContext getPortletContext()

  Return the PortletContext for this resource.

### getPath

    public final String getPath()

  Return the path for this resource.

### exists

    public boolean exists()

  This implementation checks `PortletContext.getResource`.

  Specified by:
    `exists` in interface `Resource`
  Overrides:
    `exists` in class `AbstractFileResolvingResource`
  See Also:
    `PortletContext.getResource(String)`

### isReadable

    public boolean isReadable()

  This implementation delegates to `PortletContext.getResourceAsStream`, which returns `null` in case of a non-readable resource (e.g. a directory).

  Specified by:
    `isReadable` in interface `Resource`
  Overrides:
    `isReadable` in class `AbstractFileResolvingResource`
  See Also:
    `PortletContext.getResourceAsStream(String)`

### getInputStream

    public InputStream getInputStream()
                               throws IOException

  This implementation delegates to `PortletContext.getResourceAsStream`, but throws a FileNotFoundException if not found.

  Specified by:
    `getInputStream` in interface `InputStreamSource`
  Returns:
    the input stream for the underlying resource (must not be `null`)
  Throws:
    `IOException` - if the stream could not be opened
  See Also:
    `PortletContext.getResourceAsStream(String)`

### getURL

    public URL getURL()
               throws IOException

  This implementation delegates to `PortletContext.getResource`, but throws a FileNotFoundException if no resource found.

  Specified by:
    `getURL` in interface `Resource`
  Overrides:
    `getURL` in class `AbstractResource`
  Throws:
    `IOException` - if the resource cannot be resolved as URL, i.e. if the resource is not available as descriptor
  See Also:
    `PortletContext.getResource(String)`

### getFile

    public File getFile()
                 throws IOException

  This implementation resolves "file:" URLs or alternatively delegates to `PortletContext.getRealPath`, throwing a FileNotFoundException if not found or not resolvable.

  Specified by:
    `getFile` in interface `Resource`
  Overrides:
    `getFile` in class `AbstractFileResolvingResource`
  Throws:
    `IOException` - if the resource cannot be resolved as absolute file path, i.e. if the resource is not available in a file system
  See Also:
    `PortletContext.getResource(String)`, `PortletContext.getRealPath(String)`

### createRelative

    public Resource createRelative(String relativePath)

  Description copied from class: `AbstractResource`
  This implementation throws a FileNotFoundException, assuming that relative resources cannot be created for this resource.

  Specified by:
    `createRelative` in interface `Resource`
  Overrides:
    `createRelative` in class `AbstractResource`
  Parameters:
    `relativePath` - the relative path (relative to this resource)
  Returns:
    the resource handle for the relative resource

### getFilename

    public String getFilename()

  Description copied from class: `AbstractResource`
  This implementation always returns `null`, assuming that this resource type does not have a filename.

  Specified by:
    `getFilename` in interface `Resource`
  Overrides:
    `getFilename` in class `AbstractResource`

### getDescription

    public String getDescription()

  Description copied from interface: `Resource`
  Return a description for this resource, to be used for error output when working with the resource.

  Implementations are also encouraged to return this value from their `toString` method.

  Specified by:
    `getDescription` in interface `Resource`
  See Also:
    `Object.toString()`

### getPathWithinContext

    public String getPathWithinContext()

  Description copied from interface: `ContextResource`
  Return the path within the enclosing 'context'.

  This is typically path relative to a context-specific root directory, e.g. a ServletContext root or a PortletContext root.

  Specified by:
    `getPathWithinContext` in interface `ContextResource`

### equals

    public boolean equals(Object obj)

  Description copied from class: `AbstractResource`
  This implementation compares description strings.

  Overrides:
    `equals` in class `AbstractResource`
  See Also:
    `Resource.getDescription()`

### hashCode

    public int hashCode()

  Description copied from class: `AbstractResource`
  This implementation returns the description's hash code.

  Overrides:
    `hashCode` in class `AbstractResource`
  See Also:
    `Resource.getDescription()`

Overview | Package | Class | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD