Skip to content

Commit 52fdfd5

Browse files
committed
Polishing
1 parent 5c22002 commit 52fdfd5

File tree

11 files changed

+43
-42
lines changed

11 files changed

+43
-42
lines changed

spring-test/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,9 @@
1616

1717
package org.springframework.test.util;
1818

19-
import static org.hamcrest.MatcherAssert.*;
20-
import static org.springframework.test.util.AssertionErrors.*;
21-
2219
import java.io.ByteArrayInputStream;
2320
import java.util.Collections;
2421
import java.util.Map;
25-
2622
import javax.xml.namespace.QName;
2723
import javax.xml.parsers.DocumentBuilder;
2824
import javax.xml.parsers.DocumentBuilderFactory;
@@ -42,6 +38,9 @@
4238
import org.springframework.util.StringUtils;
4339
import org.springframework.util.xml.SimpleNamespaceContext;
4440

41+
import static org.hamcrest.MatcherAssert.*;
42+
import static org.springframework.test.util.AssertionErrors.*;
43+
4544
/**
4645
* A helper class for applying assertions via XPath expressions.
4746
*
@@ -113,7 +112,7 @@ protected Document parseXmlByteArray(byte[] xml, String encoding) throws Excepti
113112
factory.setNamespaceAware(this.hasNamespaces);
114113
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
115114
InputSource inputSource = new InputSource(new ByteArrayInputStream(xml));
116-
if(StringUtils.hasText(encoding)) {
115+
if (StringUtils.hasText(encoding)) {
117116
inputSource.setEncoding(encoding);
118117
}
119118
return documentBuilder.parse(inputSource);

spring-web/src/main/java/org/springframework/web/client/HttpMessageConverterExtractor.java

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

3232
/**
33-
* Response extractor that uses the given {@linkplain HttpMessageConverter entity
34-
* converters} to convert the response into a type {@code T}.
33+
* Response extractor that uses the given {@linkplain HttpMessageConverter entity converters}
34+
* to convert the response into a type {@code T}.
3535
*
3636
* @author Arjen Poutsma
37-
* @see RestTemplate
3837
* @since 3.0
38+
* @see RestTemplate
3939
*/
4040
public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
4141

@@ -47,19 +47,18 @@ public class HttpMessageConverterExtractor<T> implements ResponseExtractor<T> {
4747

4848
private final Log logger;
4949

50+
5051
/**
51-
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given
52-
* response type and message converters. The given converters must support the response
53-
* type.
52+
* Create a new instance of the {@code HttpMessageConverterExtractor} with the given response
53+
* type and message converters. The given converters must support the response type.
5454
*/
5555
public HttpMessageConverterExtractor(Class<T> responseType, List<HttpMessageConverter<?>> messageConverters) {
5656
this((Type) responseType, messageConverters);
5757
}
5858

5959
/**
60-
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given
61-
* response type and message converters. The given converters must support the response
62-
* type.
60+
* Creates a new instance of the {@code HttpMessageConverterExtractor} with the given response
61+
* type and message converters. The given converters must support the response type.
6362
*/
6463
public HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverter<?>> messageConverters) {
6564
this(responseType, messageConverters, LogFactory.getLog(HttpMessageConverterExtractor.class));
@@ -75,10 +74,10 @@ public HttpMessageConverterExtractor(Type responseType, List<HttpMessageConverte
7574
this.logger = logger;
7675
}
7776

77+
7878
@Override
79-
@SuppressWarnings({ "unchecked", "rawtypes" })
79+
@SuppressWarnings({"unchecked", "rawtypes"})
8080
public T extractData(ClientHttpResponse response) throws IOException {
81-
8281
MessageBodyClientHttpResponseWrapper responseWrapper = new MessageBodyClientHttpResponseWrapper(response);
8382
if (!responseWrapper.hasMessageBody() || responseWrapper.hasEmptyMessageBody()) {
8483
return null;
@@ -106,9 +105,9 @@ public T extractData(ClientHttpResponse response) throws IOException {
106105
}
107106
}
108107
}
109-
throw new RestClientException(
110-
"Could not extract response: no suitable HttpMessageConverter found for response type [" +
111-
this.responseType + "] and content type [" + contentType + "]");
108+
109+
throw new RestClientException("Could not extract response: no suitable HttpMessageConverter found " +
110+
"for response type [" + this.responseType + "] and content type [" + contentType + "]");
112111
}
113112

