About
If you have ever worked with JIRA before, content and template renderings are mostly handled by the VelocityManager class. To know what are the parameters available in the context, you can grab the $ctx (java.util.Map) from it.
However, in Confluence, they do not provide any self referencing parameters in the context, therefore you may need to modify the source code in order to find out what are lurking in it.
But.. which class(es)?
| Too lazy to read the entire content? Click these: |
Velocity in Confluence
There are a few classes used in Confluence to render the content, the one which you want to look into is:
| com.atlassian.confluence.util.velocity.VelocityUtils |
|---|
There may be some which I have missed out (and also the interesting ApplyDecoratorDirective class), perhaps you would like to take a look at the See also section.
Adding self-referencing object
To add a self-reference, you need to identify the context variable then inject it into the source code.
com.atlassian.confluence.util.velocity.VelocityUtils
The VelocityUtils has two methods used for rendering:
- public static String getRenderedTemplateWithoutSwallowingErrors(String templateName, Context context)
- public static String getRenderedContent(String templateContent, Map contextMap)
getRenderedTemplateWithoutSwallowingErrors
This method, as far as I know, is used to render the Confluence templates – SiteMesh decorators. The context is a com.opensymphony.webwork.views.velocity.WebWorkVelocityContext object. Therefore, to display all the parameters in it, you can use:
<pre> #foreach($p in $ctx.getKeys()) $p.toString() - $ctx.get($p).getClass().getName().toString() #end </pre>
bootstrap - com.atlassian.confluence.setup.DefaultBootstrapManager textUtil - com.opensymphony.util.TextUtils title - java.lang.String generalUtil - com.atlassian.confluence.util.GeneralUtil resourceManager - com.atlassian.confluence.util.DefaultResourceManager sitemeshPage - com.opensymphony.module.sitemesh.parser.FastPage attachmentManager - $Proxy4 webReqUtils - com.atlassian.core.util.WebRequestUtils permissionCheckDispatcher - com.atlassian.confluence.security.PermissionCheckDispatcher res - com.atlassian.core.filters.AbstractEncodingFilter$1 setupPersister - com.atlassian.confluence.setup.DefaultSetupPersister permissionHelper - com.atlassian.confluence.security.PermissionHelper seraph - com.atlassian.confluence.util.SeraphUtils body - java.lang.String webwork - com.opensymphony.webwork.util.VelocityWebWorkUtil setup - com.atlassian.confluence.setup.DefaultBootstrapManager user - com.atlassian.user.impl.osuser.OSUUser action - com.atlassian.confluence.core.ConfluenceActionSupport fileUtil - bucket.util.FileUtils helper - com.atlassian.confluence.themes.GlobalHelper ctx - com.opensymphony.webwork.views.velocity.WebWorkVelocityContext stack - com.opensymphony.xwork.util.OgnlValueStack renderBean - com.atlassian.confluence.util.QuickPageRenderBean settingsManager - com.atlassian.confluence.setup.settings.DefaultSettingsManager head - java.lang.String licenseManager - com.atlassian.license.LicenseManager ognl - com.opensymphony.webwork.views.jsp.ui.OgnlTool req - com.atlassian.seraph.filter.SecurityHttpRequestWrapper userAccessor - $Proxy11
Ops?
The same Velocity code, if exists in the page.vmd decorator, produces this result:
bootstrap - com.atlassian.confluence.setup.DefaultBootstrapManager labelable - com.atlassian.confluence.pages.Page textUtil - com.opensymphony.util.TextUtils title - java.lang.String generalUtil - com.atlassian.confluence.util.GeneralUtil resourceManager - com.atlassian.confluence.util.DefaultResourceManager sitemeshPage - com.opensymphony.module.sitemesh.parser.FastPage attachmentManager - $Proxy4 webReqUtils - com.atlassian.core.util.WebRequestUtils permissionCheckDispatcher - com.atlassian.confluence.security.PermissionCheckDispatcher res - com.opensymphony.module.sitemesh.filter.PageResponseWrapper setupPersister - com.atlassian.confluence.setup.DefaultSetupPersister permissionHelper - com.atlassian.confluence.security.PermissionHelper seraph - com.atlassian.confluence.util.SeraphUtils userHistory - com.atlassian.confluence.user.history.UserHistory ctxFromDirective - com.opensymphony.webwork.views.velocity.WebWorkVelocityContext body - java.lang.String webwork - com.opensymphony.webwork.util.VelocityWebWorkUtil setup - com.atlassian.confluence.setup.DefaultBootstrapManager action - com.atlassian.confluence.pages.actions.ViewPageAction user - com.atlassian.user.impl.osuser.OSUUser fileUtil - bucket.util.FileUtils helper - com.atlassian.confluence.themes.PageHelper mode - java.lang.String ctxz - com.opensymphony.webwork.views.velocity.WebWorkVelocityContext stack - com.opensymphony.xwork.util.OgnlValueStack renderBean - com.atlassian.confluence.util.QuickPageRenderBean settingsManager - com.atlassian.confluence.setup.settings.DefaultSettingsManager params - java.util.HashMap head - java.lang.String licenseManager - com.atlassian.license.LicenseManager ognl - com.opensymphony.webwork.views.jsp.ui.OgnlTool confPage - com.atlassian.confluence.pages.Page req - com.atlassian.seraph.filter.SecurityHttpRequestWrapper userAccessor - $Proxy11
getRenderedContent
This method, again AFAIK, is used to render the macros, user macros, and other plugins. The context is a java.util.Map. Therefore, to display all the parameters in it, you can use:
<pre> #foreach($p in $ctx.keySet().toArray()) $p.toString() - $ctx.get($p).getClass().getName().toString() #end </pre>
bootstrap - com.atlassian.confluence.setup.DefaultBootstrapManager textUtil - com.opensymphony.util.TextUtils generalUtil - com.atlassian.confluence.util.GeneralUtil resourceManager - com.atlassian.confluence.util.DefaultResourceManager attachmentManager - $Proxy4 webReqUtils - com.atlassian.core.util.WebRequestUtils param: = | RAW | = : - java.lang.String renderContext - com.atlassian.confluence.renderer.PageContext permissionCheckDispatcher - com.atlassian.confluence.security.PermissionCheckDispatcher res - com.opensymphony.module.sitemesh.filter.PageResponseWrapper setupPersister - com.atlassian.confluence.setup.DefaultSetupPersister permissionHelper - com.atlassian.confluence.security.PermissionHelper seraph - com.atlassian.confluence.util.SeraphUtils ctx - java.util.HashMap webwork - com.opensymphony.webwork.util.VelocityWebWorkUtil setup - com.atlassian.confluence.setup.DefaultBootstrapManager action - com.atlassian.confluence.core.ConfluenceActionSupport fileUtil - bucket.util.FileUtils content - com.atlassian.confluence.pages.Page space - com.atlassian.confluence.spaces.Space$$EnhancerByCGLIB$$e6057750 renderBean - com.atlassian.confluence.util.QuickPageRenderBean settingsManager - com.atlassian.confluence.setup.settings.DefaultSettingsManager config - com.atlassian.confluence.setup.DefaultBootstrapManager licenseManager - com.atlassian.license.LicenseManager userAccessor - $Proxy11 req - com.atlassian.seraph.filter.SecurityHttpRequestWrapper
See also
Please also take a look at:
| com.atlassian.confluence.mail.MacroUtils.defaultVelocityContext() | List of default parameters used by macro |
|---|---|
| com.atlassian.confluence.mail.VelocityRenderedQueueItem | |
| com.atlassian.confluence.plugin.descriptor.web.AbstractWebBean | Adds com.atlassian.confluence.themes.PageHelper and used by WebLabel and WebLink |
| com.atlassian.confluence.servlet.ConfluenceVelocityServlet | |
| com.atlassian.confluence.setup.velocity.ApplyDecoratorDirective | Used to apply SiteMesh decorator |
| com.atlassian.confluence.setup.webwork.ConfluenceVelocityContext | A custom velocity context to return things to use in Velocity templates |
| com.opensymphony.webwork.views.velocity.VelocityManager | Webwork's VelocityManager |