Class XWikiAction

    • Field Detail

      • componentDescriptor

        @Inject
        protected org.xwiki.component.descriptor.ComponentDescriptor<com.xpn.xwiki.internal.web.LegacyAction> componentDescriptor
      • container

        @Inject
        protected org.xwiki.container.Container container
      • execution

        @Inject
        protected org.xwiki.context.Execution execution
      • observation

        @Inject
        protected org.xwiki.observation.ObservationManager observation
      • waitForXWikiInitialization

        protected boolean waitForXWikiInitialization
        Indicate if the action allow asynchronous display (among which the XWiki initialization).
    • Constructor Detail

      • XWikiAction

        public XWikiAction()
    • Method Detail

      • getFormClass

        protected Class<? extends XWikiForm> getFormClass()
        Returns:
        the class of the XWikiForm in charge of parsing the request
        Since:
        13.0
      • getCurrentMixedDocumentReferenceResolver

        protected DocumentReferenceResolver<String> getCurrentMixedDocumentReferenceResolver()
        Since:
        12.10.6, 13.2RC1
      • localizePlainOrKey

        protected String localizePlainOrKey​(String key,
                                            Object... parameters)
      • getProgress

        protected org.xwiki.job.event.status.JobProgressManager getProgress()
      • getCurrentScriptContext

        protected ScriptContext getCurrentScriptContext()
        Returns:
        the current unmodified ScriptContext instance
        Since:
        8.3M1
      • execute

        public void execute​(javax.servlet.http.HttpServletRequest servletRequest,
                            javax.servlet.http.HttpServletResponse servletResponse)
                     throws Exception
        Specified by:
        execute in interface com.xpn.xwiki.internal.web.LegacyAction
        Parameters:
        servletRequest - the request passed to the servlet
        servletResponse - the response passed to the servlet
        Throws:
        Exception - when the action produces an unexptected error
      • isEntityReferenceNameValid

        protected boolean isEntityReferenceNameValid​(EntityReference entityReference)
        Ensure that the given entity reference is valid according to the configured name strategy. Always returns true if the name strategy is not found.
        Parameters:
        entityReference - the entity reference name to validate
        Returns:
        true if the entity reference name is valid according to the name strategy.
        Since:
        12.0RC1
      • writeAjaxErrorResponse

        protected void writeAjaxErrorResponse​(int httpStatusCode,
                                              String message,
                                              XWikiContext context)
        Write an error response to an ajax request.
        Parameters:
        httpStatusCode - The status code to set on the response.
        message - The message that should be displayed.
        context - the context.
      • getName

        protected String getName()
        Returns:
        the name to put in the XWikiContext, by default the component role hint is used
        Since:
        13.0
      • initializeXWikiContext

        protected XWikiContext initializeXWikiContext​(javax.servlet.http.HttpServletRequest servletRequest,
                                                      javax.servlet.http.HttpServletResponse servletResponse,
                                                      XWikiForm form)
                                               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()
      • supportRedirections

        @Unstable
        protected boolean supportRedirections()
        Indicate if the action support redirection. The default value is false.
        Returns:
        true if the action supports redirections, false otherwise
        Since:
        14.0RC1
      • 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
        Perform a redirect to the given URL.
        Parameters:
        response - the response to use to perform the redirect
        url - the location of the redirect
        Throws:
        XWikiException - in case of IOException when performing the redirect.
      • 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
      • csrfTokenCheck

        protected boolean csrfTokenCheck​(XWikiContext context,
                                         boolean jsonAnswer)
                                  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
        jsonAnswer - if true, returns a JSON answer in case of AJAX request: allow to process it properly on client.
        Returns:
        true if the check succeeded, false if resubmission is needed
        Throws:
        XWikiException - if the check fails
        Since:
        11.3RC1
      • answerJSON

        protected void answerJSON​(XWikiContext context,
                                  int status,
                                  Map<String,​String> answer)
                           throws XWikiException
        Answer to a request with a JSON content.
        Parameters:
        context - the current context of the request.
        status - the status code to send back.
        answer - the content of the JSON answer.
        Throws:
        XWikiException - in case of error during the serialization of the JSON.
      • setContentLength

        protected void setContentLength​(XWikiResponse response,
                                        long length)
        Make sure to set the right length (or nothing) in the response.
        Parameters:
        response - the response
        length - the length to set in the response
        Since:
        11.10, 10.11.10, 11.3.6
      • resolveTemplate

        protected DocumentReference resolveTemplate​(String template)
        Helper used resolve the template passed to the action if the current user have access to it.
        Parameters:
        template - the template to copy
        Returns:
        the reference of the template if not empty and the current user have access to it
        Since:
        12.10.6, 13.2RC1
      • readFromTemplate

        protected boolean readFromTemplate​(XWikiDocument document,
                                           String template,
                                           XWikiContext context)
                                    throws XWikiException
        Helper used by various actions to initialize a document by copying a template to it.
        Parameters:
        document - the document to update
        template - the template to copy
        context - the XWiki context
        Returns:
        true if the document was updated, false otherwise (for example when the current user does not have view right on the template document)
        Throws:
        XWikiException - when failing to copy the template
        Since:
        12.10.6, 13.2RC1