Event Listener module
Job module
Language module
Macro Module
Theme module
Web UI modules
Workflow module
XWork-WebWork module

Rate this page:

Component module

The Component plugin module described below is available to OSGi-based plugins using version 2.x of the Atlassian Plugin Framework, supported in Confluence 2.10 and later.

We recommend that you use the new plugin module type described below, rather than the old-style Component and Spring Component module types. Confluence still supports the earlier module types, but the new OSGi-based plugin framework fixes a number of bugs and limitations experienced by the old-style plugin modules.

Purpose of this Module Type

Component plugin modules enable you to share Java components between other modules in your plugin and optionally with other plugins in the application. You can use it to make any type of class instance available to other plugins or modules. It's in effect a Spring bean declaration (with greatly simplified syntax, since only autowiring is supported) plus an OSGi export.

The typical uses of a component are:

  • To define a singleton class that's used internally by your plugin, which the framework instantiates for you and passes to your other classes via autowiring; or
  • To expose an API to other plugin modules.

Configuration

The root element for the Component plugin module is component. It allows the following attributes and child elements for configuration:

Attributes

Name*

Description

alias

The alias to use for the component when registering it in the internal bean factory.

Default: the plugin key.

class

The class which implements this plugin module. The class you need to provide depends on the module type. For example, Confluence theme, layout and colour-scheme modules can use classes already provided in Confluence. So you can write a theme-plugin without any Java code. But for macro and listener modules you need to write your own implementing class and include it in your plugin. See the plugin framework guide to creating plugin module instances

The Java class of the component. This does not need to extend or implement any class or interface. 

key

 The unique identifier of the plugin module. You refer to this key to use the resource from other contexts in your plugin, such as from the plugin Java code or JavaScript resources.

1
2
3
<component-import
  key="appProps"
  interface="com.atlassian.sal.api.ApplicationProperties"/>

In the example, appProps is the key for this particular module declaration, for component-import, in this case.

 

I.e. the identifier of the component.

state

Indicate whether the plugin module should be disabled by default (value='disabled') or enabled by default (value='enabled').

Default: enabled.

i18n-name-key

The localisation key for the human-readable name of the plugin module.

key

The unique identifier of the plugin module. You refer to this key to use the resource from other contexts in your plugin, such as from the plugin Java code or JavaScript resources.
1
2
3
<component-import
  key="appProps"
  interface="com.atlassian.sal.api.ApplicationProperties"/>

In the example, appProps is the key for this particular module declaration, for component-import, in this case.

name

The human-readable name of the plugin module. 

I.e. the human-readable name of the component.

Default: the plugin key.

public

Indicates whether this component should be made available to other plugins via the Component Import Plugin Module or not.

Default: false.

system

Indicates whether this plugin module is a system plugin module (value='true') or not (value='false'). Only available for non-OSGi plugins.

Default: false.

*key attribute is required.

Elements

Name*

Description

interface

The Java interface under which this component should be registered.

This element can appear zero or more times.

description

 The description of the plugin module. The 'key' attribute can be specified to declare a localisation key for the value instead of text in the element body.

service-properties

Map of simple properties to associate with a public component (Plugin Framework 2.3 and later).

Child elements are named entry and have key and value attributes.

Service properties are intended to serve as filterable values in the component-import declarations that use this component.

This allows you to define various flavors of a public component, and import them based on the value of these flavors.

For example, when importing a component named dictionaryService with a language service property,

the component-import statement can select the component flavor with language property English as follows:

1
2
3
4
<component-import
  key="dictionaryService"
  interface="com.myapp.DictionaryService"
  filter="(language=English)" />

Example

Here is an example atlassian-plugin.xml file containing a single public component:

1
2
3
4
5
6
7
8
9
10
11
12
<atlassian-plugin name="Hello World" key="example.plugin.helloworld" plugins-version="2">
    <plugin-info>
        <description>A basic component module test</description>
        <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
        <version>1.0</version>
    </plugin-info>

    <component key="helloWorldService" class="com.myapp.DefaultHelloWorldService">
        <description>Provides hello world services.</description>
        <interface>com.myapp.HelloWorldService</interface>
    </component>
</atlassian-plugin>

Here is an example public component with several service properties:

1
2
3
4
5
6
<component key="dictionaryService" class="com.myapp.DefaultDictionaryService" interface="com.myapp.DictionaryService">
    <description>Provides a dictionary service.</description>
    <service-properties>
        <entry key="language" value="English" />
    </service-properties>
</component>

Notes

Some information to be aware of when developing or configuring a Component plugin module:

Accessing Your Components

Accessing your components from within other plugin modules is extremely simple. All plugin modules in OSGi plugins are autowired. So to access a component, you need to add a Java setter method to your plugin module class.

For example, if you wanted to use the above helloWorldService component in an event listener module, you would add a field for the component and a setter method to the listener class as follows:

1
2
3
4
5
6
7
8
9
public class MyEventListener implements EventListener {
    private HelloWorldService helloWorldService;

    // ...

    public void setHelloWorldService(HelloWorldService helloWorldService) {
        this.helloWorldService = helloWorldService;
    }
}

Note that to access components in other plugins, the module needs to be marked as 'public' (as covered above) and imported into your plugin using a component-import.

Writing Confluence Plugins
Installing a Plugin
Information sourced from Plugin Framework documentation

Rate this page: