public class ClassWebResource
extends java.lang.Object
Typical use:
getInstance(javax.servlet.ServletContext, java.lang.String)
to init the member when
Servlet.init() is called.
service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
when a request is receive.
Note: it assumes the file being loaded and the output stream is encoded in UTF-8 unless the extendlet handles it differently.
Modifier and Type | Field and Description |
---|---|
static int |
FILTER_INCLUDE
Indicates that the filter is applicable if the request is dispatched
due to the inclusion.
|
static int |
FILTER_REQUEST
Indicates that the filter is applicable if the request comes
directly from the client.
|
static java.lang.String |
PATH_PREFIX
The prefix of path of web resources ("/web").
|
Modifier and Type | Method and Description |
---|---|
Extendlet |
addExtendlet(java.lang.String ext,
Extendlet extlet)
Adds an
Extendlet (a.k.a., resource processor) to process
the resource of the specified extension. |
void |
addFilter(java.lang.String ext,
Filter filter,
int flags)
Adds a filter (
Filter ) to perform filtering task for
the resource of the specified extension. |
static java.net.URL |
getClassResource(java.lang.String uri)
Returns the URL of the resource of the specified URI by searching
only the class path (with
PATH_PREFIX ). |
static java.io.InputStream |
getClassResourceAsStream(java.lang.String uri)
Returns the resource in a stream of the specified URI by searching
only the class path (with
PATH_PREFIX ). |
java.lang.String[] |
getCompress()
Returns the extension that shall be compressed if the browser
supports the compression encoding (accept-encoding).
|
java.lang.String |
getEncodeURLPrefix()
Returns the prefix used to encoding the URL, or null if no prefix.
|
Extendlet |
getExtendlet(java.lang.String ext)
Returns the Extendlet (a.k.a., resource processor) of the
specified extension, or null if not associated.
|
Extendlet |
getExtendlet(java.lang.String ext,
boolean lookup)
Returns the Extendlet (aka., resource processor) of the
specified extension, or null if not associated.
|
Locator |
getExtraLocator()
Returns the extra locator, or null if not available.
|
Filter[] |
getFilters(java.lang.String ext,
int flag)
Returns an array of the filters (
Filter ) of the specified
extension, or null if not associated. |
static ClassWebResource |
getInstance(javax.servlet.ServletContext ctx,
java.lang.String mappingURI)
Returns the instance (singleton in the whole app) for
handling resources located in class path.
|
java.net.URL |
getResource(java.lang.String uri)
Returns the URL of the resource of the specified URI by searching
the extra locator, if any, and then the class path
(with
PATH_PREFIX ). |
java.io.InputStream |
getResourceAsStream(java.lang.String uri)
Returns the resource in a stream of the specified URI by searching
the extra locator, if any, and then, the class path (with
PATH_PREFIX ). |
boolean |
isDebugJS()
Returns whether to debug JavaScript files.
|
Extendlet |
removeExtendlet(java.lang.String ext)
Removes the
Extendlet (a.k.a., resource processor)
for the specified extension. |
boolean |
removeFilter(java.lang.String ext,
Filter filter,
int flags)
Removes the filter (
Filter ) for the specified extension. |
void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response)
Process the request by retrieving the path from the path info.
|
void |
service(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response,
java.lang.String path)
Process the request with the specified path.
|
void |
setCompress(java.lang.String[] exts)
Sets the extension that shall be compressed if the browser
supports the compression encoding (accept-encoding).
|
void |
setDebugJS(boolean debug)
Sets whether to debug JavaScript files.
|
void |
setEncodeURLPrefix(java.lang.String prefix)
Sets the prefix used to encoding the URL.
|
void |
setExtraLocator(Locator loc)
Sets the extra locator.
|
void |
setMappingURI(java.lang.String mappingURI)
Called by WebManager#setUpdateUri when WebManager is created
by HttpSessionListener#contextInitialized
|
public static final java.lang.String PATH_PREFIX
public static final int FILTER_REQUEST
addFilter(java.lang.String, org.zkoss.web.util.resource.Filter, int)
,
Constant Field Valuespublic static final int FILTER_INCLUDE
addFilter(java.lang.String, org.zkoss.web.util.resource.Filter, int)
,
Constant Field Valuespublic static java.net.URL getClassResource(java.lang.String uri)
PATH_PREFIX
).
On the other hand, getResource(java.lang.String)
will search
the extra locator first (getExtraLocator()
) and then
the class path.
public static java.io.InputStream getClassResourceAsStream(java.lang.String uri)
PATH_PREFIX
).
On the other hand, getResourceAsStream(java.lang.String)
will search
the extra locator first (getExtraLocator()
) and then
the class path.
public java.net.URL getResource(java.lang.String uri)
PATH_PREFIX
).
This method becomes non-static since 5.0.0, and it
will search the extra locator (getExtraLocator()
) first.
public java.io.InputStream getResourceAsStream(java.lang.String uri)
PATH_PREFIX
).
This method becomes non-static since 5.0.0, and it
will search the extra locator (getExtraLocator()
) first.
public static final ClassWebResource getInstance(javax.servlet.ServletContext ctx, java.lang.String mappingURI)
public Locator getExtraLocator()
Default: null.
public void setExtraLocator(Locator loc)
Default: null.
public void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws javax.servlet.ServletException, java.io.IOException
Https.getThisPathInfo(javax.servlet.ServletRequest)
to retrieve the path info,
and then invoke service(HttpServletRequest,HttpServletResponse,String)
.
If the path info is not found, nothing is generated.
javax.servlet.ServletException
java.io.IOException
public void service(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, java.lang.String path) throws javax.servlet.ServletException, java.io.IOException
path
- the path related to the class pathjavax.servlet.ServletException
java.io.IOException
public Extendlet getExtendlet(java.lang.String ext, boolean lookup)
ext
- the extension, e.g, "js" and "css.dsp".lookup
- whether to search different combination of the given
extension. For example, if the extension is "js.dsp" and
lookup
is true, it first searches
any extendlet registered for "js.dsp". If not found, it searches
any extendlet for "dsp". However, if lookup
is false,
it searches only "js.dsp".public Extendlet getExtendlet(java.lang.String ext)
It is a shortcut of getExtendlet(ext, true)
.
ext
- the extension, e.g, "js" and "css.dsp".public Extendlet addExtendlet(java.lang.String ext, Extendlet extlet)
Extendlet
(a.k.a., resource processor) to process
the resource of the specified extension.ext
- the extension, e.g, "js" and "css".extlet
- the Extendlet (a.k.a., resource processor) to addpublic Extendlet removeExtendlet(java.lang.String ext)
Extendlet
(a.k.a., resource processor)
for the specified extension.ext
- the extension, e.g, "js" and "css.dsp".public Filter[] getFilters(java.lang.String ext, int flag)
Filter
) of the specified
extension, or null if not associated.
Note: if the extension is "js.dsp", then it searches any filters registered for "js.dsp". If not found, it searches any filters for "dsp". In other words, "dsp" is searched only if no filter is registered for "js.dsp".
ext
- the extension, such as "js" and "css.dsp".flag
- either FILTER_REQUEST
or
and FILTER_INCLUDE
. If 0, FILTER_REQUEST
is assumed.public void addFilter(java.lang.String ext, Filter filter, int flags)
Filter
) to perform filtering task for
the resource of the specified extension.
Unlike addExtendlet(java.lang.String, org.zkoss.web.util.resource.Extendlet)
, multiple filters can be applied to
the same extension. The first one being added will be called first.
ext
- the extensionfilter
- the filterflags
- a combination of FILTER_REQUEST
and FILTER_INCLUDE
. If 0, FILTER_REQUEST
is assumed.public boolean removeFilter(java.lang.String ext, Filter filter, int flags)
Filter
) for the specified extension.flags
- a combination of FILTER_REQUEST
and FILTER_INCLUDE
. If 0, FILTER_REQUEST
is assumed.public void setCompress(java.lang.String[] exts)
Default: null (no compression at all).
exts
- an array of extensions, e.g., {"js", "css", "html"}.
If null or zero-length, it means no compression at all.public java.lang.String[] getCompress()
Default: null (no compression at all).
public boolean isDebugJS()
setDebugJS(boolean)
public void setDebugJS(boolean debug)
Default: false.
If true is specified, it will try to load the original
Java (i.e., uncompressed) file instead of the compressed one.
For example, if service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
is called to load abc.js,
and isDebugJS()
, then service(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
will try
to load abc.src.js first. If not found, it loads ab.js instead.
If isDebugJS()
is false (default),
abc.js is always loaded.
debug
- whether to debug JavaScript files.
If true, the original JavaScript files shall be
loaded instead of the compressed files.public void setMappingURI(java.lang.String mappingURI)
mappingURI
- mapping URI excluding PATH_PREFIX.public void setEncodeURLPrefix(java.lang.String prefix)
ExtendletContext.encodeURL(javax.servlet.ServletRequest, javax.servlet.ServletResponse, java.lang.String)
is called. The prefix is usually the build number, such that browser
won't use the wrong cached version
Default: null (no special encoding).
prefix
- the prefix used to encode URL for the extendlet.
If prefix is not empty and doesn't start with '/', it will
be prefixed with '/'.public java.lang.String getEncodeURLPrefix()
Copyright © 2005-2021 Potix Corporation. All Rights Reserved.