From 0bc01fcd55ea57290f7fbfcba0117f8af90fb3ba Mon Sep 17 00:00:00 2001 From: Juergen Hoeller Date: Fri, 30 Mar 2018 13:42:23 +0200 Subject: [PATCH] Polishing --- .../jdbc/core/SingleColumnRowMapperTests.java | 14 +++++++---- .../web/filter/ShallowEtagHeaderFilter.java | 20 ++++++---------- src/docs/asciidoc/core/core-validation.adoc | 10 ++++---- src/docs/asciidoc/web/webflux.adoc | 4 ++-- src/docs/asciidoc/web/webmvc.adoc | 24 +++++++++---------- 5 files changed, 35 insertions(+), 37 deletions(-) diff --git a/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java b/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java index eb7c45cc1cb..ee12b8b63c4 100644 --- a/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java +++ b/spring-jdbc/src/test/java/org/springframework/jdbc/core/SingleColumnRowMapperTests.java @@ -24,11 +24,12 @@ import java.sql.Timestamp; import java.time.LocalDateTime; import org.junit.Test; + import org.springframework.core.convert.support.DefaultConversionService; import org.springframework.dao.TypeMismatchDataAccessException; -import static org.mockito.BDDMockito.*; import static org.junit.Assert.*; +import static org.mockito.BDDMockito.*; /** * Tests for {@link SingleColumnRowMapper}. @@ -38,7 +39,7 @@ import static org.junit.Assert.*; */ public class SingleColumnRowMapperTests { - @Test // SPR-16483 + @Test // SPR-16483 public void useDefaultConversionService() throws SQLException { Timestamp timestamp = new Timestamp(0); @@ -57,7 +58,7 @@ public class SingleColumnRowMapperTests { assertEquals(timestamp.toLocalDateTime(), actualLocalDateTime); } - @Test // SPR-16483 + @Test // SPR-16483 public void useCustomConversionService() throws SQLException { Timestamp timestamp = new Timestamp(0); @@ -81,7 +82,7 @@ public class SingleColumnRowMapperTests { assertEquals(timestamp.toLocalDateTime(), actualMyLocalDateTime.value); } - @Test(expected = TypeMismatchDataAccessException.class) // SPR-16483 + @Test(expected = TypeMismatchDataAccessException.class) // SPR-16483 public void doesNotUseConversionService() throws SQLException { SingleColumnRowMapper rowMapper = SingleColumnRowMapper.newInstance(LocalDateTime.class, null); @@ -97,9 +98,12 @@ public class SingleColumnRowMapperTests { rowMapper.mapRow(resultSet, 1); } + private static class MyLocalDateTime { + private final LocalDateTime value; - private MyLocalDateTime(LocalDateTime value) { + + public MyLocalDateTime(LocalDateTime value) { this.value = value; } } diff --git a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java index f59da7c8058..517c336e85b 100644 --- a/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java +++ b/spring-web/src/main/java/org/springframework/web/filter/ShallowEtagHeaderFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2018 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -126,10 +126,8 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { String responseETag = generateETagHeaderValue(responseWrapper.getContentInputStream(), this.writeWeakETag); rawResponse.setHeader(HEADER_ETAG, responseETag); String requestETag = request.getHeader(HEADER_IF_NONE_MATCH); - if (requestETag != null - && (responseETag.equals(requestETag) - || responseETag.replaceFirst("^W/", "").equals(requestETag.replaceFirst("^W/", "")) - || "*".equals(requestETag))) { + if (requestETag != null && ("*".equals(requestETag) || responseETag.equals(requestETag) || + responseETag.replaceFirst("^W/", "").equals(requestETag.replaceFirst("^W/", "")))) { if (logger.isTraceEnabled()) { logger.trace("ETag [" + responseETag + "] equal to If-None-Match, sending 304"); } @@ -163,19 +161,15 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { * @param response the HTTP response * @param responseStatusCode the HTTP response status code * @param inputStream the response body - * @return {@code true} if eligible for ETag generation; {@code false} otherwise + * @return {@code true} if eligible for ETag generation, {@code false} otherwise */ protected boolean isEligibleForEtag(HttpServletRequest request, HttpServletResponse response, int responseStatusCode, InputStream inputStream) { String method = request.getMethod(); - if (responseStatusCode >= 200 && responseStatusCode < 300 - && HttpMethod.GET.matches(method)) { - + if (responseStatusCode >= 200 && responseStatusCode < 300 && HttpMethod.GET.matches(method)) { String cacheControl = response.getHeader(HEADER_CACHE_CONTROL); - if (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE)) { - return true; - } + return (cacheControl == null || !cacheControl.contains(DIRECTIVE_NO_STORE)); } return false; } @@ -189,7 +183,7 @@ public class ShallowEtagHeaderFilter extends OncePerRequestFilter { * @see org.springframework.util.DigestUtils */ protected String generateETagHeaderValue(InputStream inputStream, boolean isWeak) throws IOException { - // length of W/ + 0 + " + 32bits md5 hash + " + // length of W/ + " + 0 + 32bits md5 hash + " StringBuilder builder = new StringBuilder(37); if (isWeak) { builder.append("W/"); diff --git a/src/docs/asciidoc/core/core-validation.adoc b/src/docs/asciidoc/core/core-validation.adoc index dd47b8c2d1d..a3a99e624f6 100644 --- a/src/docs/asciidoc/core/core-validation.adoc +++ b/src/docs/asciidoc/core/core-validation.adoc @@ -1106,7 +1106,7 @@ The `number` package provides a `NumberFormatter`, `CurrencyFormatter`, and `PercentFormatter` to format `java.lang.Number` objects using a `java.text.NumberFormat`. The `datetime` package provides a `DateFormatter` to format `java.util.Date` objects with a `java.text.DateFormat`. The `datetime.joda` package provides comprehensive datetime -formatting support based on the http://joda-time.sourceforge.net[Joda Time library]. +formatting support based on the http://joda-time.sourceforge.net[Joda-Time library]. Consider `DateFormatter` as an example `Formatter` implementation: @@ -1240,7 +1240,7 @@ To trigger formatting, simply annotate fields with @NumberFormat: A portable format annotation API exists in the `org.springframework.format.annotation` package. Use @NumberFormat to format java.lang.Number fields. Use @DateTimeFormat to -format java.util.Date, java.util.Calendar, java.util.Long, or Joda Time fields. +format java.util.Date, java.util.Calendar, java.util.Long, or Joda-Time fields. The example below uses @DateTimeFormat to format a java.util.Date as a ISO Date (yyyy-MM-dd): @@ -1344,10 +1344,10 @@ You will need to ensure that Spring does not register default formatters, and in you should register all formatters manually. Use the `org.springframework.format.datetime.joda.JodaTimeFormatterRegistrar` or `org.springframework.format.datetime.DateFormatterRegistrar` class depending on whether -you use the Joda Time library. +you use the Joda-Time library. For example, the following Java configuration will register a global ' `yyyyMMdd`' -format. This example does not depend on the Joda Time library: +format. This example does not depend on the Joda-Time library: [source,java,indent=0] [subs="verbatim,quotes"] @@ -1412,7 +1412,7 @@ Time: [NOTE] ==== -Joda Time provides separate distinct types to represent `date`, `time` and `date-time` +Joda-Time provides separate distinct types to represent `date`, `time` and `date-time` values. The `dateFormatter`, `timeFormatter` and `dateTimeFormatter` properties of the `JodaTimeFormatterRegistrar` should be used to configure the different formats for each type. The `DateTimeFormatterFactoryBean` provides a convenient way to create formatters. diff --git a/src/docs/asciidoc/web/webflux.adoc b/src/docs/asciidoc/web/webflux.adoc index 52a32b59ebe..a85fd9da2fd 100644 --- a/src/docs/asciidoc/web/webflux.adoc +++ b/src/docs/asciidoc/web/webflux.adoc @@ -2452,8 +2452,8 @@ In your Java config implement the `WebFluxConfigurer` interface: [.small]#<># By default formatters for `Number` and `Date` types are installed, including support for -the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda Time -formatting library is also installed if Joda Time is present on the classpath. +the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda-Time +formatting library is also installed if Joda-Time is present on the classpath. To register custom formatters and converters: diff --git a/src/docs/asciidoc/web/webmvc.adoc b/src/docs/asciidoc/web/webmvc.adoc index fdf561bd191..336becafb88 100644 --- a/src/docs/asciidoc/web/webmvc.adoc +++ b/src/docs/asciidoc/web/webmvc.adoc @@ -277,10 +277,10 @@ The table below lists the special beans detected by the `DispatcherHandler`: === Web MVC Config [.small]#<># -Applications can declare the infrastructure beans listed in <> +Applications can declare the infrastructure beans listed in <> that are required to process requests. The `DispatcherServlet` checks the -`WebApplicationContext` for each special bean. If there are no matching bean types, it -falls back on the default types listed in +`WebApplicationContext` for each special bean. If there are no matching bean types, +it falls back on the default types listed in https://github.com/spring-projects/spring-framework/blob/master/spring-webmvc/src/main/resources/org/springframework/web/servlet/DispatcherServlet.properties[DispatcherServlet.properties]. In most cases the <> is the best starting point. It declares the required @@ -3733,9 +3733,9 @@ applications along with a configuration API to customize it. For more advanced customizations, not available in the configuration API, see <> and <>. -You do not need to understand the underlying beans created by the MVC Java config and the -MVC namespace but if you want to learn more, see <> and -<>. +You do not need to understand the underlying beans created by the MVC Java config and +the MVC namespace but if you want to learn more, see <> +and <>. [[mvc-config-enable]] @@ -3796,10 +3796,10 @@ In Java config implement `WebMvcConfigurer` interface: } ---- -In XML check attributes and sub-elements of ``. You can view the -http://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or use the code -completion feature of your IDE to discover what attributes and sub-elements are -available. +In XML check attributes and sub-elements of ``. You can +view the http://schema.spring.io/mvc/spring-mvc.xsd[Spring MVC XML schema] or use +the code completion feature of your IDE to discover what attributes and +sub-elements are available. @@ -3808,8 +3808,8 @@ available. [.small]#<># By default formatters for `Number` and `Date` types are installed, including support for -the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda Time -formatting library is also installed if Joda Time is present on the classpath. +the `@NumberFormat` and `@DateTimeFormat` annotations. Full support for the Joda-Time +formatting library is also installed if Joda-Time is present on the classpath. In Java config, register custom formatters and converters: