CCM NG/ccm-core: Dispatcher used none-locale save DateFormat

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4382 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-10-17 06:57:02 +00:00
parent 44ddf8a8f4
commit 42e18ee8cb
1 changed files with 321 additions and 255 deletions

View File

@ -54,8 +54,8 @@ import org.apache.log4j.Logger;
import java.net.URLEncoder;
/**
* Class static helper methods for request dispatching.
* Contains various generally useful procedural abstractions.
* Class static helper methods for request dispatching. Contains various
* generally useful procedural abstractions.
*
* @author Bill Schneider
* @since 4.5
@ -63,10 +63,12 @@ import java.net.URLEncoder;
*/
public final class DispatcherHelper implements DispatcherConstants {
/** Internal logger instance to faciliate debugging. Enable logging output
* by editing /WEB-INF/conf/log4j.properties int hte runtime environment
* and set com.arsdigita.dispatcher.DispatcherHelper=DEBUG
* by uncommenting or adding the line. */
/**
* Internal logger instance to faciliate debugging. Enable logging output by
* editing /WEB-INF/conf/log4j.properties int hte runtime environment and
* set com.arsdigita.dispatcher.DispatcherHelper=DEBUG by uncommenting or
* adding the line.
*/
private static final Logger s_log = Logger.getLogger(DispatcherHelper.class);
private static String s_webappCtx;
private static String s_staticURL;
@ -80,7 +82,8 @@ public final class DispatcherHelper implements DispatcherConstants {
return;
}
rfc1123_formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
rfc1123_formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z",
Locale.ROOT);
rfc1123_formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
s_staticURL = DispatcherConfig.getConfig().getStaticUrlPrefix();
@ -90,17 +93,20 @@ public final class DispatcherHelper implements DispatcherConstants {
initialized = true;
}
/** The current HttpServletRequest. */
/**
* The current HttpServletRequest.
*/
private static final ThreadLocal s_request = new ThreadLocal();
/** null constructor, private so no one can instantiate! */
/**
* null constructor, private so no one can instantiate!
*/
private DispatcherHelper() {
}
/**
* Return default cache expiry.
* Default is specified in the configuration file (registry) if not
* otherweise set.
* Return default cache expiry. Default is specified in the configuration
* file (registry) if not otherweise set.
*
* @return default cache expiry
*/
@ -125,12 +131,12 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Returns the URL path (relative to the webapp root) for the
* current (calling) resource. This works around the quirk that,
* if servlet A includes servlet B, calling getRequestURI() in B
* returns "A" and not "B".
* Returns the URL path (relative to the webapp root) for the current
* (calling) resource. This works around the quirk that, if servlet A
* includes servlet B, calling getRequestURI() in B returns "A" and not "B".
*
* @param req
*
* @return the URL path (relative to the webapp root) for the currently
* executing resource.
*/
@ -156,7 +162,9 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Gets the application context from the request attributes.
*
* @param req
*
* @return the application context from the request attributes.
*/
public static RequestContext getRequestContext(HttpServletRequest req) {
@ -177,14 +185,16 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Sets the current request context as a request attribute for
* later retrieval.
* Sets the current request context as a request attribute for later
* retrieval.
*
* @param req the current request object
* @param ac the current request context
*
* @post DispatcherHelper.getRequestContext(req) == ac
*/
public static void setRequestContext(HttpServletRequest req, RequestContext ac) {
public static void setRequestContext(HttpServletRequest req,
RequestContext ac) {
req.setAttribute(REQUEST_CONTEXT_ATTR, ac);
}
@ -219,20 +229,22 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Forwards the request from this resource to another resource at
* the servlet-container level. This is a wrapper for
* javax.servlet.RequestDispatcher
* and is intended to hide the fact that you can't "forward" a request
* once you've done an "include" in it.
* @param path the URL of the resource, relative to the webapp
* root. For example, if you request a JSP page with /context/foo/bar,
* you would call this method with path == /foo/bar.
* Forwards the request from this resource to another resource at the
* servlet-container level. This is a wrapper for
* javax.servlet.RequestDispatcher and is intended to hide the fact that you
* can't "forward" a request once you've done an "include" in it.
*
* @param path the URL of the resource, relative to the webapp root. For
* example, if you request a JSP page with /context/foo/bar, you
* would call this method with path == /foo/bar.
* @param req the current request
* @param resp the current response
* @param sctx the current servlet context
* @exception java.io.IOException may be propagated from target resource
* @exception javax.servlet.ServletException may be
* propagated from target resource
*
* @exception java.io.IOException may be propagated from target
* resource
* @exception javax.servlet.ServletException may be propagated from target
* resource
*/
public static void forwardRequestByPath(String path,
HttpServletRequest req,
@ -246,9 +258,11 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Equivalent to <code>forwardRequestByPath(path, req, resp,
* DispatcherHelper.getRequestContext(req).getServletContext())</code>.
*
* @param path
* @param req
* @param resp
*
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
@ -256,28 +270,29 @@ public final class DispatcherHelper implements DispatcherConstants {
HttpServletRequest req,
HttpServletResponse resp)
throws IOException, ServletException {
ServletContext sctx =
DispatcherHelper.getRequestContext(req).getServletContext();
ServletContext sctx = DispatcherHelper.getRequestContext(req)
.getServletContext();
forwardRequestByPath(path, req, resp, sctx);
}
/**
* Forwards the request from this resource to another resource at
* the JSP container level. This is a wrapper for
* <code>PageContext.forward</code> and <code>PageContext.include</code>
* and is intended to transparently switch between "forward" and
* "include" depending on whether or not an include has already been
* done on the request.
* Forwards the request from this resource to another resource at the JSP
* container level. This is a wrapper for <code>PageContext.forward</code>
* and <code>PageContext.include</code> and is intended to transparently
* switch between "forward" and "include" depending on whether or not an
* include has already been done on the request.
*
* @param path the URL of the resource, relative to the webapp
* root. For example, if you request a JSP page with /context/foo/bar,
* you would call this method with path == /foo/bar.
* @param path the URL of the resource, relative to the webapp root.
* For example, if you request a JSP page with
* /context/foo/bar, you would call this method with path
* == /foo/bar.
*
* @param pageContext the JSP page context
*
* @exception java.io.IOException may be propagated from target resource
* @exception javax.servlet.ServletException may be
* propagated from target resource
* @exception java.io.IOException may be propagated from target
* resource
* @exception javax.servlet.ServletException may be propagated from target
* resource
*/
public static void forwardRequestByPath(String path,
PageContext pageContext)
@ -300,18 +315,20 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Forwards the request from this resource to a servlet resource
* (named in server.xml) at the servlet-container level. This is a
* wrapper for javax.servlet.RequestDispatcher and is intended to hide
* the fact that you can't "forward" a request once you've done an
* "include" in it.
* Forwards the request from this resource to a servlet resource (named in
* server.xml) at the servlet-container level. This is a wrapper for
* javax.servlet.RequestDispatcher and is intended to hide the fact that you
* can't "forward" a request once you've done an "include" in it.
*
* @param name the named servlet to forward to
* @param req the current request
* @param resp the current response
* @param sctx the current servlet context
* @exception java.io.IOException may be propagated from target resource
* @exception javax.servlet.ServletException may be
* propagated from target resource
*
* @exception java.io.IOException may be propagated from target
* resource
* @exception javax.servlet.ServletException may be propagated from target
* resource
*/
public static void forwardRequestByName(String name,
HttpServletRequest req,
@ -329,6 +346,7 @@ public final class DispatcherHelper implements DispatcherConstants {
* @param name
* @param req
* @param resp
*
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
@ -342,27 +360,38 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Given the name of a resource in the file system that is missing an
* extension, picks an extension that matches. Serves a file
* with a <code>.jsp</code> extension first, if available.
* Otherwise picks any file that matches. For directories, it tacks on
* the "index" filename plus the extension.
* extension, picks an extension that matches. Serves a file with a
* <code>.jsp</code> extension first, if available. Otherwise picks any file
* that matches. For directories, it tacks on the "index" filename plus the
* extension.
*
* <b><font color="red">Unsupported</font></b>
*
* @param abstractFile the extensionless file
* @param actx the current application context
* @return a filename suffix (".jsp", "index.html", etc.) such
* that (abstractFile.getAbsolutePath() + suffix) is a valid file
* in the filesystem
*
* @return a filename suffix (".jsp", "index.html", etc.) such that
* (abstractFile.getAbsolutePath() + suffix) is a valid file in the
* filesystem
*
* @exception com.arsdigita.dispatcher.RedirectException if the
* requested file is a directory and the original request URL does
* not end with a trailing slash.
* @exception java.io.FileNotFoundException if no matching
* file exists.
* requested
* file is a
* directory
* and the
* original
* request URL
* does not
* end with a
* trailing
* slash.
* @exception java.io.FileNotFoundException if no
* matching
* file
* exists.
* @throws com.arsdigita.dispatcher.DirectoryListingException
* @deprecated abstract URLs are no longer supported. Use
* extensions when your file on disk has an extension.
* @deprecated abstract URLs are no longer supported. Use extensions when
* your file on disk has an extension.
*/
public static String resolveAbstractFile(File abstractFile,
RequestContext actx)
@ -392,7 +421,6 @@ public final class DispatcherHelper implements DispatcherConstants {
dirToSearch = new File(abstractFile.getParent());
}
File filesInDir[] = dirToSearch.listFiles();
final String extensionSearchList[] = {".jsp"};
@ -444,18 +472,21 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* If the given servlet request is wrapped in one of our own classes, returns
* the original (unwrapped) request object and stores a reference
* to the request wrapper in the request attributes of the returned request.
* If the given servlet request is wrapped in one of our own classes,
* returns the original (unwrapped) request object and stores a reference to
* the request wrapper in the request attributes of the returned request.
* Otherwise just returns the request object.
*
* @param req the servlet request
* @return the original servlet request object, as created by
* the servlet container. This can be used as a parameter for forward().
*
* @return the original servlet request object, as created by the servlet
* container. This can be used as a parameter for forward().
*/
public static HttpServletRequest restoreOriginalRequest(HttpServletRequest req) {
public static HttpServletRequest restoreOriginalRequest(
HttpServletRequest req) {
if (req instanceof MultipartHttpServletRequest) {
HttpServletRequest oldReq = (HttpServletRequest) req.getAttribute(ORIGINAL_REQUEST_ATTR);
HttpServletRequest oldReq = (HttpServletRequest) req.getAttribute(
ORIGINAL_REQUEST_ATTR);
oldReq.setAttribute(WRAPPED_REQUEST_ATTR, req);
req = oldReq;
}
@ -463,16 +494,17 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* If we've stored a reference to a request wrapper as a request
* attribute to the current servlet request, returns the wrapper object.
* Otherwise, returns the request object.
* If we've stored a reference to a request wrapper as a request attribute
* to the current servlet request, returns the wrapper object. Otherwise,
* returns the request object.
*
* @param req the current servlet request
*
* @return the previously created wrapper around the current servlet
* request, if any;
* otherwise returns the request object.
* request, if any; otherwise returns the request object.
*/
public static HttpServletRequest restoreRequestWrapper(HttpServletRequest req) {
public static HttpServletRequest restoreRequestWrapper(
HttpServletRequest req) {
// switch back wrapped request if we're forwarded
// from somewhere else.
Object maybeWrappedReq = req.getAttribute(WRAPPED_REQUEST_ATTR);
@ -488,7 +520,9 @@ public final class DispatcherHelper implements DispatcherConstants {
* or restore the original wrapper if it was already wrapped.
*
* @param sreq
*
* @return
*
* @throws java.io.IOException
* @throws javax.servlet.ServletException
*/
@ -501,15 +535,15 @@ public final class DispatcherHelper implements DispatcherConstants {
&& type.toLowerCase().startsWith("multipart")) {
final HttpServletRequest orig = sreq;
final HttpServletRequest previous =
DispatcherHelper.restoreRequestWrapper(orig);
final HttpServletRequest previous = DispatcherHelper
.restoreRequestWrapper(orig);
if (previous instanceof MultipartHttpServletRequest) {
s_log.debug("Build new multipart request from previous "
+ previous + " and current " + orig);
MultipartHttpServletRequest previousmp =
(MultipartHttpServletRequest) previous;
MultipartHttpServletRequest previousmp
= (MultipartHttpServletRequest) previous;
sreq = new MultipartHttpServletRequest(previousmp,
orig);
@ -519,7 +553,8 @@ public final class DispatcherHelper implements DispatcherConstants {
s_log.debug("The main request is now " + sreq);
} else {
s_log.debug("The request is a new multipart; wrapping the request "
s_log.debug(
"The request is a new multipart; wrapping the request "
+ "object");
try {
sreq = new MultipartHttpServletRequest(sreq);
@ -538,6 +573,7 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Stores req as request attribute of oldReq.
*
* @param req the current servlet request (wrapper)
* @param oldReq the original servlet request
*/
@ -547,19 +583,19 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Redirects the client to the given URL without rewriting it. Delegates
* to the sendExternalRedirect method.
* Redirects the client to the given URL without rewriting it. Delegates to
* the sendExternalRedirect method.
*
* @throws java.io.IOException
* @deprecated This method does not rewrite URLs. Use
* sendRedirect(HttpServletRequest, HttpServletResponse, String) for
* redirects within this ACS or
* sendExternalRedirect(HttpServletResponse, String) for redirects to
* sites outside this ACS.
* redirects within this ACS or sendExternalRedirect(HttpServletResponse,
* String) for redirects to sites outside this ACS.
*
* @param resp the current response
* @param url the destination URL for redirect
**/
*
*/
public static void sendRedirect(HttpServletResponse resp,
String url)
throws IOException {
@ -570,12 +606,14 @@ public final class DispatcherHelper implements DispatcherConstants {
* Rewrites the given URL and redirects the client to the rewritten URL.
* This method should be used for redirects within this ACS.
*
* @param req the current request; used as a source for parameters
* for URL rewriting
* @param req the current request; used as a source for parameters for URL
* rewriting
* @param resp the current response
* @param url the destination URL for redirect
*
* @throws java.io.IOException
**/
*
*/
public static void sendRedirect(HttpServletRequest req,
HttpServletResponse resp,
String url)
@ -584,13 +622,15 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Redirects the client to the given URL without rewriting it. This
* method should be used for redirects to sites outside this ACS.
* Redirects the client to the given URL without rewriting it. This method
* should be used for redirects to sites outside this ACS.
*
* @param resp the current response
* @param url the destination URL for redirect
*
* @throws java.io.IOException
**/
*
*/
public static void sendExternalRedirect(HttpServletResponse resp,
String url)
throws IOException {
@ -634,7 +674,8 @@ public final class DispatcherHelper implements DispatcherConstants {
s_log.debug("Setting destination to " + destination);
}
} else {
final ParameterMap params = ParameterMap.fromString(url.substring(sep + 1));
final ParameterMap params = ParameterMap.fromString(url
.substring(sep + 1));
destination = URL.there(req, url.substring(0, sep), params);
if (s_log.isDebugEnabled()) {
@ -655,11 +696,12 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Adds a <code>ParameterProvider</code> to the URLRewriter engine.
* <code>ParameterProvider</code>s are used when
* <code>encodeRedirectURL</code> and <code>encodeURL</code> are
* called. They add global state parameters like the session ID (for
* cookieless login) to URLs for links and redirects.
* <code>encodeRedirectURL</code> and <code>encodeURL</code> are called.
* They add global state parameters like the session ID (for cookieless
* login) to URLs for links and redirects.
*
* @param provider the parameter provider to add
*
* @see com.arsdigita.util.URLRewriter#addParameterProvider
* @deprecated use URLRewriter.addParameterProvider
*/
@ -669,9 +711,11 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Clears all parameter providers.
*
* @deprecated use URLRewriter#clearParameterProviders() instead
* @see com.arsdigita.util.URLRewriter#clearParameterProviders()
**/
*
*/
public static void clearParameterProviders() {
URLRewriter.clearParameterProviders();
}
@ -681,36 +725,42 @@ public final class DispatcherHelper implements DispatcherConstants {
* provider is set.
*
* @return a set of Bebop parameter models.
*
* @deprecated use URLRewriter.getGlobalModels instead
* @see com.arsdigita.util.URLRewriter#getGlobalModels()
**/
*
*/
public static Set getGlobalModels() {
return URLRewriter.getGlobalModels();
}
/**
* Returns the set of global URL parameters for the given request, or
* the empty set if no provider is set.
* Returns the set of global URL parameters for the given request, or the
* empty set if no provider is set.
*
* @param req the current request
*
* @return a Set of Bebop parameter data.
*
* @deprecated use URLRewriter.getGlobalParams instead
**/
*
*/
public static Set getGlobalParams(HttpServletRequest req) {
return URLRewriter.getGlobalParams(req);
}
/**
* Prepares the given URL for a client link. If no providers are
* set, has no effect.
* Prepares the given URL for a client link. If no providers are set, has no
* effect.
*
* @param url the target URL to prepare
* @return the prepared URL with global parameters added from
* providers
*
* @return the prepared URL with global parameters added from providers
*
* @deprecated This method does not encode the servlet session ID. Use
* encodeURL(req, res, url) instead.
**/
*
*/
public static String prepareURL(String url, HttpServletRequest req) {
return URLRewriter.prepareURL(url, req);
}
@ -723,11 +773,14 @@ public final class DispatcherHelper implements DispatcherConstants {
* @param req the current request
* @param resp the current response
* @param url the target URL (for a link) to encode
* @return the new URL, with extra URL variables added
* from parameter providers
*
* @return the new URL, with extra URL variables added from parameter
* providers
*
* @deprecated use URLRewriter.encodeURL instead
* @see com.arsdigita.util.URLRewriter
**/
*
*/
public static String encodeURL(HttpServletRequest req,
HttpServletResponse resp,
String url) {
@ -737,8 +790,8 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Returns a global URL prefix for referencing static assets (images, CSS,
* etc.) on disk in href attributes. This can be on the same server
* ("/STATIC/") or a different server/port ("http://server:port/dir/").
* The return value is guaranteed to end with a trailing slash.
* ("/STATIC/") or a different server/port ("http://server:port/dir/"). The
* return value is guaranteed to end with a trailing slash.
*
* Usage example:
* <pre>
@ -755,10 +808,11 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* sets the global URL prefix for referencing static assets (images, CSS,
* etc.) from user-agents in href attributes.
* Package visibility is intentional.
* etc.) from user-agents in href attributes. Package visibility is
* intentional.
*
* @param s the static asset URL
*
* @pre s != null
*/
static void setStaticURL(String s) {
@ -773,13 +827,13 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* sets the webapp Context using the webappContext parameter in enterprise.init.
* This is an optional parameter. If it is not specified, null will be used and
* the value of s_webappContext will be set when there is a request.
* Package visibility is intentional.
* sets the webapp Context using the webappContext parameter in
* enterprise.init. This is an optional parameter. If it is not specified,
* null will be used and the value of s_webappContext will be set when there
* is a request. Package visibility is intentional.
*
* @param webappCtx the webappContext specified in enterprise.init.
* Normally this wouldbe "/".
* @param webappCtx the webappContext specified in enterprise.init. Normally
* this wouldbe "/".
*/
static void setWebappContext(String webappCtx) {
init();
@ -796,12 +850,10 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Gets the webapp Context using the following procedure:
*
* 1. If there is a request, get the value from the request.
* 2. If there is no request, get the value saved from a previous
* request.
* 3. If there is no request or previous request, use the value
* specified by the enterprise.init webappContext parameter.
* 4. Lastly, return null.
* 1. If there is a request, get the value from the request. 2. If there is
* no request, get the value saved from a previous request. 3. If there is
* no request or previous request, use the value specified by the
* enterprise.init webappContext parameter. 4. Lastly, return null.
*
* @return
*/
@ -821,7 +873,8 @@ public final class DispatcherHelper implements DispatcherConstants {
if (!s_webappCtx.equals(webappCtx)) {
s_log.warn(
"webappContext changed. Expected='" + s_webappCtx
+ "' found='" + webappCtx + "'.\nPerhaps the enterprise.init "
+ "' found='" + webappCtx
+ "'.\nPerhaps the enterprise.init "
+ "com.arsdigita.dispatcher.Initializer webappContext "
+ "parameter is wrong.");
// Save the webappCtx from the request for future use.
@ -838,22 +891,23 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Aborts all processing of the current request and treat it
* as successfully completed. We abort the request by percolating
* an unchecked Error up through the call stack. Then the
* BaseDispatcherServlet.service method traps this and commits
* whatever DML has already happened on the transaction.
* Aborts all processing of the current request and treat it as successfully
* completed. We abort the request by percolating an unchecked Error up
* through the call stack. Then the BaseDispatcherServlet.service method
* traps this and commits whatever DML has already happened on the
* transaction.
*
* @exception com.arsdigita.dispatcher.AbortRequestSignal Error thrown
* to abort current request
* @exception com.arsdigita.dispatcher.AbortRequestSignal Error thrown to
* abort current
* request
*/
public static void abortRequest() {
throw new AbortRequestSignal();
}
/**
* Stores the HttpServletRequest in a ThreadLocal so that it can be
* accessed globally.
* Stores the HttpServletRequest in a ThreadLocal so that it can be accessed
* globally.
*
* @param r
*/
@ -864,6 +918,7 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Gets the current HttpServletRequest for this thread.
*
* @return the current HttpServletRequest for this thread.
*/
public static HttpServletRequest getRequest() {
@ -871,7 +926,9 @@ public final class DispatcherHelper implements DispatcherConstants {
return (HttpServletRequest) s_request.get();
}
/***************************************************/
/**
* ************************************************
*/
/* !!! Danger Will Robinson!!!! */
/* */
/* Don't go making changes to the cache headers */
@ -879,10 +936,13 @@ public final class DispatcherHelper implements DispatcherConstants {
/* sections on caching in RFC 2616 (HTTP 1.1) */
/* */
/* -- Daniel Berrange <berrange@redhat.com> */
/***************************************************/
/**
* If no existing cache policy is set, then call
* cacheDisable to disable all caching of the response.
* ************************************************
*/
/**
* If no existing cache policy is set, then call cacheDisable to disable all
* caching of the response.
*
* @param response
*/
public static void maybeCacheDisable(HttpServletResponse response) {
@ -931,8 +991,8 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* If no existing cache policy is set, then
* call cacheForUser to enable caching for a user.
* If no existing cache policy is set, then call cacheForUser to enable
* caching for a user.
*
* @param response
*/
@ -943,9 +1003,9 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Allow caching of the response for this user only, as identified
* by the Cookie header. The response will expire according
* to the default age setting.
* Allow caching of the response for this user only, as identified by the
* Cookie header. The response will expire according to the default age
* setting.
*
* @param response
*/
@ -954,8 +1014,8 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* If no existing cache policy is set, then
* call cacheForUser to enable caching for a user
* If no existing cache policy is set, then call cacheForUser to enable
* caching for a user
*
* @param response
* @param maxage the max time in second until this expires
@ -968,8 +1028,8 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* If no existing cache policy is set, then
* call cacheForUser to enable caching for a user
* If no existing cache policy is set, then call cacheForUser to enable
* caching for a user
*
* @param response
* @param expiry the time at which to expire
@ -982,9 +1042,9 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Allow caching of the response for this user only,
* as identified by the Cookie header. The response
* will expire in 'age' seconds time.
* Allow caching of the response for this user only, as identified by the
* Cookie header. The response will expire in 'age' seconds time.
*
* @param response
* @param maxage the max life of the response in seconds
*/
@ -1002,7 +1062,8 @@ public final class DispatcherHelper implements DispatcherConstants {
// For HTTP/1.1 user agents, we tell them only cache
// for the original person making the request
response.setHeader("Last-Modified", rfc1123_formatter.format(new Date()));
response
.setHeader("Last-Modified", rfc1123_formatter.format(new Date()));
response.setHeader("Cache-Control", "private, max-age=" + maxage);
// NB. THis line is delibrately *NOT* using the actual expiry date
@ -1014,20 +1075,22 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Allowing caching of the response for this user only.
* The response will expire at time given in the expiry parameter
* Allowing caching of the response for this user only. The response will
* expire at time given in the expiry parameter
*
* @param response
* @param expiry time at which to expire
*/
public static void cacheForUser(HttpServletResponse response,
Date expiry) {
cacheForUser(response, (int) ((expiry.getTime() - (new Date()).getTime()) / 1000l));
cacheForUser(response,
(int) ((expiry.getTime() - (new Date()).getTime()) / 1000l));
}
/**
* If no existing cache policy is set, then call cacheForUser to enable
* caching for the world. The response expiry will take the default
* age setting.
* caching for the world. The response expiry will take the default age
* setting.
*
* @param response
*/
@ -1038,8 +1101,8 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Allow caching of this response for anyone in the world.
* The response take the default expiry time.
* Allow caching of this response for anyone in the world. The response take
* the default expiry time.
*
* @param response
*/
@ -1062,8 +1125,8 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* If no existing cache policy is set, then call cacheForUser to
* enable caching for the world.
* If no existing cache policy is set, then call cacheForUser to enable
* caching for the world.
*
* @param response
* @param expiry the time at which it will expire
@ -1076,9 +1139,9 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Allow caching of this response for anyone in the
* world. The response will expire at the current time
* plus maxage seconds.
* Allow caching of this response for anyone in the world. The response will
* expire at the current time plus maxage seconds.
*
* @param response
* @param maxage time in seconds until this expires
*/
@ -1104,15 +1167,16 @@ public final class DispatcherHelper implements DispatcherConstants {
}
/**
* Allow caching of this response for anyone in the world.
* THe response will expire at the time given.
* Allow caching of this response for anyone in the world. THe response will
* expire at the time given.
*
* @param response
* @param expiry
*/
public static void cacheForWorld(HttpServletResponse response,
Date expiry) {
cacheForWorld(response, (int) ((expiry.getTime() - (new Date()).getTime()) / 1000l));
cacheForWorld(response, (int) ((expiry.getTime() - (new Date())
.getTime()) / 1000l));
}
/**
@ -1127,14 +1191,16 @@ public final class DispatcherHelper implements DispatcherConstants {
// Set the preferedLocale to the default locale (first entry in the
// config parameter list)
Locale preferedLocale = new Locale(kernelConfig.getDefaultLanguage(), "", "");
Locale preferedLocale
= new Locale(kernelConfig.getDefaultLanguage(), "", "");
// The ACCEPTED_LANGUAGES from the client
Enumeration locales = null;
// Try to get the RequestContext
try {
locales = ((ServletRequest) DispatcherHelper.getRequest()).getLocales();
locales = ((ServletRequest) DispatcherHelper.getRequest())
.getLocales();
// For everey element in the enumerator
while (locales.hasMoreElements()) {
@ -1161,8 +1227,8 @@ public final class DispatcherHelper implements DispatcherConstants {
/**
* Encodes the given request into a return URL parameter. Returns
* <code>URLencode(returnURL)</code> where returnURL is
* <code>returnURI?key=URLencode(val)&...</code>. The original parameter values are
* doubly-encoded so that they are decoded appropriately.
* <code>returnURI?key=URLencode(val)&...</code>. The original parameter
* values are doubly-encoded so that they are decoded appropriately.
*
*
* @param req the request to encode