|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.springframework.core.io.AbstractResource org.springframework.web.context.support.ServletContextResource
public class ServletContextResource
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 Summary | |
---|---|
ServletContextResource(ServletContext servletContext,
String path)
Create a new ServletContextResource. |
Method Summary | |
---|---|
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. |
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. |
String |
getPath()
Return the path for this resource. |
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. |
Methods inherited from class org.springframework.core.io.AbstractResource |
---|
exists, isOpen, toString |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public 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 resourceMethod Detail |
---|
public final ServletContext getServletContext()
public final String getPath()
public InputStream getInputStream() throws IOException
ServletContext.getResourceAsStream
,
but throws a FileNotFoundException if no resource found.
IOException
- if the stream could not be openedServletContext.getResourceAsStream(String)
public URL getURL() throws IOException
ServletContext.getResource
,
but throws a FileNotFoundException if no resource found.
getURL
in interface Resource
getURL
in class AbstractResource
IOException
- if the resource cannot be resolved as URL,
i.e. if the resource is not available as descriptorServletContext.getResource(String)
public File getFile() throws IOException
ServletContext.getRealPath
,
but throws a FileNotFoundException if not found or not resolvable.
getFile
in interface Resource
getFile
in class AbstractResource
IOException
- if the resource cannot be resolved as absolute
file path, i.e. if the resource is not available in a file systemServletContext.getRealPath(String)
public Resource createRelative(String relativePath) throws IOException
createRelative
in interface Resource
createRelative
in class AbstractResource
relativePath
- the relative path (relative to this resource)
IOException
- if the relative resource cannot be determinedStringUtils.applyRelativePath(String, String)
public String getFilename()
getFilename
in interface Resource
getFilename
in class AbstractResource
StringUtils.getFilename(String)
public String getDescription()
getDescription
in interface Resource
getDescription
in class AbstractResource
Resource.getDescription()
public boolean equals(Object obj)
equals
in class AbstractResource
AbstractResource.getDescription()
public int hashCode()
hashCode
in class AbstractResource
AbstractResource.getDescription()
|
The Spring Framework | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |