Skip to content

Commit 0ec99fd

Browse files
committed
Polishing
1 parent 6f58491 commit 0ec99fd

File tree

4 files changed

+26
-30
lines changed

4 files changed

+26
-30
lines changed

spring-web/src/main/java/org/springframework/web/method/HandlerMethod.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@
3030
import org.springframework.util.ClassUtils;
3131

3232
/**
33-
* Encapsulates information about a bean method consisting of a {@link #getMethod() method}
34-
* and a {@link #getBean() bean}. Provides convenient access to method parameters,
33+
* Encapsulates information about a handler method consisting of a {@linkplain #getMethod() method}
34+
* and a {@linkplain #getBean() bean}. Provides convenient access to method parameters,
3535
* method return value, method annotations.
3636
*
37-
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy bean,
38-
* prototype bean). Use {@link #createWithResolvedBean()} to obtain an {@link HandlerMethod}
39-
* instance with a bean instance initialized through the bean factory.
37+
* <p>The class may be created with a bean instance or with a bean name (e.g. lazy-init bean,
38+
* prototype bean). Use {@link #createWithResolvedBean()} to obtain a {@link HandlerMethod}
39+
* instance with a bean instance resolved through the associated {@link BeanFactory}.
4040
*
4141
* @author Arjen Poutsma
4242
* @author Rossen Stoyanchev
@@ -228,7 +228,7 @@ public boolean equals(Object obj) {
228228
}
229229
if (obj != null && obj instanceof HandlerMethod) {
230230
HandlerMethod other = (HandlerMethod) obj;
231-
return this.bean.equals(other.bean) && this.method.equals(other.method);
231+
return (this.bean.equals(other.bean) && this.method.equals(other.method));
232232
}
233233
return false;
234234
}

spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@
2222
import java.util.Map;
2323
import java.util.Map.Entry;
2424
import java.util.Properties;
25-
2625
import javax.servlet.http.HttpServletRequest;
2726

2827
import org.apache.commons.logging.Log;
2928
import org.apache.commons.logging.LogFactory;
29+
3030
import org.springframework.util.LinkedMultiValueMap;
3131
import org.springframework.util.MultiValueMap;
3232
import org.springframework.util.StringUtils;
@@ -187,17 +187,17 @@ public String getPathWithinServletMapping(HttpServletRequest request) {
187187
// e.g. with index page: URI="/", servletPath="/index.html"
188188
return pathInfo;
189189
}
190-
if (this.urlDecode == false) {
190+
if (!this.urlDecode) {
191191
// No path info... (not mapped by prefix, nor by extension, nor "/*")
192192
// For the default servlet mapping (i.e. "/"), urlDecode=false can
193193
// cause issues since getServletPath() returns a decoded path.
194-
// If decoding pathWithinApp yields a match just use pathWithinApp
194+
// If decoding pathWithinApp yields a match just use pathWithinApp.
195195
path = getRemainingPath(decodeInternal(request, pathWithinApp), servletPath, false);
196196
if (path != null) {
197197
return pathWithinApp;
198198
}
199199
}
200-
// Otherwise, use the full servlet path
200+
// Otherwise, use the full servlet path.
201201
return servletPath;
202202
}
203203
}
@@ -230,7 +230,7 @@ public String getPathWithinApplication(HttpServletRequest request) {
230230
private String getRemainingPath(String requestUri, String mapping, boolean ignoreCase) {
231231
int index1 = 0;
232232
int index2 = 0;
233-
for ( ; (index1 < requestUri.length()) && (index2 < mapping.length()); index1++, index2++) {
233+
for (; (index1 < requestUri.length()) && (index2 < mapping.length()); index1++, index2++) {
234234
char c1 = requestUri.charAt(index1);
235235
char c2 = mapping.charAt(index2);
236236
if (c1 == ';') {
@@ -257,7 +257,7 @@ private String getRemainingPath(String requestUri, String mapping, boolean ignor
257257
else if (requestUri.charAt(index1) == ';') {
258258
index1 = requestUri.indexOf('/', index1);
259259
}
260-
return (index1 != -1) ? requestUri.substring(index1) : "";
260+
return (index1 != -1 ? requestUri.substring(index1) : "");
261261
}
262262

263263
/**
@@ -312,8 +312,7 @@ public String getServletPath(HttpServletRequest request) {
312312
if (servletPath == null) {
313313
servletPath = request.getServletPath();
314314
}
315-
if (servletPath.length() > 1 && servletPath.endsWith("/") &&
316-
shouldRemoveTrailingServletPathSlash(request)) {
315+
if (servletPath.length() > 1 && servletPath.endsWith("/") && shouldRemoveTrailingServletPathSlash(request)) {
317316
// On WebSphere, in non-compliant mode, for a "/foo/" case that would be "/foo"
318317
// on all other servlet containers: removing trailing slash, proceeding with
319318
// that remaining slash as final lookup path...
@@ -449,7 +448,6 @@ protected String determineEncoding(HttpServletRequest request) {
449448
* Remove ";" (semicolon) content from the given request URI if the
450449
* {@linkplain #setRemoveSemicolonContent(boolean) removeSemicolonContent}
451450
* property is set to "true". Note that "jssessionid" is always removed.
452-
*
453451
* @param requestUri the request URI string to remove ";" content from
454452
* @return the updated URI string
455453
*/
@@ -486,7 +484,6 @@ private String removeJsessionid(String requestUri) {
486484
* assumed the URL path from which the variables were extracted is already
487485
* decoded through a call to
488486
* {@link #getLookupPathForRequest(HttpServletRequest)}.
489-
*
490487
* @param request current HTTP request
491488
* @param vars URI variables extracted from the URL path
492489
* @return the same Map or a new Map instance
@@ -511,7 +508,6 @@ public Map<String, String> decodePathVariables(HttpServletRequest request, Map<S
511508
* assumed the URL path from which the variables were extracted is already
512509
* decoded through a call to
513510
* {@link #getLookupPathForRequest(HttpServletRequest)}.
514-
*
515511
* @param request current HTTP request
516512
* @param vars URI variables extracted from the URL path
517513
* @return the same Map or a new Map instance

spring-web/src/test/java/org/springframework/web/method/support/InvocableHandlerMethodTests.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@ public class InvocableHandlerMethodTests {
4545

4646
private NativeWebRequest webRequest;
4747

48+
4849
@Before
4950
public void setUp() throws Exception {
5051
Method method = Handler.class.getDeclaredMethod("handle", Integer.class, String.class);
5152
this.handlerMethod = new InvocableHandlerMethod(new Handler(), method);
5253
this.webRequest = new ServletWebRequest(new MockHttpServletRequest(), new MockHttpServletResponse());
5354
}
5455

56+
5557
@Test
5658
public void resolveArg() throws Exception {
5759
StubArgumentResolver intResolver = new StubArgumentResolver(Integer.class, 99);
@@ -63,11 +65,9 @@ public void resolveArg() throws Exception {
6365
handlerMethod.setHandlerMethodArgumentResolvers(composite);
6466

6567
Object returnValue = handlerMethod.invokeForRequest(webRequest, null);
66-
6768
assertEquals(1, intResolver.getResolvedParameters().size());
6869
assertEquals(1, stringResolver.getResolvedParameters().size());
6970
assertEquals("99-value", returnValue);
70-
7171
assertEquals("intArg", intResolver.getResolvedParameters().get(0).getParameterName());
7272
assertEquals("stringArg", stringResolver.getResolvedParameters().get(0).getParameterName());
7373
}
@@ -83,7 +83,6 @@ public void resolveNullArg() throws Exception {
8383
handlerMethod.setHandlerMethodArgumentResolvers(composite);
8484

8585
Object returnValue = handlerMethod.invokeForRequest(webRequest, null);
86-
8786
assertEquals(1, intResolver.getResolvedParameters().size());
8887
assertEquals(1, stringResolver.getResolvedParameters().size());
8988
assertEquals("null-null", returnValue);
@@ -119,7 +118,6 @@ public void resolveProvidedArgFirst() throws Exception {
119118
handlerMethod.setHandlerMethodArgumentResolvers(composite);
120119

121120
Object returnValue = handlerMethod.invokeForRequest(webRequest, null, 2, "value2");
122-
123121
assertEquals("2-value2", returnValue);
124122
}
125123

@@ -134,8 +132,7 @@ public void exceptionInResolvingArg() throws Exception {
134132
fail("Expected exception");
135133
}
136134
catch (HttpMessageNotReadableException ex) {
137-
// Expected..
138-
// Allow HandlerMethodArgumentResolver exceptions to propagate..
135+
// expected - allow HandlerMethodArgumentResolver exceptions to propagate
139136
}
140137
}
141138

@@ -208,6 +205,7 @@ private void invokeExceptionRaisingHandler(Throwable expected) throws Exception
208205
fail("Expected exception");
209206
}
210207

208+
211209
@SuppressWarnings("unused")
212210
private static class Handler {
213211

@@ -216,6 +214,7 @@ public String handle(Integer intArg, String stringArg) {
216214
}
217215
}
218216

217+
219218
@SuppressWarnings("unused")
220219
private static class ExceptionRaisingHandler {
221220

@@ -228,9 +227,9 @@ public ExceptionRaisingHandler(Throwable t) {
228227
public void raiseException() throws Throwable {
229228
throw t;
230229
}
231-
232230
}
233231

232+
234233
private static class ExceptionRaisingArgumentResolver implements HandlerMethodArgumentResolver {
235234

236235
@Override

spring-webmvc/src/main/java/org/springframework/web/servlet/view/AbstractView.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2013 the original author or authors.
2+
* Copyright 2002-2014 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -74,6 +74,7 @@ public abstract class AbstractView extends WebApplicationObjectSupport implement
7474
/** Whether or not the view should add path variables in the model */
7575
private boolean exposePathVariables = true;
7676

77+
7778
/**
7879
* Set the view's name. Helpful for traceability.
7980
* <p>Framework code must call this when constructing views.
@@ -244,9 +245,10 @@ public void setExposePathVariables(boolean exposePathVariables) {
244245
* Returns the value of the flag indicating whether path variables should be added to the model or not.
245246
*/
246247
public boolean isExposePathVariables() {
247-
return exposePathVariables;
248+
return this.exposePathVariables;
248249
}
249250

251+
250252
/**
251253
* Prepares the view given the specified model, merging it with static
252254
* attributes and a RequestContext attribute, if necessary.
@@ -261,7 +263,6 @@ public void render(Map<String, ?> model, HttpServletRequest request, HttpServlet
261263
}
262264

263265
Map<String, Object> mergedModel = createMergedOutputModel(model, request, response);
264-
265266
prepareResponse(request, response);
266267
renderMergedOutputModel(mergedModel, request, response);
267268
}
@@ -271,11 +272,11 @@ public void render(Map<String, ?> model, HttpServletRequest request, HttpServlet
271272
* Dynamic values take precedence over static attributes.
272273
*/
273274
protected Map<String, Object> createMergedOutputModel(Map<String, ?> model, HttpServletRequest request,
274-
275275
HttpServletResponse response) {
276+
276277
@SuppressWarnings("unchecked")
277-
Map<String, Object> pathVars = this.exposePathVariables ?
278-
(Map<String, Object>) request.getAttribute(View.PATH_VARIABLES) : null;
278+
Map<String, Object> pathVars = (this.exposePathVariables ?
279+
(Map<String, Object>) request.getAttribute(View.PATH_VARIABLES) : null);
279280

280281
// Consolidate static and dynamic model attributes.
281282
int size = this.staticAttributes.size();

0 commit comments

Comments
 (0)