Confluence Docs 2.10 : Web Resource Plugins
This page last changed on Dec 02, 2008 by smaddox.
Please take a look at our overview of how and why you should include Javascript and CSS resources into your plugin. The page below gives specific details of the Web Resource plugin module type.
On this page: Error formatting macro: toc: java.lang.NullPointerException
Purpose of this Module TypeWeb Resource plugin modules allow plugins to define downloadable resources. If your plugin requires the application to serve additional static Javascript or CSS files, you will need to use downloadable web resources to make them available. Web resources are added at the top of the page in the header with the cache-related headers set to never expire. ConfigurationThe root element for the Web Resource plugin module is web-resource. It allows the following attributes and child elements for configuration: Attributes
Elements
ExampleHere is an example atlassian-plugin.xml file containing a single web resource: <atlassian-plugin name="Hello World Resource" key="example.plugin.helloworld" pluginsVersion="2"> <plugin-info> <description>A basic web resource module test</description> <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/> <version>1.0</version> </plugin-info> <web-resource key="scriptaculous" name="Scriptaculous" > <resource type="download" name="scriptaculous.js" location="/includes/js/effects/scriptaculous.js" /> <resource type="download" name="effects.js" location="/includes/js/effects/effects.js" /> </web-resource> </atlassian-plugin> Referring to Web ResourcesIn your plugin, you need to refer to a WebResourceManager and call the requireResource() method. The reference to WebResourceManager can be injected into your constructor: public MyServlet extends HttpServlet { private WebResourceManager webResourceManager; public MyServlet(WebResourceManager webResourceManager) { this.webResourceManager = webResourceManager; } protected final void doGet(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse) throws IOException { webResourceManager.requireResource("example.plugin.helloworld:scriptaculous"); //should be the full module key for the <webreference> module. // more code } } The URL for a downloadable resource is application specific. For JIRA it would be as follows: {server root}/s/{build num}/{plugin version}/{system counter}/c/download/resources/{plugin key}:{module key}/{resource name} For the above example, the following code will be inserted in the header of the page: <script type="text/javascript" src="http://jira.example.com/s/170/1.0/1/_/download/resources/jira.extra.impresence:scriptaculous/scriptaculous.js"></script> <script type="text/javascript" src="http://jira.example.com/s/170/1.0/1/_/download/resources/jira.extra.impresence:scriptaculous/effects.js"></script> Notes
Web Resource ContextsIn Confluence 2.10 we added the ability to specify web resources like CSS and JavaScript to be included in specific contexts of Confluence. The currently available contexts are:
To configure your web resource to be included for example in the 'space' and 'page' contexts you add <context> child elements to your <web-resource> element in your atlassian-plugin.xml: <web-resource name="Resources" key="resources"> <resource name="foo.js" type="download" location="/resources/foo.js"> </resource> <context>space</context> <context>page</context> </web-resource> Using web resource contexts is a great way to provide plugins that dynamically create HTML using JavaScript. At Atlassian we built a plugin which listens to a particular keyboard shortcut to open a little search box on top the Confluence UI. RELATED TOPICSAdding Plugin and Module Resources |
![]() |
Document generated by Confluence on Dec 03, 2008 15:14 |