You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@velocity.apache.org by cb...@apache.org on 2016/07/15 07:33:20 UTC

svn commit: r1752787 - /velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java

Author: cbrisson
Date: Fri Jul 15 07:33:20 2016
New Revision: 1752787

URL: http://svn.apache.org/viewvc?rev=1752787&view=rev
Log:
enhance backward compatibility by providing a default implementation for getResourceReader

Modified:
    velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java

Modified: velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java
URL: http://svn.apache.org/viewvc/velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java?rev=1752787&r1=1752786&r2=1752787&view=diff
==============================================================================
--- velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java (original)
+++ velocity/engine/trunk/velocity-engine-core/src/main/java/org/apache/velocity/runtime/resource/loader/ResourceLoader.java Fri Jul 15 07:33:20 2016
@@ -158,8 +158,35 @@ public abstract class ResourceLoader
      * @throws ResourceNotFoundException
      * @since 2.0
      */
-    public abstract Reader getResourceReader(String source, String encoding)
-            throws ResourceNotFoundException;
+    public Reader getResourceReader(String source, String encoding)
+            throws ResourceNotFoundException
+    {
+        /*
+         * We provide a default implementation that relies on the deprecated method getResourceStream()
+         * to enhance backward compatibility. The day getResourceStream() is removed, this method should
+         * become abstract.
+         */
+        InputStream rawStream = null;
+        try
+        {
+            rawStream = getResourceStream(source);
+            return buildReader(rawStream, encoding);
+        }
+        catch(IOException ioe)
+        {
+            if (rawStream != null)
+            {
+                try
+                {
+                    rawStream.close();
+                }
+                catch (IOException e) {}
+            }
+            String msg = "Exception while loading resousrce " + source;
+            log.error(msg, ioe);
+            throw new VelocityException(msg, ioe);
+        }
+    }
 
     /**
      * Given a template, check to see if the source of InputStream