Name

Objects Available 

Macro Body Processing

No Body

Output format

HTML

Usage

objects-available

RefRipped from http://davidsimpson.me/2014/06/19/velocity-objects-atlassian-confluence-user-macro/

 

Code

## Based on Scott Dudley's answer here:## http://stackoverflow.com/a/23819584/1958200
##
## @noparams
  
#set($cashMoney = "$") ## just for display
  
#set($macroUtilClass=$action.class.forName('com.atlassian.confluence.renderer.radeox.macros.MacroUtils'))
#set($getContextMethod=$macroUtilClass.getDeclaredMethod('defaultVelocityContext',null))
#set($ctx=$getContextMethod.invoke(null))
#set($objects = $ctx.keySet().toArray())
  
<ul id="velocityObjects">
  #foreach($p in $objects)
    #set($className = $ctx.get($p).getClass().getName().toString()) 
    <li>
      <code>$cashMoney$p.toString()</code> &ndash;     
      #if ($className.contains("$") == true || $className.startsWith("com.atlassian") == false)
        $className
      #else
        #set($classUrl = "https://docs.atlassian.com/com/atlassian/confluence/atlassian-confluence/latest/" + $className.replace(".", "/") + ".html")
        <a href="$classUrl">$className</a>
      #end
    </li>
  #end
</ul>
  
<script>
  // Sort them - Confluence doesn't have velocity SortTool, so doing this client side.
  AJS.toInit(function ($) {
    var sort_by_name = function(a, b) {
      return a.innerHTML.toLowerCase().localeCompare(b.innerHTML.toLowerCase());
    }
  
    var velocityObjects = $("#velocityObjects > li").get();
    velocityObjects.sort(sort_by_name);
    for (var i = 0; i < velocityObjects.length; i++) {
      velocityObjects[i].parentNode.appendChild(velocityObjects[i]);
    }
  });
</script>
  
<style>
  /* add some style */
  #com-atlassian-confluence #velocityObjects code {
    margin: 0 2px;
    padding: 0px 5px;
    border: 1px solid #ddd;
    background-color: #f5f5f5;
    -webkit-border-radius: 3px;
    -moz-border-radius: 3px;
    border-radius: 3px;
  }
</style>