Developer
Documentation
Resources
Get Support
Sign in
Developer
Get Support
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Developer
Sign in
DOCUMENTATION
Cloud
Data Center
Resources
Sign in
Last updated Dec 8, 2017

Within a Confluence macro, how do I retrieve the current ContentEntityObject?

Within a Confluence macro, how do I retrieve the current ContentEntityObject?

You can retrieve the current ContentEntityObject (ie the content object this macro is a part of), as follows:

1
2
public String execute(Map parameters, String body, RenderContext renderContext) throws MacroException {
    // retrieve a reference to the body object this macro is in
    if (!(renderContext instanceof PageContext))
    {
        throw new MacroException("This macro can only be used in a page");
    }
    ContentEntityObject contentObject = ((PageContext)renderContext).getEntity();
    ...

Note that this method might return null if there is no current content object (for example if you are previewing a page that has not been added yet, or if a remote user is rendering a fragment of notation).

Rate this page: