Class ServletContextResource
java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.AbstractFileResolvingResource
org.springframework.web.context.support.ServletContextResource
- All Implemented Interfaces:
- ContextResource,- InputStreamSource,- Resource
public class ServletContextResource
extends AbstractFileResolvingResource
implements ContextResource
Resource implementation for
 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.
- Since:
- 28.12.2003
- Author:
- Juergen Hoeller
- See Also:
- 
Constructor SummaryConstructorsConstructorDescriptionServletContextResource(ServletContext servletContext, String path) Create a newServletContextResourcefor the given path.
- 
Method SummaryModifier and TypeMethodDescriptioncreateRelative(String relativePath) This implementation creates a ServletContextResource, applying the given path relative to the path of the underlying file of this resource descriptor.booleanThis implementation compares the underlying ServletContext resource locations.booleanexists()This implementation checksServletContext.getResource.This implementation returns a description that includes the ServletContext resource location.getFile()This implementation resolves "file:" URLs or alternatively delegates toServletContext.getRealPath, throwing a FileNotFoundException if not found or not resolvable.This implementation returns the name of the file that this ServletContext resource refers to.This implementation delegates toServletContext.getResourceAsStream, but throws a FileNotFoundException if no resource found.final StringgetPath()Return the path for this resource.Return the path within the enclosing 'context'.final ServletContextReturn the ServletContext for this resource.getURL()This implementation delegates toServletContext.getResource, but throws a FileNotFoundException if no resource found.inthashCode()This implementation returns the hash code of the underlying ServletContext resource location.booleanisFile()This implementation always returnsfalse.booleanThis implementation delegates toServletContext.getResourceAsStream, which returnsnullin case of a non-readable resource (for example, a directory).Methods inherited from class org.springframework.core.io.AbstractFileResolvingResourcecontentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, isFile, lastModified, readableChannelMethods inherited from class org.springframework.core.io.AbstractResourcegetURI, isOpen, toStringMethods inherited from class java.lang.Objectclone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.io.ResourcecontentLength, getContentAsByteArray, getContentAsString, getURI, isOpen, lastModified, readableChannel
- 
Constructor Details- 
ServletContextResourceCreate a newServletContextResourcefor the given path.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
 
 
- 
- 
Method Details- 
getServletContextReturn the ServletContext for this resource.
- 
getPathReturn the path for this resource.
- 
existspublic boolean exists()This implementation checksServletContext.getResource.- Specified by:
- existsin interface- Resource
- Overrides:
- existsin class- AbstractFileResolvingResource
- See Also:
 
- 
isReadablepublic boolean isReadable()This implementation delegates toServletContext.getResourceAsStream, which returnsnullin case of a non-readable resource (for example, a directory).- Specified by:
- isReadablein interface- Resource
- Overrides:
- isReadablein class- AbstractFileResolvingResource
- See Also:
 
- 
isFilepublic boolean isFile()Description copied from class:AbstractResourceThis implementation always returnsfalse.- Specified by:
- isFilein interface- Resource
- Overrides:
- isFilein class- AbstractFileResolvingResource
- See Also:
 
- 
getInputStreamThis implementation delegates toServletContext.getResourceAsStream, but throws a FileNotFoundException if no resource found.- Specified by:
- getInputStreamin interface- InputStreamSource
- Returns:
- the input stream for the underlying resource (must not be null)
- Throws:
- FileNotFoundException- if the underlying resource does not exist
- IOException- if the content stream could not be opened
- See Also:
 
- 
getURLThis implementation delegates toServletContext.getResource, but throws a FileNotFoundException if no resource found.- Specified by:
- getURLin interface- Resource
- Overrides:
- getURLin class- AbstractResource
- Throws:
- IOException- if the resource cannot be resolved as URL, i.e. if the resource is not available as a descriptor
- See Also:
 
- 
getFileThis implementation resolves "file:" URLs or alternatively delegates toServletContext.getRealPath, throwing a FileNotFoundException if not found or not resolvable.- Specified by:
- getFilein interface- Resource
- Overrides:
- getFilein class- AbstractFileResolvingResource
- Throws:
- FileNotFoundException- if the resource cannot be resolved as a file
- IOException- in case of general resolution/reading failures
- See Also:
 
- 
createRelativeThis implementation creates a ServletContextResource, applying the given path relative to the path of the underlying file of this resource descriptor.- Specified by:
- createRelativein interface- Resource
- Overrides:
- createRelativein class- AbstractResource
- Parameters:
- relativePath- the relative path (relative to this resource)
- Returns:
- the resource handle for the relative resource
- See Also:
 
- 
getFilenameThis implementation returns the name of the file that this ServletContext resource refers to.- Specified by:
- getFilenamein interface- Resource
- Overrides:
- getFilenamein class- AbstractResource
- See Also:
 
- 
getDescriptionThis implementation returns a description that includes the ServletContext resource location.- Specified by:
- getDescriptionin interface- Resource
- See Also:
 
- 
getPathWithinContextDescription copied from interface:ContextResourceReturn the path within the enclosing 'context'.This is typically path relative to a context-specific root directory, for example, a ServletContext root or a PortletContext root. - Specified by:
- getPathWithinContextin interface- ContextResource
 
- 
equalsThis implementation compares the underlying ServletContext resource locations.- Overrides:
- equalsin class- AbstractResource
- See Also:
 
- 
hashCodepublic int hashCode()This implementation returns the hash code of the underlying ServletContext resource location.- Overrides:
- hashCodein class- AbstractResource
- See Also:
 
 
-