Skip to content

Commit a1916ca

Browse files
committed
polishing
1 parent d6197b7 commit a1916ca

File tree

5 files changed

+70
-46
lines changed

5 files changed

+70
-46
lines changed

org.springframework.context/src/main/java/org/springframework/format/annotation/DateTimeFormat.java

Lines changed: 4 additions & 2 deletions
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.format.annotation;
1718

1819
import java.lang.annotation.ElementType;
@@ -43,7 +44,7 @@
4344
* @since 3.0
4445
* @see org.joda.time.format.DateTimeFormat
4546
*/
46-
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
47+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
4748
@Retention(RetentionPolicy.RUNTIME)
4849
public @interface DateTimeFormat {
4950

@@ -69,6 +70,7 @@
6970
*/
7071
String pattern() default "";
7172

73+
7274
/**
7375
* Common ISO date time format patterns.
7476
* @author Keith Donald
@@ -96,6 +98,6 @@ public enum ISO {
9698
* Indicates that no ISO-based format pattern should be applied.
9799
*/
98100
NONE
99-
100101
}
102+
101103
}

org.springframework.context/src/main/java/org/springframework/format/annotation/NumberFormat.java

Lines changed: 4 additions & 2 deletions
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.format.annotation;
1718

1819
import java.lang.annotation.ElementType;
@@ -36,7 +37,7 @@
3637
* @since 3.0
3738
* @see java.text.NumberFormat
3839
*/
39-
@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER })
40+
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.PARAMETER})
4041
@Retention(RetentionPolicy.RUNTIME)
4142
public @interface NumberFormat {
4243

@@ -54,6 +55,7 @@
5455
*/
5556
String pattern() default "";
5657

58+
5759
/**
5860
* Common number format styles.
5961
* @author Keith Donald
@@ -75,6 +77,6 @@ public enum Style {
7577
* The percent format for the current locale.
7678
*/
7779
PERCENT
78-
7980
}
81+
8082
}

org.springframework.context/src/main/java/org/springframework/format/datetime/joda/DateTimeFormatAnnotationFormatterFactory.java

Lines changed: 24 additions & 10 deletions
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.format.datetime.joda;
1718

1819
import java.util.Calendar;
@@ -29,6 +30,7 @@
2930
import org.joda.time.ReadableInstant;
3031
import org.joda.time.ReadablePartial;
3132
import org.joda.time.format.DateTimeFormatter;
33+
3234
import org.springframework.format.AnnotationFormatterFactory;
3335
import org.springframework.format.Parser;
3436
import org.springframework.format.Printer;
@@ -37,14 +39,17 @@
3739

