public class WikiContext extends java.lang.Object implements java.lang.Cloneable, 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 java.lang.String |
ADMIN
User is doing administrative things.
|
static java.lang.String |
ATTACH
User is downloading an attachment.
|
static java.lang.String |
COMMENT
User is commenting something.
|
static java.lang.String |
CONFLICT
User has an internal conflict, and does quite not know what to
do.
|
static java.lang.String |
CREATE_GROUP
User wishes to create a new group
|
static java.lang.String |
DELETE
User is deleting a page or an attachment.
|
static java.lang.String |
DELETE_GROUP
User is deleting an existing group.
|
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 |
EDIT_GROUP
User is editing an existing group.
|
static java.lang.String |
ERROR
An error has been encountered and the user needs to be informed.
|
static java.lang.String |
FIND
User is searching for content.
|
static java.lang.String |
INFO
User is viewing page history.
|
static java.lang.String |
INSTALL
User is administering JSPWiki (Install, SecurityConfig).
|
static java.lang.String |
LOGIN
User is preparing for a login/authentication.
|
static java.lang.String |
LOGOUT
User is preparing to log out.
|
protected HttpServletRequest |
m_request
Stores the HttpServletRequest.
|
static java.lang.String |
MESSAGE
JSPWiki wants to display a message.
|
static java.lang.String |
NO_ACCESS_ERROR
User do not have access to certain pages.
|
static java.lang.String |
NONE
This is not a JSPWiki context, use it to access static files.
|
static java.lang.String |
OTHER
Same as NONE; this is just a clarification.
|
static java.lang.String |
PREFS
User is editing preferences
|
static java.lang.String |
PREVIEW
User is previewing the changes he just made.
|
static java.lang.String |
RENAME
User is renaming a page.
|
static java.lang.String |
RSS
RSS feed is being generated.
|
static java.lang.String |
UPLOAD
User is uploading something.
|
static java.lang.String |
VIEW
The VIEW context - the user just wants to view the page
contents.
|
static java.lang.String |
VIEW_GROUP
User is viewing an existing group
|
static java.lang.String |
WORKFLOW
User wants to view or administer workflows.
|
Constructor and Description |
---|
WikiContext(WikiEngine engine,
HttpServletRequest request,
Command command)
Creates a new WikiContext for the given WikiEngine, Command and
HttpServletRequest.
|
WikiContext(WikiEngine engine,
HttpServletRequest request,
WikiPage page)
Creates a new WikiContext for the given WikiEngine, WikiPage and
HttpServletRequest.
|
WikiContext(WikiEngine engine,
WikiPage page)
Create a new WikiContext for the given WikiPage.
|
Modifier and Type | Method and Description |
---|---|
java.lang.Object |
clone()
Returns a shallow clone of the WikiContext.
|
WikiContext |
deepClone()
Creates a deep clone of the WikiContext.
|
protected static Command |
findCommand(WikiEngine engine,
HttpServletRequest request,
WikiPage page)
Looks up and returns a PageCommand based on a supplied WikiPage and HTTP
request.
|
static WikiContext |
findContext(PageContext pageContext)
This method can be used to find the WikiContext programmatically
from a JSP PageContext.
|
java.util.ResourceBundle |
getBundle(java.lang.String bundle)
Locates the i18n ResourceBundle given.
|
Command |
getCommand()
Returns the Command associated with this WikiContext.
|
java.lang.String |
getContentTemplate()
Returns the content template associated with a Command, such as
PreferencesContent.jsp . |
java.security.Principal |
getCurrentUser()
Convenience method that gets the current user.
|
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.
|
HttpServletRequest |
getHttpRequest()
If the request did originate from a HTTP request,
then the HTTP request can be fetched here.
|
java.lang.String |
getJSP()
Returns the JSP associated with the Command.
|
static java.util.Locale |
getLocale(WikiContext context)
Returns the locale of the HTTP request if available,
otherwise returns the default Locale of the server.
|
java.lang.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.
|
java.lang.String |
getRedirectURL()
Figure out to which page we are really going to.
|
java.lang.String |
getRequestContext()
Returns the request context.
|
java.lang.Object |
getTarget()
Returns the target associated with a Command, if it was created with one.
|
java.lang.String |
getTemplate()
Gets the template that is to be used throughout this request.
|
java.lang.String |
getURL(java.lang.String context,
java.lang.String page)
Creates an URL for the given request context.
|
java.lang.String |
getURL(java.lang.String context,
java.lang.String page,
java.lang.String params)
Returns an URL from a page.
|
java.lang.String |
getURLPattern()
Returns the URL pattern associated with this Command.
|
java.lang.Object |
getVariable(java.lang.String key)
Gets a previously set variable.
|
java.lang.String |
getViewURL(java.lang.String page)
A shortcut to generate a VIEW url.
|
WikiSession |
getWikiSession()
Returns the WikiSession associated with the context.
|
boolean |
hasAccess(HttpServletResponse response)
Checks whether the current user has access to this wiki context,
by obtaining the required Permission (
requiredPermission() )
and delegating the access check to
AuthorizationManager.checkPermission(WikiSession, Permission) . |
boolean |
hasAccess(HttpServletResponse response,
boolean redirect)
Checks whether the current user has access to this wiki context (and
optionally redirects if not), by obtaining the required Permission (
requiredPermission() )
and delegating the access check to
AuthorizationManager.checkPermission(WikiSession, Permission) . |
boolean |
hasAdminPermissions()
Returns true, if the current user has administrative permissions (i.e.
|
java.security.Permission |
requiredPermission()
Returns the permission required to successfully execute this context.
|
protected void |
setDefaultTemplate(HttpServletRequest request)
Figures out which template a new WikiContext should be using.
|
void |
setPage(WikiPage page)
Sets the page that is being handled.
|
WikiPage |
setRealPage(WikiPage page)
Sets a reference to the real page whose content is currently being
rendered.
|
void |
setRequestContext(java.lang.String arg)
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.
|
Command |
targetedCommand(java.lang.Object target)
Associates a target with the current Command and returns
the new targeted Command.
|
protected void |
updateCommand(java.lang.String requestContext)
Protected method that updates the internally cached Command.
|
protected HttpServletRequest m_request
public static final java.lang.String INSTALL
public static final java.lang.String NO_ACCESS_ERROR
public static final java.lang.String VIEW
public static final java.lang.String WORKFLOW
public static final java.lang.String EDIT
public static final java.lang.String LOGIN
public static final java.lang.String LOGOUT
public static final java.lang.String MESSAGE
public static final java.lang.String DIFF
public static final java.lang.String INFO
public static final java.lang.String PREVIEW
public static final java.lang.String CONFLICT
public static final java.lang.String ERROR
public static final java.lang.String UPLOAD
public static final java.lang.String COMMENT
public static final java.lang.String FIND
public static final java.lang.String CREATE_GROUP
public static final java.lang.String DELETE_GROUP
public static final java.lang.String EDIT_GROUP
public static final java.lang.String VIEW_GROUP
public static final java.lang.String PREFS
public static final java.lang.String RENAME
public static final java.lang.String DELETE
public static final java.lang.String ATTACH
public static final java.lang.String RSS
public static final java.lang.String NONE
public static final java.lang.String OTHER
public static final java.lang.String ADMIN
public WikiContext(WikiEngine engine, WikiPage page)
WikiContext(WikiEngine, HttpServletRequest, WikiPage)
.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.public WikiContext(WikiEngine engine, HttpServletRequest request, Command command) throws java.lang.IllegalArgumentException
Creates a new WikiContext for the given WikiEngine, Command and HttpServletRequest.
This constructor will also look up the HttpSession associated with the request, and determine if a WikiSession object is present. If not, a new one is created.
engine
- The WikiEngine that is handling the requestrequest
- The HttpServletRequest that should be associated with this
context. This parameter may be null
.command
- the commandjava.lang.IllegalArgumentException
- if engine
or
command
are null
public WikiContext(WikiEngine engine, HttpServletRequest request, WikiPage page)
findCommand(WikiEngine, HttpServletRequest, WikiPage)
and
delegates to
WikiContext(WikiEngine, HttpServletRequest, Command)
.engine
- The WikiEngine 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 java.lang.String getContentTemplate()
PreferencesContent.jsp
. For Commands that are not
page-related, this method will always return null
.
Calling methods should always check to see if the result
of this method is null
.getContentTemplate
in interface Command
Command.getContentTemplate()
public java.lang.String getJSP()
null
result, although in some cases the result may be an empty string.getJSP
in interface Command
Command.getJSP()
public WikiPage setRealPage(WikiPage 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.
page
- The real page which is being rendered.InsertPageTag
public 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".
InsertPageTag
,
JSPWikiMarkupParser
public java.lang.String getRedirectURL()
CommandResolver.getSpecialPageReference(String)
.public WikiEngine getEngine()
public WikiPage getPage()
public void setPage(WikiPage page)
page
- The wikipagepublic java.lang.String getRequestContext()
getRequestContext
in interface Command
public void setRequestContext(java.lang.String arg)
arg
- The request context (one of the predefined contexts.)public java.lang.Object getTarget()
Command.targetedCommand(Object)
will
always return a non-null
object. Calling
methods should always check to see if the result of this method
is null
.getTarget
in interface Command
Command.getTarget()
public java.lang.String getURLPattern()
null
String.getURLPattern
in interface Command
Command.getURLPattern()
public java.lang.Object getVariable(java.lang.String key)
key
- The variable name.public void setVariable(java.lang.String key, java.lang.Object data)
key
- The variable name.data
- The variable value.public java.lang.String getHttpParameter(java.lang.String paramName)
paramName
- Parameter name to look for.public HttpServletRequest getHttpRequest()
public void setTemplate(java.lang.String dir)
dir
- The template namepublic java.lang.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 Command
PageCommand.getName()
,
GroupCommand.getName()
public java.lang.String getTemplate()
public java.security.Principal getCurrentUser()
public java.lang.String getViewURL(java.lang.String page)
page
- The page to which to link.public java.lang.String getURL(java.lang.String context, java.lang.String page)
context
- e.g. WikiContext.EDITpage
- The page to which to linkpublic 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 page to which to linkparams
- A list of parameters, separated with "&"public Command getCommand()
public java.lang.Object clone()
clone
in class java.lang.Object
public WikiContext deepClone()
public WikiSession getWikiSession()
WikiSession.guestSession(WikiEngine)
.public static WikiContext findContext(PageContext pageContext)
WikiTagBase.ATTR_CONTEXT
.pageContext
- the JSP page contextpublic java.security.Permission requiredPermission()
PropertyPermission
"os.name",
"read"
). This method is guaranteed to always return a valid,
non-null permission.requiredPermission
in interface Command
public Command targetedCommand(java.lang.Object target)
targetedCommand
in interface Command
target
- the object to combine, such as a GroupPrincipal or WikiPage{@inheritDoc}
public boolean hasAccess(HttpServletResponse response) throws java.io.IOException
requiredPermission()
)
and delegating the access check to
AuthorizationManager.checkPermission(WikiSession, Permission)
.
If the user is allowed, this method returns true
;
false
otherwise. If access is allowed,
the wiki context will be added to the request as an attribute
with the key name WikiTagBase.ATTR_CONTEXT
.
Note that this method will automatically redirect the user to
a login or error page, as appropriate, if access fails. This is
NOT guaranteed to be default behavior in the future.response
- the http responsejava.io.IOException
- In case something goes wrongpublic boolean hasAccess(HttpServletResponse response, boolean redirect) throws java.io.IOException
requiredPermission()
)
and delegating the access check to
AuthorizationManager.checkPermission(WikiSession, Permission)
.
If the user is allowed, this method returns true
;
false
otherwise. If access is allowed,
the wiki context will be added to the request as attribute
with the key name WikiTagBase.ATTR_CONTEXT
.response
- The servlet response objectredirect
- If true, makes an automatic redirect to the responsejava.io.IOException
- If something goes wrongpublic boolean hasAdminPermissions()
protected void setDefaultTemplate(HttpServletRequest request)
request
- the HTTP requestprotected static Command findCommand(WikiEngine engine, HttpServletRequest request, WikiPage page)
PageCommand.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(java.lang.String requestContext)
requestContext
- the desired request contextpublic java.util.ResourceBundle getBundle(java.lang.String bundle) throws java.util.MissingResourceException
bundle
- The name of the bundle you are looking for.java.util.MissingResourceException
- If the bundle cannot be foundInternationalizationManager
public static java.util.Locale getLocale(WikiContext context)
context
- The WikiContextstSoftware Copyright © 2001-2014 stSoftware All Rights Reserved.