Package com.xpn.xwiki
Class XWikiContext
- java.lang.Object
-
- java.util.Dictionary<K,V>
-
- java.util.Hashtable<Object,Object>
-
- com.xpn.xwiki.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 theContext
class is available as a predefined variable for scripting inside any wiki page. You can access it using$xcontext
in Velocity scripts or simplyxcontext
in Groovy ones. TheContext
class provides a means of getting contextual information about the current request or configuring XWiki on the fly.- Version:
- $Id: d3bd2995b505b998df7103e93dba39d603d8aed9 $
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static String
EXECUTIONCONTEXT_KEY
static 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.static String
KEY_LEGACY_VELOCITYCONTEXT
Deprecated.useVelocityManager.getVelocityContext()
insteadprotected static org.slf4j.Logger
LOGGER
Logging helper object.static int
MODE_ATOM
static int
MODE_GWT
static int
MODE_GWT_DEBUG
static int
MODE_PDF
static int
MODE_PORTLET
static int
MODE_SERVLET
static int
MODE_XMLRPC
static ParameterizedType
TYPE_PROVIDER
Type instance forProvider<XWikiContext>
.
-
Constructor Summary
Constructors Constructor Description XWikiContext()
-
Method Summary
-
Methods inherited from class java.util.Hashtable
clear, compute, computeIfAbsent, computeIfPresent, contains, containsKey, containsValue, elements, entrySet, equals, forEach, getOrDefault, hashCode, isEmpty, keys, keySet, merge, putAll, putIfAbsent, rehash, remove, replace, replace, replaceAll, size, toString, values
-
-
-
-
Field Detail
-
TYPE_PROVIDER
public static final ParameterizedType TYPE_PROVIDER
Type instance forProvider<XWikiContext>
.- Since:
- 5.0M1
-
MODE_SERVLET
public static final int MODE_SERVLET
- See Also:
- Constant Field Values
-
MODE_PORTLET
public static final int MODE_PORTLET
- See Also:
- Constant Field Values
-
MODE_XMLRPC
public static final int MODE_XMLRPC
- See Also:
- Constant Field Values
-
MODE_ATOM
public static final int MODE_ATOM
- See Also:
- Constant Field Values
-
MODE_PDF
public static final int MODE_PDF
- See Also:
- Constant Field Values
-
MODE_GWT
public static final int MODE_GWT
- See Also:
- Constant Field Values
-
MODE_GWT_DEBUG
public static final int MODE_GWT_DEBUG
- See Also:
- Constant Field Values
-
EXECUTIONCONTEXT_KEY
public static final String EXECUTIONCONTEXT_KEY
- See Also:
- Constant Field Values
-
KEY_LEGACY_VELOCITYCONTEXT
@Deprecated public static final String KEY_LEGACY_VELOCITYCONTEXT
Deprecated.useVelocityManager.getVelocityContext()
instead- See Also:
- Constant Field Values
-
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.
-
-
Method Detail
-
getWiki
public XWiki getWiki()
-
getUtil
public Util getUtil()
-
setWiki
public void setWiki(XWiki wiki)
-
getEngineContext
public XWikiEngineContext getEngineContext()
-
setEngineContext
public void setEngineContext(XWikiEngineContext engine_context)
-
getRequest
public XWikiRequest getRequest()
-
setRequest
public void setRequest(XWikiRequest request)
-
getAction
public String getAction()
-
setAction
public void setAction(String action)
-
getResponse
public XWikiResponse getResponse()
-
setResponse
public void setResponse(XWikiResponse response)
-
getDatabase
@Deprecated public String getDatabase()
Deprecated.since 6.1M1, usegetWikiId()
instead
-
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
-
setDatabase
@Deprecated public void setDatabase(String wikiId)
Deprecated.since 6.1M1, usesetWikiId(String)
instead- Parameters:
wikiId
- the current wiki id
-
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, usegetOriginalWikiId()
insteadGet 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
-
setOriginalDatabase
@Deprecated public void setOriginalDatabase(String wikiId)
Deprecated.since 6.1M1, usesetOriginalWikiId(String)
instead
-
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
.
-
setDoc
public void setDoc(XWikiDocument doc)
-
getUserReference
public DocumentReference getUserReference()
-
setUserReference
public void setUserReference(DocumentReference userReference)
-
setUser
@Deprecated public void setUser(String user)
Deprecated.since 3.1M1 usesetUserReference(DocumentReference)
instead
-
getUser
@Deprecated public String getUser()
Deprecated.since 3.1M1 usegetUserReference()
instead
-
getLocalUser
@Deprecated public String getLocalUser()
Deprecated.since 3.1M1 usegetUserReference()
instead
-
getXWikiUser
@Deprecated public XWikiUser getXWikiUser()
Deprecated.since 3.1M1 usegetUserReference()
instead
-
getLanguage
@Deprecated public String getLanguage()
Deprecated.since 4.3M1 usegetLocale()
instead
-
setLanguage
@Deprecated public void setLanguage(String language)
Deprecated.since 4.3M1 usesetLocale(Locale)
instead
-
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
-
getInterfaceLanguage
@Deprecated public String getInterfaceLanguage()
Deprecated.since 6.0M1, usegetInterfaceLocale()
instead
-
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
- theLocale
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)
-
getURLFactory
public XWikiURLFactory getURLFactory()
-
setURLFactory
public void setURLFactory(XWikiURLFactory URLFactory)
-
getForm
public XWikiForm getForm()
-
setForm
public void setForm(XWikiForm form)
-
isFinished
public boolean isFinished()
Define if a response has been already sent or not. Note that contrary toisResponseSent()
this method will ensure that the template is executed even if the result of the execution is not sent. SeeUtils.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)
SeeisFinished()
.- Parameters:
finished
- Set totrue
if the response has been sent.
-
isResponseSent
public boolean isResponseSent()
Define if a response has been already sent or not and if the template parsing should be done. Note that contrary toisFinished()
this method will always prevent the execution of the template. SeeUtils.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)
SeeisResponseSent()
.- Parameters:
responseSent
- Set totrue
if the response has been sent and the template should not be executed.
-
getWikiServer
public XWikiDocument getWikiServer()
-
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)
-
getBaseClass
public BaseClass getBaseClass(DocumentReference classReference)
- Since:
- 2.2M2
-
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()
-
getMessageTool
@Deprecated public XWikiMessageTool getMessageTool()
Deprecated.since 4.3M2 useContextualLocalizationManager
component instead
-
getValidationStatus
public XWikiValidationStatus getValidationStatus()
-
setValidationStatus
public void setValidationStatus(XWikiValidationStatus status)
-
addDisplayedField
public void addDisplayedField(String fieldname)
-
getEditorWysiwyg
@Deprecated public String getEditorWysiwyg()
Deprecated.since 8.2RC1 when we started using the Edit Module to load the configured WYSIWYG editorReturns 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
-
dropPermissions
public void dropPermissions()
Drop permissions for the remainder of the request cycle.After this is called:
- 1.
Api.hasProgrammingRights()
will always return false. - 2.
XWiki.getDocumentAsAuthor(org.xwiki.model.reference.DocumentReference)
,XWiki.getDocumentAsAuthor(String)
,Document.saveAsAuthor()
,Document.saveAsAuthor(String)
,Document.saveAsAuthor(String, boolean)
, andDocument.deleteAsAuthor()
will perform all of their actions as if the document's content author was the guest user (XWiki.XWikiGuest).
In effect, no code requiring "programming right" will run, and if the document content author (see:
Document.getContentAuthor()
) is a user who has "programming right", there will be no way for code following this call to save another document as this user, blessing it too with programming right.Once dropped, permissions cannot be regained for the duration of the request.
If you are interested in a more flexable sandboxing method which sandboxed code only for the remainder of the rendering cycle, consider using
Document.dropPermissions()
.- Since:
- 3.0M3
- 1.
-
hasDroppedPermissions
public boolean hasDroppedPermissions()
- Returns:
- true if
dropPermissions()
has been called on this context, or if theXWikiConstant.DROPPED_PERMISSIONS
key has been set in theExecutionContext
for this thread. This is done by calling {Document#dropPermissions()}
-
clone
public XWikiContext clone()
-
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
-
-