Discussion:
Accessing Module Resource in Velocity Template
Stefan Gränitz
2010-10-22 13:23:19 UTC
Permalink
Hello,

for some reasons I disabled the Default Top Navigation Bar and defined
my own. So far it works. Now I need an additional image file that I want
to ship with my plugin. So I defined it as a resource:
{code}
<top-navigation key="division_custom_topnav" ...>
<order>9</order>
<description key="division.topnav.desc" />

<resource type="velocity" name="view"
location="templates/topnav.vm" />
<resource type="download" name="arrow_right.gif"
location="images/arrow_right.gif" />
</top-navigation>
{code}

..and put the file to the specified directory. In my velocity template I
want to include this image, but how can I access it? *Who gives me the
URL to use?*

In the jira-calendar-plugin I found this approach to reference resources:
{code}
<script type="text/javascript"
src="$webResourceManager.getStaticPluginResource(
'com.atlassian.jira.ext.calendar:issues-calendar-resource-js',
'issuescalendar.js')">
</script>
{code}

For me this would mean:
{code}
$webResourceManager.getStaticPluginResource(
'com.nativeinstruments.jira.plugins.dialogs:division_custom_topnav',
'arrow_right.gif')
{code}

..should work. But it does not. Velocity doesn't even touch it! The
string is not replaced by anything and occurs unchanged in the HTML
output. Anyone knows whats wrong??

thanx
--
Stefan Gränitz - Software Services
stefan.graenitz-***@public.gmane.org

NATIVE INSTRUMENTS GmbH
Schlesische Str. 28
10997 Berlin, Germany
http://www.native-instruments.com

***

TRAKTOR KONTROL S4 - the ultimate integrated DJ system
=> http://www.native-instruments.com/traktor-kontrol-s4

KOMPLETE 7 - the NI instruments and effects collection
=> http://www.native-instruments.com/komplete7

->>>>>> NATIVE INSTRUMENTS - The Future of Sound <<<<<<-

Registergericht: Amtsgericht Charlottenburg
Registernummer: HRB 72458
UST.-ID.-Nr. DE 20 374 7747

Geschäftsführung: Daniel Haver (CEO), Mate Galic
forums-YrDk4eUcT3KaMJb+
2010-10-22 15:24:48 UTC
Permalink
Some more information:

When I just type $webResourceManager in my velocity template, it is correctly replaced by:
***@ec77cb

So the object itself is available in the velocity context. What method must be called to get the URL for a certain resource? ..getStaticPluginResource seems not to work..
--
Post by stefan.graenitz - online at:
http://forums.atlassian.com/thread.jspa?forumID=100&threadID=48456
forums-YrDk4eUcT3KaMJb+
2010-10-22 17:26:11 UTC
Permalink
This thread helped to do this without the webResourceManager:
[http://forums.atlassian.com/thread.jspa?messageID=257308965&#257308965]

*Here is a short description for the impatient* ;-)

*1.* define your module descriptor including the resource declaration as shown in the first post

*2.* in your velocity template build up the resource path by yourself, it follows this scheme:
{code}
{contextPath}/download/resources/{groupId}.{artifactId}:{moduleKey}/{resourceName}
{code}
e.g. my code for this is:
{code}
## build URL of resources used in topnav
#set($basePath = "$req.contextPath/download/resources")
#set($groupId = "com.nativeinstruments.jira.plugins.dialogs")
#set($artifactId = "NIdialogs")
#set($moduleKey = "division_custom_topnav")
#set($resPath = "$basePath/$groupId.$artifactId:$moduleKey")
{code}

*3.* now you can load your resource easily via:
{code} <img src="$resPath/arrow_right.gif" alt="-&gt;" />
{code}
btw.: the +greater than+ should be escaped ;o)

*4.* this is generated for the image-tags +src+ attribute:
{code}
/jira/download/resources/com.nativeinstruments.jira.plugins.dialogs.NIdialogs:division_custom_topnav/arrow_right.gif
{code}
notice: of cause for the absolute path, you have to add your host-prefix (for me this is http://localhost:2990), but this is not necessary for the +src+ attribute
--
Post by stefan.graenitz - online at:
http://forums.atlassian.com/thread.jspa?forumID=100&threadID=48456
forums-YrDk4eUcT3KaMJb+
2010-10-22 17:28:40 UTC
Permalink
so for now this is ok, it works.

but how can I get the *webResourceManager* do the work for me?
--
Post by stefan.graenitz - online at:
http://forums.atlassian.com/thread.jspa?forumID=100&threadID=48456
forums-YrDk4eUcT3KaMJb+
2011-01-04 16:19:04 UTC
Permalink
Stefan,

I am being a little lazy. Did you ever resolve this resource inclusion issue?

I ask because I have about 50 images that I need for a plug-in I'm building, and I don't see any easy answer in the documentation.

Thanks,
Scott
--
Post by speimann-FSwd2CgsKTRPSR/vp4dg0gC/***@public.gmane.org - online at:
http://forums.atlassian.com/thread.jspa?forumID=100&threadID=48456
Loading...