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.
ServletContext.getResourceAsStream(java.lang.String),
ServletContext.getResource(java.lang.String),
ServletContext.getRealPath(java.lang.String)| Constructor and Description |
|---|
ServletContextResource(ServletContext servletContext,
String path)
Create a new ServletContextResource.
|
| Modifier and Type | Method and Description |
|---|---|
org.springframework.core.io.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 resolves "file:" URLs or alternatively delegates to
ServletContext.getRealPath, throwing 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. |
String |
getPath()
Return the path for this resource.
|
String |
getPathWithinContext() |
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.
|
boolean |
isReadable()
This implementation delegates to
ServletContext.getResourceAsStream,
which returns null in case of a non-readable resource (e.g. |
contentLength, customizeConnection, customizeConnection, getFile, getFileForLastModifiedCheck, lastModifiedpublic ServletContextResource(ServletContext servletContext, String 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.
servletContext - the ServletContext to load frompath - the path of the resourcepublic final ServletContext getServletContext()
public final String getPath()
public boolean exists()
ServletContext.getResource.exists in interface org.springframework.core.io.Resourceexists in class org.springframework.core.io.AbstractFileResolvingResourceServletContext.getResource(String)public boolean isReadable()
ServletContext.getResourceAsStream,
which returns null in case of a non-readable resource (e.g. a directory).isReadable in interface org.springframework.core.io.ResourceisReadable in class org.springframework.core.io.AbstractFileResolvingResourceServletContext.getResourceAsStream(String)public InputStream getInputStream() throws IOException
ServletContext.getResourceAsStream,
but throws a FileNotFoundException if no resource found.getInputStream in interface org.springframework.core.io.InputStreamSourceIOExceptionServletContext.getResourceAsStream(String)public URL getURL() throws IOException
ServletContext.getResource,
but throws a FileNotFoundException if no resource found.getURL in interface org.springframework.core.io.ResourcegetURL in class org.springframework.core.io.AbstractResourceIOExceptionServletContext.getResource(String)public File getFile() throws IOException
ServletContext.getRealPath, throwing a FileNotFoundException
if not found or not resolvable.getFile in interface org.springframework.core.io.ResourcegetFile in class org.springframework.core.io.AbstractFileResolvingResourceIOExceptionServletContext.getResource(String),
ServletContext.getRealPath(String)public org.springframework.core.io.Resource createRelative(String relativePath)
createRelative in interface org.springframework.core.io.ResourcecreateRelative in class org.springframework.core.io.AbstractResourceStringUtils.applyRelativePath(String, String)public String getFilename()
getFilename in interface org.springframework.core.io.ResourcegetFilename in class org.springframework.core.io.AbstractResourceStringUtils.getFilename(String)public String getDescription()
getDescription in interface org.springframework.core.io.Resourcepublic String getPathWithinContext()
getPathWithinContext in interface org.springframework.core.io.ContextResourcepublic boolean equals(Object obj)
equals in class org.springframework.core.io.AbstractResourcepublic int hashCode()
hashCode in class org.springframework.core.io.AbstractResource