From bdc01ffb855998c6c3478aa604a4638abe057166 Mon Sep 17 00:00:00 2001 From: "Donald J. Brown" Date: Fri, 2 May 2008 05:34:09 +0000 Subject: [PATCH] Reformatting annoying code WW-2623 git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@652768 13f79535-47bb-0310-9956-ffa450edef68 --- .../struts2/dispatcher/FilterDispatcher.java | 123 +++++++++--------- 1 file changed, 63 insertions(+), 60 deletions(-) diff --git a/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java b/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java index 162f93686..baf73110d 100644 --- a/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java +++ b/core/src/main/java/org/apache/struts2/dispatcher/FilterDispatcher.java @@ -65,90 +65,89 @@ import com.opensymphony.xwork2.util.profiling.UtilTimerStack; /** * Master filter for Struts that handles four distinct * responsibilities: - * + *

*

- * + *

*

IMPORTANT: this filter must be mapped to all requests. Unless you know exactly what you are doing, always * map to this URL pattern: /* - * + *

*

Executing actions - * + *

*

This filter executes actions by consulting the {@link ActionMapper} and determining if the requested URL should * invoke an action. If the mapper indicates it should, the rest of the filter chain is stopped and the action is * invoked. This is important, as it means that filters like the SiteMesh filter must be placed before this * filter or they will not be able to decorate the output of actions. - * + *

*

Cleaning up the {@link ActionContext} - * + *

*

This filter will also automatically clean up the {@link ActionContext} for you, ensuring that no memory leaks * take place. However, this can sometimes cause problems integrating with other products like SiteMesh. See {@link * ActionContextCleanUp} for more information on how to deal with this. - * + *

*

Serving static content - * + *

*

This filter also serves common static content needed when using various parts of Struts, such as JavaScript * files, CSS files, etc. It works by looking for requests to /struts/*, and then mapping the value after "/struts/" * to common packages in Struts and, optionally, in your class path. By default, the following packages are * automatically searched: - * + *

*

- * + *

*

This means that you can simply request /struts/xhtml/styles.css and the XHTML UI theme's default stylesheet * will be returned. Likewise, many of the AJAX UI components require various JavaScript files, which are found in the * org.apache.struts2.static package. If you wish to add additional packages to be searched, you can add a comma * separated (space, tab and new line will do as well) list in the filter init parameter named "packages". Be * careful, however, to expose any packages that may have sensitive information, such as properties file with * database access credentials. - * *

- * + *

+ *

*

- * + *

* This filter supports the following init-params: * - * + *

*

- * + *

* - * + *

*

- * + *

* To use a custom {@link Dispatcher}, the createDispatcher() method could be overriden by * the subclass. * + * @version $Date$ $Id$ * @see ActionMapper * @see ActionContextCleanUp - * - * @version $Date$ $Id$ */ public class FilterDispatcher implements StrutsStatics, Filter { @@ -229,22 +228,22 @@ public class FilterDispatcher implements StrutsStatics, Filter { if (factoryName != null) { try { Class cls = ClassLoaderUtils.loadClass(factoryName, this.getClass()); - LoggerFactory fac = (LoggerFactory)cls.newInstance(); + LoggerFactory fac = (LoggerFactory) cls.newInstance(); LoggerFactory.setLoggerFactory(fac); } catch (InstantiationException e) { - System.err.println("Unable to instantiate logger factory: "+factoryName+", using default"); + System.err.println("Unable to instantiate logger factory: " + factoryName + ", using default"); e.printStackTrace(); } catch (IllegalAccessException e) { - System.err.println("Unable to access logger factory: "+factoryName+", using default"); + System.err.println("Unable to access logger factory: " + factoryName + ", using default"); e.printStackTrace(); } catch (ClassNotFoundException e) { - System.err.println("Unable to locate logger factory class: "+factoryName+", using default"); + System.err.println("Unable to locate logger factory class: " + factoryName + ", using default"); e.printStackTrace(); } } - + log = LoggerFactory.getLogger(FilterDispatcher.class); - + } /** @@ -273,8 +272,8 @@ public class FilterDispatcher implements StrutsStatics, Filter { * @return Initialized Dispatcher */ protected Dispatcher createDispatcher(FilterConfig filterConfig) { - Map params = new HashMap(); - for (Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements(); ) { + Map params = new HashMap(); + for (Enumeration e = filterConfig.getInitParameterNames(); e.hasMoreElements();) { String name = (String) e.nextElement(); String value = filterConfig.getInitParameter(name); params.put(name, value); @@ -284,6 +283,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { /** * Modify state of StrutsConstants.STRUTS_SERVE_STATIC_CONTENT setting. + * * @param val New setting */ @Inject(StrutsConstants.STRUTS_SERVE_STATIC_CONTENT) @@ -293,6 +293,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { /** * Modify state of StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE setting. + * * @param val New setting */ @Inject(StrutsConstants.STRUTS_SERVE_STATIC_BROWSER_CACHE) @@ -302,6 +303,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { /** * Modify state of StrutsConstants.STRUTS_I18N_ENCODING setting. + * * @param val New setting */ @Inject(StrutsConstants.STRUTS_I18N_ENCODING) @@ -311,6 +313,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { /** * Modify ActionMapper instance. + * * @param mapper New instance */ @Inject @@ -344,7 +347,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { * Wrap and return the given request, if needed, so as to to transparently * handle multipart data as a wrapped class around the given request. * - * @param request Our ServletRequest object + * @param request Our ServletRequest object * @param response Our ServerResponse object * @return Wrapped HttpServletRequest object * @throws ServletException on any error @@ -428,12 +431,12 @@ public class FilterDispatcher implements StrutsStatics, Filter { String timerKey = "FilterDispatcher_doFilter: "; try { - + // FIXME: this should be refactored better to not duplicate work with the action invocation ValueStack stack = dispatcher.getContainer().getInstance(ValueStackFactory.class).createValueStack(); ActionContext ctx = new ActionContext(stack.getContext()); ActionContext.setContext(ctx); - + UtilTimerStack.push(timerKey); request = prepareDispatcherAndWrapRequest(request, response); ActionMapping mapping; @@ -479,8 +482,8 @@ public class FilterDispatcher implements StrutsStatics, Filter { * Locate a static resource and copy directly to the response, * setting the appropriate caching headers. * - * @param name The resource name - * @param request The request + * @param name The resource name + * @param request The request * @param response The response * @throws IOException If anything goes wrong */ @@ -494,31 +497,31 @@ public class FilterDispatcher implements StrutsStatics, Filter { // check for if-modified-since, prior to any other headers long ifModifiedSince = 0; try { - ifModifiedSince = request.getDateHeader("If-Modified-Since"); + ifModifiedSince = request.getDateHeader("If-Modified-Since"); } catch (Exception e) { - log.warn("Invalid If-Modified-Since header value: '" + request.getHeader("If-Modified-Since") + "', ignoring"); + log.warn("Invalid If-Modified-Since header value: '" + request.getHeader("If-Modified-Since") + "', ignoring"); } - long lastModifiedMillis = lastModifiedCal.getTimeInMillis(); - long now = cal.getTimeInMillis(); + long lastModifiedMillis = lastModifiedCal.getTimeInMillis(); + long now = cal.getTimeInMillis(); cal.add(Calendar.DAY_OF_MONTH, 1); long expires = cal.getTimeInMillis(); - if (ifModifiedSince > 0 && ifModifiedSince <= lastModifiedMillis) { - // not modified, content is not sent - only basic headers and status SC_NOT_MODIFIED + if (ifModifiedSince > 0 && ifModifiedSince <= lastModifiedMillis) { + // not modified, content is not sent - only basic headers and status SC_NOT_MODIFIED response.setDateHeader("Expires", expires); - response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); - is.close(); - return; - } + response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); + is.close(); + return; + } - // set the content-type header + // set the content-type header String contentType = getContentType(name); if (contentType != null) { response.setContentType(contentType); } if (serveStaticBrowserCache) { - // set heading information for caching static content + // set heading information for caching static content response.setDateHeader("Date", now); response.setDateHeader("Expires", expires); response.setDateHeader("Retry-After", expires); @@ -574,7 +577,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { /** * Copy bytes from the input stream to the output stream. * - * @param input The input stream + * @param input The input stream * @param output The output stream * @throws IOException If anything goes wrong */ @@ -590,7 +593,7 @@ public class FilterDispatcher implements StrutsStatics, Filter { /** * Look for a static resource in the classpath. * - * @param name The resource name + * @param name The resource name * @param packagePrefix The package prefix to use to locate the resource * @return The inputstream of the resource * @throws IOException If there is a problem locating the resource