Uploaded image for project: 'Velocity'
  1. Velocity
  2. VELOCITY-180

new event handler for input directives (#parse, #include)

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Duplicate
    • 1.4
    • 1.5
    • Engine
    • None
    • Operating System: All
      Platform: All
    • 20342

    Description

      I've created a simple but flexible new event handler that is called by the
      #parse and #include directive. This event handler takes as an argument the
      resource path argument for #parse or #include, and returns a modified path
      indicating the resource to actually be returned. If the event handler returns
      null, no page is included.

      This has many uses. A few examples.
      – Relative path. All #include/#parse directives can be forced to refer to a
      directory relative to the current template

      – Security. A page can be restricted to only be able to refer to a
      particular group of pages.

      – Localization. Templates can include pages for a particular language or
      region, and the app can switch those pages to refer to a different language or
      region as appropriate.

      This patch is 100% backwards compatible with existing templates and code.

      Personally, I have urgent need of this feature. My web app allows numerous
      (untrusted) users to upload templates into a common web space (each user has
      their own directory). A major problem was that users could access other
      user's pages with #parse and #include. In just a few lines of code, I've
      implemented a security-oriented implementation of this event handler to allow
      each user to only be able to include their own set of pages. Without this
      event handler, I was not able to figure out a straight forward solution to
      this problem.

      As a side note, I believe this presents an elegant way to solve this problem
      as well (allowing the developer to force paths to be relative to the template).

      http://www.mail-archive.com/velocity-dev@jakarta.apache.org/msg07223.html

      Best, WILL

      P.S. If this approach is acceptable to the committers, I'll go ahead and
      create test cases and documentation in relatively short order. I've already
      built some informal test code. I can't run "ant test" completely as it fails
      (on the encoding test), even without the patch, but it ran fine up until that
      point.

      Attachments

        1. ASF.LICENSE.NOT.GRANTED--testcases.xml
          14 kB
          Will Glass-Husain
        2. ASF.LICENSE.NOT.GRANTED--inputtest_supporting_files.zip
          9 kB
          Will Glass-Husain
        3. ASF.LICENSE.NOT.GRANTED--InputEventHandlingTestCase.java
          9 kB
          Will Glass-Husain
        4. ASF.LICENSE.NOT.GRANTED--InputEventHandler.java
          4 kB
          Will Glass-Husain
        5. ASF.LICENSE.NOT.GRANTED--inputdirective_patch.txt
          29 kB
          Will Glass-Husain

        Activity

          People

            Unassigned Unassigned
            wglass@forio.com Will Glass-Husain
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: