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:
XWiki-specific context
action(XWikiContext)
action(XWikiContext)
returns true, run the overridden render(XWikiContext)
render(XWikiContext)
returned a string (template name), render the template with that nameDuring 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.
Modifier and Type | Field and Description |
---|---|
static String |
ACTION_PROGRESS |
protected boolean |
handleRedirectObject
Indicate if the XWiki.RedirectClass is handled by the action (see handleRedirectObject()).
|
protected boolean |
waitForXWikiInitialization
Indicate if the action allow asynchronous display (among which the XWiki initialization).
|
Constructor and Description |
---|
XWikiAction() |
Modifier and Type | Method and Description |
---|---|
boolean |
action(XWikiContext context) |
protected void |
answerJSON(XWikiContext context,
int status,
Map<String,String> answer)
Answer to a request with a JSON content.
|
protected void |
cleanupComponents() |
protected boolean |
csrfTokenCheck(XWikiContext context)
Perform CSRF check and redirect to the resubmission page if needed.
|
protected boolean |
csrfTokenCheck(XWikiContext context,
boolean jsonAnswer)
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) |
protected ContextualAuthorizationManager |
getContextualAuthorizationManager() |
protected DocumentReferenceResolver<String> |
getCurrentMixedDocumentReferenceResolver() |
protected ScriptContext |
getCurrentScriptContext() |
protected EntityNameValidationConfiguration |
getEntityNameValidationConfiguration() |
protected EntityNameValidationManager |
getEntityNameValidationManager() |
protected ContextualLocalizationManager |
getLocalization() |
protected EntityReferenceSerializer<String> |
getLocalSerializer() |
protected org.xwiki.job.event.status.JobProgressManager |
getProgress() |
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 boolean |
handleRedirectObject(XWikiContext context)
Redirect the user to an other location if the document holds an XWiki.RedirectClass instance (used when a
document is moved).
|
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) |
protected boolean |
isEntityReferenceNameValid(EntityReference entityReference)
Ensure that the given entity reference is valid according to the configured name strategy.
|
protected String |
localizePlainOrKey(String key,
Object... parameters) |
protected boolean |
readFromTemplate(XWikiDocument document,
String template,
XWikiContext context)
Helper used by various actions to initialize a document by copying a template to it.
|
String |
render(XWikiContext context) |
protected DocumentReference |
resolveTemplate(String template)
Helper used resolve the template passed to the action if the current user have access to it.
|
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)
Perform a redirect to the given URL.
|
protected void |
setContentLength(XWikiResponse response,
long length)
Make sure to set the right length (or nothing) in the response.
|
protected void |
writeAjaxErrorResponse(int httpStatusCode,
String message,
XWikiContext context)
Write an error response to an ajax request.
|
addErrors, addMessages, execute, generateToken, getErrors, getLocale, getMessages, getResources, getResources, getServlet, isCancelled, isTokenValid, isTokenValid, resetToken, saveErrors, saveErrors, saveMessages, saveMessages, saveToken, setLocale, setServlet
public static final String ACTION_PROGRESS
protected boolean waitForXWikiInitialization
protected boolean handleRedirectObject
protected ContextualLocalizationManager getLocalization()
protected DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
protected ContextualAuthorizationManager getContextualAuthorizationManager()
protected org.xwiki.job.event.status.JobProgressManager getProgress()
protected EntityNameValidationManager getEntityNameValidationManager()
protected EntityNameValidationConfiguration getEntityNameValidationConfiguration()
protected EntityReferenceSerializer<String> getLocalSerializer()
protected ScriptContext getCurrentScriptContext()
ScriptContext
instancepublic 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
execute
in class org.apache.struts.action.Action
mapping
- The ActionMapping used to select this instanceform
- The optional ActionForm bean for this request (if any)req
- The HTTP request we are processingresp
- The HTTP response we are creatingIOException
- if an input/output error occursjavax.servlet.ServletException
- if a servlet exception occursException
@Unstable protected boolean isEntityReferenceNameValid(EntityReference entityReference)
entityReference
- the entity reference name to validatetrue
if the entity reference name is valid according to the name strategy.protected void writeAjaxErrorResponse(int httpStatusCode, String message, XWikiContext context)
httpStatusCode
- The status code to set on the response.message
- The message that should be displayed.context
- the context.public org.apache.struts.action.ActionForward execute(XWikiContext context) throws Exception
Exception
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
XWikiException
javax.servlet.ServletException
protected void initializeContainerComponent(XWikiContext context) throws javax.servlet.ServletException
javax.servlet.ServletException
protected void cleanupComponents()
public boolean action(XWikiContext context) throws XWikiException
XWikiException
public String render(XWikiContext context) throws XWikiException
XWikiException
protected boolean handleRedirectObject(XWikiContext context) throws XWikiException
context
- the XWiki contextXWikiException
- if error occursprotected void handleRevision(XWikiContext context) throws XWikiException
XWikiException
protected boolean sendGlobalRedirect(XWikiResponse response, String url, XWikiContext context) throws Exception
response
- the servlet responseurl
- url of the requestcontext
- the XWiki contextException
protected void sendRedirect(XWikiResponse response, String url) throws XWikiException
response
- the response to use to perform the redirecturl
- the location of the redirectXWikiException
- in case of IOException when performing the redirect.protected XWikiDocument getTranslatedDocument(XWikiDocument doc, String language, XWikiContext context) throws XWikiException
doc
- the main (default, untranslated) document to translatelanguage
- the requested document languagecontext
- the current request contextXWikiException
- if the translation cannot be retrieved from the databaseprotected boolean csrfTokenCheck(XWikiContext context) throws XWikiException
context
- current xwiki context containing the requestXWikiException
- if the check fails@Unstable protected boolean csrfTokenCheck(XWikiContext context, boolean jsonAnswer) throws XWikiException
context
- current xwiki context containing the requestjsonAnswer
- if true, returns a JSON answer in case of AJAX request: allow to process it properly on client.XWikiException
- if the check failsprotected void answerJSON(XWikiContext context, int status, Map<String,String> answer) throws XWikiException
context
- the current context of the request.status
- the status code to send back.answer
- the content of the JSON answer.XWikiException
- in case of error during the serialization of the JSON.protected void setContentLength(XWikiResponse response, long length)
response
- the responselength
- the length to set in the responseprotected DocumentReference resolveTemplate(String template)
template
- the template to copy@Unstable protected boolean readFromTemplate(XWikiDocument document, String template, XWikiContext context) throws XWikiException
document
- the document to updatetemplate
- the template to copycontext
- the XWiki contextXWikiException
- when failing to copy the templateCopyright © 2004–2021 XWiki. All rights reserved.