Developing Wiki Plugins for codeBeamer: The AbstractCodeBeamerWikiPlugin Class (Part 2)Table of Contents
OverviewIn the first article of this series, a simple example was shown for developing and deploying a custom wiki plugin for CodeBeamer. In the second part, we will delve deeper into plugin development and explain some more advanced CodeBeamer-specific wiki plugin features. Subclassing AbstractCodeBeamerWikiPluginWhat is AbstractCodeBeamerWikiPlugin?In order to have convenient access to CodeBeamer-specific features, your plugin classes must extend the com.intland.codebeamer.wiki.plugins.AbstractCodeBeamerWikiPlugin class. Doing this, you will have access to:
However the AbstractCodeBeamerWikiPlugin evolves in future versions, we will keep its API stable and 100% backward compatible, so your plugin development efforts will not break when upgrading to a new CodeBeamer version. Accessing the User and the Wiki Page ObjectsYou can use the following getter methods provided by AbstractCodeBeamerWikiPlugin:
Note that transitively through the WikiPageDto, you can also get the project that owns the current wiki page: ProjectDto project = getPageFromContext(wikiContext).getProject(); You can access the children of the current page, the administrator of the current project and other related information similarly through accessor ("getter") methods. Rendering TemplatesWhy Use Templates?CodeBeamer includes support for templating the wiki plugin output, i.e. isolating the HTML template from the actual Java code and rendering it at runtime using a set of variables. CodeBeamer's templating mechanism is built on the top of Velocity, a full-blown open source templating engine developed at the Apache Software Foundation. Templating in CodeBeamer's WikiRendering a template in CodeBeamer is usually a three-step process:
The following code snippet demonstrates this: VelocityContext velocityContext = getDefaultVelocityContextFromContext(context); // 1 velocityContext.put("currentTime", new Date()); // 2 velocityContext.put("yearBorn", new Integer(1976)); // 2 return renderPluginTemplate("mytest-plugin.vm", velocityContext); // 3 Using CodeBeamer's Built-in Velocity MacrosCodeBeamer is shipped with an extensive library of reusable Velocity macros that can be found in $CODEBEAMER_HOME/tomcat/webapps/cb/config/templates/VM_global_library.vm. These can be used, for example, to generate links to tracker items or to construct HTML tables. Please take a look at that VM_global_library.vm file for details. Why might you prefer these macros to your custom macro library?
Using CSFR tag in Velocity templatesThe 'cbCsrfToken' has been added to the velocity context.
By default, the page load event globally adds a token hidden field to all forms. This is the expected behavior.
Other Approaches for TemplatingUsing Velocity is recommended but not required. Alternative solutions might include:
Compiling, Deploying and TestingCompiling and deploying the Java code is done in the same way as with our first HelloWorldPlugin. In this case, we have one more file, the Velocity template second-plugin.vm. You have to copy that to $CODEBEAMER_HOME/tomcat/webapps/cb/config/templates, this is where CodeBeamer will look for the templates. This directory stores not only the wiki plugin templates, but the email templates and wiki page templates, too. TestingCreate a testpage and enter: [{SecondDemoPlugin}] You should see something like this: Printing Basic Information * Signed in as: bond (Administrator, CodeBeamer) * Reading page: "My favourite trumpet dealers" (Mon Jun 26 15:06:45 CEST 2006) * Working in project: "Kind of Blue" * Now: Jun 26 17:52 2006 * Am I the owner of this page? yes Using Link Macros * View bond (Administrator, CodeBeamer) * View Home * View Kind of Blue Please note that wiki pages are living entities, always reflecting the latest information available when rendering them: for example, rename your project and then reload the Wiki page and you'll see the changes immediately. AppendixSecondDemoPlugin.javapackage com.intland.codebeamer.wiki.plugins; import java.util.Date; import java.util.Map; import org.apache.velocity.VelocityContext; import com.ecyrd.jspwiki.WikiContext; import com.intland.codebeamer.persistence.dto.UserDto; import com.intland.codebeamer.persistence.dto.WikiPageDto; public class SecondDemoPlugin extends AbstractCodeBeamerWikiPlugin { public String execute(WikiContext context, Map params) { // get beans from wiki context UserDto user = getUserFromContext(context); WikiPageDto page = getPageFromContext(context); // get default Velocity context VelocityContext velocityContext = getDefaultVelocityContextFromContext(context); // put the current system time in the user's format to the context velocityContext.put("currentTime", user.getDateTimeFormat().format(new Date())); // put whether the current user is the owner of the current page to the context velocityContext.put("owner", page.getOwner().getId().equals(user.getId()) ? "yes" : "no"); // render template return renderPluginTemplate("second-plugin.vm", velocityContext); }} Comments:
seconddemo-plugin.vm<h3>Printing Basic Information</h3> <ul> <li>Signed in as: <i>${user.name} (${user.lastName}, ${user.firstName})</i></li> <li>Reading page: <i>"${wikiPage.name}" (${wikiPage.lastModifiedAt})</i></li> <li>Working in project: <i>"${wikiPage.project.name}"</i></li> <li>Now: <i>${currentTime}</i></li> <li>Am I the owner of this page? <i>${owner}</i></li> </ul> <h3>Using Link Macros</h3> <ul> <li>View #linkUser($user)</li> <li>View #linkWikiPage($wikiPage)</li> <li>View #linkProject($wikiPage.project)</li> </ul> Comments: .vm files contain only HTML snippets, so there is no need for a HTML <head>, <body> and other structural elements. |
Fast Links
codebeamer Overview codebeamer Knowledge Base Services by Intland Software |
This website stores cookies on your computer. These cookies are used to improve your browsing experience, constantly optimize the functionality and content of our website, furthermore helps us to understand your interests and provide more personalized services to you, both on this website and through other media. With your permission we and our partners may use precise geolocation data and identification through device scanning. You may click accept to consent to our and our partners’ processing as described above. Please be aware that some processing of your personal data may not require your consent, but you have a right to object to such processing. By using our website, you acknowledge this notice of our cookie practices. By accepting and continuing to browse this site, you agree to this use. For more information about the cookies we use, please visit our Privacy Policy.Your preferences will apply to this website only.
Note that user-behavior analytics are being captured on this server for the purpose of improving the Codebeamer user experience.