19
19
import java .util .ArrayList ;
20
20
import java .util .Collections ;
21
21
import java .util .Comparator ;
22
- import java .util .HashMap ;
22
+ import java .util .LinkedHashMap ;
23
23
import java .util .List ;
24
24
import java .util .Map ;
25
25
import javax .servlet .http .HttpServletRequest ;
@@ -58,7 +58,7 @@ public class VersionResourceResolver extends AbstractResourceResolver {
58
58
private AntPathMatcher pathMatcher = new AntPathMatcher ();
59
59
60
60
/** Map from path pattern -> VersionStrategy */
61
- private final Map <String , VersionStrategy > versionStrategyMap = new HashMap <String , VersionStrategy >();
61
+ private final Map <String , VersionStrategy > versionStrategyMap = new LinkedHashMap <String , VersionStrategy >();
62
62
63
63
64
64
/**
@@ -146,14 +146,14 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
146
146
String candidateVersion = versionStrategy .extractVersion (requestPath );
147
147
if (StringUtils .isEmpty (candidateVersion )) {
148
148
if (logger .isTraceEnabled ()) {
149
- logger .trace ("No version found in path= \" " + requestPath + "\" " );
149
+ logger .trace ("No version found in path \" " + requestPath + "\" " );
150
150
}
151
151
return null ;
152
152
}
153
153
154
154
String simplePath = versionStrategy .removeVersion (requestPath , candidateVersion );
155
155
if (logger .isTraceEnabled ()) {
156
- logger .trace ("Extracted version from path, re-resolving without version, path= \" " + simplePath + "\" " );
156
+ logger .trace ("Extracted version from path, re-resolving without version: \" " + simplePath + "\" " );
157
157
}
158
158
159
159
Resource baseResource = chain .resolveResource (request , simplePath , locations );
@@ -164,14 +164,14 @@ protected Resource resolveResourceInternal(HttpServletRequest request, String re
164
164
String actualVersion = versionStrategy .getResourceVersion (baseResource );
165
165
if (candidateVersion .equals (actualVersion )) {
166
166
if (logger .isTraceEnabled ()) {
167
- logger .trace ("resource matches extracted version" );
167
+ logger .trace ("Resource matches extracted version [" + candidateVersion + "] " );
168
168
}
169
169
return baseResource ;
170
170
}
171
171
else {
172
172
if (logger .isTraceEnabled ()) {
173
- logger .trace ("Potential resource found for [" + requestPath + "] , but version [" +
174
- candidateVersion + "] doesn't match. " );
173
+ logger .trace ("Potential resource found for \" " + requestPath + "\" , but version [" +
174
+ candidateVersion + "] does not match" );
175
175
}
176
176
return null ;
177
177
}
@@ -186,12 +186,12 @@ protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends R
186
186
return null ;
187
187
}
188
188
if (logger .isTraceEnabled ()) {
189
- logger .trace ("Getting the original resource to determine version" );
189
+ logger .trace ("Getting the original resource to determine version for path \" " + resourceUrlPath + " \" " );
190
190
}
191
191
Resource resource = chain .resolveResource (null , baseUrl , locations );
192
192
String version = versionStrategy .getResourceVersion (resource );
193
193
if (logger .isTraceEnabled ()) {
194
- logger .trace ("Version= " + version );
194
+ logger .trace ("Determined version [ " + version + "] for " + resource );
195
195
}
196
196
return versionStrategy .addVersion (baseUrl , version );
197
197
}
@@ -204,17 +204,17 @@ protected String resolveUrlPathInternal(String resourceUrlPath, List<? extends R
204
204
*/
205
205
protected VersionStrategy getStrategyForPath (String requestPath ) {
206
206
String path = "/" .concat (requestPath );
207
- List <String > matchingPatterns = new ArrayList <String >();
207
+ List <String > matchingPatterns = new ArrayList <String >();
208
208
for (String pattern : this .versionStrategyMap .keySet ()) {
209
209
if (this .pathMatcher .match (pattern , path )) {
210
- matchingPatterns .add (pattern );
210
+ matchingPatterns .add (pattern );
211
211
}
212
212
}
213
- if (!matchingPatterns .isEmpty ()) {
214
- Comparator <String > comparator = this .pathMatcher .getPatternComparator (path );
215
- Collections .sort (matchingPatterns , comparator );
216
- return this .versionStrategyMap .get (matchingPatterns .get (0 ));
217
- }
213
+ if (!matchingPatterns .isEmpty ()) {
214
+ Comparator <String > comparator = this .pathMatcher .getPatternComparator (path );
215
+ Collections .sort (matchingPatterns , comparator );
216
+ return this .versionStrategyMap .get (matchingPatterns .get (0 ));
217
+ }
218
218
return null ;
219
219
}
220
220
0 commit comments