For indentation and formating purposes, the author often uses "non-breakable spaces" ( ).

As JSPWiki markup does not permit the explicit insertion of   HTML entities, the nbsp plugin has been written for that purpose.

Compilation#

Save the source code shown at the bottom of this page into a file called nbsp.java. Then invoke the Java compiler as follows

  javac nbsp.java
(or similar - depending on the development environment you are using)

Installation#

Create a JAR archive containing the Java class file for the plugin. You may use the command

  jar cvf nbsp.jar nbsp.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

  [{nbsp count=1}]
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.

The optional "count" parameter takes a positive ordinal number as its value and specifies how many "non-breakable spaces" will be inserted at the place of the plugin invocation - without any parameter given, the plugin will insert a single character only.

Source Code#

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

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

public class nbsp implements WikiPlugin {
  public String execute (WikiContext Context, Map ParameterMap) throws PluginException {
    int Count = 1;                                              // default value

  /**** retrieve any given parameter ****/

    String Literal = (String) ParameterMap.get("count");
    if (Literal != null) try {
      Count = Integer.parseInt(Literal);
    } catch (Exception Signal) {
      throw new PluginException(
        "nbsp-PlugIn: invalid value for \"count\" given: \"" + Literal + "\""
      );
    };

  /**** check "Count" for validity ****/

    if (Count <= 0) throw new PluginException(
      "nbsp-PlugIn: invalid value for \"count\" given: " + Count
    );

  /**** now deliver the requested number of "non-breaking spaces" ****/

    StringBuffer Result = new StringBuffer(6*Count);
      for (int i = 0; i < Count; i++) {
        Result.append("&nbsp;");
      };
    return Result.toString();
  };
};
Andreas Rozek (EMail: Andreas.Rozek@GMX.De)

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-7) was last changed on 03-Mar-2011 11:00 by Janne Jalkanen