Writing a Confluence User Macro is a good and easy way to implement your own little requirements. But sometimes your requirements to the macro are getting much more complex. At this point you will notice that a User macro not allowes you to access the Confluence Manager API.
But you can achieve this with a little trick. The following user macro code will give you access to the common used managers. At the and you will find a little example how to use the space manager.
#set($containerManagerClass=$action.class.forName('com.atlassian.spring.container.ContainerManager')) #set($getInstanceMethod=$containerManagerClass.getDeclaredMethod('getInstance',null)) #set($containerManager=$getInstanceMethod.invoke(null,null)) #set($containerContext=$containerManager.containerContext) ## the pageManager gives you access to the pages in confluence #set($pageManager=$containerContext.getComponent('pageManager')) ## the spaceManager gives you access to the spaces of confluence #set($spaceManager=$containerContext.getComponent('spaceManager')) ## A little simple example to list all spaces of this confluence. Be aware, the method "getAllSpaces()" does not check for permissions! Simple Space List <ul> #foreach ( $space in $spaceManager.getAllSpaces() ) <li>$space.name</li> #end </ul>
This code above should work for all 3.x Confluence releases. The managers and its methods are described in the Confluence API documentation: