Refactor code to use Java 5 features

- Apply and use Generics
- Remove JdkVersion.isAtLeastJava15() conditionals
- Replace iterator loops with foreach syntax
- Switch on warning in eclipse

Issues: SWF-1532
This commit is contained in:
Phil Webb
2012-03-29 21:02:07 -07:00
parent 619249b52b
commit 4d008f3f09
457 changed files with 3220 additions and 3148 deletions

View File

@@ -65,7 +65,7 @@ public class AjaxTilesView extends TilesView {
public void afterPropertiesSet() throws Exception {
super.afterPropertiesSet();
tilesRequestContextFactory = new ServletTilesRequestContextFactory();
tilesRequestContextFactory.init(new HashMap());
tilesRequestContextFactory.init(new HashMap<String, String>());
}
public AjaxHandler getAjaxHandler() {
@@ -76,8 +76,8 @@ public class AjaxTilesView extends TilesView {
this.ajaxHandler = ajaxHandler;
}
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
throws Exception {
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) throws Exception {
ServletContext servletContext = getServletContext();
if (ajaxHandler.isAjaxRequest(request, response)) {
@@ -101,12 +101,12 @@ public class AjaxTilesView extends TilesView {
exposeModelAsRequestAttributes(model, request);
JstlUtils.exposeLocalizationContext(new RequestContext(request, servletContext));
TilesRequestContext tilesRequestContext = tilesRequestContextFactory.createRequestContext(container
.getApplicationContext(), new Object[] { request, response });
TilesRequestContext tilesRequestContext = tilesRequestContextFactory.createRequestContext(
container.getApplicationContext(), new Object[] { request, response });
Definition compositeDefinition = container.getDefinitionsFactory().getDefinition(getUrl(),
tilesRequestContext);
Map flattenedAttributeMap = new HashMap();
Map<String, Attribute> flattenedAttributeMap = new HashMap<String, Attribute>();
flattenAttributeMap(container, tilesRequestContext, flattenedAttributeMap, compositeDefinition, request,
response);
addRuntimeAttributes(container, flattenedAttributeMap, request, response);
@@ -115,11 +115,11 @@ public class AjaxTilesView extends TilesView {
request.setAttribute(ServletUtil.FORCE_INCLUDE_ATTRIBUTE_NAME, true);
}
for (int i = 0; i < fragmentsToRender.length; i++) {
Attribute attributeToRender = (Attribute) flattenedAttributeMap.get(fragmentsToRender[i]);
for (String element : fragmentsToRender) {
Attribute attributeToRender = flattenedAttributeMap.get(element);
if (attributeToRender == null) {
throw new ServletException("No tiles attribute with a name of '" + fragmentsToRender[i]
throw new ServletException("No tiles attribute with a name of '" + element
+ "' could be found for the current view: " + this);
} else {
container.startContext(request, response).inheritCascadedAttributes(compositeDefinition);
@@ -132,7 +132,8 @@ public class AjaxTilesView extends TilesView {
}
}
protected String[] getRenderFragments(Map model, HttpServletRequest request, HttpServletResponse response) {
protected String[] getRenderFragments(Map<String, Object> model, HttpServletRequest request,
HttpServletResponse response) {
String attrName = request.getParameter(FRAGMENTS_PARAM);
String[] renderFragments = StringUtils.commaDelimitedListToStringArray(attrName);
return StringUtils.trimArrayElements(renderFragments);
@@ -153,10 +154,11 @@ public class AjaxTilesView extends TilesView {
* @param response the servlet response
*/
protected void flattenAttributeMap(BasicTilesContainer container, TilesRequestContext requestContext,
Map resultMap, Definition compositeDefinition, HttpServletRequest request, HttpServletResponse response) {
Iterator iterator = compositeDefinition.getAttributeNames();
Map<String, Attribute> resultMap, Definition compositeDefinition, HttpServletRequest request,
HttpServletResponse response) {
Iterator<String> iterator = compositeDefinition.getAttributeNames();
while (iterator.hasNext()) {
String attributeName = (String) iterator.next();
String attributeName = iterator.next();
Attribute attribute = compositeDefinition.getAttribute(attributeName);
if (attribute.getValue() == null || !(attribute.getValue() instanceof String)) {
continue;
@@ -184,19 +186,19 @@ public class AjaxTilesView extends TilesView {
* @param request the Servlet request
* @param response the Servlet response
*/
protected void addRuntimeAttributes(BasicTilesContainer container, Map resultMap, HttpServletRequest request,
HttpServletResponse response) {
protected void addRuntimeAttributes(BasicTilesContainer container, Map<String, Attribute> resultMap,
HttpServletRequest request, HttpServletResponse response) {
AttributeContext attributeContext = container.getAttributeContext(new Object[] { request, response });
Set attributeNames = new HashSet();
Set<String> attributeNames = new HashSet<String>();
if (attributeContext.getLocalAttributeNames() != null) {
attributeNames.addAll(attributeContext.getLocalAttributeNames());
}
if (attributeContext.getCascadedAttributeNames() != null) {
attributeNames.addAll(attributeContext.getCascadedAttributeNames());
}
Iterator iterator = attributeNames.iterator();
Iterator<String> iterator = attributeNames.iterator();
while (iterator.hasNext()) {
String name = (String) iterator.next();
String name = iterator.next();
Attribute attr = attributeContext.getAttribute(name);
resultMap.put(name, attr);
}

View File

@@ -72,7 +72,7 @@ public class ResourceServlet extends HttpServletBean {
private boolean gzipEnabled = true;
private Set allowedResourcePaths = new HashSet();
private Set<String> allowedResourcePaths = new HashSet<String>();
{
allowedResourcePaths.add("/**/*.css");
allowedResourcePaths.add("/**/*.gif");
@@ -90,7 +90,7 @@ public class ResourceServlet extends HttpServletBean {
allowedResourcePaths.add("META-INF/**/*.png");
};
private Map defaultMimeTypes = new HashMap();
private Map<String, String> defaultMimeTypes = new HashMap<String, String>();
{
defaultMimeTypes.put(".css", "text/css");
defaultMimeTypes.put(".gif", "image/gif");
@@ -101,7 +101,7 @@ public class ResourceServlet extends HttpServletBean {
defaultMimeTypes.put(".png", "image/png");
}
private Set compressedMimeTypes = new HashSet();
private Set<String> compressedMimeTypes = new HashSet<String>();
{
compressedMimeTypes.add("text/*");
}
@@ -131,8 +131,8 @@ public class ResourceServlet extends HttpServletBean {
OutputStream out = selectOutputStream(request, response);
try {
for (int i = 0; i < resources.length; i++) {
URLConnection resourceConn = resources[i].openConnection();
for (URL resource : resources) {
URLConnection resourceConn = resource.openConnection();
InputStream in = resourceConn.getInputStream();
try {
byte[] buffer = new byte[1024];
@@ -166,9 +166,9 @@ public class ResourceServlet extends HttpServletBean {
private boolean matchesCompressedMimeTypes(String mimeType) {
PathMatcher pathMatcher = new AntPathMatcher();
Iterator compressedMimeTypesIt = compressedMimeTypes.iterator();
Iterator<String> compressedMimeTypesIt = compressedMimeTypes.iterator();
while (compressedMimeTypesIt.hasNext()) {
String compressedMimeType = (String) compressedMimeTypesIt.next();
String compressedMimeType = compressedMimeTypesIt.next();
if (pathMatcher.match(compressedMimeType, mimeType)) {
return true;
}
@@ -181,16 +181,16 @@ public class ResourceServlet extends HttpServletBean {
long lastModified = -1;
int contentLength = 0;
String mimeType = null;
for (int i = 0; i < resources.length; i++) {
URLConnection resourceConn = resources[i].openConnection();
for (URL resource : resources) {
URLConnection resourceConn = resource.openConnection();
if (resourceConn.getLastModified() > lastModified) {
lastModified = resourceConn.getLastModified();
}
String currentMimeType = getServletContext().getMimeType(resources[i].getPath());
String currentMimeType = getServletContext().getMimeType(resource.getPath());
if (currentMimeType == null) {
String extension = resources[i].getPath().substring(resources[i].getPath().lastIndexOf('.'));
currentMimeType = (String) defaultMimeTypes.get(extension);
String extension = resource.getPath().substring(resource.getPath().lastIndexOf('.'));
currentMimeType = defaultMimeTypes.get(extension);
}
if (mimeType == null) {
mimeType = currentMimeType;
@@ -226,10 +226,10 @@ public class ResourceServlet extends HttpServletBean {
long lastModified = -1;
for (int i = 0; i < resources.length; i++) {
for (URL resource : resources) {
URLConnection resourceConn;
try {
resourceConn = resources[i].openConnection();
resourceConn = resource.openConnection();
} catch (IOException e) {
return -1;
}
@@ -298,9 +298,9 @@ public class ResourceServlet extends HttpServletBean {
return false;
}
PathMatcher pathMatcher = new AntPathMatcher();
Iterator allowedResourcePathsIt = allowedResourcePaths.iterator();
Iterator<String> allowedResourcePathsIt = allowedResourcePaths.iterator();
while (allowedResourcePathsIt.hasNext()) {
String pattern = (String) allowedResourcePathsIt.next();
String pattern = allowedResourcePathsIt.next();
if (pathMatcher.match(pattern, resourcePath)) {
return true;
}
@@ -380,14 +380,6 @@ public class ResourceServlet extends HttpServletBean {
}
gzipStream.write(b, off, len);
}
public boolean closed() {
return (this.closed);
}
public void reset() {
// noop
}
}
/**
@@ -404,8 +396,8 @@ public class ResourceServlet extends HttpServletBean {
* @see AntPathMatcher
*/
public void setAllowedResourcePaths(String allowedResourcePaths) {
this.allowedResourcePaths = new HashSet(Arrays.asList(StringUtils.tokenizeToStringArray(allowedResourcePaths,
",", true, true)));
this.allowedResourcePaths = new HashSet<String>(Arrays.asList(StringUtils.tokenizeToStringArray(
allowedResourcePaths, ",", true, true)));
}
/**
@@ -415,8 +407,8 @@ public class ResourceServlet extends HttpServletBean {
* @see AntPathMatcher
*/
public void setCompressedMimeTypes(String compressedMimeTypes) {
this.compressedMimeTypes = new HashSet(Arrays.asList(StringUtils.tokenizeToStringArray(compressedMimeTypes,
",", true, true)));
this.compressedMimeTypes = new HashSet<String>(Arrays.asList(StringUtils.tokenizeToStringArray(
compressedMimeTypes, ",", true, true)));
}
/**