public class IfPlugin extends Object implements WikiPlugin
If any of them match, the body of the plugin is executed. You can negate the content by prefixing it with a "!". For example, to greet all admins, put the following in your LeftMenu:
[{If group='Admin' Hello, Admin, and your mighty powers!}]
In order to send a message to everybody except Jack use
[{If user='!Jack' %%warning Jack's surprise birthday party at eleven! %%}]
Note that you can't use "!Jack|!Jill", because for Jack, !Jill matches; and for Jill, !Jack matches. These are not regular expressions (though they might become so in the future).
To check for page content, use
[{If page='TestPage' contains='xyzzy' Page contains the text "xyzzy"}]
The difference between "contains" and "is" is that "is" is always an exact match, whereas "contains" just checks if a pattern is available.
To check for page existence, use
[{If page='TestPage' exists='true' Page "TestPage" exists.}]
With the same mechanism, it's also possible to test for the existence of a variable - just use "var" instead of "page".
Another caveat is that the plugin body content is not counted towards ReferenceManager links. So any links do not appear on any reference lists. Depending on your position, this may be a good or a bad thing.
The functional, decision-making part of this plugin may be called from
other code (e.g., other plugins) since it is available as a static method
ifInclude(WikiContext,Map)
. Note that the plugin body may contain
references to other plugins.
Modifier and Type | Field and Description |
---|---|
static String |
PARAM_CONTAINS
The parameter name for setting the contents of the page to check.
|
static String |
PARAM_EXISTS
The parameter name for checking whether a page/var exists.
|
static String |
PARAM_GROUP
The parameter name for setting the group to check.
|
static String |
PARAM_IP
The parameter name for setting the ip address to check.
|
static String |
PARAM_IS
The parameter name for setting the exact content to check.
|
static String |
PARAM_PAGE
The parameter name for setting the page name to check.
|
static String |
PARAM_USER
The parameter name for setting the user id to check.
|
static String |
PARAM_VAR
The parameter name for setting the variable name to check.
|
CORE_PLUGINS_RESOURCEBUNDLE
Constructor and Description |
---|
IfPlugin() |
Modifier and Type | Method and Description |
---|---|
String |
execute(WikiContext context,
Map<String,String> params)
This is the main entry point for any plugin.
|
static boolean |
ifInclude(WikiContext context,
Map<String,String> params)
Returns a boolean result based on processing the WikiContext and
parameter Map as according to the rules stated in the IfPlugin
documentation.
|
public static final String PARAM_GROUP
public static final String PARAM_USER
public static final String PARAM_IP
public static final String PARAM_PAGE
public static final String PARAM_CONTAINS
public static final String PARAM_VAR
public static final String PARAM_IS
public static final String PARAM_EXISTS
public IfPlugin()
public String execute(WikiContext context, Map<String,String> params) throws PluginException
Note that it is preferred that the plugin returns XHTML-compliant HTML (i.e. close all tags, use <br /> instead of <br>, etc.
execute
in interface WikiPlugin
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.PluginException
- In case anything goes wrong.public static boolean ifInclude(WikiContext context, Map<String,String> params) throws PluginException
context
- The current WikiContext.params
- The parameter Map which contains key-value pairs.PluginException
- If something goes wrongCopyright © 2001-2019 The Apache Software Foundation. All rights reserved.