3840
/**
3941
* Formats fields annotated with the {@link DateTimeFormat} annotation.
42+
*
4043
* @author Keith Donald
44+
* @author Juergen Hoeller
4145
* @since 3.0
4246
* @see DateTimeFormat
4347
*/
4448
public final class DateTimeFormatAnnotationFormatterFactory implements AnnotationFormatterFactory<DateTimeFormat> {
4549

4650
private final Set<Class<?>> fieldTypes;
4751

52+
4853
public DateTimeFormatAnnotationFormatterFactory() {
4954
this.fieldTypes = Collections.unmodifiableSet(createFieldTypes());
5055
}
@@ -53,16 +58,20 @@ public Set<Class<?>> getFieldTypes() {
5358
return this.fieldTypes;
5459
}
5560

61+
5662
public Printer<?> getPrinter(DateTimeFormat annotation, Class<?> fieldType) {
5763
DateTimeFormatter formatter = configureDateTimeFormatterFrom(annotation);
5864
if (ReadableInstant.class.isAssignableFrom(fieldType)) {
5965
return new ReadableInstantPrinter(formatter);
60-
} else if (ReadablePartial.class.isAssignableFrom(fieldType)) {
66+
}
67+
else if (ReadablePartial.class.isAssignableFrom(fieldType)) {
6168
return new ReadablePartialPrinter(formatter);
62-
} else if (Calendar.class.isAssignableFrom(fieldType)) {
69+
}
70+
else if (Calendar.class.isAssignableFrom(fieldType)) {
6371
// assumes Calendar->ReadableInstant converter is registered
6472
return new ReadableInstantPrinter(formatter);
65-
} else {
73+
}
74+
else {
6675
// assumes Date->Long converter is registered
6776
return new MillisecondInstantPrinter(formatter);
6877
}
@@ -72,6 +81,7 @@ public Parser<DateTime> getParser(DateTimeFormat annotation, Class<?> fieldType)
7281
return new DateTimeParser(configureDateTimeFormatterFrom(annotation));
7382
}
7483

84+
7585
// internal helpers
7686

7787
private Set<Class<?>> createFieldTypes() {
@@ -90,9 +100,11 @@ private Set<Class<?>> createFieldTypes() {
90100
private DateTimeFormatter configureDateTimeFormatterFrom(DateTimeFormat annotation) {
91101
if (!annotation.pattern().isEmpty()) {
92102
return forPattern(annotation.pattern());
93-
} else if (annotation.iso() != ISO.NONE) {
94-
return forISO(annotation.iso());
95-
} else {
103+
}
104+
else if (annotation.iso() != ISO.NONE) {
105+
return forIso(annotation.iso());
106+
}
107+
else {
96108
return forStyle(annotation.style());
97109
}
98110
}
@@ -101,12 +113,14 @@ private DateTimeFormatter forPattern(String pattern) {
101113
return org.joda.time.format.DateTimeFormat.forPattern(pattern);
102114
}
103115

104-
private DateTimeFormatter forISO(ISO iso) {
116+
private DateTimeFormatter forIso(ISO iso) {
105117
if (iso == ISO.DATE) {
106118
return org.joda.time.format.ISODateTimeFormat.date();
107-
} else if (iso == ISO.TIME) {
119+
}
120+
else if (iso == ISO.TIME) {
108121
return org.joda.time.format.ISODateTimeFormat.time();
109-
} else {
122+
}
123+
else {
110124
return org.joda.time.format.ISODateTimeFormat.dateTime();
111125
}
112126
}
@@ -115,4 +129,4 @@ private DateTimeFormatter forStyle(String style) {
115129
return org.joda.time.format.DateTimeFormat.forStyle(style);
116130
}
117131

118-
}
132+
}

org.springframework.context/src/main/java/org/springframework/format/datetime/joda/JodaTimeFormattingConfigurer.java

Lines changed: 35 additions & 24 deletions
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.format.datetime.joda;
1718

1819
import java.util.Calendar;
@@ -26,19 +27,22 @@
2627
import org.joda.time.format.DateTimeFormat;
2728
import org.joda.time.format.DateTimeFormatter;
2829
import org.joda.time.format.ISODateTimeFormat;
30+
2931
import org.springframework.format.FormatterRegistry;
3032
import org.springframework.format.Parser;
3133
import org.springframework.format.Printer;
3234

3335
/**
3436
* Configures Joda Time's Formatting system for use with Spring.
37+
*
3538
* @author Keith Donald
39+
* @author Juergen Hoeller
3640
* @since 3.0
37-
* @see #setDateStyle(String)
38-
* @see #setTimeStyle(String)
39-
* @see #setDateTimeStyle(String)
40-
* @see #setUseISOFormat(boolean)
41-
* @see #installJodaTimeFormatting(FormatterRegistry)
41+
* @see #setDateStyle
42+
* @see #setTimeStyle
43+
* @see #setDateTimeStyle
44+
* @see #setUseIsoFormat
45+
* @see #installJodaTimeFormatting
4246
*/
4347
public class JodaTimeFormattingConfigurer {
4448

@@ -48,12 +52,12 @@ public class JodaTimeFormattingConfigurer {
4852

4953
private String dateTimeStyle;
5054

51-
private boolean useISOFormat;
55+
private boolean useIsoFormat;
56+
5257

5358
/**
5459
* Set the default format style of Joda {@link LocalDate} objects.
5560
* Default is {@link DateTimeFormat#shortDate()}.
56-
* @param dateStyle the date format style
5761
*/
5862
public void setDateStyle(String dateStyle) {
5963
this.dateStyle = dateStyle;
@@ -62,16 +66,15 @@ public void setDateStyle(String dateStyle) {
6266
/**
6367
* Set the default format style of Joda {@link LocalTime} objects.
6468
* Default is {@link DateTimeFormat#shortTime()}.
65-
* @param timeStyle the time format style
6669
*/
6770
public void setTimeStyle(String timeStyle) {
6871
this.timeStyle = timeStyle;
6972
}
7073

7174
/**
72-
* Set the default format style of Joda {@link LocalDateTime} and {@link DateTime} objects, as well as JDK {@link Date} and {@link Calendar} objects.
75+
* Set the default format style of Joda {@link LocalDateTime} and {@link DateTime} objects,
76+
* as well as JDK {@link Date} and {@link Calendar} objects.
7377
* Default is {@link DateTimeFormat#shortDateTime()}.
74-
* @param dateTimeStyle the date time format style
7578
*/
7679
public void setDateTimeStyle(String dateTimeStyle) {
7780
this.dateTimeStyle = dateTimeStyle;
@@ -81,27 +84,30 @@ public void setDateTimeStyle(String dateTimeStyle) {
8184
* Set whether standard ISO formatting should be applied to all Date/Time types.
8285
* Default is false (no).
8386
* If set to true, the dateStyle, timeStyle, and dateTimeStyle properties are ignored.
84-
* @param useISOFormat true to enable ISO formatting
8587
*/
86-
public void setUseISOFormat(boolean useISOFormat) {
87-
this.useISOFormat = useISOFormat;
88+
public void setUseIsoFormat(boolean useIsoFormat) {
89+
this.useIsoFormat = useIsoFormat;
8890
}
8991

92+
9093
/**
9194
* Install Joda Time formatters given the current configuration of this {@link JodaTimeFormattingConfigurer}.
9295
*/
9396
public void installJodaTimeFormatting(FormatterRegistry formatterRegistry) {
94-
JodaTimeConverters.registerConverters(formatterRegistry.getConverterRegistry());
97+
JodaTimeConverters.registerConverters(formatterRegistry);
9598

9699
DateTimeFormatter jodaDateFormatter = getJodaDateFormatter();
97-
formatterRegistry.addFormatterForFieldType(LocalDate.class, new ReadablePartialPrinter(jodaDateFormatter), new DateTimeParser(jodaDateFormatter));
100+
formatterRegistry.addFormatterForFieldType(LocalDate.class,
101+
new ReadablePartialPrinter(jodaDateFormatter), new DateTimeParser(jodaDateFormatter));
98102

99103
DateTimeFormatter jodaTimeFormatter = getJodaTimeFormatter();
100-
formatterRegistry.addFormatterForFieldType(LocalTime.class, new ReadablePartialPrinter(jodaTimeFormatter), new DateTimeParser(jodaTimeFormatter));
104+
formatterRegistry.addFormatterForFieldType(LocalTime.class,
105+
new ReadablePartialPrinter(jodaTimeFormatter), new DateTimeParser(jodaTimeFormatter));
101106

102107
DateTimeFormatter jodaDateTimeFormatter = getJodaDateTimeFormatter();
103108
Parser<DateTime> dateTimeParser = new DateTimeParser(jodaDateTimeFormatter);
104-
formatterRegistry.addFormatterForFieldType(LocalDateTime.class, new ReadablePartialPrinter(jodaDateTimeFormatter), dateTimeParser);
109+
formatterRegistry.addFormatterForFieldType(LocalDateTime.class,
110+
new ReadablePartialPrinter(jodaDateTimeFormatter), dateTimeParser);
105111

106112
Printer<ReadableInstant> readableInstantPrinter = new ReadableInstantPrinter(jodaDateTimeFormatter);
107113
formatterRegistry.addFormatterForFieldType(ReadableInstant.class, readableInstantPrinter, dateTimeParser);
@@ -111,37 +117,42 @@ public void installJodaTimeFormatting(FormatterRegistry formatterRegistry) {
111117
formatterRegistry.addFormatterForFieldAnnotation(new DateTimeFormatAnnotationFormatterFactory());
112118
}
113119

120+
114121
// internal helpers
115-
122+
116123
private DateTimeFormatter getJodaDateFormatter() {
117-
if (this.useISOFormat) {
124+
if (this.useIsoFormat) {
118125
return ISODateTimeFormat.date();
119126
}
120127
if (this.dateStyle != null) {
121128
return DateTimeFormat.forStyle(this.dateStyle + "-");
122-
} else {
129+
130+
}
131+
else {
123132
return DateTimeFormat.shortDate();
124133
}
125134
}
126135

127136
private DateTimeFormatter getJodaTimeFormatter() {
128-
if (this.useISOFormat) {
137+
if (this.useIsoFormat) {
129138
return ISODateTimeFormat.time();
130139
}
131140
if (this.timeStyle != null) {
132141
return DateTimeFormat.forStyle("-" + this.timeStyle);
133-
} else {
142+
}
143+
else {
134144
return DateTimeFormat.shortTime();
135145
}
136146
}
137147

138148
private DateTimeFormatter getJodaDateTimeFormatter() {
139-
if (this.useISOFormat) {
149+
if (this.useIsoFormat) {
140150
return ISODateTimeFormat.dateTime();
141151
}
142152
if (this.dateTimeStyle != null) {
143153
return DateTimeFormat.forStyle(this.dateTimeStyle);
144-
} else {
154+
}
155+
else {
145156
return DateTimeFormat.shortDateTime();
146157
}
147158
}

org.springframework.web.servlet/src/main/java/org/springframework/web/servlet/tags/UrlTag.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,23 +18,21 @@
1818

1919
import java.io.IOException;
2020
import java.io.UnsupportedEncodingException;
21-
import java.net.URLEncoder;
2221
import java.util.HashSet;
2322
import java.util.LinkedList;
2423
import java.util.List;
2524
import java.util.Set;
26-
2725
import javax.servlet.http.HttpServletRequest;
2826
import javax.servlet.http.HttpServletResponse;
2927
import javax.servlet.jsp.JspException;
3028
import javax.servlet.jsp.PageContext;
3129

30+
import org.springframework.util.StringUtils;
3231
import org.springframework.web.util.ExpressionEvaluationUtils;
3332
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;
37-
import org.springframework.util.StringUtils;
3836

3937
/**
4038
* JSP tag for creating URLs. Modeled after the JSTL c:url tag with backwards
@@ -44,7 +42,7 @@
4442
* <ul>
4543
* <li>URL encoded template URI variables</li>
4644
* <li>HTML/XML escaping of URLs</li>
47-
* <li>JavaScipt escaping of URLs</li>
45+
* <li>JavaScript escaping of URLs</li>
4846
* </ul>
4947
*
5048
* <p>Template URI variables are indicated in the {@link #setValue(String) 'value'}
@@ -235,13 +233,11 @@ private String createUrl() throws JspException {
235233
* @param includeQueryStringDelimiter true if the query string should start
236234
* with a '?' instead of '&'
237235
* @return the query string
238-
* @throws JspException
239236
*/
240237
protected String createQueryString(List<Param> params, Set<String> usedParams, boolean includeQueryStringDelimiter)
241238
throws JspException {
242239

243240
String encoding = pageContext.getResponse().getCharacterEncoding();
244-
245241
StringBuilder qs = new StringBuilder();
246242
for (Param param : params) {
247243
if (!usedParams.contains(param.getName()) && StringUtils.hasLength(param.getName())) {
@@ -274,12 +270,11 @@ protected String createQueryString(List<Param> params, Set<String> usedParams, b
274270
* @param params parameters used to replace template markers
275271
* @param usedParams set of template parameter names that have been replaced
276272
* @return the URL with template parameters replaced
277-
* @throws JspException
278273
*/
279274
protected String replaceUriTemplateParams(String uri, List<Param> params, Set<String> usedParams)
280275
throws JspException {
281-
String encoding = pageContext.getResponse().getCharacterEncoding();
282276

277+
String encoding = pageContext.getResponse().getCharacterEncoding();
283278
for (Param param : params) {
284279
String template = URL_TEMPLATE_DELIMITER_PREFIX + param.getName() + URL_TEMPLATE_DELIMITER_SUFFIX;
285280
if (uri.contains(template)) {

0 commit comments

Comments
 (0)