public class WikiContext extends Object implements Context, Command
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.
When a WikiContext is created, it automatically associates a WikiSession object with the user's HttpSession. The
WikiSession contains information about the user's authentication status, and is consulted by getCurrentUser() object.
Do not cache the page object that you get from the WikiContext; always use getPage()!
Counter| Modifier and Type | Field and Description |
|---|---|
static String |
ADMIN
User is doing administrative things.
|
static String |
ATTACH
User is downloading an attachment.
|
static String |
COMMENT
User is commenting something.
|
static String |
CONFLICT
User has an internal conflict, and does quite not know what to do.
|
static String |
CREATE_GROUP
User wishes to create a new group
|
static String |
DELETE
User is deleting a page or an attachment.
|
static String |
DELETE_GROUP
User is deleting an existing group.
|
static String |
DIFF
User is viewing a DIFF between the two versions of the page.
|
static String |
EDIT
The EDIT context - the user is editing the page.
|
static String |
EDIT_GROUP
User is editing an existing group.
|
static String |
ERROR
An error has been encountered and the user needs to be informed.
|
static String |
FIND
User is searching for content.
|
static String |
INFO
User is viewing page history.
|
static String |
INSTALL
User is administering JSPWiki (Install, SecurityConfig).
|
static String |
LOGIN
User is preparing for a login/authentication.
|
static String |
LOGOUT
User is preparing to log out.
|
protected javax.servlet.http.HttpServletRequest |
m_request
Stores the HttpServletRequest.
|
static String |
MESSAGE
JSPWiki wants to display a message.
|
static String |
NONE
This is not a JSPWiki context, use it to access static files.
|
static String |
OTHER
Same as NONE; this is just a clarification.
|
static String |
PREFS
User is editing preferences
|
static String |
PREVIEW
User is previewing the changes he just made.
|
static String |
RENAME
User is renaming a page.
|
static String |
RSS
RSS feed is being generated.
|
static String |
UPLOAD
User is uploading something.
|
static String |
VIEW
The VIEW context - the user just wants to view the page contents.
|
static String |
VIEW_GROUP
User is viewing an existing group
|
static String |
WORKFLOW
User wants to view or administer workflows.
|
ATTR_CONTEXT, VAR_EXECUTE_PLUGINS, VAR_WYSIWYG_EDITOR_MODE| Constructor and Description |
|---|
WikiContext(Engine engine,
javax.servlet.http.HttpServletRequest request,
Command command)
Creates a new WikiContext for the given Engine, Command and HttpServletRequest.
|
WikiContext(Engine engine,
javax.servlet.http.HttpServletRequest request,
Page page)
Creates a new WikiContext for the given Engine, WikiPage and HttpServletRequest.
|
WikiContext(Engine engine,
javax.servlet.http.HttpServletRequest request,
String requestContext)
Creates a new WikiContext from a supplied HTTP request, using a default wiki context.
|
WikiContext(Engine engine,
Page page)
Create a new WikiContext for the given WikiPage.
|
| Modifier and Type | Method and Description |
|---|---|
WikiContext |
clone()
Returns a shallow clone of the WikiContext.
|
WikiContext |
deepClone()
Creates a deep clone of the WikiContext.
|
protected static Command |
findCommand(Engine engine,
javax.servlet.http.HttpServletRequest request,
Page page)
Looks up and returns a PageCommand based on a supplied WikiPage and HTTP request.
|
static WikiContext |
findContext(javax.servlet.jsp.PageContext pageContext)
Deprecated.
use
Context.findContext( PageContext ) instead. |
boolean |
getBooleanWikiProperty(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 WikiContext.
|
String |
getContentTemplate() |
Principal |
getCurrentUser()
Convenience method that gets the current user.
|
WikiEngine |
getEngine()
Returns the handling engine.
|
String |
getHttpParameter(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.
|
String |
getJSP() |
String |
getName()
Returns the target of this wiki context: a page, group name or JSP.
|
WikiPage |
getPage()
Returns the page that is being handled.
|
WikiPage |
getRealPage()
Gets a reference to the real page whose content is currently being rendered.
|
String |
getRedirectURL()
Figure out to which page we are really going to.
|
String |
getRequestContext()
Returns the request context.
|
Object |
getTarget() |
String |
getTemplate()
Gets the template that is to be used throughout this request.
|
String |
getURL(String context,
String page)
Creates an URL for the given request context.
|
String |
getURL(String context,
String page,
String params)
Returns an URL from a page.
|
String |
getURLPattern() |
<T> T |
getVariable(String key)
Gets a previously set variable.
|
String |
getViewURL(String page)
A shortcut to generate a VIEW url.
|
WikiSession |
getWikiSession()
Returns the Session associated with the context.
|
boolean |
hasAdminPermissions()
Returns true, if the current user has administrative permissions (i.e. the omnipotent AllPermission).
|
Permission |
requiredPermission()
Returns the permission required to successfully execute this context.
|
protected void |
setDefaultTemplate(javax.servlet.http.HttpServletRequest request)
Figures out which template a new WikiContext should be using.
|
void |
setPage(Page page)
Sets the page that is being handled.
|
WikiPage |
setRealPage(Page page)
Sets a reference to the real page whose content is currently being rendered.
|
void |
setRequestContext(String arg)
Sets the request context.
|
void |
setTemplate(String dir)
Sets the template to be used for this request.
|
void |
setVariable(String key,
Object data)
Sets a variable.
|
Command |
targetedCommand(Object target)
Associates a target with the current Command and returns the new targeted Command.
|
protected void |
updateCommand(String requestContext)
Protected method that updates the internally cached Command.
|
protected javax.servlet.http.HttpServletRequest m_request
public static final String CONFLICT
public static final String CREATE_GROUP
public static final String DELETE_GROUP
public static final String EDIT_GROUP
public static final String ERROR
public static final String VIEW
public static final String VIEW_GROUP
public WikiContext(Engine engine, Page page)
WikiContext(Engine, HttpServletRequest, Page).engine - The Engine 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.public WikiContext(Engine engine, javax.servlet.http.HttpServletRequest request, Command command) throws IllegalArgumentException
Creates a new WikiContext for the given Engine, Command and HttpServletRequest.
This constructor will also look up the HttpSession associated with the request, and determine if a Session object is present. If not, a new one is created.
engine - The Engine that is handling the requestrequest - The HttpServletRequest that should be associated with this context. This parameter may be null.command - the commandIllegalArgumentException - if engine or command are nullpublic WikiContext(Engine engine, javax.servlet.http.HttpServletRequest request, Page page)
findCommand(Engine, HttpServletRequest, Page) and delegates to
WikiContext(Engine, HttpServletRequest, Command).engine - The Engine that is handling the requestrequest - The HttpServletRequest that should be associated with this context. This parameter may be null.page - The WikiPage. If you want to create a WikiContext for an older version of a page, you must supply this parameterpublic WikiContext(Engine engine, javax.servlet.http.HttpServletRequest request, String requestContext)
engine - The Engine that is handling the requestrequest - the HTTP requestrequestContext - the default context to useCommandResolver,
Commandpublic String getContentTemplate()
getContentTemplate in interface CommandCommand.getContentTemplate()public String getJSP()
getJSP in interface CommandCommand.getJSP()public WikiPage setRealPage(Page page)
Sometimes you may want to render the page using some other page's context. In those cases, it is highly recommended that you set the setRealPage() to point at the real page 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 page added with InsertPageTag, you should consider what you want to do - do you wish to really reference the "master" page or the included page.
setRealPage in interface Contextpage - The real page which is being rendered.InsertPageTagpublic WikiPage getRealPage()
For example, in the default template, there is a page called "LeftMenu". Whenever you access a page, e.g. "Main", the master page 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".
getRealPage in interface ContextInsertPageTag,
JSPWikiMarkupParserpublic String getRedirectURL()
CommandResolver.getSpecialPageReference(String).getRedirectURL in interface Contextpublic WikiEngine getEngine()
public String getRequestContext()
getRequestContext in interface Commandpublic void setRequestContext(String arg)
setRequestContext in interface Contextarg - The request context (one of the predefined contexts.)public Object getTarget()
getTarget in interface CommandCommand.getTarget()public String getURLPattern()
getURLPattern in interface CommandCommand.getURLPattern()public <T> T getVariable(String key)
getVariable in interface Contextkey - The variable name.public void setVariable(String key, Object data)
setVariable in interface Contextkey - The variable name.data - The variable value.public boolean getBooleanWikiProperty(String key, boolean defValue)
getBooleanWikiProperty in interface Contextkey - What key are we searching for?defValue - Default value for the booleantrue or false.public String getHttpParameter(String paramName)
getHttpParameter in interface ContextparamName - Parameter name to look for.public javax.servlet.http.HttpServletRequest getHttpRequest()
getHttpRequest in interface Contextpublic void setTemplate(String dir)
setTemplate in interface Contextdir - The template namepublic String getName()
Command.getName()
method. Calling classes can rely on the results of this method for looking up canonically-correct page or group names. Because it
does not automatically assume that the wiki context is a PageCommand, calling this method is inherently safer than calling
getPage().getName().getName in interface CommandPageCommand.getName(),
GroupCommand.getName()public String getTemplate()
getTemplate in interface Contextpublic Principal getCurrentUser()
getCurrentUser in interface Contextpublic String getViewURL(String page)
getViewURL in interface Contextpage - The page to which to link.public String getURL(String context, String page)
public String getURL(String context, String page, String params)
public Command getCommand()
getCommand in interface Contextpublic WikiContext clone()
public WikiContext deepClone()
public WikiSession getWikiSession()
WikiSession.guestSession(Engine).getWikiSession in interface Context@Deprecated public static WikiContext findContext(javax.servlet.jsp.PageContext pageContext)
Context.findContext( PageContext ) instead.Context.ATTR_CONTEXT.findContext in interface ContextpageContext - the JSP page contextContext.findContext( PageContext )public Permission requiredPermission()
PropertyPermission "os.name", "read"). This method is guaranteed
to always return a valid, non-null permission.requiredPermission in interface Commandpublic Command targetedCommand(Object target)
targetedCommand in interface Command{@inheritDoc}public boolean hasAdminPermissions()
hasAdminPermissions in interface Contextprotected void setDefaultTemplate(javax.servlet.http.HttpServletRequest request)
request - the HTTP requestprotected static Command findCommand(Engine engine, javax.servlet.http.HttpServletRequest request, Page page)
ContextEnum.PAGE_VIEW. If the Command is a PageCommand (and it should be, in most
cases), a targeted Command is created using the (non-null) WikiPage as target.engine - the wiki enginerequest - the HTTP requestpage - the wiki pageprotected void updateCommand(String requestContext)
requestContext - the desired request contextCopyright © 2001-2020 The Apache Software Foundation. All rights reserved.