Skip to content

Commit 9bd0bd9

Browse files
committed
SpringTemplateLoader supports last-modified timestamp through Resource abstraction (SPR-7454)
1 parent 99733ae commit 9bd0bd9

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

org.springframework.context.support/src/main/java/org/springframework/ui/freemarker/SpringTemplateLoader.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
/*
2-
* Copyright 2002-2005 the original author or authors.
3-
*
2+
* Copyright 2002-2010 the original author or authors.
3+
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
66
* You may obtain a copy of the License at
7-
*
7+
*
88
* http://www.apache.org/licenses/LICENSE-2.0
9-
*
9+
*
1010
* Unless required by applicable law or agreed to in writing, software
1111
* distributed under the License is distributed on an "AS IS" BASIS,
1212
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -32,9 +32,6 @@
3232
* Used by FreeMarkerConfigurationFactory for any resource loader path that
3333
* cannot be resolved to a java.io.File.
3434
*
35-
* <p>Note that this loader does not allow for modification detection:
36-
* Use FreeMarker's default TemplateLoader for java.io.File resources.
37-
*
3835
* @author Juergen Hoeller
3936
* @since 14.03.2004
4037
* @see FreeMarkerConfigurationFactory#setTemplateLoaderPath
@@ -89,7 +86,17 @@ public Reader getReader(Object templateSource, String encoding) throws IOExcepti
8986

9087

9188
public long getLastModified(Object templateSource) {
92-
return -1;
89+
Resource resource = (Resource) templateSource;
90+
try {
91+
return resource.lastModified();
92+
}
93+
catch (IOException ex) {
94+
if (logger.isDebugEnabled()) {
95+
logger.debug("Could not obtain last-modified timestamp for FreeMarker template in " +
96+
resource + ": " + ex);
97+
}
98+
return -1;
99+
}
93100
}
94101

95102
public void closeTemplateSource(Object templateSource) throws IOException {

0 commit comments

Comments
 (0)