| java.lang.Object com.ecyrd.jspwiki.modules.ModuleManager com.ecyrd.jspwiki.plugin.PluginManager
PluginManager | public class PluginManager extends ModuleManager (Code) | | 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:
- The plugin class
- The plugin parameters
- The plugin body
For example, in the following line of code:
[{INSERT com.ecyrd.jspwiki.plugin.FunnyPlugin foo='bar'
blob='goo'
abcdefghijklmnopqrstuvw
01234567890}]
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 plugin body is
accessible via a special parameter called "_body".
If the parameter "debug" is set to "true" for the plugin,
JSPWiki will output debugging information directly to the page if there
is an exception.
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
jspwiki.properties 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'}]
Plugin property files
Since 2.3.25 you can also define a generic plugin XML properties file per
each JAR file.
Janne Jalkanen
foo.css
code
Janne Jalkanen
Plugin lifecycle
Plugin can implement multiple interfaces to let JSPWiki know at which stages they should
be invoked:
- InitializablePlugin: If your plugin implements this interface, the initialize()-method is
called once for this class
before any actual execute() methods are called. You should use the initialize() for e.g.
precalculating things. But notice that this method is really called only once during the
entire WikiEngine lifetime. The InitializablePlugin is available from 2.5.30 onwards.
- ParserStagePlugin: If you implement this interface, the executeParse() method is called
when JSPWiki is forming the DOM tree. You will receive an incomplete DOM tree, as well
as the regular parameters. However, since JSPWiki caches the DOM tree to speed up later
places, which means that whatever this method returns would be irrelevant. You can do some DOM
tree manipulation, though. The ParserStagePlugin is available from 2.5.30 onwards.
- WikiPlugin: The regular kind of plugin which is executed at every rendering stage. Each
new page load is guaranteed to invoke the plugin, unlike with the ParserStagePlugins.
author: Janne Jalkanen since: 1.6.1 |
Inner Class :final public static class WikiPluginInfo extends WikiModuleInfo | |
DEFAULT_FORMS_PACKAGE | final public static String DEFAULT_FORMS_PACKAGE(Code) | | |
DEFAULT_PACKAGE | final public static String DEFAULT_PACKAGE(Code) | | This is the default package to try in case the instantiation
fails.
|
PARAM_BODY | final public static String PARAM_BODY(Code) | | The name of the body content. Current value is "_body".
|
PARAM_BOUNDS | final public static String PARAM_BOUNDS(Code) | | The name of the parameter containing the start and end positions in the
read stream of the plugin text (stored as a two-element int[], start
and end resp.).
|
PARAM_CMDLINE | final public static String PARAM_CMDLINE(Code) | | The name of the command line content parameter. The value is "_cmdline".
|
PARAM_DEBUG | final public static String PARAM_DEBUG(Code) | | A special name to be used in case you want to see debug output
|
PROP_SEARCHPATH | final public static String PROP_SEARCHPATH(Code) | | The property name defining which packages will be searched for properties.
|
PluginManager | public PluginManager(WikiEngine engine, Properties props)(Code) | | Create a new PluginManager.
Parameters: props - Contents of a "jspwiki.properties" file. |
enablePlugins | public void enablePlugins(boolean enabled)(Code) | | Enables or disables plugin execution.
|
execute | public String execute(WikiContext context, String classname, Map params) throws PluginException(Code) | | Executes a plugin class in the given context.
Used to be private, but is public since 1.9.21.
Parameters: context - The current WikiContext. Parameters: classname - The name of the class. Can also be ashortened version without the package name, since the class name is searched from thepackage search path. Parameters: params - A parsed map of key-value pairs. Whatever the plugin returns. throws: PluginException - If the plugin execution failed forsome reason. since: 2.0 |
execute | public String execute(WikiContext context, String commandline) throws PluginException(Code) | | 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.
Parameters: context - The current WikiContext. Parameters: commandline - The full command line, including pluginname, parameters and body. HTML as returned by the plugin, or possibly an errormessage. |
isPluginLink | public static boolean isPluginLink(String link)(Code) | | 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 "{$".
Parameters: link - Link text, i.e. the contents of text between []. True, if this link seems to be a command to insert a plugin here. |
parseArgs | public Map parseArgs(String argstring) throws IOException(Code) | | Parses plugin arguments. Handles quotes and all other kewl stuff.
Special parameters
The plugin body is put into a special parameter defined by
PluginManager.PARAM_BODY ;
the plugin's command line into a parameter defined by
PluginManager.PARAM_CMDLINE ;
and the bounds of the plugin within the wiki page text by a parameter defined
by
PluginManager.PARAM_BOUNDS , whose value is stored as a two-element int[] array,
i.e., [start,end].
Parameters: argstring - The argument string to the plugin. This istypically a list of key-value pairs, using "'" to escapespaces in strings, followed by an empty line and then theplugin body. In case the parameter is null, will return anempty parameter list. A parsed list of parameters. throws: IOException - If the parsing fails. |
pluginsEnabled | public boolean pluginsEnabled()(Code) | | 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.
|
|
|