Skip to content

Commit 75e0869

Browse files
committed
Mixed polishing along with recent changes
(cherry picked from commit 14e5a02)
1 parent 5da79eb commit 75e0869

File tree

5 files changed

+50
-29
lines changed

5 files changed

+50
-29
lines changed

spring-context/src/main/java/org/springframework/cache/CacheManager.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2011 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.
@@ -19,7 +19,8 @@
1919
import java.util.Collection;
2020

2121
/**
22-
* A manager for a set of {@link Cache}s.
22+
* Spring's central cache manager SPI.
23+
* Allows for retrieving named {@link Cache} regions.
2324
*
2425
* @author Costin Leau
2526
* @since 3.1
@@ -28,14 +29,14 @@ public interface CacheManager {
2829

2930
/**
3031
* Return the cache associated with the given name.
31-
* @param name cache identifier (must not be {@code null})
32-
* @return associated cache, or {@code null} if none is found
32+
* @param name the cache identifier (must not be {@code null})
33+
* @return the associated cache, or {@code null} if none found
3334
*/
3435
Cache getCache(String name);
3536

3637
/**
37-
* Return a collection of the caches known by this cache manager.
38-
* @return names of caches known by the cache manager.
38+
* Return a collection of the cache names known by this manager.
39+
* @return the names of all caches known by the cache manager
3940
*/
4041
Collection<String> getCacheNames();
4142

spring-expression/src/test/java/org/springframework/expression/spel/MapAccessTests.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,19 @@ public void testGetValue(){
8181
Object bean = new TestBean("name1", new TestBean("name2", null, "Description 2", 15, props1), "description 1", 6, props1);
8282

8383
ExpressionParser parser = new SpelExpressionParser();
84-
Expression exp = parser.parseExpression("testBean.properties['key2']");
85-
String key = (String) exp.getValue(bean);
86-
assertNotNull(key);
84+
Expression expr = parser.parseExpression("testBean.properties['key2']");
85+
assertEquals("value2", expr.getValue(bean));
86+
}
87+
88+
@Test
89+
public void testGetValueFromRootMap() {
90+
Map<String, String> map = new HashMap<String, String>();
91+
map.put("key", "value");
92+
EvaluationContext context = new StandardEvaluationContext(map);
93+
94+
ExpressionParser spelExpressionParser = new SpelExpressionParser();
95+
Expression expr = spelExpressionParser.parseExpression("#root['key']");
96+
assertEquals("value", expr.getValue(map));
8797
}
8898

8999

spring-tx/src/main/java/org/springframework/transaction/interceptor/RollbackRuleAttribute.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -16,10 +16,10 @@
1616

1717
package org.springframework.transaction.interceptor;
1818

19-
import org.springframework.util.Assert;
20-
2119
import java.io.Serializable;
2220

