Velocity
  1. Velocity
  2. VELOCITY-439

Improve Resource existence detection

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Trivial Trivial
    • Resolution: Fixed
    • Affects Version/s: 1.4, 1.5
    • Fix Version/s: 1.6
    • Component/s: Engine
    • Labels:
      None

      Description

      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.

      1. resourceloader.patch
        2 kB
        Henning Schmiedehausen

        Activity

        Tassos Bassoukos created issue -
        Henning Schmiedehausen made changes -
        Field Original Value New Value
        Attachment resourceloader.patch [ 12340254 ]
        Henning Schmiedehausen made changes -
        Affects Version/s 1.5 [ 12310253 ]
        Fix Version/s 1.6 [ 12310290 ]
        Henning Schmiedehausen made changes -
        Component/s Engine [ 12311337 ]
        Component/s Source [ 12310214 ]
        Nathan Bubna made changes -
        Status Open [ 1 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Mark Thomas made changes -
        Workflow jira [ 12363058 ] Default workflow, editable Closed status [ 12551535 ]
        Mark Thomas made changes -
        Workflow Default workflow, editable Closed status [ 12551535 ] jira [ 12552421 ]

          People

          • Assignee:
            Unassigned
            Reporter:
            Tassos Bassoukos
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development