This documentation relates to the latest version of Confluence.
If you are using an earlier version, please go to the documentation home page and select the relevant version.

Accessing Confluence Components From Plugin Modules

All Versions

Confluence 3.0 Documentation

Confluence is built around Spring, an open-source component framework for for Java.

If you are familiar with Spring, then you may only wish to know that Confluence plugin modules (and their implementing classes) are autowired by name. Thus, if you want to access a Confluence component from your plugin, just include the appropriate setter method in your implementing class.

If you want to write Confluence plugins but are unfamiliar with Spring, the rest of this page should give you more than enough information on how to have your plugin interact with Confluence.

Interacting with Confluence

When you are writing anything but the simplest Confluence plugin, you will need to interact with the Confluence application itself in order to retrieve, change or store information. This document describes how this can be done.

Manager Objects

At the core of Confluence is a group of "Manager" objects. For example, the pageManager is in charge of Confluence pages, the spaceManager of spaces, the attachmentManager of attachments, and so on.

Dependency Injection

Traditionally, in a component-based system, components are retrieved from some kind of central repository. For example, in an EJB-based system, you would retrieve the bean from the application server's JNDI repository.

Confluence works the other way round. When a plugin module is instantiated, Confluence determines which components the module needs, and delivers them to it.

Confluence determines which components a module needs by reflecting on the module's methods. Any method with a signature that matches a standard JavaBeans-style setter of the same name as a Confluence component will have that component passed to it when the module is initialised.

So, if your plugin module needs to access the pageManager, all you need to do is put the following setter method on your module's implementing class:

public void setPageManager(PageManager pageManager)
{
    this.pageManager = pageManager;
}

Manager Classes

There are several dozen managers for different areas of functionality in Confluence. The following table lists some of the more commonly used ones:

Manager class Responsibility Sample methods
PageManager Pages, blogs getPage(), getBlogPost(), getRecentlyAddedPages(), findNextBlogPost(), saveContentEntity()
SpaceManager Spaces getSpace(), getPersonalSpace(), createSpace()
UserAccessor Users, groups, preferences getUser(), addUser(), addMembership(), hasMembership(), getConfluenceUserPreferences(), getUserProfilePicture()
CommentManager Comments getComment(), updateCommentContent()
LabelManager Labels addLabel(), removeLabel(), getCurrentContentForLabel()
AttachmentManager Attachment storage and retrieval getAttachments(Content), getAttachmentData(Attachment), saveAttachment()
SmartListManager Searching (2.8 and earlier) getListQueryResults()
SearchManager Searching (2.9 and later) search(), convertToEntities(), searchEntities()
ContentEntityManager Saving and retrieving all content. Parent interface of PageManager, CommentManager, etc. saveContentEntity(), getVersionHistorySummaries()
SettingsManager Global, space, plugin configuration getGlobalSettings(), updateSpaceSettings(), getPluginSettings()
I18NBean Getting localised text getText(String), getText(String, Object[]), getText(String, List)
PermissionManager Checking permissions (do this before calling a manager) hasPermission(), hasCreatePermission(), isConfluenceAdministrator(), getPermittedEntities()
SpacePermissionManager Adding or modifying space permissions savePermission(), getGlobalPermissions(), getGroupsWithPermissions()
EventManager Register listeners or publish events publishEvent(), registerListener()
WebInterfaceManager Rendering web-sections and web-items in Velocity getDisplayableSections(), getDisplayableItems()

Note that these are all interfaces. The actual implementation will be injected in your class by Spring, if you include the appropriate setter method in your class as described above.

Do not directly use implementations or cast the injected class to a particular implementation. Implementation classes are subject to change across versions without warning. Where possible, interface methods will be marked as deprecated for two major versions before being removed.

Service Classes

Managers in Confluence are responsible for the data integrity of their domain, but they are not generally responsible for validation or security. Invalid calls will typically result in a runtime exception. Historically, this wasn't a major problem, but as time went by there was more duplication of this functionality across actions, remote API methods and plugins. In recent releases, a service layer is being introduced in Confluence to address this.

The services will follow a command pattern, where the service is responsible for creating a command that can then be validated and executed. The following nascent services are available:

Service class Responsibility Sample commands
CommentService Comments CreateCommentCommand, DeleteCommentCommand, EditCommentCommand
PageService Pages, blog posts MovePageCommand
SearchService (2.9+) Performing searches  

These simpler services don't follow the command pattern, nor do they perform any data modification. They are generally used to simplify other functionality:

Service class Responsibility
HttpRetrievalService Http Connectivity to External Services

More information

Labels

howto howto Delete
guide guide Delete
plugin plugin Delete
integration integration Delete
manager manager Delete
module module Delete
confluence confluence Delete
component component Delete
spring spring Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.
  1. Dec 02, 2008

    Michael Breu says:

    Using Confluence 2.9.2. I'm still having problems to use the settings manager i...

    Using Confluence 2.9.2.

    I'm still having problems to use the settings manager in a clustered environment.

    Plugins are correctly pushed to the other node. However it seems, that the configuration settings from the settings manager are managed by a different classloader compared to the settings managed by the plugin.

    This results e.g. in a ClassCastException as in the following logfile excerpt.

    getSettings class loader of old Settings: com.atlassian.confluence.extra.invite.InviteSettings:com.atlassian.plugin.classloader.PluginClassLoader@69956995
    getSettings class loader of new Settings: com.atlassian.confluence.extra.invite.InviteSettings:com.atlassian.plugin.classloader.PluginClassLoader@70bc70bc
    java.lang.ClassCastException: com.atlassian.confluence.extra.invite.InviteSettings incompatible with com.atlassian.confluence.extra.invite.InviteSettings
    

    What is the correct usage of the settings manager in a clustered environment?

    1. Dec 10, 2008

      Matt Ryall (Atlassian) says:

      Michael, we normally recommend using JDK data structures for plugin storage (Map...

      Michael, we normally recommend using JDK data structures for plugin storage (Maps, Lists, etc.) because this problem can also occur when reloading the plugin. I can't seem to find a bug in JIRA related to this, so please raise a new one if you'd like us to look into it further.

Add Comment


Except where otherwise noted, content in this space is licensed under a Creative Commons Attribution 2.5 Australia License.