Uploaded image for project: 'Confluence Data Center'
  1. Confluence Data Center
  2. CONFSERVER-14459

VelocityUtil.getRenderedTemplate doesn't load plugin Velocity templates in OSGi plugins

      VelocityUtils uses the Confluence ClassLoader, so Velocity templates inside the plugin aren't visible to it.

      We need to document a workaround for this. One possible one is loading the resource manually:

      public void execute(Map params, String body, RenderContext renderContext) {
          // ... create context
          InputStream template = getClass().getClassLoader().getResourceAsStream("path/to/template.vm");
          return VelocityUtils.getRenderedContent(IOUtils.toString(template), context);
      }
      

      We should probably wrap this in some kind of helper for plugins though.

            [CONFSERVER-14459] VelocityUtil.getRenderedTemplate doesn't load plugin Velocity templates in OSGi plugins

            Matt Ryall added a comment -

            Closing as "Cannot Reproduce", as this issue has remained unverified for more than a year.

            Matt Ryall added a comment - Closing as "Cannot Reproduce", as this issue has remained unverified for more than a year.

            Matt Ryall added a comment -

            Unfortunately, I haven't had time to look into this so far. I'm going to be away for a couple of months, so I'm unassigning this issue.

            If anyone wants to test this out with 3.0 (or a recent beta) and report back with the outcome, that would be much appreciated.

            Matt Ryall added a comment - Unfortunately, I haven't had time to look into this so far. I'm going to be away for a couple of months, so I'm unassigning this issue. If anyone wants to test this out with 3.0 (or a recent beta) and report back with the outcome, that would be much appreciated.

            Need to verify whether this is fixed in 3.0.

            Matt Ryall added a comment - Need to verify whether this is fixed in 3.0.

            Matt Ryall added a comment -

            Actually, Don Brown tells me this relates to the path which a template is found in. In Confluence 2.10 (atlassian-plugins 2.1.x), you can only have one plugin exposing a particular resource path.

            So for example, if your Velocity template is located at /templates/foo.vm, and there's another plugin also using /templates/, you won't be able to render your template with VelocityUtils.

            To work around this, you can move your Velocity templates into a Java-package-style directory structure, which will be unique for your plugin.

            This is apparently fixed in Confluence 3.0 (atlassian-plugins 2.2.x), but I need to test it out before resolving this issue.

            Matt Ryall added a comment - Actually, Don Brown tells me this relates to the path which a template is found in. In Confluence 2.10 (atlassian-plugins 2.1.x), you can only have one plugin exposing a particular resource path. So for example, if your Velocity template is located at /templates/foo.vm , and there's another plugin also using /templates/ , you won't be able to render your template with VelocityUtils. To work around this, you can move your Velocity templates into a Java-package-style directory structure, which will be unique for your plugin. This is apparently fixed in Confluence 3.0 (atlassian-plugins 2.2.x), but I need to test it out before resolving this issue.

              matt@atlassian.com Matt Ryall
              matt@atlassian.com Matt Ryall
              Affected customers:
              0 This affects my team
              Watchers:
              4 Start watching this issue

                Created:
                Updated:
                Resolved: