com.ecyrd.jspwiki
Class WikiContext

java.lang.Object
  |
  +--com.ecyrd.jspwiki.WikiContext

public class WikiContext
extends java.lang.Object

Provides state information throughout the processing of a page. A WikiContext is born when the JSP pages that are the main entry points, are invoked. The JSPWiki engine creates the new WikiContext, which basically holds information about the page, the handling engine, and in which context (view, edit, etc) the call was done.

A WikiContext also provides request-specific variables, which can be used to communicate between plugins on the same page, or between different instances of the same plugin. A WikiContext variable is valid until the processing of the page has ended. For an example, please see the Counter plugin.

Author:
Janne Jalkanen
See Also:
Counter

Field Summary
static java.lang.String COMMENT
           
static java.lang.String CONFLICT
          User has an internal conflict, and does quite not know what to do.
static java.lang.String DIFF
          User is viewing a DIFF between the two versions of the page.
static java.lang.String EDIT
          The EDIT context - the user is editing the page.
static java.lang.String ERROR
          An error has been encountered and the user needs to be informed.
static java.lang.String INFO
          User is viewing page history.
static java.lang.String LOGIN
          User is preparing for a login/authentication.
static java.lang.String PREVIEW
          User is previewing the changes he just made.
static java.lang.String UPLOAD
           
static java.lang.String VIEW
          The VIEW context - the user just wants to view the page contents.
 
Constructor Summary
WikiContext(WikiEngine engine, java.lang.String pagename)
          Create a new WikiContext.
WikiContext(WikiEngine engine, WikiPage page)
          Create a new WikiContext for the given WikiPage.
 
Method Summary
 WikiEngine getEngine()
          Returns the handling engine.
 java.lang.String getHttpParameter(java.lang.String paramName)
          This method will safely return any HTTP parameters that might have been defined.
 javax.servlet.http.HttpServletRequest getHttpRequest()
          If the request did originate from a HTTP request, then the HTTP request can be fetched here.
 WikiPage getPage()
          Returns the page that is being handled.
 java.lang.String getRequestContext()
          Returns the request context.
 java.lang.Object getVariable(java.lang.String key)
          Gets a previously set variable.
 void setHttpRequest(javax.servlet.http.HttpServletRequest req)
          If the request originated from a HTTP server, the HTTP request is stored here.
 void setRequestContext(java.lang.String arg)
          Sets the request context.
 void setVariable(java.lang.String key, java.lang.Object data)
          Sets a variable.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

VIEW

public static final java.lang.String VIEW
The VIEW context - the user just wants to view the page contents.

See Also:
Constant Field Values

EDIT

public static final java.lang.String EDIT
The EDIT context - the user is editing the page.

See Also:
Constant Field Values

LOGIN

public static final java.lang.String LOGIN
User is preparing for a login/authentication.

See Also:
Constant Field Values

DIFF

public static final java.lang.String DIFF
User is viewing a DIFF between the two versions of the page.

See Also:
Constant Field Values

INFO

public static final java.lang.String INFO
User is viewing page history.

See Also:
Constant Field Values

PREVIEW

public static final java.lang.String PREVIEW
User is previewing the changes he just made.

See Also:
Constant Field Values

CONFLICT

public static final java.lang.String CONFLICT
User has an internal conflict, and does quite not know what to do. Please provide some counseling.

See Also:
Constant Field Values

ERROR

public static final java.lang.String ERROR
An error has been encountered and the user needs to be informed.

See Also:
Constant Field Values

UPLOAD

public static final java.lang.String UPLOAD
See Also:
Constant Field Values

COMMENT

public static final java.lang.String COMMENT
See Also:
Constant Field Values
Constructor Detail

WikiContext

public WikiContext(WikiEngine engine,
                   java.lang.String pagename)
Create a new WikiContext.

Parameters:
engine - The WikiEngine that is handling the request.
pagename - The name of the page. A new WikiPage is created.

WikiContext

public WikiContext(WikiEngine engine,
                   WikiPage page)
Create a new WikiContext for the given WikiPage.

Parameters:
engine - The WikiEngine that is handling the request.
page - The WikiPage. If you want to create a WikiContext for an older version of a page, you must use this constructor.
Method Detail

getEngine

public WikiEngine getEngine()
Returns the handling engine.


getPage

public WikiPage getPage()
Returns the page that is being handled.


getRequestContext

public java.lang.String getRequestContext()
Returns the request context.


setRequestContext

public void setRequestContext(java.lang.String arg)
Sets the request context. See above for the different request contexts (VIEW, EDIT, etc.)

Parameters:
arg - The request context (one of the predefined contexts.)

getVariable

public java.lang.Object getVariable(java.lang.String key)
Gets a previously set variable.

Parameters:
key - The variable name.
Returns:
The variable contents.

setVariable

public void setVariable(java.lang.String key,
                        java.lang.Object data)
Sets a variable. The variable is valid while the WikiContext is valid, i.e. while page processing continues. The variable data is discarded once the page processing is finished.

Parameters:
key - The variable name.
data - The variable value.

getHttpParameter

public java.lang.String getHttpParameter(java.lang.String paramName)
This method will safely return any HTTP parameters that might have been defined. You should use this method instead of peeking directly into the result of getHttpRequest(), since this method is smart enough to do all of the right things, figure out UTF-8 encoded parameters, etc.

Parameters:
paramName - Parameter name to look for.
Returns:
HTTP parameter, or null, if no such parameter existed.
Since:
2.0.13.

setHttpRequest

public void setHttpRequest(javax.servlet.http.HttpServletRequest req)
If the request originated from a HTTP server, the HTTP request is stored here.

Parameters:
req - The HTTP servlet request.
Since:
2.0.13.

getHttpRequest

public javax.servlet.http.HttpServletRequest getHttpRequest()
If the request did originate from a HTTP request, then the HTTP request can be fetched here. However, it the request did NOT originate from a HTTP request, then this method will return null, and YOU SHOULD CHECK FOR IT!

Returns:
Null, if no HTTP request was done.
Since:
2.0.13.