Package com.xpn.xwiki

Class XWikiContext

  • All Implemented Interfaces:
    Serializable, Cloneable, Map<Object,​Object>

    public class XWikiContext
    extends Hashtable<Object,​Object>
    Represents the execution environment for all the wiki pages. An instance of the Context class is available as a predefined variable for scripting inside any wiki page. You can access it using $xcontext in Velocity scripts or simply xcontext in Groovy ones. The Context class provides a means of getting contextual information about the current request or configuring XWiki on the fly.
    Version:
    $Id: 77d5e73e83142360ea9a3585e338b29d44a70213 $
    See Also:
    Serialized Form
    • Field Detail

      • TYPE_PROVIDER

        public static final ParameterizedType TYPE_PROVIDER
        Type instance for Provider<XWikiContext>.
        Since:
        5.0M1
      • INACTIVE_USER_REFERENCE

        @Unstable
        public static final String INACTIVE_USER_REFERENCE
        The reference of a logged-in inactive user: in such case the context user reference is guest, so we store the actual logged-in user with that key.
        Since:
        14.3RC1, 13.10.5
        See Also:
        Constant Field Values
      • LOGGER

        protected static final org.slf4j.Logger LOGGER
        Logging helper object.
    • Constructor Detail

      • XWikiContext

        public XWikiContext()
    • Method Detail

      • getWiki

        public XWiki getWiki()
      • getUtil

        public Util getUtil()
      • setWiki

        public void setWiki​(XWiki wiki)
      • setRequest

        public void setRequest​(XWikiRequest request)
      • getAction

        public String getAction()
      • setAction

        public void setAction​(String action)
      • setResponse

        public void setResponse​(XWikiResponse response)
      • getWikiId

        public String getWikiId()
        Returns:
        the id of the current wiki, or null if none is set
        Since:
        6.1M1
      • getWikiReference

        public WikiReference getWikiReference()
        Returns:
        the reference of the current wiki or null if none is set
        Since:
        7.2M1
      • setWikiId

        public void setWikiId​(String wikiId)
        Parameters:
        wikiId - the current wiki id
        Since:
        6.1M1
      • setWikiReference

        public void setWikiReference​(WikiReference wikiReference)
        Parameters:
        wikiReference - the current wiki reference
        Since:
        7.2M1
      • getOriginalDatabase

        @Deprecated
        public String getOriginalDatabase()
        Deprecated.
        since 6.1M1, use getOriginalWikiId() instead
        Get the "original" wiki id. This will be the wiki id for the wiki which the user requested. If the wiki is switched to load some piece of data, this will remember what it should be switched back to.
        Returns:
        the wiki id originally requested by the user.
      • getOriginalWikiId

        public String getOriginalWikiId()
        Get the "original" wiki id. This will be the wiki id for the wiki which the user requested. If the wiki is switched to load some piece of data, this will remember what it should be switched back to.
        Returns:
        the wiki id originally requested by the user.
        Since:
        6.1M1
      • setOriginalWikiId

        public void setOriginalWikiId​(String wikiId)
        Set the "original" wiki id. This will be the wiki id for the wiki which the user requested. If the wiki is switched to load some piece of data, this will remember what it should be switched back to.
        Parameters:
        wikiId - the wiki id originally requested by the user
        Since:
        6.1M1
      • isMainWiki

        public boolean isMainWiki()
        Returns:
        true it's main wiki's context, false otherwise.
      • isMainWiki

        public boolean isMainWiki​(String wikiName)
        Parameters:
        wikiName - the name of the wiki.
        Returns:
        true it's main wiki's context, false otherwise.
      • getDoc

        public XWikiDocument getDoc()
        Returns:
        the current document handled in the context or null.
      • setUserReference

        public void setUserReference​(DocumentReference userReference)
      • getLocale

        public Locale getLocale()
        Returns:
        the current locale
        Since:
        4.3M1
      • setLocale

        public void setLocale​(Locale locale)
        Parameters:
        locale - the current locale
        Since:
        4.3M1
      • getInterfaceLocale

        public Locale getInterfaceLocale()
        Returns:
        the Locale to use to display the user interface
        Since:
        6.0M1
      • setInterfaceLocale

        public void setInterfaceLocale​(Locale interfaceLocale)
        Parameters:
        interfaceLocale - the Locale to use to display the content
        Since:
        6.0M1
      • getMode

        public int getMode()
      • setMode

        public void setMode​(int mode)
      • getURL

        public URL getURL()
      • setURL

        public void setURL​(URL url)
      • setURLFactory

        public void setURLFactory​(XWikiURLFactory URLFactory)
      • setForm

        public void setForm​(XWikiForm form)
      • isFinished

        public boolean isFinished()
        Define if a response has been already sent or not. Note that contrary to isResponseSent() this method will ensure that the template is executed even if the result of the execution is not sent. See Utils.parseTemplate(String, boolean, XWikiContext) for details.
        Returns:
        true if the response has been sent and no new reponse should be sent anymore.
      • setFinished

        public void setFinished​(boolean finished)
        Parameters:
        finished - Set to true if the response has been sent.
      • isResponseSent

        @Unstable
        public boolean isResponseSent()
        Define if a response has been already sent or not and if the template parsing should be done. Note that contrary to isFinished() this method will always prevent the execution of the template. See Utils.parseTemplate(String, boolean, XWikiContext) for details.
        Returns:
        true if the response has been sent, no new reponse should be sent anymore and the template should not be parsed.
        Since:
        13.3RC1
      • setResponseSent

        public void setResponseSent​(boolean responseSent)
        Parameters:
        responseSent - Set to true if the response has been sent and the template should not be executed.
      • getCacheDuration

        public int getCacheDuration()
      • setCacheDuration

        public void setCacheDuration​(int cacheDuration)
      • getMainXWiki

        public String getMainXWiki()
      • setMainXWiki

        public void setMainXWiki​(String str)
      • addBaseClass

        public void addBaseClass​(BaseClass bclass)
      • removeBaseClass

        public void removeBaseClass​(DocumentReference classReference)
        Parameters:
        classReference - the reference of the class
        Since:
        9.0RC1
      • flushClassCache

        public void flushClassCache()
        Empty the class cache.
      • setLinksAction

        public void setLinksAction​(String action)
      • unsetLinksAction

        public void unsetLinksAction()
      • getLinksAction

        public String getLinksAction()
      • setLinksQueryString

        public void setLinksQueryString​(String value)
      • unsetLinksQueryString

        public void unsetLinksQueryString()
      • getLinksQueryString

        public String getLinksQueryString()
      • addDisplayedField

        public void addDisplayedField​(String fieldname)
      • getDisplayedFields

        public List<String> getDisplayedFields()
      • getEditorWysiwyg

        @Deprecated
        public String getEditorWysiwyg()
        Deprecated.
        since 8.2RC1 when we started using the Edit Module to load the configured WYSIWYG editor
        Returns the list of TextArea fields that use the WYSIWYG editor. This list is automatically built when displaying TextArea properties.
        Returns:
        a string containing a comma-separated list of TextArea field names for which the WYSIWYG editor should be enabled
      • hasDroppedPermissions

        public boolean hasDroppedPermissions()
        Returns:
        true if dropPermissions() has been called on this context, or if the XWikiConstant.DROPPED_PERMISSIONS key has been set in the ExecutionContext for this thread. This is done by calling {Document#dropPermissions()}
      • declareInExecutionContext

        public void declareInExecutionContext​(org.xwiki.context.ExecutionContext executionContext)
        There are several places where the XWiki context needs to be declared in the execution, so we add a common method here.
        Parameters:
        executionContext - The execution context.
      • getAuthorReference

        public DocumentReference getAuthorReference()
        Returns:
        the reference of the user being used to check script and programming right (i.e. the author of the current script)
        Since:
        8.3M2