public class

ServletContextResource

extends AbstractFileResolvingResource
implements ContextResource
java.lang.Object
   ↳ org.springframework.core.io.AbstractResource
     ↳ org.springframework.core.io.AbstractFileResolvingResource
       ↳ org.springframework.web.context.support.ServletContextResource

Class Overview

Resource implementation for javax.servlet.ServletContext resources, interpreting relative paths within the web application root directory.

Always supports stream access and URL access, but only allows java.io.File access when the web application archive is expanded.

Summary

Public Constructors
ServletContextResource(ServletContext servletContext, String path)
Create a new ServletContextResource.
Public Methods
Resource createRelative(String relativePath)
This implementation creates a ServletContextResource, applying the given path relative to the path of the underlying file of this resource descriptor.
boolean equals(Object obj)
This implementation compares the underlying ServletContext resource locations.
boolean exists()
This implementation checks ServletContext.getResource.
String getDescription()
This implementation returns a description that includes the ServletContext resource location.
File getFile()
This implementation delegates to ServletContext.getRealPath, but throws a FileNotFoundException if not found or not resolvable.
String getFilename()
This implementation returns the name of the file that this ServletContext resource refers to.
InputStream getInputStream()
This implementation delegates to ServletContext.getResourceAsStream, but throws a FileNotFoundException if no resource found.
final String getPath()
Return the path for this resource.
String getPathWithinContext()
Return the path within the enclosing 'context'.
final ServletContext getServletContext()
Return the ServletContext for this resource.
URL getURL()
This implementation delegates to ServletContext.getResource, but throws a FileNotFoundException if no resource found.
int hashCode()
This implementation returns the hash code of the underlying ServletContext resource location.
[Expand]
Inherited Methods
From class org.springframework.core.io.AbstractFileResolvingResource
From class org.springframework.core.io.AbstractResource
From class java.lang.Object
From interface org.springframework.core.io.ContextResource
From interface org.springframework.core.io.InputStreamSource
From interface org.springframework.core.io.Resource

Public Constructors

public ServletContextResource (ServletContext servletContext, String path)

Create a new ServletContextResource.

The Servlet 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
servletContext the ServletContext to load from
path the path of the resource

Public Methods

public Resource createRelative (String relativePath)

This implementation creates a ServletContextResource, applying the given path relative to the path of the underlying file of this resource descriptor.

Parameters
relativePath the relative path (relative to this resource)
Returns
  • the resource handle for the relative resource

public boolean equals (Object obj)

This implementation compares the underlying ServletContext resource locations.

public boolean exists ()

This implementation checks ServletContext.getResource.

public String getDescription ()

This implementation returns a description that includes the ServletContext resource location.

public File getFile ()

This implementation delegates to ServletContext.getRealPath, but throws a FileNotFoundException if not found or not resolvable.

Throws
IOException

public String getFilename ()

This implementation returns the name of the file that this ServletContext resource refers to.

public InputStream getInputStream ()

This implementation delegates to ServletContext.getResourceAsStream, but throws a FileNotFoundException if no resource found.

Throws
IOException

public final String getPath ()

Return the path for this resource.

public String getPathWithinContext ()

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.

public final ServletContext getServletContext ()

Return the ServletContext for this resource.

public URL getURL ()

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

Throws
IOException

public int hashCode ()

This implementation returns the hash code of the underlying ServletContext resource location.