public interface Context extends java.lang.Cloneable, Command
Provides state information throughout the processing of a page. A Context is born when the JSP pages that are the main entry points, are invoked. The JSPWiki engine creates the new Context, which basically holds information about the page, the handling engine, and in which context (view, edit, etc) the call was done.
A Context 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 Context variable is valid until the processing of the WikiPage has ended. For an example, please see the Counter plugin.
When a Context is created, it automatically associates a Session object with the user's
HttpSession. The Session contains information about the user's authentication status, and is consulted by getCurrentUser()
object.
Do not cache the WikiPage object that you get from the WikiContext; always use getPage()!
org.apache.wiki.plugin.Counter}| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
ATTR_CONTEXT |
static java.lang.String |
VAR_EXECUTE_PLUGINS
Variable name which tells whether plugins should be executed or not.
|
static java.lang.String |
VAR_WYSIWYG_EDITOR_MODE
Name of the variable which is set to Boolean.TRUE or Boolean.FALSE depending on whether WYSIWYG is currently in effect.
|
| Modifier and Type | Method and Description |
|---|---|
Context |
clone() |
Context |
deepClone()
Creates a deep clone of the Context.
|
static Context |
findContext(javax.servlet.jsp.PageContext pageContext)
This method can be used to find the WikiContext programmatically from a JSP PageContext.
|
boolean |
getBooleanWikiProperty(java.lang.String key,
boolean defValue)
This is just a simple helper method which will first check the context if there is already an override in place, and if there is not,
it will then check the given properties.
|
Command |
getCommand()
Returns the Command associated with this Context.
|
java.security.Principal |
getCurrentUser()
Convenience method that gets the current user.
|
Engine |
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 an HTTP request, then the HTTP request can be fetched here.
|
Page |
getPage()
Returns the WikiPage that is being handled.
|
Page |
getRealPage()
Gets a reference to the real WikiPage whose content is currently being rendered.
|
java.lang.String |
getRedirectURL()
Figure out to which WikiPage we are really going to.
|
java.lang.String |
getTemplate()
Gets the template that is to be used throughout this request.
|
default java.lang.String |
getURL(java.lang.String context,
java.lang.String page)
Creates a URL for the given request context.
|
default java.lang.String |
getURL(java.lang.String context,
java.lang.String page,
java.lang.String params)
Returns a URL from a page.
|
<T> T |
getVariable(java.lang.String key)
Gets a previously set variable.
|
java.lang.String |
getViewURL(java.lang.String WikiPage)
A shortcut to generate a VIEW url.
|
Session |
getWikiSession()
Returns the Session associated with the context.
|
boolean |
hasAdminPermissions()
Returns true, if the current user has administrative permissions (i.e. the omnipotent AllPermission).
|
void |
setPage(Page wikiPage)
Sets the WikiPage that is being handled.
|
Page |
setRealPage(Page wikiPage)
Sets a reference to the real WikiPage whose content is currently being rendered.
|
void |
setRequestContext(java.lang.String context)
Sets the request context.
|
void |
setTemplate(java.lang.String dir)
Sets the template to be used for this request.
|
void |
setVariable(java.lang.String key,
java.lang.Object data)
Sets a variable.
|
getContentTemplate, getJSP, getName, getRequestContext, getTarget, getURLPattern, requiredPermission, targetedCommandstatic final java.lang.String ATTR_CONTEXT
static final java.lang.String VAR_EXECUTE_PLUGINS
Boolean.TRUE or
Boolean.FALSE. While not set its value is null.static final java.lang.String VAR_WYSIWYG_EDITOR_MODE
Page getPage()
void setPage(Page wikiPage)
wikiPage - The wikipagePage getRealPage()
For example, in the default template, there is a WikiPage called "LeftMenu". Whenever you access a page, e.g. "Main", the master WikiPage will be Main, and that's what the getPage() will return - regardless of whether your plugin resides on the LeftMenu or on the Main page. However, getRealPage() will return "LeftMenu".
org.apache.wiki.tags.InsertPageTag},
org.apache.wiki.parser.JSPWikiMarkupParser}Page setRealPage(Page wikiPage)
Sometimes you may want to render the WikiPage using some other page's context. In those cases, it is highly recommended that you set the setRealPage() to point at the real WikiPage you are rendering. Please see InsertPageTag for an example.
Also, if your plugin e.g. does some variable setting, be aware that if it is embedded in the LeftMenu or some other WikiPage added with InsertPageTag, you should consider what you want to do - do you wish to really reference the "master" WikiPage or the included page.
wikiPage - The real WikiPage which is being rendered.org.apache.wiki.tags.InsertPageTag}Engine getEngine()
void setRequestContext(java.lang.String context)
context - The request context (one of the predefined contexts.)<T> T getVariable(java.lang.String key)
key - The variable name.void setVariable(java.lang.String key, java.lang.Object data)
key - The variable name.data - The variable value.boolean getBooleanWikiProperty(java.lang.String key, boolean defValue)
key - What key are we searching for?defValue - Default value for the booleantrue or false.java.lang.String getHttpParameter(java.lang.String paramName)
paramName - Parameter name to look for.javax.servlet.http.HttpServletRequest getHttpRequest()
void setTemplate(java.lang.String dir)
dir - The template namejava.lang.String getTemplate()
Session getWikiSession()
java.security.Principal getCurrentUser()
boolean hasAdminPermissions()
java.lang.String getViewURL(java.lang.String WikiPage)
WikiPage - The WikiPage to which to link.java.lang.String getRedirectURL()
Command getCommand()
default java.lang.String getURL(java.lang.String context, java.lang.String page)
context - e.g. WikiContext.EDITpage - The WikiPage to which to linkdefault java.lang.String getURL(java.lang.String context, java.lang.String page, java.lang.String params)
context - The request context (e.g. WikiContext.UPLOAD)page - The WikiPage to which to linkparams - A list of parameters, separated with "&"Context deepClone()
static Context findContext(javax.servlet.jsp.PageContext pageContext)
ATTR_CONTEXT.pageContext - the JSP page contextCopyright (c) 2001-2022 The Apache Software Foundation. All rights reserved.