spring-webmvc-portlet

org.springframework.web.portlet.context
Class PortletContextResource

java.lang.Object
  extended by org.springframework.core.io.AbstractResource
      extended by org.springframework.core.io.AbstractFileResolvingResource
          extended by org.springframework.web.portlet.context.PortletContextResource
All Implemented Interfaces:
org.springframework.core.io.ContextResource, org.springframework.core.io.InputStreamSource, org.springframework.core.io.Resource

public class PortletContextResource
extends org.springframework.core.io.AbstractFileResolvingResource
implements org.springframework.core.io.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(javax.portlet.PortletContext portletContext, java.lang.String path)
          Create a new PortletContextResource.
 
Method Summary
 org.springframework.core.io.Resource createRelative(java.lang.String relativePath)
           
 boolean equals(java.lang.Object obj)
           
 boolean exists()
          This implementation checks PortletContext.getResource.
 java.lang.String getDescription()
           
 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()
           
 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()
           
 javax.portlet.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()
           
 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(javax.portlet.PortletContext portletContext,
                              java.lang.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 javax.portlet.PortletContext getPortletContext()
Return the PortletContext for this resource.


getPath

public final java.lang.String getPath()
Return the path for this resource.


exists

public boolean exists()
This implementation checks PortletContext.getResource.

Specified by:
exists in interface org.springframework.core.io.Resource
Overrides:
exists in class org.springframework.core.io.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 org.springframework.core.io.Resource
Overrides:
isReadable in class org.springframework.core.io.AbstractFileResolvingResource
See Also:
PortletContext.getResourceAsStream(String)

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
This implementation delegates to PortletContext.getResourceAsStream, but throws a FileNotFoundException if not found.

Specified by:
getInputStream in interface org.springframework.core.io.InputStreamSource
Specified by:
getInputStream in interface org.springframework.core.io.Resource
Throws:
java.io.IOException
See Also:
PortletContext.getResourceAsStream(String)

getURL

public java.net.URL getURL()
                    throws java.io.IOException
This implementation delegates to PortletContext.getResource, but throws a FileNotFoundException if no resource found.

Specified by:
getURL in interface org.springframework.core.io.Resource
Overrides:
getURL in class org.springframework.core.io.AbstractResource
Throws:
java.io.IOException
See Also:
PortletContext.getResource(String)

getFile

public java.io.File getFile()
                     throws java.io.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 org.springframework.core.io.Resource
Overrides:
getFile in class org.springframework.core.io.AbstractFileResolvingResource
Throws:
java.io.IOException
See Also:
PortletContext.getResource(String), PortletContext.getRealPath(String)

createRelative

public org.springframework.core.io.Resource createRelative(java.lang.String relativePath)
Specified by:
createRelative in interface org.springframework.core.io.Resource
Overrides:
createRelative in class org.springframework.core.io.AbstractResource

getFilename

public java.lang.String getFilename()
Specified by:
getFilename in interface org.springframework.core.io.Resource
Overrides:
getFilename in class org.springframework.core.io.AbstractResource

getDescription

public java.lang.String getDescription()
Specified by:
getDescription in interface org.springframework.core.io.Resource

getPathWithinContext

public java.lang.String getPathWithinContext()
Specified by:
getPathWithinContext in interface org.springframework.core.io.ContextResource

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class org.springframework.core.io.AbstractResource

hashCode

public int hashCode()
Overrides:
hashCode in class org.springframework.core.io.AbstractResource

spring-webmvc-portlet