Author: nbubna
Date: Thu Feb 19 06:50:17 2009
New Revision: 745758
URL: http://svn.apache.org/viewvc?rev=745758&view=rev
Log:
VELOCITY-702 fix obscure caching issue w/multiple resource loaders and
resources that come and go
Added:
velocity/engine/branches/2.0_Exp/src/test/org/apache/velocity/test/issues/Velocity702TestCase.java
- copied unchanged from r745757,
velocity/engine/trunk/src/test/org/apache/velocity/test/issues/Velocity702TestCase.java
Modified:
velocity/engine/branches/2.0_Exp/src/changes/changes.xml
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
Modified: velocity/engine/branches/2.0_Exp/src/changes/changes.xml
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/changes/changes.xml?rev=745758&r1=745757&r2=745758&view=diff
==============================================================================
--- velocity/engine/branches/2.0_Exp/src/changes/changes.xml (original)
+++ velocity/engine/branches/2.0_Exp/src/changes/changes.xml Thu Feb 19
06:50:17 2009
@@ -142,6 +142,12 @@
<release version="1.6.2" date="In Subversion">
+ <action type="fix" dev="nbubna" issue="VELOCITY-702">
+ Fix obscure caching problem in multiple resource loader situations
+ where resources may exist in more than one loader and appear and
+ disappear from loaders.
+ </action>
+
<action type="fix" dev="nbubna" issue="VELOCITY-701">
Fix old regression from 1.4 in supporting methods declared as abstract
in a public class but implemented in a non-public class.
Modified:
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
URL:
http://svn.apache.org/viewvc/velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java?rev=745758&r1=745757&r2=745758&view=diff
==============================================================================
---
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
(original)
+++
velocity/engine/branches/2.0_Exp/src/java/org/apache/velocity/runtime/resource/ResourceManagerImpl.java
Thu Feb 19 06:50:17 2009
@@ -513,6 +513,19 @@
*/
resource.touch();
+ /* check whether this can now be found in a higher priority
+ * resource loader. if so, pass the request off to loadResource.
+ */
+ ResourceLoader loader = resource.getResourceLoader();
+ if (resourceLoaders.size() > 0 && resourceLoaders.indexOf(loader) > 0)
+ {
+ String name = resource.getName();
+ if (loader != getLoaderForResource(name))
+ {
+ return loadResource(name, resource.getType(), encoding);
+ }
+ }
+
if (resource.isSourceModified())
{
/*
@@ -535,7 +548,7 @@
* read how old the resource is _before_
* processing (=>reading) it
*/
- long howOldItWas =
resource.getResourceLoader().getLastModified(resource);
+ long howOldItWas = loader.getLastModified(resource);
String resourceKey = resource.getType() + resource.getName();
@@ -550,8 +563,8 @@
newResource.setRuntimeServices(rsvc);
newResource.setName(resource.getName());
newResource.setEncoding(resource.getEncoding());
- newResource.setResourceLoader(resource.getResourceLoader());
-
newResource.setModificationCheckInterval(resource.getResourceLoader().getModificationCheckInterval());
+ newResource.setResourceLoader(loader);
+
newResource.setModificationCheckInterval(loader.getModificationCheckInterval());
newResource.process();
newResource.setLastModified(howOldItWas);
@@ -573,17 +586,29 @@
*/
public String getLoaderNameForResource(String resourceName)
{
- /*
- * loop through our loaders...
- */
- for (Iterator it = resourceLoaders.iterator(); it.hasNext(); )
+ ResourceLoader loader = getLoaderForResource(resourceName);
+ if (loader == null)
{
- ResourceLoader resourceLoader = (ResourceLoader) it.next();
- if (resourceLoader.resourceExists(resourceName))
+ return null;
+ }
+ return loader.getClass().toString();
+ }
+
+ /**
+ * Returns the first {...@link ResourceLoader} in which the specified
+ * resource exists.
+ */
+ private ResourceLoader getLoaderForResource(String resourceName)
+ {
+ for (Iterator i = resourceLoaders.iterator(); i.hasNext(); )
+ {
+ ResourceLoader loader = (ResourceLoader)i.next();
+ if (loader.resourceExists(resourceName))
{
- return resourceLoader.getClass().toString();
+ return loader;
}
}
return null;
}
+
}