1
1
/*
2
- * Copyright 2002-2020 the original author or authors.
2
+ * Copyright 2002-2023 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
28
28
import org .springframework .util .StringUtils ;
29
29
30
30
/**
31
- * Abstract implementation of the {@link Errors} interface. Provides common
32
- * access to evaluated errors; however, does not define concrete management
31
+ * Abstract implementation of the {@link Errors} interface.
32
+ * Provides nested path handling but does not define concrete management
33
33
* of {@link ObjectError ObjectErrors} and {@link FieldError FieldErrors}.
34
34
*
35
35
* @author Juergen Hoeller
36
36
* @author Rossen Stoyanchev
37
37
* @since 2.5.3
38
+ * @see AbstractBindingResult
38
39
*/
39
40
@ SuppressWarnings ("serial" )
40
41
public abstract class AbstractErrors implements Errors , Serializable {
@@ -81,8 +82,8 @@ protected void doSetNestedPath(@Nullable String nestedPath) {
81
82
nestedPath = "" ;
82
83
}
83
84
nestedPath = canonicalFieldName (nestedPath );
84
- if (nestedPath .length () > 0 && !nestedPath .endsWith (Errors . NESTED_PATH_SEPARATOR )) {
85
- nestedPath += Errors . NESTED_PATH_SEPARATOR ;
85
+ if (nestedPath .length () > 0 && !nestedPath .endsWith (NESTED_PATH_SEPARATOR )) {
86
+ nestedPath += NESTED_PATH_SEPARATOR ;
86
87
}
87
88
this .nestedPath = nestedPath ;
88
89
}
@@ -97,7 +98,7 @@ protected String fixedField(@Nullable String field) {
97
98
}
98
99
else {
99
100
String path = getNestedPath ();
100
- return (path .endsWith (Errors . NESTED_PATH_SEPARATOR ) ?
101
+ return (path .endsWith (NESTED_PATH_SEPARATOR ) ?
101
102
path .substring (0 , path .length () - NESTED_PATH_SEPARATOR .length ()) : path );
102
103
}
103
104
}
@@ -112,117 +113,19 @@ protected String canonicalFieldName(String field) {
112
113
return field ;
113
114
}
114
115
115
-
116
- @ Override
117
- public void reject (String errorCode ) {
118
- reject (errorCode , null , null );
119
- }
120
-
121
- @ Override
122
- public void reject (String errorCode , String defaultMessage ) {
123
- reject (errorCode , null , defaultMessage );
124
- }
125
-
126
- @ Override
127
- public void rejectValue (@ Nullable String field , String errorCode ) {
128
- rejectValue (field , errorCode , null , null );
129
- }
130
-
131
- @ Override
132
- public void rejectValue (@ Nullable String field , String errorCode , String defaultMessage ) {
133
- rejectValue (field , errorCode , null , defaultMessage );
134
- }
135
-
136
-
137
- @ Override
138
- public boolean hasErrors () {
139
- return !getAllErrors ().isEmpty ();
140
- }
141
-
142
- @ Override
143
- public int getErrorCount () {
144
- return getAllErrors ().size ();
145
- }
146
-
147
- @ Override
148
- public List <ObjectError > getAllErrors () {
149
- List <ObjectError > result = new ArrayList <>();
150
- result .addAll (getGlobalErrors ());
151
- result .addAll (getFieldErrors ());
152
- return Collections .unmodifiableList (result );
153
- }
154
-
155
- @ Override
156
- public boolean hasGlobalErrors () {
157
- return (getGlobalErrorCount () > 0 );
158
- }
159
-
160
- @ Override
161
- public int getGlobalErrorCount () {
162
- return getGlobalErrors ().size ();
163
- }
164
-
165
- @ Override
166
- @ Nullable
167
- public ObjectError getGlobalError () {
168
- List <ObjectError > globalErrors = getGlobalErrors ();
169
- return (!globalErrors .isEmpty () ? globalErrors .get (0 ) : null );
170
- }
171
-
172
- @ Override
173
- public boolean hasFieldErrors () {
174
- return (getFieldErrorCount () > 0 );
175
- }
176
-
177
- @ Override
178
- public int getFieldErrorCount () {
179
- return getFieldErrors ().size ();
180
- }
181
-
182
- @ Override
183
- @ Nullable
184
- public FieldError getFieldError () {
185
- List <FieldError > fieldErrors = getFieldErrors ();
186
- return (!fieldErrors .isEmpty () ? fieldErrors .get (0 ) : null );
187
- }
188
-
189
- @ Override
190
- public boolean hasFieldErrors (String field ) {
191
- return (getFieldErrorCount (field ) > 0 );
192
- }
193
-
194
- @ Override
195
- public int getFieldErrorCount (String field ) {
196
- return getFieldErrors (field ).size ();
197
- }
198
-
199
116
@ Override
200
117
public List <FieldError > getFieldErrors (String field ) {
201
118
List <FieldError > fieldErrors = getFieldErrors ();
202
119
List <FieldError > result = new ArrayList <>();
203
120
String fixedField = fixedField (field );
204
- for (FieldError error : fieldErrors ) {
205
- if (isMatchingFieldError (fixedField , error )) {
206
- result .add (error );
121
+ for (FieldError fieldError : fieldErrors ) {
122
+ if (isMatchingFieldError (fixedField , fieldError )) {
123
+ result .add (fieldError );
207
124
}
208
125
}
209
126
return Collections .unmodifiableList (result );
210
127
}
211
128
212
- @ Override
213
- @ Nullable
214
- public FieldError getFieldError (String field ) {
215
- List <FieldError > fieldErrors = getFieldErrors (field );
216
- return (!fieldErrors .isEmpty () ? fieldErrors .get (0 ) : null );
217
- }
218
-
219
- @ Override
220
- @ Nullable
221
- public Class <?> getFieldType (String field ) {
222
- Object value = getFieldValue (field );
223
- return (value != null ? value .getClass () : null );
224
- }
225
-
226
129
/**
227
130
* Check whether the given FieldError matches the given field.
228
131
* @param field the field that we are looking up FieldErrors for
0 commit comments