Skip to content

Commit 2c73c5a

Browse files
committed
Polishing
1 parent 987d93f commit 2c73c5a

File tree

7 files changed

+32
-33
lines changed

7 files changed

+32
-33
lines changed

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

Lines changed: 10 additions & 16 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-2015 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.
@@ -56,8 +56,7 @@ public class XpathExpectationsHelper {
5656

5757

5858
/**
59-
* Class constructor.
60-
*
59+
* XpathExpectationsHelper constructor.
6160
* @param expression the XPath expression
6261
* @param namespaces XML namespaces referenced in the XPath expression, or {@code null}
6362
* @param args arguments to parameterize the XPath expression with using the
@@ -72,6 +71,7 @@ public XpathExpectationsHelper(String expression, Map<String, String> namespaces
7271
this.hasNamespaces = !CollectionUtils.isEmpty(namespaces);
7372
}
7473

74+
7575
private XPathExpression compileXpathExpression(String expression, Map<String, String> namespaces)
7676
throws XPathExpressionException {
7777

@@ -83,36 +83,33 @@ private XPathExpression compileXpathExpression(String expression, Map<String, St
8383
}
8484

8585
/**
86-
* @return the compiled XPath expression.
86+
* Return the compiled XPath expression.
8787
*/
8888
protected XPathExpression getXpathExpression() {
8989
return this.xpathExpression;
9090
}
9191

9292
/**
93-
* Parse the content, evaluate the XPath expression as a {@link Node}, and
94-
* assert it with the given {@code Matcher<Node>}.
93+
* Parse the content, evaluate the XPath expression as a {@link Node},
94+
* and assert it with the given {@code Matcher<Node>}.
9595
*/
96-
public void assertNode(String content, final Matcher<? super Node> matcher) throws Exception {
96+
public void assertNode(String content, Matcher<? super Node> matcher) throws Exception {
9797
Document document = parseXmlString(content);
9898
Node node = evaluateXpath(document, XPathConstants.NODE, Node.class);
9999
assertThat("XPath " + this.expression, node, matcher);
100100
}
101101

102102
/**
103103
* Parse the given XML content to a {@link Document}.
104-
*
105104
* @param xml the content to parse
106105
* @return the parsed document
107-
* @throws Exception in case of errors
108106
*/
109-
protected Document parseXmlString(String xml) throws Exception {
107+
protected Document parseXmlString(String xml) throws Exception {
110108
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
111109
factory.setNamespaceAware(this.hasNamespaces);
112110
DocumentBuilder documentBuilder = factory.newDocumentBuilder();
113111
InputSource inputSource = new InputSource(new StringReader(xml));
114-
Document document = documentBuilder.parse(inputSource);
115-
return document;
112+
return documentBuilder.parse(inputSource);
116113
}
117114

118115
/**
@@ -149,7 +146,6 @@ public void doesNotExist(String content) throws Exception {
149146
/**
150147
* Apply the XPath expression and assert the resulting content with the
151148
* given Hamcrest matcher.
152-
*
153149
* @throws Exception if content parsing or expression evaluation fails
154150
*/
155151
public void assertNodeCount(String content, Matcher<Integer> matcher) throws Exception {
@@ -171,7 +167,6 @@ public void assertNodeCount(String content, int expectedCount) throws Exception
171167
/**
172168
* Apply the XPath expression and assert the resulting content with the
173169
* given Hamcrest matcher.
174-
*
175170
* @throws Exception if content parsing or expression evaluation fails
176171
*/
177172
public void assertString(String content, Matcher<? super String> matcher) throws Exception {
@@ -193,7 +188,6 @@ public void assertString(String content, String expectedValue) throws Exception
193188
/**
194189
* Apply the XPath expression and assert the resulting content with the
195190
* given Hamcrest matcher.
196-
*
197191
* @throws Exception if content parsing or expression evaluation fails
198192
*/
199193
public void assertNumber(String content, Matcher<? super Double> matcher) throws Exception {
@@ -222,4 +216,4 @@ public void assertBoolean(String content, boolean expectedValue) throws Exceptio
222216
assertEquals("XPath " + this.expression, expectedValue, Boolean.parseBoolean(actual));
223217
}
224218

225-
}
219+
}

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/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
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2014 the original author or authors.
2+
* Copyright 2002-2015 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.
@@ -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;

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

Lines changed: 3 additions & 2 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-2015 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.
@@ -30,7 +30,6 @@
3030

3131
import org.springframework.util.StringUtils;
3232
import org.springframework.web.servlet.support.RequestDataValueProcessor;
33-
import org.springframework.web.util.HtmlUtils;
3433
import org.springframework.web.util.JavaScriptUtils;
3534
import org.springframework.web.util.TagUtils;
3635
import org.springframework.web.util.UriUtils;
@@ -311,10 +310,12 @@ protected String replaceUriTemplateParams(String uri, List<Param> params, Set<St
311310
return uri;
312311
}
313312

313+
314314
/**
315315
* Internal enum that classifies URLs by type.
316316
*/
317317
private enum UrlType {
318+
318319
CONTEXT_RELATIVE, RELATIVE, ABSOLUTE
319320
}
320321

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,8 @@
8989
* @see InternalResourceViewResolver
9090
* @see BeanNameViewResolver
9191
*/
92-
public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport implements ViewResolver, Ordered, InitializingBean {
93-
94-
private static final Log logger = LogFactory.getLog(ContentNegotiatingViewResolver.class);
92+
public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
93+
implements ViewResolver, Ordered, InitializingBean {
9594

9695
private int order = Ordered.HIGHEST_PRECEDENCE;
9796

@@ -267,7 +266,7 @@ protected void initServletContext(ServletContext servletContext) {
267266
}
268267
}
269268
else {
270-
for (int i=0; i < viewResolvers.size(); i++) {
269+
for (int i = 0; i < viewResolvers.size(); i++) {
271270
if (matchingBeans.contains(viewResolvers.get(i))) {
272271
continue;
273272
}
@@ -326,8 +325,8 @@ protected List<MediaType> getMediaTypes(HttpServletRequest request) {
326325
ServletWebRequest webRequest = new ServletWebRequest(request);
327326

328327
List<MediaType> acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest);
329-
acceptableMediaTypes = acceptableMediaTypes.isEmpty() ?
330-
Collections.singletonList(MediaType.ALL) : acceptableMediaTypes;
328+
acceptableMediaTypes = (!acceptableMediaTypes.isEmpty() ? acceptableMediaTypes :
329+
Collections.singletonList(MediaType.ALL));
331330

332331
List<MediaType> producibleMediaTypes = getProducibleMediaTypes(request);
333332
Set<MediaType> compatibleMediaTypes = new LinkedHashSet<MediaType>();
@@ -369,7 +368,7 @@ private List<MediaType> getProducibleMediaTypes(HttpServletRequest request) {
369368
*/
370369
private MediaType getMostSpecificMediaType(MediaType acceptType, MediaType produceType) {
371370
produceType = produceType.copyQualityValue(acceptType);
372-
return MediaType.SPECIFICITY_COMPARATOR.compare(acceptType, produceType) < 0 ? acceptType : produceType;
371+
return (MediaType.SPECIFICITY_COMPARATOR.compare(acceptType, produceType) < 0 ? acceptType : produceType);
373372
}
374373

375374
private List<View> getCandidateViews(String viewName, Locale locale, List<MediaType> requestedMediaTypes)
@@ -416,8 +415,8 @@ private View getBestView(List<View> candidateViews, List<MediaType> requestedMed
416415
MediaType candidateContentType = MediaType.parseMediaType(candidateView.getContentType());
417416
if (mediaType.isCompatibleWith(candidateContentType)) {
418417
if (logger.isDebugEnabled()) {
419-
logger.debug("Returning [" + candidateView + "] based on requested media type '"
420-
+ mediaType + "'");
418+
logger.debug("Returning [" + candidateView + "] based on requested media type '" +
419+
mediaType + "'");
421420
}
422421
attrs.setAttribute(View.SELECTED_CONTENT_TYPE, mediaType, RequestAttributes.SCOPE_REQUEST);
423422
return candidateView;

0 commit comments

Comments
 (0)