Class designation: Interface org.apache.wiki.api.plugin.WikiPlugin
WikiPlugin is the Java interface for a JSPWiki plugin. As noted in the Javadocs:
The plugin should return XHTML-compliant
HTML markup (i.e. close all tags, quote attributes values, use <br /> instead of <br>, etc.
HTML markup (i.e. close all tags, quote attributes values, use <br /> instead of <br>, etc.
API#
The WikiPlugin interface contains a single method:
- public String execute( WikiContext context, Map<String,String> params ) throws PluginException
- This is the main entry point for any plugin. The parameters are parsed, and a special parameter called "_body" signifies the name of the plugin body, i.e. the part of the plugin that is not a parameter of the form "key=value". This is separated using an empty line. Note that it is preferred that the plugin returns XHTML-compliant HTML (i.e. close all tags, use <br /> instead of <br>, etc.
Parameters#
- context - The current WikiContext.
- params - A Map which contains key-value pairs. Any parameter that the user has specified on the wiki page will contain String-String parameters, but it is possible that at some future date, JSPWiki will give you other things that are not Strings.
Returns #
HTML, ready to be included into the rendered page.
Throws#
PluginException - In case anything goes wrong.
Example#
Following is an example of a simple "Hello World" plugin. This returns an HTML <div> element containing the content of the text parameter, or "Hello World!" if it is absent.
public class HelloWorld implements WikiPlugin
{
public String execute( WikiContext context, Map<String,String> params )
throws PluginException
{
StringBuilder out = new StringBuilder();
try {
out.append( "<div class=\"helloworld\">\n" );
String text = (String)params.get("text");
if ( text == null ) {
out.append("Hello, World!");
} else {
out.append( text );
}
out.append( "</div>" );
} catch ( Exception e ) {
out.append( "<div class=\"error\">\n" );
out.append( e.getClass().getName()
+ " thrown by HelloWorld plugin: " + e.getMessage() );
out.append( "</div>\n" );
}
return out.toString();
}
}
Once installed, this plugin would be invoked via the following WikiMarkup:
[{HelloWorld text='Good morning.'}]

);
background-repeat:no-repeat;
background-position:top;
background-size:48px;
text-align:center;
}