Class PluginManager


public class PluginManager
extends java.lang.Object

Manages plugin classes. There exists a single instance of PluginManager per each instance of WikiEngine, that is, each JSPWiki instance.

A plugin is defined to have three parts:

  1. The plugin class
  2. The plugin parameters
  3. The plugin body
For example, in the following line of code:
  [{INSERT com.ecyrd.jspwiki.plugin.FunnyPlugin  foo='bar'

The plugin class is "com.ecyrd.jspwiki.plugin.FunnyPlugin", the parameters are "foo" and "blob" (having values "bar" and "goo", respectively), and the plugin body is then "abcdefghijklmnopqrstuvw\n01234567890".

The class name can be shortened, and marked without the package. For example, "FunnyPlugin" would be expanded to "com.ecyrd.jspwiki.plugin.FunnyPlugin" automatically. It is also possible to defined other packages, by setting the "jspwiki.plugin.searchPath" property. See the included file for examples.

Even though the nominal way of writing the plugin is

  [{INSERT pluginclass WHERE param1=value1...}],
it is possible to shorten this quite a lot, by skipping the INSERT, and WHERE words, and dropping the package name. For example:
  [{INSERT com.ecyrd.jspwiki.plugin.Counter WHERE name='foo'}]
is the same as
  [{Counter name='foo'}]

Janne Jalkanen

Field Summary
static java.lang.String DEFAULT_PACKAGE
          This is the default package to try in case the instantiation fails.
static java.lang.String PARAM_BODY
          The name of the body content.
static java.lang.String PROP_SEARCHPATH
          The property name defining which packages will be searched for properties.
Constructor Summary
PluginManager(java.util.Properties props)
          Create a new PluginManager.
Method Summary
 void enablePlugins(boolean enabled)
          Enables or disables plugin execution.
 java.lang.String execute(WikiContext context, java.lang.String commandline)
          Parses a plugin.
 java.lang.String execute(WikiContext context, java.lang.String classname, java.util.Map params)
          Executes a plugin class in the given context.
static boolean isPluginLink(java.lang.String link)
          Returns true if the link is really command to insert a plugin.
 java.util.Map parseArgs(java.lang.String argstring)
          Parses plugin arguments.
 boolean pluginsEnabled()
          Returns plugin execution status.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Field Detail


public static final java.lang.String DEFAULT_PACKAGE
This is the default package to try in case the instantiation fails.

See Also:
Constant Field Values


public static final java.lang.String PROP_SEARCHPATH
The property name defining which packages will be searched for properties.

See Also:
Constant Field Values


public static final java.lang.String PARAM_BODY
The name of the body content. Current value is "_body".

See Also:
Constant Field Values
Constructor Detail


public PluginManager(java.util.Properties props)
Create a new PluginManager.

props - Contents of a "" file.
Method Detail


public void enablePlugins(boolean enabled)
Enables or disables plugin execution.


public boolean pluginsEnabled()
Returns plugin execution status. If false, plugins are not executed when they are encountered on a WikiPage, and an empty string is returned in their place.


public static boolean isPluginLink(java.lang.String link)
Returns true if the link is really command to insert a plugin.

Currently we just check if the link starts with "{INSERT", or just plain "{" but not "{$".

link - Link text, i.e. the contents of text between [].
True, if this link seems to be a command to insert a plugin here.


public java.lang.String execute(WikiContext context,
                                java.lang.String classname,
                                java.util.Map params)
                         throws PluginException
Executes a plugin class in the given context.

Used to be private, but is public since 1.9.21.

context - The current WikiContext.
classname - The name of the class. Can also be a shortened version without the package name, since the class name is searched from the package search path.
params - A parsed map of key-value pairs.
Whatever the plugin returns.
PluginException - If the plugin execution failed for some reason.


public java.util.Map parseArgs(java.lang.String argstring)
Parses plugin arguments. Handles quotes and all other kewl stuff.

argstring - The argument string to the plugin. This is typically a list of key-value pairs, using "'" to escape spaces in strings, followed by an empty line and then the plugin body.
A parsed list of parameters. The plugin body is put into a special parameter defined by PluginManager.PARAM_BODY.
Throws: - If the parsing fails.


public java.lang.String execute(WikiContext context,
                                java.lang.String commandline)
                         throws PluginException
Parses a plugin. Plugin commands are of the form: [{INSERT myplugin WHERE param1=value1, param2=value2}] myplugin may either be a class name or a plugin alias.

This is the main entry point that is used.

context - The current WikiContext.
commandline - The full command line, including plugin name, parameters and body.
HTML as returned by the plugin, or possibly an error message.