Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Scan text for words before publishing

Jonathan Jacobi September 11, 2017

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

0 votes
Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2017

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.

Jonathan Jacobi September 11, 2017

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

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 11, 2017

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

Jonathan Jacobi September 12, 2017

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

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

Jonathan Jacobi September 12, 2017

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:

"AbstractCreateAndEditPageAction"

but I'm not sure this is the correct one

)
Thanks :D

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2017

You may start with com.atlassian.confluence.event.events.content.ContentEvent as in:

 @EventListener
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.

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2017

Labels have their own events: com.atlassian.confluence.event.events.label.LabelEvent
(e.g. com.atlassian.confluence.event.events.label.LabelAddEvent).

Jonathan Jacobi September 12, 2017

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!

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 12, 2017

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?

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 13, 2017

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

Jonathan Jacobi September 14, 2017

Thanks!!!!

Jonathan Jacobi September 14, 2017

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!

 

Edit:

I've started to read deeply more about the Event Listener modules, and I see that java code is needed (src: https://developer.atlassian.com/confdev/confluence-plugin-guide/confluence-plugin-module-types/event-listener-module?_ga=2.228386526.23600538.1505396919-511758074.1501773387),

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 : https://developer.atlassian.com/confdev/confluence-plugin-guide/confluence-plugin-module-types/event-listener-module/annotation-based-event-listener-example )... 

 

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

 

Thanks

 

Robert Reiner _smartics_
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 14, 2017

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
TAGS
AUG Leaders

Atlassian Community Events