Java 5 code style

This commit is contained in:
Juergen Hoeller
2008-11-21 00:04:10 +00:00
parent 9e419dacfc
commit 597e92a1a6
17 changed files with 217 additions and 303 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2005 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -16,9 +16,7 @@
package org.springframework.web.context.support;
import java.util.Iterator;
import java.util.Map;
import javax.servlet.ServletContext;
import org.apache.commons.logging.Log;
@@ -50,7 +48,8 @@ public class ServletContextAttributeExporter implements ServletContextAware {
protected final Log logger = LogFactory.getLog(getClass());
private Map attributes;
private Map<String, Object> attributes;
/**
* Set the ServletContext attributes to expose as key-value pairs.
@@ -59,19 +58,17 @@ public class ServletContextAttributeExporter implements ServletContextAware {
* <p>Usually, you will use bean references for the values,
* to export Spring-defined beans as ServletContext attributes.
* Of course, it is also possible to define plain values to export.
* @param attributes Map with String keys and Object values
*/
public void setAttributes(Map attributes) {
public void setAttributes(Map<String, Object> attributes) {
this.attributes = attributes;
}
public void setServletContext(ServletContext servletContext) {
for (Iterator it = this.attributes.entrySet().iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
String attributeName = (String) entry.getKey();
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
String attributeName = entry.getKey();
if (logger.isWarnEnabled()) {
if (servletContext.getAttribute(attributeName) != null) {
logger.warn("Overwriting existing ServletContext attribute with name '" + attributeName + "'");
logger.warn("Replacing existing ServletContext attribute with name '" + attributeName + "'");
}
}
servletContext.setAttribute(attributeName, entry.getValue());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2007 the original author or authors.
* Copyright 2002-2008 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -20,7 +20,6 @@ import java.io.IOException;
import java.util.Iterator;
import java.util.LinkedHashSet;
import java.util.Set;
import javax.servlet.ServletContext;
import org.springframework.core.io.Resource;
@@ -68,12 +67,14 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
* @see javax.servlet.ServletContext#getResourcePaths
*/
@Override
protected Set doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException {
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
throws IOException {
if (rootDirResource instanceof ServletContextResource) {
ServletContextResource scResource = (ServletContextResource) rootDirResource;
ServletContext sc = scResource.getServletContext();
String fullPattern = scResource.getPath() + subPattern;
Set result = new LinkedHashSet(8);
Set<Resource> result = new LinkedHashSet<Resource>(8);
doRetrieveMatchingServletContextResources(sc, fullPattern, scResource.getPath(), result);
return result;
}
@@ -95,11 +96,12 @@ public class ServletContextResourcePatternResolver extends PathMatchingResourceP
* @see javax.servlet.ServletContext#getResourcePaths
*/
protected void doRetrieveMatchingServletContextResources(
ServletContext servletContext, String fullPattern, String dir, Set result) throws IOException {
ServletContext servletContext, String fullPattern, String dir, Set<Resource> result)
throws IOException {
Set candidates = servletContext.getResourcePaths(dir);
if (candidates != null) {
boolean dirDepthNotFixed = (fullPattern.indexOf("**") != -1);
boolean dirDepthNotFixed = fullPattern.contains("**");
for (Iterator it = candidates.iterator(); it.hasNext();) {
String currPath = (String) it.next();
if (!currPath.startsWith(dir)) {

View File

@@ -17,8 +17,6 @@
package org.springframework.web.jsf;
import java.util.Collection;
import java.util.Iterator;
import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
@@ -68,19 +66,13 @@ public class DelegatingPhaseListenerMulticaster implements PhaseListener {
}
public void beforePhase(PhaseEvent event) {
Collection listeners = getDelegates(event.getFacesContext());
Iterator it = listeners.iterator();
while (it.hasNext()) {
PhaseListener listener = (PhaseListener) it.next();
for (PhaseListener listener : getDelegates(event.getFacesContext())) {
listener.beforePhase(event);
}
}
public void afterPhase(PhaseEvent event) {
Collection listeners = getDelegates(event.getFacesContext());
Iterator it = listeners.iterator();
while (it.hasNext()) {
PhaseListener listener = (PhaseListener) it.next();
for (PhaseListener listener : getDelegates(event.getFacesContext())) {
listener.afterPhase(event);
}
}
@@ -93,7 +85,7 @@ public class DelegatingPhaseListenerMulticaster implements PhaseListener {
* @see #getBeanFactory
* @see org.springframework.beans.factory.ListableBeanFactory#getBeansOfType(Class)
*/
protected Collection getDelegates(FacesContext facesContext) {
protected Collection<PhaseListener> getDelegates(FacesContext facesContext) {
ListableBeanFactory bf = getBeanFactory(facesContext);
return BeanFactoryUtils.beansOfTypeIncludingAncestors(bf, PhaseListener.class, true, false).values();
}

View File

@@ -19,10 +19,8 @@ package org.springframework.web.util;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Enumeration;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.ServletContext;
import javax.servlet.ServletRequest;
import javax.servlet.http.Cookie;
@@ -177,7 +175,7 @@ public abstract class WebUtils {
return false;
}
String param = servletContext.getInitParameter(HTML_ESCAPE_CONTEXT_PARAM);
return Boolean.valueOf(param).booleanValue();
return Boolean.valueOf(param);
}
/**
@@ -421,7 +419,7 @@ public abstract class WebUtils {
* @param servletName the name of the offending servlet
*/
public static void exposeErrorRequestAttributes(HttpServletRequest request, Throwable ex, String servletName) {
exposeRequestAttributeIfNotPresent(request, ERROR_STATUS_CODE_ATTRIBUTE, new Integer(HttpServletResponse.SC_OK));
exposeRequestAttributeIfNotPresent(request, ERROR_STATUS_CODE_ATTRIBUTE, HttpServletResponse.SC_OK);
exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_TYPE_ATTRIBUTE, ex.getClass());
exposeRequestAttributeIfNotPresent(request, ERROR_MESSAGE_ATTRIBUTE, ex.getMessage());
exposeRequestAttributeIfNotPresent(request, ERROR_EXCEPTION_ATTRIBUTE, ex);
@@ -467,16 +465,10 @@ public abstract class WebUtils {
* @param request current HTTP request
* @param attributes the attributes Map
*/
public static void exposeRequestAttributes(ServletRequest request, Map attributes) {
public static void exposeRequestAttributes(ServletRequest request, Map<String, Object> attributes) {
Assert.notNull(request, "Request must not be null");
Iterator it = attributes.entrySet().iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
if (!(entry.getKey() instanceof String)) {
throw new IllegalArgumentException(
"Invalid key [" + entry.getKey() + "] in attributes Map - only Strings allowed as attribute keys");
}
request.setAttribute((String) entry.getKey(), entry.getValue());
for (Map.Entry<String, Object> entry : attributes.entrySet()) {
request.setAttribute(entry.getKey(), entry.getValue());
}
}
@@ -491,9 +483,9 @@ public abstract class WebUtils {
Assert.notNull(request, "Request must not be null");
Cookie cookies[] = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
if (name.equals(cookies[i].getName())) {
return cookies[i];
for (Cookie cookie : cookies) {
if (name.equals(cookie.getName())) {
return cookie;
}
}
}
@@ -515,8 +507,7 @@ public abstract class WebUtils {
if (request.getParameter(name) != null) {
return true;
}
for (int i = 0; i < SUBMIT_IMAGE_SUFFIXES.length; i++) {
String suffix = SUBMIT_IMAGE_SUFFIXES[i];
for (String suffix : SUBMIT_IMAGE_SUFFIXES) {
if (request.getParameter(name + suffix) != null) {
return true;
}
@@ -533,6 +524,7 @@ public abstract class WebUtils {
* @return the value of the parameter, or <code>null</code>
* if the parameter does not exist in given request
*/
@SuppressWarnings("unchecked")
public static String findParameterValue(ServletRequest request, String name) {
return findParameterValue(request.getParameterMap(), name);
}
@@ -560,21 +552,22 @@ public abstract class WebUtils {
* @return the value of the parameter, or <code>null</code>
* if the parameter does not exist in given request
*/
public static String findParameterValue(Map parameters, String name) {
public static String findParameterValue(Map<String, ?> parameters, String name) {
// First try to get it as a normal name=value parameter
String value = (String) parameters.get(name);
if (value != null) {
return value;
Object value = parameters.get(name);
if (value instanceof String[]) {
String[] values = (String[]) value;
return (values.length > 0 ? values[0] : null);
}
else if (value != null) {
return value.toString();
}
// If no value yet, try to get it as a name_value=xyz parameter
String prefix = name + "_";
Iterator paramNames = parameters.keySet().iterator();
while (paramNames.hasNext()) {
String paramName = (String) paramNames.next();
for (String paramName : parameters.keySet()) {
if (paramName.startsWith(prefix)) {
// Support images buttons, which would submit parameters as name_value.x=123
for (int i = 0; i < SUBMIT_IMAGE_SUFFIXES.length; i++) {
String suffix = SUBMIT_IMAGE_SUFFIXES[i];
for (String suffix : SUBMIT_IMAGE_SUFFIXES) {
if (paramName.endsWith(suffix)) {
return paramName.substring(prefix.length(), paramName.length() - suffix.length());
}
@@ -600,10 +593,10 @@ public abstract class WebUtils {
* @see javax.servlet.ServletRequest#getParameterValues
* @see javax.servlet.ServletRequest#getParameterMap
*/
public static Map getParametersStartingWith(ServletRequest request, String prefix) {
public static Map<String, Object> getParametersStartingWith(ServletRequest request, String prefix) {
Assert.notNull(request, "Request must not be null");
Enumeration paramNames = request.getParameterNames();
Map params = new TreeMap();
Map<String, Object> params = new TreeMap<String, Object>();
if (prefix == null) {
prefix = "";
}