com.xpn.xwiki.web
Class XWikiAction

java.lang.Object
  extended by org.apache.struts.action.Action
      extended by com.xpn.xwiki.web.XWikiAction
Direct Known Subclasses:
AbstractPropChangeAction, AdminAction, AttachAction, CancelAction, CommentAddAction, CreateAction, DeleteAction, DeleteAttachmentAction, DeleteSpaceAction, DeleteVersionsAction, DotAction, DownloadAction, DownloadRevAction, EditAction, ExportAction, GetAction, ImportAction, InlineAction, LockAction, LoginAction, LoginErrorAction, LoginSubmitAction, LogoutAction, ObjectAddAction, ObjectRemoveAction, ObjectsSynchronizeAction, PDFAction, PreviewAction, PropAddAction, PropUpdateAction, RedirectAction, RegisterAction, ResetVersionsAction, RollbackAction, SaveAndContinueAction, SkinAction, SVGAction, TempResourceAction, TexAction, UndeleteAction, UnknownAction, UploadAction, ViewAction, ViewAttachRevAction, ViewrevAction

public abstract class XWikiAction
extends org.apache.struts.action.Action

Root class for most XWiki actions. It provides a common framework that allows actions to execute just the specific action code, handling the extra activities, such as preparing the context and retrieving the document corresponding to the URL.

It defines two methods, action(XWikiContext) and render(XWikiContext), that should be overridden by specific actions. action(XWikiContext) should contain the processing part of the action. render(XWikiContext) should return the name of a template that should be rendered, or manually write to the response stream.

Serving a request goes through the following phases:

During this process, also handle specific errors, like when a document does not exist, or the user does not have the right to perform the current action.


Field Summary
 
Fields inherited from class org.apache.struts.action.Action
defaultLocale, servlet
 
Constructor Summary
XWikiAction()
           
 
Method Summary
 boolean action(XWikiContext context)
           
protected  void cleanupComponents()
           
protected  boolean csrfTokenCheck(XWikiContext context)
          Perform CSRF check and redirect to the resubmission page if needed.
 org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
          Handle server requests.
 org.apache.struts.action.ActionForward execute(XWikiContext context)
           
 String getRealPath(String path)
           
protected  XWikiDocument getTranslatedDocument(XWikiDocument doc, String language, XWikiContext context)
          Gets the translated version of a document, in the specified language.
protected  void handleRevision(XWikiContext context)
           
protected  void initializeContainerComponent(XWikiContext context)
           
protected  XWikiContext initializeXWikiContext(org.apache.struts.action.ActionMapping mapping, org.apache.struts.action.ActionForm form, javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp)
           
 String render(XWikiContext context)
           
protected  boolean sendGlobalRedirect(XWikiResponse response, String url, XWikiContext context)
          Send redirection based on a regexp pattern (if any) set at the main wiki level.
protected  void sendRedirect(XWikiResponse response, String url)
           
 
Methods inherited from class org.apache.struts.action.Action
addErrors, addMessages, execute, generateToken, getDataSource, getDataSource, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XWikiAction

public XWikiAction()
Method Detail

execute

public org.apache.struts.action.ActionForward execute(org.apache.struts.action.ActionMapping mapping,
                                                      org.apache.struts.action.ActionForm form,
                                                      javax.servlet.http.HttpServletRequest req,
                                                      javax.servlet.http.HttpServletResponse resp)
                                               throws Exception
Handle server requests.

Overrides:
execute in class org.apache.struts.action.Action
Parameters:
mapping - The ActionMapping used to select this instance
form - The optional ActionForm bean for this request (if any)
req - The HTTP request we are processing
resp - The HTTP response we are creating
Throws:
IOException - if an input/output error occurs
javax.servlet.ServletException - if a servlet exception occurs
Exception

execute

public org.apache.struts.action.ActionForward execute(XWikiContext context)
                                               throws Exception
Throws:
Exception

initializeXWikiContext

protected XWikiContext initializeXWikiContext(org.apache.struts.action.ActionMapping mapping,
                                              org.apache.struts.action.ActionForm form,
                                              javax.servlet.http.HttpServletRequest req,
                                              javax.servlet.http.HttpServletResponse resp)
                                       throws XWikiException,
                                              javax.servlet.ServletException
Throws:
XWikiException
javax.servlet.ServletException

initializeContainerComponent

protected void initializeContainerComponent(XWikiContext context)
                                     throws javax.servlet.ServletException
Throws:
javax.servlet.ServletException

cleanupComponents

protected void cleanupComponents()

getRealPath

public String getRealPath(String path)

action

public boolean action(XWikiContext context)
               throws XWikiException
Throws:
XWikiException

render

public String render(XWikiContext context)
              throws XWikiException
Throws:
XWikiException

handleRevision

protected void handleRevision(XWikiContext context)
                       throws XWikiException
Throws:
XWikiException

sendGlobalRedirect

protected boolean sendGlobalRedirect(XWikiResponse response,
                                     String url,
                                     XWikiContext context)
                              throws Exception
Send redirection based on a regexp pattern (if any) set at the main wiki level. To enable this feature you must add xwiki.preferences.redirect=1 to your xwiki.cfg.

Parameters:
response - the servlet response
url - url of the request
context - the XWiki context
Returns:
true if a redirection has been sent
Throws:
Exception

sendRedirect

protected void sendRedirect(XWikiResponse response,
                            String url)
                     throws XWikiException
Throws:
XWikiException

getTranslatedDocument

protected XWikiDocument getTranslatedDocument(XWikiDocument doc,
                                              String language,
                                              XWikiContext context)
                                       throws XWikiException
Gets the translated version of a document, in the specified language. If the translation does not exist, a new document translation is created. If the requested language does not correspond to a translation (is not defined or is the same as the main document), then the main document is returned.

Parameters:
doc - the main (default, untranslated) document to translate
language - the requested document language
context - the current request context
Returns:
the translated document, or the original untranslated document if the requested language is not a translation
Throws:
XWikiException - if the translation cannot be retrieved from the database

csrfTokenCheck

protected boolean csrfTokenCheck(XWikiContext context)
                          throws XWikiException
Perform CSRF check and redirect to the resubmission page if needed. Throws an exception if the access should be denied, returns false if the check failed and the user will be redirected to a resubmission page.

Parameters:
context - current xwiki context containing the request
Returns:
true if the check succeeded, false if resubmission is needed
Throws:
XWikiException - if the check fails


Copyright © 2004-2013 XWiki. All Rights Reserved.