Package org.zkoss.web.util.resource
Class ServletContextLocator
java.lang.Object
org.zkoss.web.util.resource.ServletContextLocator
- All Implemented Interfaces:
Locator
Locator based on ServletContext.
- Author:
- tomyeh
-
Constructor Summary
ConstructorsConstructorDescriptionServletContextLocator(javax.servlet.ServletContext ctx) Constructor.ServletContextLocator(javax.servlet.ServletContext ctx, boolean acceptURL) Constructor.ServletContextLocator(javax.servlet.ServletContext ctx, String dir) Constructor.ServletContextLocator(javax.servlet.ServletContext ctx, String dir, String prefix) Constructor.ServletContextLocator(javax.servlet.ServletContext ctx, String dir, String prefix, boolean acceptURL) Constructor.ServletContextLocator(javax.servlet.ServletContext ctx, String dir, String prefix, boolean acceptURL, String externalPrefix) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns the directory used to resolve the relative path, or null if relative path is not allowed.getResource(String name) Finds the resource with the given name.getResourceAsStream(String name) Returns an input stream for reading the specified resource.javax.servlet.ServletContextReturns the servlet context.inthashCode()
-
Constructor Details
-
ServletContextLocator
public ServletContextLocator(javax.servlet.ServletContext ctx) Constructor. A short cut of ServletContextLocator(ctx, null, null, false) -
ServletContextLocator
public ServletContextLocator(javax.servlet.ServletContext ctx, boolean acceptURL) Constructor.- Parameters:
acceptURL- whether to URL (such as file:/, http:// and ftp://) are accepted. In other words,Servlets.getResource(javax.servlet.ServletContext, java.lang.String)will be used.- Since:
- 5.0.7
- See Also:
-
ServletContextLocator
Constructor. A short of ServletContextLocator(ctx, dir, null, false, null).- Parameters:
dir- the directory used when relative path is specified (forgetResource(java.lang.String)andgetResourceAsStream(java.lang.String)). It must be null, empty, or starts with /.
-
ServletContextLocator
Constructor. A short cut of ServletContextLocator(ctx, dir, prefix, false, null). -
ServletContextLocator
public ServletContextLocator(javax.servlet.ServletContext ctx, String dir, String prefix, boolean acceptURL) Constructor. A short cut of ServletContextLocator(ctx, dir, prefix, acceptURL, null). -
ServletContextLocator
public ServletContextLocator(javax.servlet.ServletContext ctx, String dir, String prefix, boolean acceptURL, String externalPrefix) Constructor. For example, if prefix is "/WEB-INF/cwr", then getResource("/abc") will look for "/WEB-INF/cwr/abc" first, and then "/abc".Another example, if prefix is "/WEB-INF/cwr" and dir is "/subdir", then getResource("abc") will look for "/WEB-INF/cwr/subdir/abc".
- Parameters:
dir- the directory used when relative path is specified (forgetResource(java.lang.String)andgetResourceAsStream(java.lang.String)). It must be null, empty, or starts with /.prefix- the directory to prefix each directory specified (forgetResource(java.lang.String)andgetResourceAsStream(java.lang.String)). It must be null, empty, or starts with /.acceptURL- whether to URL (such as file:/, http:// and ftp://) are accepted. In other words,Servlets.getResource(javax.servlet.ServletContext, java.lang.String)will be used.
-
-
Method Details
-
getServletContext
public javax.servlet.ServletContext getServletContext()Returns the servlet context. -
getDirectory
Description copied from interface:LocatorReturns the directory used to resolve the relative path, or null if relative path is not allowed.Note: if the returned directory is not null, it must end with '/'.
- Specified by:
getDirectoryin interfaceLocator
-
getResource
Description copied from interface:LocatorFinds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.- Specified by:
getResourcein interfaceLocator- Returns:
- a URL for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the resource
-
getResourceAsStream
Description copied from interface:LocatorReturns an input stream for reading the specified resource.- Specified by:
getResourceAsStreamin interfaceLocator- Returns:
- an input stream for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the resource
-
hashCode
public int hashCode() -
equals
-