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

Module Type module

Purpose of this Module Type

Module Type plugin modules allow you to dynamically add new plugin module types to the plugin framework, generally building on other plugin modules. For example, a plugin developer could create a <dictionary> plugin module that is used to feed a dictionary service used by still other plugins.

Configuration

The root element for the Module Type plugin module is module-type. It allows the following attributes and child elements for configuration:

Attributes

Name*

Description

class

The ModuleDescriptor class to instantiate when a new plugin module of this type is found.

See the plugin framework guide to creating plugin module instances.

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
<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 module type. This value will be used as the XML element name to match.

name

The human-readable name of the plugin module.

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

  • 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.

Example

Here is an example atlassian-plugin.xml file containing a plugin module type:

1
2
<atlassian-plugin name="Hello World" key="example.plugin.helloworld" plugins-version="2">
    <plugin-info>
        <description>A dictionary module type test</description>
        <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
        <version>1.0</version>
    </plugin-info>

    <module-type key="dictionary" class="example.plugin.DictionaryModuleDescriptor" />
</atlassian-plugin>

Our dictionary module descriptor allows plugins to provide dictionaries that get definitions of technical terms and phrases in various languages. We have a Dictionary interface that looks like this:

1
2
public interface Dictionary
{
    String getDefinition(String text);
}

The Java code for DictionaryModuleDescriptor could look like this:

1
2
public class DictionaryModuleDescriptor extends AbstractModuleDescriptor<Dictionary>
{
    private String language;

    @Override
    public DictionaryModuleDescriptor(ModuleFactory moduleFactory)
    {
        super(moduleFactory);
    }

    @Override
    public void init(Plugin plugin, Element element) throws PluginParseException
    {
        super.init(plugin, element);
        language = element.attributeValue("lang");
    }

    public Dictionary getModule()
    {
         return moduleFactory.createModule(moduleClassName, this);
    }

    public String getLanguage()
    {
        return language;
    }
}

This will add the new module type 'dictionary' to the plugin framework, allowing other plugins to use the new module type. Here is a plugin that uses the new 'dictionary' module type:

1
2
<atlassian-plugin name="Hello World" key="example.plugin.helloworld" plugins-version="2">
    <plugin-info>
        <description>An english dictionary</description>
        <vendor name="Atlassian Software Systems" url="http://www.atlassian.com"/>
        <version>1.0</version>
    </plugin-info>

    <dictionary key="myEnglishDictionary" lang="english" class="example.plugin.english.MyDictionary" />
</atlassian-plugin>

Accessing modules of your dynamic module type can be done using com.atlassian.plugin.PluginAccessor.

1
2
// To get all the enabled modules of this module descriptor
List<DictionaryModuleDescriptor> dictionaryModuleDescriptors =
        pluginAccessor.getEnabledModuleDescriptorsByClass(DictionaryModuleDescriptor.class);
// Now we'll use each one to get a map of languages to translations of the word "OSGi"
Map<String, String> results = new HashMap<String, String>();
for (DictionaryModuleDescriptor dictionaryModuleDescriptor : dictionaryModuleDescriptors)
{
    results.put(dictionaryModuleDescriptor.getLanguage(),
            dictionaryModuleDescriptor.getModule().getDefinition("OSGi"));
}

Note that it is not advisable to cache the results of calls to com.atlassian.plugin.PluginAccessor's methods, since the return values can change at any time as a result of plugins being installed, uninstalled, enabled, or disabled.

Notes

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

  • Not all dynamic module types will need to use the class attribute on the modules that implement them. For example, if the above dictionary example just used a resource file to translate terms, and not an interface that plugins had to implement, plugins using the dictionary module type might look like this:

    1
    2
    <dictionary key="myEnglishDictionary" lang="english" resource="example/plugin/english/myDictionary.properties" />
    
  • The plugin that defines a new module type cannot use the module type in the Plugin Framework 2.1, but can in 2.2 or later.

  • If you want to have control over the construction of the ModuleDescriptor, you can skip the 'module-type' module and make public a component registered against the ModuleDescriptorFactory interface:

    1
    2
    <component key="dictionaryFactory" class="example.plugin.DictionaryModuleDescriptorFactory" public="true">
      <interface>com.atlassian.plugin.ModuleDescriptorFactory</interface>
    </component>
    

    Ensure your ModuleDescriptorFactory implements com.atlassian.plugin.osgi.external.ListableModuleDescriptorFactory.

  • By specifying the application attribute in your module type element, you can ensure that a plugin only uses that module type when it is running in a specific application. For example, with the following snippet, the dictionary module type is only used when the plugin is loaded in JIRA:

    1
    2
    <dictionary key="myEnglishDictionary" lang="english" class="example.plugin.english.MyDictionary" application="jira" />
    

    The supported values for application are the Product Keys listed in the Atlassian Plugin SDK documentation.

Writing Confluence Plugins
Information sourced from Plugin Framework documentation

Rate this page: