Class ServletContextResource
java.lang.Object
org.springframework.core.io.AbstractResource
org.springframework.core.io.AbstractFileResolvingResource
org.springframework.web.context.support.ServletContextResource
- All Implemented Interfaces:
org.springframework.core.io.ContextResource,org.springframework.core.io.InputStreamSource,org.springframework.core.io.Resource
public class ServletContextResource
extends org.springframework.core.io.AbstractFileResolvingResource
implements org.springframework.core.io.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 Summary
ConstructorsConstructorDescriptionServletContextResource(ServletContext servletContext, String path) Create a newServletContextResourcefor the given path. -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.core.io.ResourcecreateRelative(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.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()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.AbstractFileResolvingResource
contentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, isFile, lastModified, readableChannelMethods inherited from class org.springframework.core.io.AbstractResource
getURI, isOpen, toStringMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.core.io.Resource
contentLength, getContentAsByteArray, getContentAsString, getURI, isOpen, lastModified, readableChannel
-
Constructor Details
-
ServletContextResource
Create 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 frompath- the path of the resource
-
-
Method Details
-
getServletContext
Return the ServletContext for this resource. -
getPath
Return the path for this resource. -
exists
public boolean exists()This implementation checksServletContext.getResource.- Specified by:
existsin interfaceorg.springframework.core.io.Resource- Overrides:
existsin classorg.springframework.core.io.AbstractFileResolvingResource- See Also:
-
isReadable
public boolean isReadable()This implementation delegates toServletContext.getResourceAsStream, which returnsnullin case of a non-readable resource (for example, a directory).- Specified by:
isReadablein interfaceorg.springframework.core.io.Resource- Overrides:
isReadablein classorg.springframework.core.io.AbstractFileResolvingResource- See Also:
-
isFile
public boolean isFile()- Specified by:
isFilein interfaceorg.springframework.core.io.Resource- Overrides:
isFilein classorg.springframework.core.io.AbstractFileResolvingResource
-
getInputStream
This implementation delegates toServletContext.getResourceAsStream, but throws a FileNotFoundException if no resource found.- Specified by:
getInputStreamin interfaceorg.springframework.core.io.InputStreamSource- Throws:
IOException- See Also:
-
getURL
This implementation delegates toServletContext.getResource, but throws a FileNotFoundException if no resource found.- Specified by:
getURLin interfaceorg.springframework.core.io.Resource- Overrides:
getURLin classorg.springframework.core.io.AbstractResource- Throws:
IOException- See Also:
-
getFile
This implementation resolves "file:" URLs or alternatively delegates toServletContext.getRealPath, throwing a FileNotFoundException if not found or not resolvable.- Specified by:
getFilein interfaceorg.springframework.core.io.Resource- Overrides:
getFilein classorg.springframework.core.io.AbstractFileResolvingResource- Throws:
IOException- See Also:
-
createRelative
This implementation creates a ServletContextResource, applying the given path relative to the path of the underlying file of this resource descriptor.- Specified by:
createRelativein interfaceorg.springframework.core.io.Resource- Overrides:
createRelativein classorg.springframework.core.io.AbstractResource- See Also:
-
StringUtils.applyRelativePath(String, String)
-
getFilename
This implementation returns the name of the file that this ServletContext resource refers to.- Specified by:
getFilenamein interfaceorg.springframework.core.io.Resource- Overrides:
getFilenamein classorg.springframework.core.io.AbstractResource- See Also:
-
StringUtils.getFilename(String)
-
getDescription
This implementation returns a description that includes the ServletContext resource location.- Specified by:
getDescriptionin interfaceorg.springframework.core.io.Resource
-
getPathWithinContext
- Specified by:
getPathWithinContextin interfaceorg.springframework.core.io.ContextResource
-
equals
This implementation compares the underlying ServletContext resource locations.- Overrides:
equalsin classorg.springframework.core.io.AbstractResource
-
hashCode
public int hashCode()This implementation returns the hash code of the underlying ServletContext resource location.- Overrides:
hashCodein classorg.springframework.core.io.AbstractResource
-