resources, interpreting
relative paths within the web application root directory.
| Method from org.springframework.web.context.support.ServletContextResource Detail: |
public Resource createRelative(String relativePath) {
String pathToUse = StringUtils.applyRelativePath(this.path, relativePath);
return new ServletContextResource(this.servletContext, pathToUse);
}
This implementation creates a ServletContextResource, applying the given path
relative to the path of the underlying file of this resource descriptor. |
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
if (obj instanceof ServletContextResource) {
ServletContextResource otherRes = (ServletContextResource) obj;
return (this.servletContext.equals(otherRes.servletContext) && this.path.equals(otherRes.path));
}
return false;
}
This implementation compares the underlying ServletContext resource locations. |
public boolean exists() {
try {
URL url = this.servletContext.getResource(this.path);
return (url != null);
}
catch (MalformedURLException ex) {
return false;
}
}
This implementation checks ServletContext.getResource. |
public String getDescription() {
return "ServletContext resource [" + this.path + "]";
}
This implementation returns a description that includes the ServletContext
resource location. |
public File getFile() throws IOException {
String realPath = WebUtils.getRealPath(this.servletContext, this.path);
return new File(realPath);
}
This implementation delegates to ServletContext.getRealPath,
but throws a FileNotFoundException if not found or not resolvable. |
public String getFilename() {
return StringUtils.getFilename(this.path);
}
This implementation returns the name of the file that this ServletContext
resource refers to. |
public InputStream getInputStream() throws IOException {
InputStream is = this.servletContext.getResourceAsStream(this.path);
if (is == null) {
throw new FileNotFoundException("Could not open " + getDescription());
}
return is;
}
This implementation delegates to ServletContext.getResourceAsStream,
but throws a FileNotFoundException if no resource found. |
public final String getPath() {
return this.path;
}
Return the path for this resource. |
public String getPathWithinContext() {
return this.path;
}
|
public final ServletContext getServletContext() {
return this.servletContext;
}
Return the ServletContext for this resource. |
public URL getURL() throws IOException {
URL url = this.servletContext.getResource(this.path);
if (url == null) {
throw new FileNotFoundException(
getDescription() + " cannot be resolved to URL because it does not exist");
}
return url;
}
This implementation delegates to ServletContext.getResource,
but throws a FileNotFoundException if no resource found. |
public int hashCode() {
return this.path.hashCode();
}
This implementation returns the hash code of the underlying
ServletContext resource location. |