114113
private MediaType getContentType(ClientHttpResponse response) {

spring-webmvc/src/main/java/org/springframework/web/servlet/config/ResourcesBeanDefinitionParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ private void parseResourceResolversTransformers(boolean isAutoRegistration,
310310
}
311311

312312
if (isAutoRegistration) {
313-
if(isWebJarsAssetLocatorPresent) {
313+
if (isWebJarsAssetLocatorPresent) {
314314
RootBeanDefinition webJarsResolverDef = new RootBeanDefinition(WebJarsResourceResolver.class);
315315
webJarsResolverDef.setSource(source);
316316
webJarsResolverDef.setRole(BeanDefinition.ROLE_INFRASTRUCTURE);

spring-webmvc/src/main/java/org/springframework/web/servlet/config/annotation/ResourceChainRegistration.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class ResourceChainRegistration {
4545
private static final boolean isWebJarsAssetLocatorPresent = ClassUtils.isPresent(
4646
"org.webjars.WebJarAssetLocator", ResourceChainRegistration.class.getClassLoader());
4747

48+
4849
private final List<ResourceResolver> resolvers = new ArrayList<ResourceResolver>(4);
4950

5051
private final List<ResourceTransformer> transformers = new ArrayList<ResourceTransformer>(4);
@@ -103,7 +104,7 @@ public ResourceChainRegistration addTransformer(ResourceTransformer transformer)
103104
protected List<ResourceResolver> getResourceResolvers() {
104105
if (!this.hasPathResolver) {
105106
List<ResourceResolver> result = new ArrayList<ResourceResolver>(this.resolvers);
106-
if(isWebJarsAssetLocatorPresent) {
107+
if (isWebJarsAssetLocatorPresent) {
107108
result.add(new WebJarsResourceResolver());
108109
}
109110
result.add(new PathResourceResolver());

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/CachingResourceResolver.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
8686
protected String computeKey(HttpServletRequest request, String requestPath) {
8787
StringBuilder key = new StringBuilder(RESOLVED_RESOURCE_CACHE_KEY_PREFIX);
8888
key.append(requestPath);
89-
if(request != null) {
89+
if (request != null) {
9090
String encoding = request.getHeader("Accept-Encoding");
91-
if(encoding != null && encoding.contains("gzip")) {
91+
if (encoding != null && encoding.contains("gzip")) {
9292
key.append("+encoding=gzip");
9393
}
9494
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,10 @@ private boolean isResourceUnderLocation(Resource resource, Resource location) th
161161
if (!resource.getClass().equals(location.getClass())) {
162162
return false;
163163
}
164+
164165
String resourcePath;
165166
String locationPath;
167+
166168
if (resource instanceof UrlResource) {
167169
resourcePath = resource.getURL().toExternalForm();
168170
locationPath = StringUtils.cleanPath(location.getURL().toString());
@@ -179,13 +181,15 @@ else if (resource instanceof ServletContextResource) {
179181
resourcePath = resource.getURL().getPath();
180182
locationPath = StringUtils.cleanPath(location.getURL().getPath());
181183
}
182-
if(locationPath.equals(resourcePath)) {
184+
185+
if (locationPath.equals(resourcePath)) {
183186
return true;
184187
}
185188
locationPath = (locationPath.endsWith("/") || locationPath.isEmpty() ? locationPath : locationPath + "/");
186189
if (!resourcePath.startsWith(locationPath)) {
187190
return false;
188191
}
192+
189193
if (resourcePath.contains("%")) {
190194
// Use URLDecoder (vs UriUtils) to preserve potentially decoded UTF-8 chars...
191195
if (URLDecoder.decode(resourcePath, "UTF-8").contains("../")) {
@@ -195,6 +199,7 @@ else if (resource instanceof ServletContextResource) {
195199
return false;
196200
}
197201
}
202+
198203
return true;
199204
}
200205

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ protected MediaType getMediaType(Resource resource) {
416416
*/
417417
protected void setETagHeader(HttpServletRequest request, HttpServletResponse response) {
418418
String versionString = (String) request.getAttribute(VersionResourceResolver.RESOURCE_VERSION_ATTRIBUTE);
419-
if(versionString != null) {
419+
if (versionString != null) {
420420
response.setHeader(HttpHeaders.ETAG, "\"" + versionString + "\"");
421421
}
422422
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceUrlProvider.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import org.springframework.web.servlet.handler.SimpleUrlHandlerMapping;
3737
import org.springframework.web.util.UrlPathHelper;
3838

39-
4039
/**
4140
* A central component to use to obtain the public URL path that clients should
4241
* use to access a static resource.
@@ -130,7 +129,7 @@ public void onApplicationEvent(ContextRefreshedEvent event) {
130129
if (this.handlerMap.isEmpty() && logger.isDebugEnabled()) {
131130
logger.debug("No resource handling mappings found");
132131
}
133-
if(!this.handlerMap.isEmpty()) {
132+
if (!this.handlerMap.isEmpty()) {
134133
this.autodetect = false;
135134
}
136135
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/VersionResourceResolver.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* See the License for the specific language governing permissions and
1414
* limitations under the License.
1515
*/
16+
1617
package org.springframework.web.servlet.resource;
1718

1819
import java.util.ArrayList;
@@ -167,7 +168,7 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
167168
if (logger.isTraceEnabled()) {
168169
logger.trace("resource matches extracted version");
169170
}
170-
if(request != null) {
171+
if (request != null) {
171172
request.setAttribute(VersionResourceResolver.RESOURCE_VERSION_ATTRIBUTE, candidateVersion);
172173
}
173174
return baseResource;

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/WebJarsResourceResolver.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,18 @@
2525
import org.springframework.core.io.Resource;
2626

2727
/**
28-
* A {@code ResourceResolver} that delegates to the chain to locate a resource
29-
* and then attempts to find a matching versioned resource contained in a WebJar JAR file.
28+
* A {@code ResourceResolver} that delegates to the chain to locate a resource and then
29+
* attempts to find a matching versioned resource contained in a WebJar JAR file.
3030
*
3131
* <p>This allows WebJars.org users to write version agnostic paths in their templates,
3232
* like {@code <script src="/jquery/jquery.min.js"/>}.
3333
* This path will be resolved to the unique version {@code <script src="/jquery/1.2.0/jquery.min.js"/>},
3434
* which is a better fit for HTTP caching and version management in applications.
3535
*
36-
* <p>This also resolves Resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}.
36+
* <p>This also resolves resources for version agnostic HTTP requests {@code "GET /jquery/jquery.min.js"}.
3737
*
38-
* <p>This resolver requires the "org.webjars:webjars-locator" library on classpath, and is automatically
39-
* registered if that library is present.
38+
* <p>This resolver requires the "org.webjars:webjars-locator" library on classpath,
39+
* and is automatically registered if that library is present.
4040
*
4141
* @author Brian Clozel
4242
* @since 4.2
@@ -49,12 +49,7 @@ public class WebJarsResourceResolver extends AbstractResourceResolver {
4949

5050
private final static int WEBJARS_LOCATION_LENGTH = WEBJARS_LOCATION.length();
5151

52-
private final WebJarAssetLocator webJarAssetLocator;
53-
54-
55-
public WebJarsResourceResolver() {
56-
this.webJarAssetLocator = new WebJarAssetLocator();
57-
}
52+
private final WebJarAssetLocator webJarAssetLocator = new WebJarAssetLocator();
5853

5954

6055
@Override
@@ -64,7 +59,7 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
6459
Resource resolved = chain.resolveResource(request, requestPath, locations);
6560
if (resolved == null) {
6661
String webJarResourcePath = findWebJarResourcePath(requestPath);
67-
if(webJarResourcePath != null) {
62+
if (webJarResourcePath != null) {
6863
return chain.resolveResource(request, webJarResourcePath, locations);
6964
}
7065
}
@@ -78,7 +73,7 @@ protected String resolveUrlPathInternal(String resourceUrlPath,
7873
String path = chain.resolveUrlPath(resourceUrlPath, locations);
7974
if (path == null) {
8075
String webJarResourcePath = findWebJarResourcePath(resourceUrlPath);
81-
if(webJarResourcePath != null) {
76+
if (webJarResourcePath != null) {
8277
return chain.resolveUrlPath(webJarResourcePath, locations);
8378
}
8479
}

0 commit comments

Comments
 (0)