Sling
  1. Sling
  2. SLING-1500

Patch Submission: Expression Language (EL) Functions for JSP Taglib

    Details

      Description

      I've noticed that the Sling Resource API is not very accessible for tag- and EL-focused JSP development. In order to promote readable JSP code, I created a set of static methods to implement commonly-used ResourceResolver methods as well as to expose the rather useful ResourceUtil methods as EL functions. The functions use ResourceWrappers to work around the isse https://issues.apache.org/jira/browse/SLING-1414 where the Resource.getPath() method is inaccessible in EL for JcrNodeResource objects.

      I've found these taglib functions to be very useful for Day CQ5 development, so I thought I'd offer to contribute them to the project.

      1. add-files.zip
        5 kB
        Mark Adamcin
      2. SLING-1500.diff
        57 kB
        Dan Klco
      3. taglib11.tld.patch
        10 kB
        Mark Adamcin

        Issue Links

          Activity

          Mark Adamcin created issue -
          Mark Adamcin made changes -
          Field Original Value New Value
          Attachment jsp-taglib-patch.zip [ 12442763 ]
          Mark Adamcin made changes -
          Attachment jsp-taglib-patch.zip [ 12442763 ]
          Mark Adamcin made changes -
          Attachment jsp-taglib-patch.zip [ 12442765 ]
          Mark Adamcin made changes -
          Attachment taglib11.tld.patch [ 12442766 ]
          Mark Adamcin made changes -
          Attachment jsp-taglib-patch.zip [ 12442765 ]
          Mark Adamcin made changes -
          Attachment sling-new-files.zip [ 12442767 ]
          Mark Adamcin made changes -
          Comment [ Zip file containing the following files:

          src/main/java/org/apache/sling/scripting/jsp/taglib/Functions.java
          src/main/java/org/apache/sling/scripting/jsp/taglib/WrappedResourceIterator.java
          src/main/resources/META-INF/taglib11.tld.diff ]
          Mark Adamcin made changes -
          Comment [ Replaced the zip with one that contains an actual patch file. ]
          Mark Adamcin made changes -
          Attachment sling-new-files.zip [ 12442767 ]
          Hide
          Mark Adamcin added a comment -

          Two java files to be added under bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib

          Show
          Mark Adamcin added a comment - Two java files to be added under bundles/scripting/jsp-taglib/src/main/java/org/apache/sling/scripting/jsp/taglib
          Mark Adamcin made changes -
          Attachment add-files.zip [ 12442768 ]
          Mark Adamcin made changes -
          Attachment taglib11.tld.patch [ 12442766 ]
          Mark Adamcin made changes -
          Attachment taglib11.tld.patch [ 12442769 ]
          Hide
          Mark Adamcin added a comment -

          Probably not worthy of 'major' priority.

          Show
          Mark Adamcin added a comment - Probably not worthy of 'major' priority.
          Mark Adamcin made changes -
          Priority Major [ 3 ] Minor [ 4 ]
          Hide
          Dan Klco added a comment -

          Attached is a new patch to integrate the functionality provided by Mark into the SlingFunctions class for the 1.3 version of the Sling Taglibs.

          I did not reproduce the use of ResourceWrappers as the referenced issue has been closed. This patch adds the following:

          Tags:

          • New FindResources tag, for invoking the resourceResolver.findResources functionality
          • Updated: GetResources tag, adds the ability to specify a base resource under which to retrieve a relative resource

          New Functions:

          • adaptTo: adding the ability to adapt adaptables in EL functions
          • findResources: enable invoking the resourceResolver.findResources functionality EL functions
          • getRelativeResource: enables finding resources by a relative path in EL functions

          I've also included jUnit tests for all of these new methods and have verified them in a Sling 6 vanilla instance.

          Show
          Dan Klco added a comment - Attached is a new patch to integrate the functionality provided by Mark into the SlingFunctions class for the 1.3 version of the Sling Taglibs. I did not reproduce the use of ResourceWrappers as the referenced issue has been closed. This patch adds the following: Tags: New FindResources tag, for invoking the resourceResolver.findResources functionality Updated: GetResources tag, adds the ability to specify a base resource under which to retrieve a relative resource New Functions: adaptTo: adding the ability to adapt adaptables in EL functions findResources: enable invoking the resourceResolver.findResources functionality EL functions getRelativeResource: enables finding resources by a relative path in EL functions I've also included jUnit tests for all of these new methods and have verified them in a Sling 6 vanilla instance.
          Dan Klco made changes -
          Attachment SLING-1500.diff [ 12569969 ]
          Gavin made changes -
          Workflow no-reopen-closed,doc-test-required [ 12509277 ] Copy of no-reopen-closed,doc-test-required [ 12762792 ]
          Gavin made changes -
          Workflow Copy of no-reopen-closed,doc-test-required [ 12762792 ] no-reopen-closed,doc-test-required [ 12766933 ]
          Hide
          Felix Meschberger added a comment -

          Thanks. I am +1 in general.

          I wonder whether we should create a separate tag lib for the Resource API related tags and EL functions ?

          Show
          Felix Meschberger added a comment - Thanks. I am +1 in general. I wonder whether we should create a separate tag lib for the Resource API related tags and EL functions ?
          Felix Meschberger made changes -
          Link This issue supercedes SLING-577 [ SLING-577 ]
          Dan Klco made changes -
          Assignee Dan Klco [ klcodanr ]
          Hide
          Alexander Klimetschek added a comment -

          The most useful one is missing - getting a value or a default, if the value is null. Especially for the ValueMap. While you can do $

          {properties.foo}

          which will do properties.get("foo") if properties is a (Value)Map, you are missing out on the extremely useful ValueMap#get(name, default).

          Something like this:

          $

          {sling:get(properties.foo, "default")}

          Good name is welcome. Nice would be an "elvis" operator in EL, such as ?: (groovy), || (ruby) or ?? (C#):

          $

          {properties.foo ?: "default"}

          But that would require to extend the EL parser/evaluator (javax.el) in the sling JSP scripting language.

          Show
          Alexander Klimetschek added a comment - The most useful one is missing - getting a value or a default, if the value is null. Especially for the ValueMap. While you can do $ {properties.foo} which will do properties.get("foo") if properties is a (Value)Map, you are missing out on the extremely useful ValueMap#get(name, default). Something like this: $ {sling:get(properties.foo, "default")} Good name is welcome. Nice would be an "elvis" operator in EL, such as ?: (groovy), || (ruby) or ?? (C#): $ {properties.foo ?: "default"} But that would require to extend the EL parser/evaluator (javax.el) in the sling JSP scripting language.
          Gavin made changes -
          Workflow no-reopen-closed,doc-test-required [ 12766933 ] re-open possible,doc-test-required [ 12788450 ]
          Gavin made changes -
          Workflow re-open possible,doc-test-required [ 12788450 ] no-reopen-closed,doc-test-required [ 12792960 ]
          Hide
          Dan Klco added a comment -

          Added support for getting default and casted values with the EL function 'getValue' I believe all other major pieces of functionality are complete.

          Show
          Dan Klco added a comment - Added support for getting default and casted values with the EL function 'getValue' I believe all other major pieces of functionality are complete.
          Dan Klco made changes -
          Status Open [ 1 ] Resolved [ 5 ]
          Resolution Fixed [ 1 ]
          Dan Klco made changes -
          Fix Version/s Scripting JSP-Taglib 2.1.10 [ 12323463 ]
          Hide
          Dan Klco added a comment -

          Closed with the release of Sling JSP Taglib 2.2.0

          Show
          Dan Klco added a comment - Closed with the release of Sling JSP Taglib 2.2.0
          Dan Klco made changes -
          Status Resolved [ 5 ] Closed [ 6 ]

            People

            • Assignee:
              Dan Klco
              Reporter:
              Mark Adamcin
            • Votes:
              1 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development