+ * This very simple macro shows you the very basic use-case of displaying *something* on the Confluence page where it is used.
+ * Use this example macro to toy around, and then quickly move on to the next example - this macro doesn't
+ * really show you all the fun stuff you can do with Confluence.
+public class ExampleMacro extends BaseMacro
+ // We just have to define the variables and the setters, then Spring injects the correct objects for us to use. Simple and efficient.
+ // You just need to know *what* you want to inject and use.
+ private final PageManager pageManager;
+ private final SpaceManager spaceManager;
+ public ExampleMacro(PageManager pageManager, SpaceManager spaceManager)
+ this.pageManager = pageManager;
+ this.spaceManager = spaceManager;
+ public boolean isInline()
+ public boolean hasBody()
+ public RenderMode getBodyRenderMode()
+ return RenderMode.NO_RENDER;
+ * This method returns XHTML to be displayed on the page that uses this macro
+ * we just do random stuff here, trying to show how you can access the most basic
+ * managers and model objects. No emphasis is put on beauty of code nor on
+ * doing actually useful things :-)
+ public String execute(Map params, String body, RenderContext renderContext)
+ // in this most simple example, we build the result in memory, appending HTML code to it at will.
+ // this is something you absolutely don't want to do once you start writing plugins for real. Refer
+ // to the next example for better ways to render content.
+ StringBuffer result = new StringBuffer();
+ // get the currently logged in user and display his name
+ User user = AuthenticatedUserThreadLocal.getUser();
+ String greeting = "Hello " + TextUtils.htmlEncode(user.getFullName()) + "<br><br>";
+ //get the pages added in the last 55 days to the DS space ("Demo Space"), and display them
+ List list = pageManager.getRecentlyAddedPages(55, "DS");
+ result.append("Some stats for the Demo space: <br> ");
+ for (Iterator i = list.iterator(); i.hasNext();)
+ Page page = (Page) i.next();
+ int numberOfChildren = page.getChildren().size();
+ String pageWithChildren = "Page " + TextUtils.htmlEncode(page.getTitle()) + " has " + numberOfChildren + " children <br> ";
+ // and show the number of all spaces in this installation.
+ String spaces = "<br>Altogether, this installation has " + spaceManager.getAllSpaces().size() + " spaces. <br>";
+ // this concludes our little demo. Now you should understand the basics of code injection use in Confluence, and how
+ // to get a really simple macro running.
+ return result.toString();