Scan text for words before publishing

I wanted to write a plugin that'd be very helpful to me,

the idea is before publishing an entry for the confluence, the plugin will search for certain words in the article (the words will be in a given list), and if it does find some words that are both in the article and in the list, it will ask the user if he wants to add these words as labels to the article.

Is that possible? if so, how do I approach the problem?

I have written a question but I think I haven't made myself clear enough, so re-posting in a much more understandable way...

BTW, I am using confluence 5.4.3 :)

Thanks in advance ! :-)

1 answer

You could listen in your plugin to PageEvents.

Event Listener Module, Annotation Based Event Listener Example, and Writing an Event Listener Plugin Module provide an introduction on how to write a plugin for Confluence Server.

Sorry for the ignorance, but I wanted to ask, how can I add labels using a plugin? :)

No problem: You need to inject the com.atlassian.confluence.labels.LabelManager and use its methods to add labels to com.atlassian.confluence.labels.Labelable (e.g. pages).

This might be helpful: Accessing Confluence Components from Plugin Modules

and accessing the post that is going to be published is also from the Confluence Components?

Thanks a lot Robert, you're the best :)!!!!! 

I assume it is some kind of an event that occurs whenever a user tries to post an "article", but is accessing the text possible as well as adding a label?
(I tried finding the event and wasn't successful, beside:


but I'm not sure this is the correct one

Thanks :D

You may start with as in:

public void onEvent(final ContentEvent event) {

to check which events will be thrown. Probably the PageUpdateEvent (which is a subclasses of the ContentEvent) will do. The events have references to the page from which you can access the body content.

Labels have their own events:

I need the plugin to check the content of the publishment for certain words, if they do exist, to suggest the user to add them as labels, isn't a label event not used here?
Or am I getting it wrong?
Thanks a lot!

Sorry, I'm completely wrong! :(

I thought you need to add labels automatically dependent on the content. This could be done on the save/update event of the page. I completely missed the fact to ask the user for consent. Sorry!

Now that I understand your use case I think you need to run another approach where you implement the query in the front end (I suppose that is where you have already been headed before I lured you on the wrong path). Unfortunately I have very limited knowledge on how to do that. I suppose you need to use the REST API if the JavaScript API does not provide access to all information you require for your use case.

I found Adding a Custom Action to Confluence , but this tutorial only shows how a label can be set on a web action (no user interaction and not bound to the save event). I'm not sure if you'd better search for hooks in the editor (TinyMCE). Maybe this could be a start: Enabling TinyMCE Plugins?

To inspect web elements (in order to find the hook in the frontend) the Web Fragment Finder by Wittified may be very helpful.

Also, if it were to be automatically add labels dependant on the content-

How would I approach it?
Writing an event listener module for a plugin?
Using the " PageUpdateEvent " Event?

Thank you!



I've started to read deeply more about the Event Listener modules, and I see that java code is needed (src:,

where is the java file supposed to be kept?

also, I'm not sure that the required java packages are installed (for example, the ones that are used here : )... 


Isn't there any other way to implement the plugin module? other than in java? 




The Java code is required to be bundled in a JAR as an plugin (aka add-on, which is lately called an "App"). All dependencies are either already deployed with the Confluence Server or they can be added to the OBR bundle (which contains the JAR I mentioned above plus dependencies). So you would need the Atlassian Plugin SDK to build your plugin/add-on/app.

If you do not want to use Java, you could go with JavaScript in the front end (I do not know if Atlassian Connect is already running on server). But again I think you need to create a plugin to install on Confluence Server. The plugin will contain your JavaScript files that are applied with the atlassian-plugin.xml (e.g. web-fragment).

I do not think that there is an solution that can be directly configured to the server (such as User Macros). Maybe there are third-party plugins that allow such a configuration, but I don't know such a plugin.

Suggest an answer

Log in or Sign up to answer
Community showcase
Published Mar 12, 2019 in Confluence

Confluence Admin Certification now $150 for Community Members

More and more people are building their careers with Atlassian, and we want you to be at the front of this wave! Important Dates Start the Certification Prep Course by 2 April 2019 Take your e...

1,544 views 4 13
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you