Missed Team ’24? Catch up on announcements here.

×
Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How can i use a Java plugin to add a macro to a page?

Matt Albone January 15, 2014

So using Confluence Java plugins I'm currently creating a page and adding certain labels to it, and a specific title, etc etc.

How can I programmatically add a macro to that page as well?

Thanks in advance, Matt

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Adrien Ragot 2
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.
January 15, 2014

You need to set the BodyContent for the page. The body is in XML, you should take an example from a real page with your macro to understand how it works.

If you download the source of Confluence, you'll find files such as TestPage.java. Go through them an see how they perform this operation.

For example, here's the contents of XhtmlSoapService:

public RemotePage storePage(String token, RemotePage page) throws RemoteException
    {
        PageContext pageContext;
        ContentEntityObject pageCeo = contentEntityObjectDao.getById(page.getId());
        if (pageCeo != null)
        {
            pageContext = new PageContext(pageCeo);
        }
        else
        {
            pageContext = new PageContext(page.getSpace());
        }

        String storageFormattedContent = migrateStorageFormat(pageContext, page.getContent());

        page.setContent(storageFormattedContent);

        return pagesService.storePage(page);
    }

Matt Albone January 15, 2014

Ok well I can get the BodyContent as follows:

Page p = pageManager.getPage(pId);
ContentEntityObject pageCeo = p.getContentEntityObject();
BodyContent bc = pageCeo.getBodyContent();

But it seems like the code you posted is turning this in to a string (and therefore making it open for manipulation) inside the 'migrateStorageFormat' function.

Could you show me what that's doing? Unfortunately our license doesn't cover us downloading the source.

Adrien Ragot 2
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.
January 15, 2014

It calls a method, which calls a method, which ... pretty much in the style of FizzBuzzEnterpriseEdition (It's a programmer joke in case it's not obvious).

More seriously, you just need to create a page with your macro, and call getBodyContent() on that page. I don't think looking at the code will be more efficient than looking at the result.

Could you show me what that's doing? Unfortunately our license doesn't cover us downloading the source.

If you don't have access to the source of Confluence, I'm not even sure it's legal for me to show it to you:

  • The Starter license costs $10 and gives you access to the source. Are you sure you don't have it? At least could you buy it and expense it to your org?
  • If it's too hard to find the license owner in your company, submit a support ticket to Atlassian with your SEN (Support Entitlement Number) and they'll be happy to tell you who in your organization is the Technical Contact and the Billing Contact.
  • If you don't have access to your SEN, then you don't have support for your instance, it will be hard to develop a suitable plugin. You'd better start searching for it now, since one day or another you will actually need an answer from them.

Hope you'll succeed in your license hunt!

TAGS
AUG Leaders

Atlassian Community Events