[ 
http://issues.apache.org/jira/browse/VELOCITY-439?page=comments#action_12432804 
] 
            
Henning Schmiedehausen commented on VELOCITY-439:
-------------------------------------------------

I also like this and I actually wrote up some code based on your example 
(attached as a patch). However, there are a few more things to check out before 
we actually add this:

There is a method in the VelocityEngine, called resourceExists(). It uses 
getLoaderNameForResource to determine whether a resource exists or not. It also 
leverages the cache to reduce the number of hits to the actual resource 
loaders. There is some code in ResourceManagerImpl around line 590, that very 
closely resembles the proposed code, so it might probably be replaced with a 
call to resourceExists, but there are no unit tests for this and just ripping 
the current code out without test is not really a good thing. Especially as we 
are discussing to cut an RC now.

I do postpone this for 1.6. Tassos, if you could write some unit tests, that 
check the functionality of VelocityEngine.resourceExists() and also the new 
resourceExists() method in e.g. the File loader, this would greatly improve the 
chances that your code goes in. :-) 

> Improve Resource existence detection
> ------------------------------------
>
>                 Key: VELOCITY-439
>                 URL: http://issues.apache.org/jira/browse/VELOCITY-439
>             Project: Velocity
>          Issue Type: Improvement
>          Components: Source
>    Affects Versions: 1.4
>            Reporter: Tassos Bassoukos
>            Priority: Trivial
>         Attachments: resourceloader.patch
>
>
> Depending on the ResourceLoader used, testing the existence of a resource is 
> somewhat expensive, as the resource has to be opened to test for its 
> existence.
> I'm proposing the following changes:
> 1.
> Add a new method to 
> org.apache.velocity.runtime.resource.loader.ResourceLoader:
>     public boolean resourceExists(String source) {
>         InputStream is = null;
>         try {
>             is = resourceLoader.getResourceStream(resourceName);
>             if (is != null) {
>                 return true;
>             }
>         } catch (ResourceNotFoundException e) {
>         } finally {
>             if (is != null) {
>                 try {
>                     is.close();
>                 } catch (Exception e) {
>                 }
>             }
>         }
>         return false;
>     }
> This method keeps compatibility with all current ResourceLoaders, and can be 
> overriden by subclasses.
> 2. org.apache.velocity.runtime.resource.ResourceManagerImpl
> Modify the String getLoaderNameForResource(String resourceName) method to use
> the new ResourceLoader.resourceExists(String) method.

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to