When invoked, every plugin also gets a reference to the actual "WikiContext" with additional information about the actual environment.

The "showWikiContext" plugin examines this context and displays some of its contents.

Compilation#

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

  javac showWikiContext.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 showWikiContext.jar showWikiContext.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

  [{showWikiContext}]
without any parameters (they would be ignored anyway). 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.

A possible output of the plugin could look as follows:

showWikiContext - examines the actual "WikiContext"#

Wiki Engine: RozekWiki (75 pages, up since Wed Apr 08 21:12:53 CEST 2003)
Wiki Page: SandBox (version -1, modified on Wed Apr 08 21:15:27 CEST 2003)
Request Context: view

Source Code#

import java.util.*;                  // Java utility classes and data structures
//import javax.servlet.http.*;                             // servlet HTTP support

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

public class showWikiContext implements WikiPlugin {
  public String execute (WikiContext Context, Map ParameterMap) throws PluginException {
    String Result = "<h4>showWikiContext - examines the actual \"WikiContext\"</h4>\n\n";
      Result += "<table width=100%>";

    /**** examine the actual wiki engine ****/

      WikiEngine Engine = Context.getEngine();

      Result += "  <tr valign=top>\n";
        Result += "    <td><b>Wiki Engine:</b></td>\n";
        Result += "    <td>" + Engine.getApplicationName() + " (" +
          Engine.getPageCount() + " pages, up since " + Engine.getStartTime() + ")</td>\n";
      Result += "  </tr>\n";

    /**** examine the actual wiki page ****/

      WikiPage Page   = Context.getPage();
        String Author = Page.getAuthor();

      Result += "  <tr valign=top>\n";
        Result += "    <td><b>Wiki Page:</b></td>\n";
        Result += "    <td>" + Page.getName() + " (version " + Page.getVersion() +
          ", modified on " + Page.getLastModified() +
          (Author == null ? "" : " by " + Author) + ")</td>\n";
      Result += "  </tr>\n";

    /**** examine the underlying HTTP request ****/
/*
      HttpServletRequest Request = Context.getHttpRequest();

      Result += "  <tr valign=top>\n";
        Result += "    <td><b>HTTP Request:</b></td>\n";
        Result += "    <td>" + Request + "</td>\n";
      Result += "  </tr>\n";
*/
    /**** finally show the request context ****/

      Result += "  <tr valign=top>\n";
        Result += "    <td><b>Request Context:</b></td>\n";
        Result += "    <td>" + Context.getRequestContext() + "</td>\n";
      Result += "  </tr>\n";
    return Result + "</table>";
  };
};

Andreas Rozek (EMail: Andreas.Rozek@GMX.De)

Add new attachment

Only authorized users are allowed to upload new attachments.
« This page (revision-4) was last changed on 09-Apr-2003 17:19 by 129.69.13.219