Interface Context
-
- All Known Implementing Classes:
ContextImpl
,PageTesterContext
public interface Context
An API agnostic version ofServletContext
, used to bridge the gaps between the Servlet API and the Portlet API.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Object
getAttribute(String name)
Returns an attribute previously stored into the context with the given name.List<String>
getAttributeNames()
Returns the names of all attributes of the context, sorted alphabetically.String
getInitParameter(String name)
Returns an initial parameter value defined by servlet.String
getMimeType(String file)
Returns the MIME content type of the specified file, or null if no content type is known.File
getRealFile(String path)
Attempts to find the actual file, on the file system, that would be provided by the servlet container for the given path (which must start with a leading slash).URL
getResource(String path)
Returns a URL to a resource stored within the context.List<String>
getResourcePaths(String path)
Looks for resources within the web application within the supplied path.
-
-
-
Method Detail
-
getResource
URL getResource(String path)
Returns a URL to a resource stored within the context. The path should start with a leading slash.- Parameters:
path
- to the resource (with a leading slash)- Returns:
- the URL for the path, or null if the path does not correspond to a file.
-
getRealFile
File getRealFile(String path)
Attempts to find the actual file, on the file system, that would be provided by the servlet container for the given path (which must start with a leading slash). This may return null if no such file exists, or if the resource in question is packaged inside a WAR. If packaged inside a WAR, the contents may be accessed viagetResource(String)
.- Parameters:
path
- to the resource (with a leading slash)- Returns:
- the underlying File, or null if no such file
-
getInitParameter
String getInitParameter(String name)
Returns an initial parameter value defined by servlet.
-
getResourcePaths
List<String> getResourcePaths(String path)
Looks for resources within the web application within the supplied path. The list will be recurively expanded, as necessary. The path must start with a leading slash, and usually ends with a slash as well.- Parameters:
path
- to search for (should start with a leading slash)- Returns:
- the matches, sorted alphabetically
-
getAttribute
Object getAttribute(String name)
Returns an attribute previously stored into the context with the given name.- Parameters:
name
- used to retrieve the attribute- Returns:
- the attribute, or null if not found
-
getAttributeNames
List<String> getAttributeNames()
Returns the names of all attributes of the context, sorted alphabetically.
-
getMimeType
String getMimeType(String file)
Returns the MIME content type of the specified file, or null if no content type is known. MIME types are built-in to servlet containers and may be futher specified via the web application deployment descriptor.- Parameters:
file
- name of file- Returns:
- the presumed MIME content type, or null if not known
- Since:
- 5.1.0.0
-
-