Confluence Docs 2.10 : Web Item Plugin Module
This page last changed on Dec 02, 2008 by smaddox.
On this page: Error formatting macro: toc: java.lang.NullPointerException
Purpose of this Module TypeWeb Item plugin modules allow plugins to define new links in application menus. ConfigurationThe root element for the Web Item plugin module is web-item. It allows the following attributes and child elements for configuration: AttributesElementsThe table summarises the elements. The sections below contain further information.
Label ElementsLabel elements may contain optional parameters, as shown below:
<label key="common.concepts.create.new.issue"> <param name="param0">$helper.project.name</param> </label>
Tooltip ElementsTooltip elements have the same attributes and parameters as the label elements. See above. Link ElementsLink elements may contain additional information:
<link linkId="create_link">/secure/CreateIssue!default.jspa</link>
The body of the link element is its URL. The URL is rendered with Velocity, so you can include dynamic information in the link. For example, in Confluence, the following link would include the page ID: <link linkId="view-attachments-link">/pages/viewpageattachments.action?pageId=$page.id</link> Icon ElementsIcon elements have a height and a width attribute. The location of the icon is specified within a link element: <icon height="16" width="16"> <link>/images/icons/print.gif</link> </icon> Param ElementsParam elements represent a map of key/value pairs, where each entry corresponds to the param elements attribute: name and value respectively.
<param name="key" value="value" />
The value can be retrieved from within the Velocity view with the following code, where $item is a WebItemModuleDescriptor: $item.webParams.get("key") <!-- retrieve the value --> $item.webParams.getRenderedParam("key", $user, $helper) <!-- retrieve the Velocity rendered value --> If the value attribute is not specified, the value will be set to the body of the element. I.e. the following two param elements are equivalent: <param name="isPopupLink" value="true" /> <param name="isPopupLink">true</param> Context-provider Element
The context-provider element adds to the Velocity context available to the web section and web item modules. You can add what you need to the context, to build more flexible section and item elements. Currently only one context-provider can be specified per module. Additional context-providers are ignored. The context-provider element must contain a class attribute with the fully-qualified name of a Java class. The referenced class:
For example, the following context-provider will add historyWindowHeight and filtersWindowHeight to the context. In the following example, HeightContextProvider extends AbstractJiraContextProvider, which is only available in JIRA and happens to implement ContextProvider. The AbstractJiraContextProvider conveniently extracts the User and JiraHelper from the context map, which you would otherwise have to do manually. public class HeightContextProvider extends AbstractJiraContextProvider { private final ApplicationProperties applicationProperties; public HeightContextProvider(ApplicationProperties applicationProperties) { this.applicationProperties = applicationProperties; } public Map getContextMap(User user, JiraHelper jiraHelper) { int historyIssues = 0; if (jiraHelper != null && jiraHelper.getRequest() != null) { UserHistory history = (UserHistory) jiraHelper.getRequest().getSession().getAttribute(SessionKeys.USER_ISSUE_HISTORY); if (history != null) { historyIssues = history.getIssues().size(); } } int logoHeight = TextUtils.parseInt(applicationProperties.getDefaultBackedString(APKeys.JIRA_LF_LOGO_HEIGHT)); String historyHeight = String.valueOf(80 + logoHeight + (25 * historyIssues)); String filterHeight = String.valueOf(205 + logoHeight); return EasyMap.build("historyWindowHeight", historyHeight, "filtersWindowHeight", filterHeight); } } The above HeightContextProvider can be used by nesting the following element in a web item module.
<context-provider class="com.atlassian.jira.plugin.web.contextproviders.HeightContextProvider" />
The newly added context entries historyWindowHeight and filtersWindowHeight can be used in the XML module descriptors just like normal velocity context variables, by prefixing them with the dollar symbol ($): <!-- pass the value of historyWindowHeight as a parameter called windowHeight (see param element above for its usage) --> <param name="windowHeight">$historyWindowHeight</param> <!-- set the link's label to print the value of filtersWindowHeight --> <label>filter window height is: $filtersWindowHeight</label> Condition and Conditions ElementsConditions can be added to the web section and web item modules, to display them only when all the given conditions are true. Condition elements must contain a class attribute with the fully-qualified name of a Java class. The referenced class:
Condition elements can take optional parameters. These parameters will be passed in to the condition's init() method as a map of string key/value pairs after autowiring, but before any condition checks are performed. For example:
<condition class="com.atlassian.jira.plugin.web.conditions.JiraGlobalPermissionCondition"> <param name="permission">admin</param> </condition> To invert a condition, add the attribute 'invert="true"' to the condition element. This is useful where you want to show the section if a certain condition is not satisfied.
For example: The following condition is true if the current user is a system administrator OR a project administrator:
<conditions type="OR"> <condition class="com.atlassian.jira.plugin.web.conditions.JiraGlobalPermissionCondition"> <param name="permission">admin</param> </condition> <condition class="com.atlassian.jira.plugin.web.conditions.UserHasProjectsCondition"> <param name="permission">project</param> </condition> </conditions> ExampleHere is an example atlassian-plugin.xml file containing a single web item: <atlassian-plugin name="Hello World Plugin" key="example.plugin.helloworld" pluginsVersion="2"> <plugin-info> <description>A basic web item module test</description> <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/> <version>1.0</version> </plugin-info> <web-item key="google_home" name="Google Home" section="system.admin/example1" weight="10"> <description key="item.google.home.desc">Simple link to google.com.</description> <label key="item.google.home.label" /> <link linkId="google_home">http://google.com</link> </web-item> </atlassian-plugin> Notes about Web Items in ConfluenceLink elementsHere is another example of a Link elements containing additional information: <link linkId="editPageLink" accessKey="$helper.action.getTextStrict('navlink.edit.accesskey')">/pages/editpage.action?pageId=$helper.page.id</link> The accessKey is optional and provides an access key for the link being generated.
RELATED TOPICSWeb UI Plugins |
![]() |
Document generated by Confluence on Dec 03, 2008 15:14 |