Creating a plugin (Part 2)

Creating a plugin (Part 2)

  • | Facebook
  • Twitter
  • Delicious
  • print

Advanced features for plugin

Section(s): back office, community, front office, learning, plugin

In this article, we will detail more deeply what can be done with plugins and what are the best practices.

Important notes

It is assumed that you just complete the part 1 of the tutorial.
It is important to keep in mind a few rules about plugins. There is nothing that will prevent you from braking the rules, but it will make your work much more difficult if you bypass them.

  • A plugin is independent from any other plugin. It should not require another plugin to be installed to be used.
  • You should never modify a plugin you're not the author of. If you want to change an existing plugin, duplicate the existing one, rename the copy and work with it.
  • Embeded JARs containing java classes you wrote should also contain the source (.java files)

Adding parameters to a plugin

As we have seen in part 1 of this tutorial, a plugin must define a config.xml file in its /config directory. Let's edit our helloworld plugin config file and change it to this content :

<?xml version="1.0" encoding="utf-8"?>
<root>
  <info>
    <site>http://wms.wedia-group.com/resources/knowledge-base/plugins/creating-a-plugin-@/111/view-62-article.html</site>
    <authors>WEDIA</authors>
    <description></description>
    <example></example>
    <faq></faq>
    <installation></installation>
    <requires></requires>
    <version>1.0.0</version>
  </info>
  <parameters>
       <parameter name="hello_to" description="Who should the plugin say hello to" type="string" mandatory="false" default="John Doe" value=""/>
     </parameters>
</root>


If you go back to the plugin list page and click on the configure (http://localhost:8080/wms/admin/plugin/view?action=edit&name=helloworld) link on the helloworld line, you should see something like :

Screen shot of plugin configuration
Now you can set a new value for hello_to parameter for let's say "Guillaume".
If you then edit the /bov2/dataindex/blocs/bookmarks_before.jsp file and change it for the following code :

<%@page pageEncoding="ISO-8859-15" %>
<%@taglib prefix="noheto" uri="/WEB-INF/noheto.tld" %>
<%@taglib prefix="c" uri="/WEB-INF/c.tld" %>
<noheto:skipPage test="${not pageContext.request.included}"/>
<h1>Hello <c:out value="${plugin.parameters.hello_to.value}"/></h1>
<a href="<c:url value="${plugin.pagePath}entrypoint.jspz"/>">Entry point</a>	

Now refresh youre web browser, and see who we say hello to...
Parameters can have one of the following types :

  • string (for small string parameter)
  • boolean (true false value choice)
  • int (for integer number)
  • text (for longer text - with a textarea)
  • password (for password - value not visible )
  • mail (for mail - will return a String in plugin parameters map, will check if is an email address)

Note: When editing parameters from the web console, you will be informed wether a parameter is valid or not. Nevertheless, an invalid parameter will not prevent you from saving or activating the plugin.

The IPlugin interface

Once you are in a JSP that belongs to a Plugin, an object set in the request attributes implementing the com.noheto.plugins.IPlugin interface is available with the key plugin.
With this object, you can retrieve plugin informations such as name, version... (have a look at the API documentation) but also parameters values:
${plugin.parameters[parameter_name].value}
There are other usefull methods for getting paths easily:

  • getPagePath will return path part containing page directory name and trailing '/', that's why we wrote <c:url value="${plugin.pagePath}entrypoint.jspz"/>
  • getResourcePath will return path part containing res directory and trailing '/'. Images, javascript resources, cascading style sheets and other static resources can be embedded in a plugin in the res directory. This method helps to retrieve paths
  • invoke This method is used to invoke static methods from objects. We will explain with more details in  the third part of this tutorial.
Read part 3 of the tutorial and learn how to embed JARs inside a plugin