public class DefaultPluginManager extends ModuleManager implements PluginManager
A plugin is defined to have three parts:
[{INSERT org.apache.wiki.plugin.FunnyPlugin foo='bar'
blob='goo'
abcdefghijklmnopqrstuvw
01234567890}]
The plugin class is "org.apache.wiki.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 "org.apache.wiki.plugin.FunnyPlugin" automatically. It is also possible to define 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 org.apache.wiki.plugin.Counter WHERE name='foo'}]
is the same as
[{Counter name='foo'}]
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 can implement multiple interfaces to let JSPWiki know at which stages they should be invoked:
| Modifier and Type | Class and Description |
|---|---|
static class |
DefaultPluginManager.WikiPluginInfo
Contains information about a bunch of plugins.
|
m_engine, PLUGIN_RESOURCE_LOCATIONDEFAULT_PACKAGE, PARAM_BODY, PARAM_BOUNDS, PARAM_CMDLINE, PARAM_DEBUG, PROP_EXTERNALJARS, PROP_SEARCHPATH| Constructor and Description |
|---|
DefaultPluginManager(WikiEngine engine,
Properties props)
Create a new PluginManager.
|
| Modifier and Type | Method and Description |
|---|---|
void |
enablePlugins(boolean enabled)
Enables or disables plugin execution.
|
String |
execute(WikiContext context,
String commandline)
Parses a plugin.
|
String |
execute(WikiContext context,
String classname,
Map<String,String> params)
Executes a plugin class in the given context.
|
DefaultPluginManager.WikiPluginInfo |
getModuleInfo(String moduleName)
Returns the
WikiModuleInfo information about the provided moduleName. |
org.apache.oro.text.regex.Pattern |
getPluginPattern()
Returns plugin insert pattern.
|
String |
getPluginSearchPath()
Returns plugins' search path.
|
Collection<WikiModuleInfo> |
modules()
Returns a collection of modules currently managed by this ModuleManager.
|
WikiPlugin |
newWikiPlugin(String pluginName,
ResourceBundle rb)
Creates a
WikiPlugin. |
Map<String,String> |
parseArgs(String argstring)
Parses plugin arguments.
|
boolean |
pluginsEnabled()
Returns plugin execution status.
|
checkCompatibility, modulespublic DefaultPluginManager(WikiEngine engine, Properties props)
engine - WikiEngine which owns this manager.props - Contents of a "jspwiki.properties" file.public void enablePlugins(boolean enabled)
enablePlugins in interface PluginManagerenabled - True, if plugins should be globally enabled; false, if disabled.public boolean pluginsEnabled()
pluginsEnabled in interface PluginManagerpublic org.apache.oro.text.regex.Pattern getPluginPattern()
getPluginPattern in interface PluginManagerpublic String getPluginSearchPath()
getPluginSearchPath in interface PluginManagerpublic String execute(WikiContext context, String classname, Map<String,String> params) throws PluginException
Used to be private, but is public since 1.9.21.
execute in interface PluginManagercontext - 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.PluginException - If the plugin execution failed for
some reason.public Map<String,String> parseArgs(String argstring) throws IOException
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].parseArgs in interface PluginManagerargstring - 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. In case the parameter is null, will return an
empty parameter list.IOException - If the parsing fails.public String execute(WikiContext context, String commandline) throws PluginException
This is the main entry point that is used.
execute in interface PluginManagercontext - The current WikiContext.commandline - The full command line, including plugin name, parameters and body.PluginException - From the plugin itself, it propagates, waah!public Collection<WikiModuleInfo> modules()
modules in interface PluginManagermodules in class ModuleManagerpublic DefaultPluginManager.WikiPluginInfo getModuleInfo(String moduleName)
WikiModuleInfo information about the provided moduleName.getModuleInfo in interface PluginManagergetModuleInfo in class ModuleManagerpublic WikiPlugin newWikiPlugin(String pluginName, ResourceBundle rb) throws PluginException
WikiPlugin.newWikiPlugin in interface PluginManagerpluginName - plugin's classnamerb - ResourceBundle with i18ned text for exceptions.WikiPlugin.PluginException - if there is a problem building the WikiPlugin.Copyright © 2001-2019 The Apache Software Foundation. All rights reserved.