21+
import org.springframework.util.Assert;
22+
2323
/**
2424
* Rule determining whether or not a given exception (and any subclasses)
2525
* should cause a rollback.
@@ -59,8 +59,8 @@ public class RollbackRuleAttribute implements Serializable{
5959
* @throws IllegalArgumentException if the supplied {@code clazz} is
6060
* not a {@code Throwable} type or is {@code null}
6161
*/
62-
public RollbackRuleAttribute(Class clazz) {
63-
Assert.notNull(clazz, "'clazz' cannot be null.");
62+
public RollbackRuleAttribute(Class<?> clazz) {
63+
Assert.notNull(clazz, "'clazz' cannot be null");
6464
if (!Throwable.class.isAssignableFrom(clazz)) {
6565
throw new IllegalArgumentException(
6666
"Cannot construct rollback rule from [" + clazz.getName() + "]: it's not a Throwable");
@@ -87,7 +87,7 @@ public RollbackRuleAttribute(Class clazz) {
8787
* {@code exceptionName} is {@code null} or empty
8888
*/
8989
public RollbackRuleAttribute(String exceptionName) {
90-
Assert.hasText(exceptionName, "'exceptionName' cannot be null or empty.");
90+
Assert.hasText(exceptionName, "'exceptionName' cannot be null or empty");
9191
this.exceptionName = exceptionName;
9292
}
9393

@@ -110,8 +110,8 @@ public int getDepth(Throwable ex) {
110110
}
111111

112112

113-
private int getDepth(Class exceptionClass, int depth) {
114-
if (exceptionClass.getName().indexOf(this.exceptionName) != -1) {
113+
private int getDepth(Class<?> exceptionClass, int depth) {
114+
if (exceptionClass.getName().contains(this.exceptionName)) {
115115
// Found it!
116116
return depth;
117117
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ServletRequestMethodArgumentResolver.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 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.
@@ -19,7 +19,6 @@
1919
import java.io.IOException;
2020
import java.io.InputStream;
2121
import java.io.Reader;
22-
import java.lang.reflect.Method;
2322
import java.security.Principal;
2423
import java.util.Locale;
2524

@@ -102,9 +101,9 @@ else if (Reader.class.isAssignableFrom(paramType)) {
102101
return request.getReader();
103102
}
104103
else {
105-
// should never happen..
106-
Method method = parameter.getMethod();
107-
throw new UnsupportedOperationException("Unknown parameter type: " + paramType + " in method: " + method);
104+
// should never happen...
105+
throw new UnsupportedOperationException(
106+
"Unknown parameter type: " + paramType + " in method: " + parameter.getMethod());
108107
}
109108
}
110109

spring-webmvc/src/main/java/org/springframework/web/servlet/tags/form/FormTag.java

Lines changed: 18 additions & 7 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.
@@ -16,8 +16,8 @@
1616

1717
package org.springframework.web.servlet.tags.form;
1818

19+
import java.io.UnsupportedEncodingException;
1920
import java.util.Map;
20-
2121
import javax.servlet.ServletRequest;
2222
import javax.servlet.ServletResponse;
2323
import javax.servlet.http.HttpServletRequest;
@@ -32,6 +32,7 @@
3232
import org.springframework.util.StringUtils;
3333
import org.springframework.web.servlet.support.RequestDataValueProcessor;
3434
import org.springframework.web.util.HtmlUtils;
35+
import org.springframework.web.util.UriUtils;
3536

3637
/**
3738
* Databinding-aware JSP tag for rendering an HTML '{@code form}' whose
@@ -352,8 +353,7 @@ protected int writeTagContent(TagWriter tagWriter) throws JspException {
352353
tagWriter.startTag(FORM_TAG);
353354
writeDefaultAttributes(tagWriter);
354355
tagWriter.writeAttribute(ACTION_ATTRIBUTE, resolveAction());
355-
writeOptionalAttribute(tagWriter, METHOD_ATTRIBUTE,
356-
isMethodBrowserSupported(getMethod()) ? getMethod() : DEFAULT_METHOD);
356+
writeOptionalAttribute(tagWriter, METHOD_ATTRIBUTE, getHttpMethod());
357357
writeOptionalAttribute(tagWriter, TARGET_ATTRIBUTE, getTarget());
358358
writeOptionalAttribute(tagWriter, ENCTYPE_ATTRIBUTE, getEnctype());
359359
writeOptionalAttribute(tagWriter, ACCEPT_CHARSET_ATTRIBUTE, getAcceptCharset());
@@ -389,6 +389,10 @@ protected int writeTagContent(TagWriter tagWriter) throws JspException {
389389
return EVAL_BODY_INCLUDE;
390390
}
391391

392+
private String getHttpMethod() {
393+
return (isMethodBrowserSupported(getMethod()) ? getMethod() : DEFAULT_METHOD);
394+
}
395+
392396
private void assertHttpMethod(String method) {
393397
for (HttpMethod httpMethod : HttpMethod.values()) {
394398
if (httpMethod.name().equalsIgnoreCase(method)) {
@@ -426,7 +430,6 @@ protected String resolveModelAttribute() throws JspException {
426430
* with the context and servlet paths, and the result is used. Otherwise, the
427431
* {@link org.springframework.web.servlet.support.RequestContext#getRequestUri()
428432
* originating URI} is used.
429-
*
430433
* @return the value that is to be used for the '{@code action}' attribute
431434
*/
432435
protected String resolveAction() throws JspException {
@@ -438,14 +441,22 @@ protected String resolveAction() throws JspException {
438441
}
439442
else if (StringUtils.hasText(servletRelativeAction)) {
440443
String pathToServlet = getRequestContext().getPathToServlet();
441-
if (servletRelativeAction.startsWith("/") && !servletRelativeAction.startsWith(getRequestContext().getContextPath())) {
444+
if (servletRelativeAction.startsWith("/") &&
445+
!servletRelativeAction.startsWith(getRequestContext().getContextPath())) {
442446
servletRelativeAction = pathToServlet + servletRelativeAction;
443447
}
444448
servletRelativeAction = getDisplayString(evaluate(ACTION_ATTRIBUTE, servletRelativeAction));
445449
return processAction(servletRelativeAction);
446450
}
447451
else {
448452
String requestUri = getRequestContext().getRequestUri();
453+
String encoding = this.pageContext.getResponse().getCharacterEncoding();
454+
try {
455+
requestUri = UriUtils.encodePath(requestUri, encoding);
456+
}
457+
catch (UnsupportedEncodingException ex) {
458+
// shouldn't happen - if it does, proceed with requestUri as-is
459+
}
449460
ServletResponse response = this.pageContext.getResponse();
450461
if (response instanceof HttpServletResponse) {
451462
requestUri = ((HttpServletResponse) response).encodeURL(requestUri);
@@ -471,7 +482,7 @@ else if (StringUtils.hasText(servletRelativeAction)) {
471482
private String processAction(String action) {
472483
RequestDataValueProcessor processor = getRequestContext().getRequestDataValueProcessor();
473484
ServletRequest request = this.pageContext.getRequest();
474-
if ((processor != null) && (request instanceof HttpServletRequest)) {
485+
if (processor != null && request instanceof HttpServletRequest) {
475486
action = processor.processAction((HttpServletRequest) request, action);
476487
}
477488
return action;

0 commit comments

Comments
 (0)