Creating a plugin (Part 1)

Creating a plugin (Part 1)

  • | Facebook
  • Twitter
  • Delicious
  • print

Learn how plugins work and how to create your own ones.

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

Creating plugins is a good way to partition developments. By Developing a plugin, you can add code before or after any jsp included via the noheto:include tag. Plugins can easily be activated/deactivated, and should always be easy to share between projects.

Creating your first hello world plugin

In this article, we assume that you have a running wedia wms instance on http://localhost:8080/wms/ . In your /SAN/__perso/_plugins directory, create a new helloworld directory. In this helloworld directory, create the following directories: config and page.

The config directory is here to store a single file: config.xml. This file describes the plugin name, description, author, version, parameters, faq…

The page directory is used to store all JSP included in the plugin.

In the config directory, create a config.xml file and copy/paste the following code:

<?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>Hello world plugin</description>
    <example>no example</example>
    <faq>no faq</faq>
    <installation>deploy the plugin in your application /SAN/_plugins directory</installation>
    <requires>engine 8.7.2 or newer</requires>
    <version>1.0.0</version>
  </info>
</root>


In the page directory, create the directories: bov2/dataindex/blocs. In the blocs directory, create a file named bookmarks_before.jsp and copy/paste inside 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 World</h1>

Once you're done,on your browser, go to http://localhost:8080/wms/admin.

  • In the technical configuration tab, click on basic parameters
  • Make sure that in the Modules section, Plugins is set to yes (at the bottom of the page) ; save if necessary.
  • Go back to the administration page (click on Administration on the top of the page)
  • In the Application configuration, click on Plugin, lock the functionality.
  • In the Liste des plugins désactivés table (second list), you should see helloworld. Click on activate on the right of the helloworld plugin line.
  • Go back to the BO home (http://localhost:8080/wms/wcm.jspz)

How does it work?

Pages of a plugin are automatically included (if plugins are activated in the basic parameters page and the plugin is activated) through the noheto:include tag: when you include a page /foo/bar.jsp in this way :
<noheto:include page="/foo/bar.jspz"/>

The WEDIA WMS Core enginge will try to find plugins having in their page directory a /foo/bar_before.jsp to include before the /foo/bar.jsp and plugins having in their page directory a /foo/bar_after.jsp to include after the /foo/bar.jsp.
Note: If several plugins define a plugable JSP, all of them will be used. It is possible to order plugins from the plugin administration page

Does /foo/bar.jsp have to exist in /SAN directory?

No, keep in mind that the entry point for a plugin is the noheto:include tag. If you have this code in a JSP :

<noheto:include page="/foo/bar.jspz">
  <noheto:include page="/foo/foobar.jspz">
    Nore /foo/bar.jsp neither /foo/foobar.jsp exist
 </noheto:include>
</noheto:include>


You could still have plugins defining /foo/bar_before.jsp, /foo/bar_after.jsp, /foo/foobar_before.jsp or  /foo/foobar_after.jsp.
Caution: if /foo/bar.jsp exists, /foo/foobar.jsp won't be executed therefor, plugins defining /foo/foobar_before.jsp or  /foo/foobar_after.jsp won't be executed.

Can a plugin JSP page be an entry point ?

Yes, plugins can be accessed directly. It is very usefull for AJAX issues.
In the helloworld plugin, add a JSP page entrypoint.jsp in the /page directory and copy/paste the following code :

<html>
<head>
  <title>Hello World entry point</title>
</head>
<body>
Hello world entry point
</body>
</html>

Then edit the previously created bookmarks_before.jsp and copy/paste the following code (replace existing 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 World</h1>
<a href="<c:url value="${plugin.pagePath}entrypoint.jspz"/>">Entry point</a>
<%-- We will discuss this code later in the 2nd part of the tutorial --%>


If you refresh your back office home page, you will see the link "Entry point". If you click on it, you'll access the plugin entry point.

Read next : part 2 of this tutorial