I've scoured the mostly JIRA-centric entries about download resources, specifically trying to get URLs for images, get images to show, etc.
Figured it out how to do this with css a while back
#myicon{ background: url('images/my-icon.png'); vertical-align: middle; height: 16px; width: 16px; display:inline-block }
but in this case I'm using the NotificaitionBuilder and I'm forced to find a way to get a relative/FQ path to the actual image. When I look at the paths generated by the above css-based images, they're always in bundled resources which makes hardcoding that path untenable.
This is what I think should work but does not:
String iconURL = webResourceUrlProvider.getResourceUrl("com.my.plugins.my-cnfl-plugin", "image.jpg"); <--generated a url but it's always broken link Notification notification = notificationService.createOrUpdate(recipient, new NotificationBuilder() .application("com.my.plugins.my-cnfl-plugin") .title(title) .itemIconUrl(iconURL) .itemTitle(message) .itemUrl(itemURL) .action(envelopeId) .actionIconUrl(iconURL) //<--has to be static. can't css it. :( .description(message) .iconUrl(iconURL) //<--has to go here. can't css it. :( .groupingId(myobjID) .createNotification()).get(); return notification; }
Community moderators have prevented the ability to post new answers.
After much trial and error...got this to work. Thanks to @Panos Karampis for the initial direction.
atlassian-plugin.xml
<web-resource key="myicons" type="download" name="DOESN'T SEEM TO MATTER" location="images/"> <param name="content-type" value="image/png"/> </web-resource>
Snippet
String iconURL = StaticAccessor.getWebResourceUrlProvider() .getStaticPluginResourceUrl("com.my.plugins.my-cnfl-plugin:myicons", "images/some-icon.png", UrlMode.RELATIVE);
Atlassian JavaDoc
public abstract String getStaticPluginResourceUrl (String moduleCompleteKey, String resourceName, UrlMode urlMode) ... This method returns a URL in either a relative or an absolute format, depending on the value of urlMode. See UrlMode for details of the different options for URL format. If a module with the given key cannot be found null is returned. Parameters moduleCompleteKey complete plugin module key resourceName the name of the resource as defined in the plugin manifest
Lessons Learned:
I am glad you made it. Documentation is a bit ugly sometimes and have to improvise
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
<web-item key="somekey" section="somesection" weight="10"><label key="text" /> <link>somelink</link> <param name="icon" value="a resource here (grlupid.artifactid:key)" /> </web-item>
And then declare a resource as per value and parse the webitem. I cant write a descent answer with mobile... Sorry.
I hope thats what you ask.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
To parse the webitem use the WebInterfaceManager
final String[] tokens = webItem.getParams().get("icon").split(":"); final String moduleKey = tokens[0]; final String resourceName = tokens[1]; final DataSource source = dataSourceFactory.forPlugin(your plugin key).get().resourceFromModuleByName(moduleKey, resourceName).get(); new DefaultDataSourceFactory.NamedDataSource(source, webItem.getWebLabel().getKey());
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks, Panos, but your answer doesn't appear to be entirely complete.
Why would one need to declare a web-item simply to obtain an icon image? Is it actually necessary to split webitem tokens and use a mail service like dataSourceFactory?
I've tried both these approaches. Each time the webResourceUrlProvider.getResourceUrl() returns a path (no errors) but to nothing..
<resource key="images" name="images/" type="download" location="images"/> <resource type="download" name="ds-16.jpg" location="images/ds-16.jpg"> <param name="content-type" value="image/jpg"/> </resource>
There's got to be a more straightforward way to accomplish this.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Steve, I realize that my answer is based on my needs and is part of my production code, which makes it a bit more complicated than should.
The webResourceUrlProvider has a bunch of methods and the one you are using does not
"This method is not responsible for adding any static caching url prefixes." maybe the other methods give something more concrete?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So supposedly these should work but I've never got them to return anything but null. Sigh.
String iconURL = StaticAccessor.getWebResourceUrlProvider() .getStaticPluginResourceUrl("com.my.plugins.my-cnfl-plugin:images", "ds-16.jpg", UrlMode.RELATIVE); String iconURL2 = StaticAccessor.getWebResourceUrlProvider() .getStaticPluginResourceUrl("com.my.plugins.my-cnfl-plugin:icon", "icon16", UrlMode.RELATIVE);
correlates to these to atlassian-plugin.xml resource declarations:
//iconURL1 - the standard image folder xml entry <resource key="images" name="images/" type="download" location="images"/> //iconURL2 <resource key="icon" type="download" name="icon16" location="images/icon-16.jpg"> <param name="content-type" value="image/jpg"/> </resource>
I noticed that "moduleCompleteKey" is the first argument of "getStaticPluginResoucesUrl". Does the resource have to belong to a module to work? I'll try it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.