When invoked, a JSPWiki plugin may be given an arbitrary number of "parameters" in the form of key-value pairs.



The showParameters plugin examines its parameter table and lists all parameters that were given in the plugin invocation.

!!Compilation

Save the source code shown at the bottom of this page into a file called {{showParameters.java}}. Then invoke the Java compiler as follows
{{{
  javac showParameters.java
}}}
(or similar - depending on the development environment you are using)
\\You may need to include JSPWiki.jar in your classpath, example:
{{{javac -classpath JSPWiki.jar showParameters.java}}}

!!Installation

Create a JAR archive containing the Java class file for the plugin. You may use the command
{{{
  jar cvf showParameters.jar showParameters.class
}}}
for that purpose.

Then move that file into any directory within your wiki's class path - preferrably into the {{WEB-INF/lib/}} folder within your web server's ''web application directory'' for the JSPWiki.

Finally restart the Wiki for the plugin to be recognized.

!!Usage

Within wiki markup, invoke the plugin as follows
{{{
  [{showParameters literal=singleWord, anotherLiteral='multiple words', number=1234, boolean=true}]
}}}
As the class resides in the default directory, there is no need neither to prefix the plugin name with a package path nor to modify the plugin search path within the JSPWiki configuration file. 

You may also add any other parameters you like - the only restriction is given by the syntactic constraints imposed by JSPWiki.

The final wiki output should then contain a section like

!showParameters - lists the given plugin parameters

;literal (java.lang.String):"singleWord"
;anotherLiteral (java.lang.String):"multiple words"
;number (java.lang.String):"1234 "
;boolean (java.lang.String):"true"

__Nota bene:__ while you may omit the commas (used to separate individual name-value pairs) you should __never use double quotes (") instead of single ones (')!__ Otherwise, JSPWiki may omit some parameters or mix names and values.

!!Source Code

{{{
import java.util.*;                  // Java utility classes and data structures

import com.ecyrd.jspwiki.*;
import com.ecyrd.jspwiki.plugin.*;

public class showParameters implements WikiPlugin {
  public String execute (WikiContext Context, Map ParameterMap) throws PluginException {
    String Result = "<h4>showParameters - lists the given plugin parameters</h4>\n";

  /**** take care of a missing ParameterMap (may that ever happen?) ****/

    if (ParameterMap == null || ParameterMap.isEmpty()) {
      return Result + "(no parameters given)";
    }

  /**** otherwise retrieve (and show) any given parameters ****/

    Result += "<dl>";
      for (Iterator ParameterInterator = ParameterMap.entrySet().iterator(); ParameterInterator.hasNext(); ) {
        Map.Entry Entry = (Map.Entry)ParameterInterator.next();
        Object Key = Entry.getKey();
        Result += "<dt>" + Key + (Key != null ? " (" + Key.getClass().getName() + ")" : "") + "\n";

        Object Value = Entry.getValue();
        if (Value == null) {
          Result += "<dd>(null)";
        } else {
          if (Value instanceof String) {
            Result += "<dd>\"" + Value + "\"";
          } else {
            Result += "<dd>(" + Value.getClass().getName() + ") " + Value + "\n";
          };
        };
      };
    return Result + "</dl>";
  };
};
}}}

[Andreas Rozek|http://www.Andreas-Rozek.de] (EMail: [Andreas.Rozek@GMX.De|mailto:Andreas.Rozek@GMX.De])