| java.lang.Object com.ecyrd.jspwiki.WikiContext
WikiContext | public class WikiContext implements Cloneable,Command(Code) | | 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
WikiContext.getCurrentUser() .
object
Do not cache the page object that you get from the WikiContext; always
use getPage()!
See Also: com.ecyrd.jspwiki.plugin.Counter author: Janne Jalkanen author: Andrew R. Jaquith |
Field Summary | |
final public static String | ADMIN User is doing administrative things. | final public static String | ATTACH User is downloading an attachment. | final public static String | COMMENT User is commenting something. | final public static String | CONFLICT User has an internal conflict, and does quite not know what to
do. | final public static String | CREATE_GROUP | final public static String | DELETE User is deleting a page or an attachment. | final public static String | DELETE_GROUP User is deleting an existing group. | final public static String | DIFF User is viewing a DIFF between the two versions of the page. | final public static String | EDIT The EDIT context - the user is editing the page. | final public static String | EDIT_GROUP User is editing an existing group. | final public static String | ERROR An error has been encountered and the user needs to be informed. | final public static String | FIND User is searching for content. | final public static String | INFO User is viewing page history. | final public static String | INSTALL User is administering JSPWiki (Install, SecurityConfig). | final public static String | LOGIN User is preparing for a login/authentication. | final public static String | LOGOUT User is preparing to log out. | final public static String | MESSAGE JSPWiki wants to display a message. | final public static String | NONE This is not a JSPWiki context, use it to access static files. | final public static String | OTHER Same as NONE; this is just a clarification. | final public static String | PREFS | final public static String | PREVIEW User is previewing the changes he just made. | final public static String | RENAME User is renaming a page. | final public static String | RSS RSS feed is being generated. | final public static String | UPLOAD User is uploading something. | final public static String | VIEW The VIEW context - the user just wants to view the page
contents. | final public static String | VIEW_GROUP | final public static String | WORKFLOW User wants to view or administer workflows. | protected HttpServletRequest | m_request Stores the HttpServletRequest. |
Method Summary | |
public Object | clone() Returns a shallow clone of the WikiContext.
since: 2.1.37. | protected static Command | findCommand(WikiEngine engine, HttpServletRequest request, WikiPage page) Looks up and returns a PageCommand based on a supplied WikiPage and HTTP
request. | public static WikiContext | findContext(PageContext pageContext) This method can be used to find the WikiContext programmatically
from a JSP PageContext. | public ResourceBundle | getBundle(String bundle) Locates the i18n ResourceBundle given. | public Command | getCommand() Returns the Command associated with this WikiContext. | public String | getContentTemplate() | public Principal | getCurrentUser() Convenience method that gets the current user. | public WikiEngine | getEngine() Returns the handling engine. | public String | getHttpParameter(String paramName) This method will safely return any HTTP parameters that
might have been defined. | public HttpServletRequest | getHttpRequest() If the request did originate from a HTTP request,
then the HTTP request can be fetched here. | public String | getJSP() | public static Locale | getLocale(WikiContext context) Returns the locale of the HTTP request if available,
otherwise returns the default Locale of the server. | public String | getName() Returns the target of this wiki context: a page, group name or JSP. | public WikiPage | getPage() Returns the page that is being handled. | public WikiPage | getRealPage() Gets a reference to the real page whose content is currently being rendered.
If your plugin e.g. | public String | getRedirectURL() Figure out to which page we are really going to. | public String | getRequestContext() Returns the request context.
The name of the request context (e.g. | public Object | getTarget() | public String | getTemplate() Gets the template that is to be used throughout this request.
since: 2.1.15. | public String | getURL(String context, String page) Creates an URL for the given request context.
Parameters: context - e.g. | public String | getURL(String context, String page, String params) Returns an URL from a page. | public String | getURLPattern() | public Object | getVariable(String key) Gets a previously set variable.
Parameters: key - The variable name. | public String | getViewURL(String page) A shortcut to generate a VIEW url.
Parameters: page - The page to which to link. | public WikiSession | getWikiSession() Returns the WikiSession associated with the context. | public boolean | hasAccess(HttpServletResponse response) Checks whether the current user has access to this wiki context,
by obtaining the required Permission (
WikiContext.requiredPermission() )
and delegating the access check to
com.ecyrd.jspwiki.auth.AuthorizationManager.checkPermission(WikiSessionPermission) .
If the user is allowed, this method returns true ;
false otherwise. | public 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 (
WikiContext.requiredPermission() )
and delegating the access check to
com.ecyrd.jspwiki.auth.AuthorizationManager.checkPermission(WikiSessionPermission) .
If the user is allowed, this method returns true ;
false otherwise. | public boolean | hasAdminPermissions() Returns true, if the current user has administrative permissions (i.e. | public Permission | requiredPermission() Returns the permission required to successfully execute this context.
For example, the a wiki context of VIEW for a certain page means that
the PagePermission "view" is required for the page. | protected void | setDefaultTemplate(HttpServletRequest request) Figures out which template a new WikiContext should be using. | public void | setPage(WikiPage page) Sets the page that is being handled. | public WikiPage | setRealPage(WikiPage page) Sets a reference to the real page whose content is currently being
rendered.
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. | public void | setRequestContext(String arg) Sets the request context. | public void | setTemplate(String dir) Sets the template to be used for this request. | public void | setVariable(String key, Object data) Sets a variable. | public 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. |
ADMIN | final public static String ADMIN(Code) | | User is doing administrative things.
|
ATTACH | final public static String ATTACH(Code) | | User is downloading an attachment.
|
COMMENT | final public static String COMMENT(Code) | | User is commenting something.
|
CONFLICT | final public static String CONFLICT(Code) | | User has an internal conflict, and does quite not know what to
do. Please provide some counseling.
|
CREATE_GROUP | final public static String CREATE_GROUP(Code) | | User wishes to create a new group
|
DELETE | final public static String DELETE(Code) | | User is deleting a page or an attachment.
|
DELETE_GROUP | final public static String DELETE_GROUP(Code) | | User is deleting an existing group.
|
DIFF | final public static String DIFF(Code) | | User is viewing a DIFF between the two versions of the page.
|
EDIT | final public static String EDIT(Code) | | The EDIT context - the user is editing the page.
|
EDIT_GROUP | final public static String EDIT_GROUP(Code) | | User is editing an existing group.
|
ERROR | final public static String ERROR(Code) | | An error has been encountered and the user needs to be informed.
|
FIND | final public static String FIND(Code) | | User is searching for content.
|
INFO | final public static String INFO(Code) | | User is viewing page history.
|
INSTALL | final public static String INSTALL(Code) | | User is administering JSPWiki (Install, SecurityConfig).
|
LOGIN | final public static String LOGIN(Code) | | User is preparing for a login/authentication.
|
LOGOUT | final public static String LOGOUT(Code) | | User is preparing to log out.
|
MESSAGE | final public static String MESSAGE(Code) | | JSPWiki wants to display a message.
|
NONE | final public static String NONE(Code) | | This is not a JSPWiki context, use it to access static files.
|
OTHER | final public static String OTHER(Code) | | Same as NONE; this is just a clarification.
|
PREFS | final public static String PREFS(Code) | | User is editing preferences
|
PREVIEW | final public static String PREVIEW(Code) | | User is previewing the changes he just made.
|
RENAME | final public static String RENAME(Code) | | User is renaming a page.
|
RSS | final public static String RSS(Code) | | RSS feed is being generated.
|
UPLOAD | final public static String UPLOAD(Code) | | User is uploading something.
|
VIEW | final public static String VIEW(Code) | | The VIEW context - the user just wants to view the page
contents.
|
VIEW_GROUP | final public static String VIEW_GROUP(Code) | | User is viewing an existing group
|
WORKFLOW | final public static String WORKFLOW(Code) | | User wants to view or administer workflows.
|
m_request | protected HttpServletRequest m_request(Code) | | Stores the HttpServletRequest. May be null, if the request did not
come from a servlet.
|
WikiContext | public WikiContext(WikiEngine engine, HttpServletRequest request, Command command) throws IllegalArgumentException(Code) | |
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.
After the WikiSession object is obtained, the current authentication
status is checked. If not authenticated, or if the login status reported
by the container has changed, the constructor attempts to log in the user
with
com.ecyrd.jspwiki.auth.AuthenticationManager.login(HttpServletRequest) .
If an login process throws an exception, this method logs the error but
does not re-throw it.
Parameters: engine - The WikiEngine that is handling the request Parameters: request - The HttpServletRequest that should be associated with thiscontext. This parameter may be null . Parameters: command - the command throws: IllegalArgumentException - if engine orcommand are null |
clone | public Object clone()(Code) | | Returns a shallow clone of the WikiContext.
since: 2.1.37. A shallow clone of the WikiContext |
findCommand | protected static Command findCommand(WikiEngine engine, HttpServletRequest request, WikiPage page)(Code) | | Looks up and returns a PageCommand based on a supplied WikiPage and HTTP
request. First, the appropriate Command is obtained by examining the HTTP
request; the default is
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.
Parameters: engine - the wiki engine Parameters: request - the HTTP request Parameters: page - the wiki page the correct command |
findContext | public static WikiContext findContext(PageContext pageContext)(Code) | | This method can be used to find the WikiContext programmatically
from a JSP PageContext. We check the request context.
The wiki context, if it exists,
is looked up using the key
com.ecyrd.jspwiki.tags.WikiTagBase.ATTR_CONTEXT .
since: 2.4 Parameters: pageContext - the JSP page context Current WikiContext, or null, of no context exists. |
getCommand | public Command getCommand()(Code) | | Returns the Command associated with this WikiContext.
the command |
getCurrentUser | public Principal getCurrentUser()(Code) | | Convenience method that gets the current user. Delegates the
lookup to the WikiSession associated with this WikiContect.
May return null, in case the current
user has not yet been determined; or this is an internal system.
If the WikiSession has not been set, always returns null.
The current user; or maybe null in case of internal calls. |
getEngine | public WikiEngine getEngine()(Code) | | Returns the handling engine.
The wikiengine owning this context. |
getHttpParameter | public String getHttpParameter(String paramName)(Code) | | 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.
since: 2.0.13. Parameters: paramName - Parameter name to look for. HTTP parameter, or null, if no such parameter existed. |
getHttpRequest | public HttpServletRequest getHttpRequest()(Code) | | 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!
Null, if no HTTP request was done. since: 2.0.13. |
getLocale | public static Locale getLocale(WikiContext context)(Code) | | Returns the locale of the HTTP request if available,
otherwise returns the default Locale of the server.
A valid locale object Parameters: context - The WikiContext |
getName | public String getName()(Code) | | Returns the target of this wiki context: a page, group name or JSP. If
the associated Command is a PageCommand, this method returns the page's
name. Otherwise, this method delegates to the associated Command's
com.ecyrd.jspwiki.ui.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() .
the name of the target of this wiki context See Also: com.ecyrd.jspwiki.ui.PageCommand.getName See Also: com.ecyrd.jspwiki.ui.GroupCommand.getName |
getPage | public WikiPage getPage()(Code) | | Returns the page that is being handled.
the page which was fetched. |
getRealPage | public WikiPage getRealPage()(Code) | | Gets a reference to the real page whose content is currently being rendered.
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.
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".
A reference to the real page. See Also: com.ecyrd.jspwiki.tags.InsertPageTag See Also: com.ecyrd.jspwiki.parser.JSPWikiMarkupParser |
getRequestContext | public String getRequestContext()(Code) | | Returns the request context.
The name of the request context (e.g. VIEW). |
getTemplate | public String getTemplate()(Code) | | Gets the template that is to be used throughout this request.
since: 2.1.15. template name |
getURL | public String getURL(String context, String page)(Code) | | Creates an URL for the given request context.
Parameters: context - e.g. WikiContext.EDIT Parameters: page - The page to which to link An URL to the page, honours the absolute/relative setting in jspwiki.properties |
getURL | public String getURL(String context, String page, String params)(Code) | | Returns an URL from a page. It this WikiContext instance was constructed
with an actual HttpServletRequest, we will attempt to construct the
URL using HttpUtil, which preserves the HTTPS portion if it was used.
Parameters: context - The request context (e.g. WikiContext.UPLOAD) Parameters: page - The page to which to link Parameters: params - A list of parameters, separated with "&" An URL to the given context and page. |
getVariable | public Object getVariable(String key)(Code) | | Gets a previously set variable.
Parameters: key - The variable name. The variable contents. |
getViewURL | public String getViewURL(String page)(Code) | | A shortcut to generate a VIEW url.
Parameters: page - The page to which to link. An URL to the page. This honours the current absolute/relative setting. |
getWikiSession | public WikiSession getWikiSession()(Code) | | Returns the WikiSession associated with the context.
This method is guaranteed to always return a valid WikiSession.
If this context was constructed without an associated
HttpServletRequest, it will return
WikiSession.guestSession(WikiEngine) .
The WikiSession associate with this context. |
hasAdminPermissions | public boolean hasAdminPermissions()(Code) | | Returns true, if the current user has administrative permissions (i.e. the omnipotent
AllPermission).
since: 2.4.46 true, if the user has all permissions. |
requiredPermission | public Permission requiredPermission()(Code) | | Returns the permission required to successfully execute this context.
For example, the a wiki context of VIEW for a certain page means that
the PagePermission "view" is required for the page. In some cases, no
particular permission is required, in which case a dummy permission will
be returned (
java.util.PropertyPermission "os.name",
"read" ). This method is guaranteed to always return a valid,
non-null permission.
the permission since: 2.4 |
setDefaultTemplate | protected void setDefaultTemplate(HttpServletRequest request)(Code) | | Figures out which template a new WikiContext should be using.
Parameters: request - the HTTP request |
setPage | public void setPage(WikiPage page)(Code) | | Sets the page that is being handled.
Parameters: page - The wikipage since: 2.1.37. |
setRealPage | public WikiPage setRealPage(WikiPage page)(Code) | | Sets a reference to the real page whose content is currently being
rendered.
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.
Parameters: page - The real page which is being rendered. The previous real page since: 2.3.14 See Also: com.ecyrd.jspwiki.tags.InsertPageTag |
setRequestContext | public void setRequestContext(String arg)(Code) | | Sets the request context. See above for the different
request contexts (VIEW, EDIT, etc.)
Parameters: arg - The request context (one of the predefined contexts.) |
setTemplate | public void setTemplate(String dir)(Code) | | Sets the template to be used for this request.
Parameters: dir - The template name since: 2.1.15. |
setVariable | public void setVariable(String key, Object data)(Code) | | 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. Parameters: data - The variable value. |
updateCommand | protected void updateCommand(String requestContext)(Code) | | Protected method that updates the internally cached Command.
Will always be called when the page name, request context, or variable
changes.
Parameters: requestContext - the desired request context since: 2.4 |
|
|