public abstract class XWikiAction extends Object implements com.xpn.xwiki.internal.web.LegacyAction
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 org.xwiki.component.descriptor.ComponentDescriptor<com.xpn.xwiki.internal.web.LegacyAction> |
componentDescriptor |
protected org.xwiki.container.Container |
container |
protected org.xwiki.context.Execution |
execution |
protected boolean |
handleRedirectObject
Indicate if the XWiki.RedirectClass is handled by the action (see handleRedirectObject()).
|
protected org.xwiki.observation.ObservationManager |
observation |
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.
|
void |
execute(javax.servlet.http.HttpServletRequest servletRequest,
javax.servlet.http.HttpServletResponse servletResponse) |
void |
execute(XWikiContext context) |
protected ContextualAuthorizationManager |
getContextualAuthorizationManager() |
protected DocumentReferenceResolver<String> |
getCurrentMixedDocumentReferenceResolver() |
protected ScriptContext |
getCurrentScriptContext() |
protected EntityNameValidationConfiguration |
getEntityNameValidationConfiguration() |
protected EntityNameValidationManager |
getEntityNameValidationManager() |
protected Class<? extends XWikiForm> |
getFormClass() |
protected ContextualLocalizationManager |
getLocalization() |
protected EntityReferenceSerializer<String> |
getLocalSerializer() |
protected String |
getName() |
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(javax.servlet.http.HttpServletRequest servletRequest,
javax.servlet.http.HttpServletResponse servletResponse) |
protected XWikiContext |
initializeXWikiContext(javax.servlet.http.HttpServletRequest servletRequest,
javax.servlet.http.HttpServletResponse servletResponse,
XWikiForm form) |
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.
|
public static final String ACTION_PROGRESS
@Inject protected org.xwiki.component.descriptor.ComponentDescriptor<com.xpn.xwiki.internal.web.LegacyAction> componentDescriptor
@Inject protected org.xwiki.container.Container container
@Inject protected org.xwiki.context.Execution execution
@Inject protected org.xwiki.observation.ObservationManager observation
protected boolean waitForXWikiInitialization
protected boolean handleRedirectObject
@Unstable protected Class<? extends XWikiForm> getFormClass()
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 void execute(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse) throws Exception
execute
in interface com.xpn.xwiki.internal.web.LegacyAction
servletRequest
- the request passed to the servletservletResponse
- the response passed to the servletException
- when the action produces an unexptected error@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 void execute(XWikiContext context) throws Exception
Exception
protected XWikiContext initializeXWikiContext(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse) throws XWikiException, javax.servlet.ServletException, InstantiationException, IllegalAccessException
XWikiException
javax.servlet.ServletException
InstantiationException
IllegalAccessException
@Unstable protected String getName()
XWikiContext
, by default the component role hint is usedprotected XWikiContext initializeXWikiContext(javax.servlet.http.HttpServletRequest servletRequest, javax.servlet.http.HttpServletResponse servletResponse, XWikiForm form) 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 failsprotected 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.