public class Context extends Api
XWikiContext
class, that can be used safely in scripts. All
dangerous methods are protected by requiring Programming Rights.Constructor and Description |
---|
Context(XWikiContext context)
The Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
dropPermissions()
After this is called: 1.
|
Object |
get(String key)
Returns the value associated with the given key in the XWiki context.
|
String |
getAction()
Returns the current action.
|
int |
getCacheDuration()
Returns the amount of time this document should be cached.
|
XWikiContext |
getContext()
Returns the XWiki context.
|
String |
getDatabase()
Returns the current database name.
|
List<String> |
getDisplayedFields()
Returns the list with the currently displayed fields.
|
String |
getDisplayMode()
Returns the default field display mode, when using
Document.display(String) or
Document.display(String, Object) . |
XWikiDocument |
getDoc()
Returns the current requested document.
|
String |
getEditorWysiwyg()
Deprecated.
since 8.2RC1 when we started using the Edit Module to load the configured WYSIWYG editor
|
String |
getInterfaceLanguage()
Deprecated.
since 6.0M1, use
getInterfaceLocale() instead |
Locale |
getInterfaceLocale()
Returns the interface locale preference of the current user.
|
String |
getLanguage()
Deprecated.
since 6.0M1, use
getLocale() instead |
String |
getLinksAction()
Returns the action used by XWiki URL factories to replace the view action when creating URLs.
|
String |
getLinksQueryString()
Returns the extra query string that is added to all the URLs created by XWiki URL factories.
|
Locale |
getLocale()
Returns the locale of the current request.
|
String |
getLocalUser()
Returns the current user which made the request.
|
Object |
getMacro()
Retrieves the information about the currently executing macro.
|
String |
getMainWikiName()
Returns the name of the main wiki.
|
String |
getMessage()
Get the registered (generally error) message for the previous action.
|
int |
getMode()
Specifies the container or environment in which XWiki is currently running.
|
String |
getOriginalDatabase()
Returns the name of the original database.
|
XWikiRequest |
getRequest()
Returns the current request object.
|
XWikiResponse |
getResponse()
Returns the current response object.
|
Object |
getUix()
Return the current uix object.
|
XWikiURLFactory |
getURLFactory()
Returns the URL factory matching both the protocol used to make the current request and the container or
environment in which XWiki is running.
|
String |
getUser()
Returns the current user which made the request.
|
DocumentReference |
getUserReference()
Returns the document reference for the profile page of the current user which made the request.
|
XWikiValidationStatus |
getValidationStatus()
Returns the form field validation status, which contains the exceptions or errors that may have occured during
the validation process performed during a save.
|
XWiki |
getXWiki()
Returns the XWiki object.
|
boolean |
isMainWiki()
Specifies if the current request was made to a virtual (non-main) wiki, or to the main wiki.
|
void |
put(String key,
Object value)
Puts an object on the context using the given key.
|
void |
setCacheDuration(int duration)
Sets the cache duration in seconds.
|
void |
setDatabase(String database)
Sets the current database.
|
void |
setDisplayMode(String mode)
Sets the default field display mode, when using
Document.display(String) or
Document.display(String, Object) . |
void |
setDoc(XWikiDocument doc)
Sets the current document.
|
void |
setFinished(boolean finished)
Specifies if the current page should be sent to the client or not.
|
void |
setLinksAction(String action)
Sets the action to be used instead of the view action inside URLs.
|
void |
setLinksQueryString(String value)
Sets an extra query string to be added to all the URLs created by XWiki URL factories.
|
void |
unsetLinksAction()
Stops the view action from being replaced with another action inside URLs.
|
void |
unsetLinksQueryString()
Specifies that no additional query string should be added to XWiki URLs.
|
convert, convert, convert, convertAttachments, getAuthorizationManager, getContextualAuthorizationManager, getXWikiContext, hasAccess, hasAccessLevel, hasAdminRights, hasProgrammingRights, hasWikiAdminRights
public Context(XWikiContext context)
context
- The XWikiContext
to wrap.public XWikiRequest getRequest()
HttpServletRequest
instance.public XWikiResponse getResponse()
HttpServletResponse
instance.public int getMode()
Return | Meaning |
---|---|
0 | Servlet Container |
1 | Portlet Container |
2 | XML RPC |
3 | Atom |
4 | |
5 | GWT |
6 | GWT Debugging |
public String getDatabase()
isMainWiki()
returns true
then the current database
name is the same as getMainWikiName()
. Otherwise, each virtual wiki has it's own database. In this case
the returned string identifies the current virtual wiki we operate on and prefixes document names like in
databaseName:spaceName.pageName.isMainWiki()
,
getMainWikiName()
public String getMainWikiName()
public String getOriginalDatabase()
#includeTopic("virtualwiki:Some.Document")
.@Programming public void setDatabase(String database)
database
- a database namegetDatabase()
public XWikiURLFactory getURLFactory()
XWikiURLFactory
is XWikiServletURLFactory
. XWikiURLFactory
offers a generic way of creating XWiki
specific URLs that should be chosen instead of the basic string concatenation. Hard-coding the protocol used,
like HTTP, inside wiki pages should be avoided.public boolean isMainWiki()
Specifies if the current request was made to a virtual (non-main) wiki, or to the main wiki.
In virtual mode the server can host more than one wiki, each having it's own database and its own URL. We refer
to them as virtual wikis. One of them stores information about the others and it is called the main
wiki. You can switch to virtual mode by changing the xwiki.virtual
parameter from 0
to 1
in the configuration file.
true
if XWiki is in the main wiki, or if virtual mode is disabled.getDatabase()
,
getMainWikiName()
public String getAction()
@Deprecated public String getLanguage()
getLocale()
insteadgetLocale()
but as String.getInterfaceLanguage()
public Locale getLocale()
multilingual
is turned off then the locale used is
given by the default_language
preference. Otherwise, the locale is taken from either the request
object, the cookie, user preferences or from the navigator locale settings, the last having the lower priority.getInterfaceLocale()
@Deprecated public String getInterfaceLanguage()
getInterfaceLocale()
insteadgetInterfaceLocale()
but as String.getLanguage()
public Locale getInterfaceLocale()
multilingual
is turned off then the
locale used is given by the default_language
preference. Otherwise, the locale is taken from either
the request object, the context, the cookie, user preferences or from the navigator locale settings, the last
having the lower priority.getLocale()
@Programming public XWiki getXWiki()
$xwiki
in Velocity.null
otherwise.@Programming public XWikiDocument getDoc()
$doc
in
Velocity.null
otherwise.public String getUser()
XWiki.UserLogin
. If the user comes from another wiki the full prefixed name will be returned as
in wikiid:XWiki.UserLogin
. At the same time this method returns the name of the document containing
the current user's profile so in Velocity you can do, for instance,
$xwiki.getDocument($xcontext.user)
to find out more about the current user, like his/hers real name
or e-mail address.getLocalUser()
,
getDatabase()
,
getUserReference()
public DocumentReference getUserReference()
getUserReference().getWikiReference().getName()
will always return the name of the user's wiki.null
if
there is no currently logged in user (anonymous/guest user).public String getLocalUser()
getUser()
is that the returned
string is never prefixed with the database name, not even in virtual mode.getUser()
,
getDatabase()
@Programming public void setDoc(XWikiDocument doc)
doc
- XWiki document to set as the context document.@Programming public XWikiContext getContext()
null
otherwise.@Programming public Object get(String key)
key
- The key to look for in the context.null
otherwise.put(String, java.lang.Object)
@Deprecated public String getEditorWysiwyg()
@Programming public void put(String key, Object value)
key
- The parameter name.value
- The parameter value.get(String)
public void setFinished(boolean finished)
.xar
archive.finished
- true
to avoid rendering of the current pagepublic int getCacheDuration()
setCacheDuration(int)
public void setCacheDuration(int duration)
duration
- The cache duration specified in seconds.getCacheDuration()
public void setLinksAction(String action)
action
- view action replacementunsetLinksAction()
,
getLinksAction()
,
getURLFactory()
public void unsetLinksAction()
setLinksAction(String)
,
getLinksAction()
public String getLinksAction()
null
.null
.setLinksAction(String)
,
unsetLinksAction()
,
getURLFactory()
public void setLinksQueryString(String value)
value
- The additional query string to be added to all the URLs created by XWiki URL factories.unsetLinksQueryString()
,
getLinksQueryString()
,
getURLFactory()
public void unsetLinksQueryString()
setLinksQueryString(String)
,
getLinksQueryString()
public String getLinksQueryString()
null
.null
.setLinksQueryString(String)
,
unsetLinksQueryString()
,
getURLFactory()
public XWikiValidationStatus getValidationStatus()
public List<String> getDisplayedFields()
display
on a document for a
specific field that field is added to the list returned by this method.Document.display(String)
public void setDisplayMode(String mode)
Document.display(String)
or
Document.display(String, Object)
. It is automatically set to "edit" when the action is "edit" or
"inline", and to "view" in all other cases.mode
- the display mode, one of "view", "edit", "hidden", "search", "rendered".public String getDisplayMode()
Document.display(String)
or
Document.display(String, Object)
.public Object getMacro()
Map
containing the macro content
, the
params
, and the macro execution context
public void dropPermissions()
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)
, and
Document.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.public String getMessage()
public Object getUix()
Copyright © 2004–2022 XWiki. All rights reserved.