Class XWiki


  • public class XWiki
    extends Api
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected static org.slf4j.Logger LOGGER
      Logging helper object.
      • Fields inherited from class com.xpn.xwiki.api.Api

        context
    • Constructor Summary

      Constructors 
      Constructor Description
      XWiki​(XWiki xwiki, XWikiContext context)
      XWiki API Constructor
    • Method Summary

      All Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      String addMandatory()  
      void addToAllGroup​(String fullwikiname)
      Privileged API to add a user to the XWiki.XWikiAllGroup
      String addTooltip​(String html, String message)
      Inserts a tooltip using toolTip.js
      String addTooltip​(String html, String message, String params)
      Inserts a tooltip using toolTip.js
      String addTooltipJS()
      Inserts the tooltip Javascript
      boolean checkAccess​(String docname, String right)
      Verify the rights the current user has on a document.
      XWikiUser checkAuth()
      Check authentication from request and set according persitent login information If it fails user is unlogged
      XWikiUser checkAuth​(String username, String password, String rememberme)
      Check authentication from username and password and set according persitent login information If it fails user is unlogged
      String convertUsername​(String username)
      API to convert the username depending on the configuration The username can be converted from email to a valid XWiki page name hidding the email address The username can be then used to login and link to the right user page
      boolean copyDocument​(String docname, String targetdocname)
      API to copy a document to another document in the same wiki
      boolean copyDocument​(String docname, String targetdocname, String wikilocale)
      API to copy a translation of a document to another document in the same wiki
      boolean copyDocument​(String docname, String sourceWiki, String targetWiki, String wikilocale)
      API to copy a translation of a document to another document of the same name in another wiki
      boolean copyDocument​(String docname, String targetdocname, String sourceWiki, String targetWiki, String wikilocale, boolean reset)
      API to copy a translation of a document to another document of the same name in another wiki additionally resetting the version
      boolean copyDocument​(String docname, String targetdocname, String sourceWiki, String targetWiki, String wikilocale, boolean reset, boolean force)
      API to copy a translation of a document to another document of the same name in another wiki additionally resetting the version and overwriting the previous document
      boolean copyDocument​(DocumentReference sourceDocumentReference, DocumentReference targetDocumentReference, String wikilocale, boolean resetHistory, boolean overwrite)
      API to copy a translation of a document to another document of the same name in another wiki additionally resetting the version and overwriting the previous document
      int copySpaceBetweenWikis​(String space, String sourceWiki, String targetWiki, String locale, boolean clean)
      Privileged API to copy a space to another wiki, optionally deleting all document of the target space
      int countAttachments​(String parametrizedSqlClause, List<?> parameterValues)
      Count attachments returned by a given parameterized query
      Document createDocument()
      API to create an empty document
      int createUser()
      Privileged API to create a new user from the request This API is used by RegisterNewUser wiki page
      int createUser​(boolean withValidation)
      Privileged API to create a new user from the request This API is used by RegisterNewUser wiki page This version sends a validation email to the user Configuration of validation email is in the XWiki Preferences
      int createUser​(boolean withValidation, String userRights)
      Privileged API to create a new user from the request.
      boolean exists​(String fullname)
      Returns whether a document exists or not
      boolean exists​(DocumentReference reference)
      Returns whether a document exists or not
      boolean exists​(PageReference reference)
      Returns whether a page exists or not.
      void flushCache()
      Privileged API to flush the cache of the Wiki installation This flushed the cache of all wikis, all plugins, all renderers
      String formatDate​(Date date)
      API allowing to format a date according to the default Wiki setting The date format is provided in the 'dateformat' parameter of the XWiki Preferences
      String formatDate​(Date date, String format)
      API allowing to format a date according to a custom format The date format is from java.text.SimpleDateFormat Example: "dd/MM/yyyy HH:mm:ss" or "d MMM yyyy" If the format is invalid the default format will be used to show the date
      Api get​(String name)
      Returns a plugin from the plugin API.
      String getAdClientId()
      Returns the Advertisement client ID from the preferences
      String getAdType()
      Returns the Advertisement system from the preferences
      String getAttachmentURL​(String fullname, String filename)
      API to retrieve the URL of an attached file in a Wiki Document The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object For compatibility with any target environment (and especially the portlet environment) It is important to always use the URL functions to generate URL and never hardcode URLs
      List<Locale> getAvailableLocales()
      Get the available locales according to the preferences.
      org.xwiki.rendering.syntax.Syntax getAvailableRendererSyntax​(String syntaxType, String syntaxVersion)
      Find the corresponding available renderer syntax.
      String getBaseSkin()
      API to retrieve the current skin for this request and user.
      Class getClass​(String documentName)
      Get the XWiki Class object defined in the passed Document name.
      Class getClass​(EntityReference docReference)
      Get the XWiki Class object defined in the passed Document name.
      List<String> getClassList()
      Get the list of available classes in the wiki
      String getCounter​(String name)
      Provides an absolute counter
      CriteriaService getCriteriaService()
      API to get the xwiki criteria service which allow to create various criteria : integer ranges, date periods, date intervals, etc.
      String getCurrentContentSyntaxId()
      Get the syntax of the content currently being executed.
      org.xwiki.job.event.status.JobStatus getCurrentInitializerJobStatus()  
      String getDefaultDocumentSyntax()  
      DeletedAttachment getDeletedAttachment​(String id)
      Retrieve a specific attachment from the trash.
      List<DeletedAttachment> getDeletedAttachments​(String docName)
      Retrieve all the deleted attachments that belonged to a certain document.
      List<DeletedAttachment> getDeletedAttachments​(String docName, String filename)
      Retrieve all the deleted attachments that belonged to a certain document and had the specified name.
      DeletedDocument getDeletedDocument​(String index)  
      DeletedDocument getDeletedDocument​(String fullname, String locale, String index)
      Deprecated.
      since 9.4RC1.
      List<DeletedDocument> getDeletedDocuments​(String batchId)  
      List<DeletedDocument> getDeletedDocuments​(String fullname, String locale)  
      Document getDocument​(Document doc, String rev)
      Load a specific revision of a document
      Document getDocument​(String documentReference)
      Loads an Document from the database.
      Document getDocument​(String space, String fullname)
      Loads an Document from the database.
      Document getDocument​(DocumentReference reference)
      Loads a Document from the database.
      Document getDocument​(DocumentReference reference, String revision)
      Load a specific revision of a document
      Document getDocument​(EntityReference reference)
      Loads a Document from the store.
      Document getDocumentAsAuthor​(String fullName)
      Loads an Document from the database.
      Document getDocumentAsAuthor​(DocumentReference reference)
      Loads an Document from the database.
      String getEditorPreference()
      Retrieves the current editor preference for the request The preference is first looked up in the user preference and then in the space and wiki preference
      String getEncoding()
      API to retrieve the current encoding of the wiki engine The encoding is stored in xwiki.cfg Default encoding is ISO-8891-1
      Document getEntityDocument​(String reference, EntityType type)
      Loads an Document from the database.
      List<String> getIncludedMacros​(String defaultSpace, String content)
      Returns the list of Macros documents in the specified content
      String getInterfaceLanguagePreference()
      Deprecated.
      since 8.0M1, use getInterfaceLocalePreference() instead
      Locale getInterfaceLocalePreference()
      API to access the interface locale preference for the request Order of evaluation is: locale of the wiki in mono-lingual mode locale request parameter locale in context locale user preference locale in cookie locale accepted by the navigator
      com.xpn.xwiki.internal.XWikiInitializerJobStatus getJobStatus()  
      String getLanguagePreference()
      Deprecated.
      since 8.0M1, use getLocalePreference() instead
      Locale getLocalePreference()
      First try to find the current locale in use from the XWiki context.
      String getLocalUserName​(String user)
      API to retrieve a link to the User Name page displayed for the first name and last name of the user.
      String getLocalUserName​(String user, boolean link)
      API to retrieve a text representing the user with the first name and last name of the user.
      String getLocalUserName​(String user, String format)
      API to retrieve a link to the User Name page displayed with a custom view.
      String getLocalUserName​(String user, String format, boolean link)
      API to retrieve a text representing the user with a custom view.
      String getMacroList()
      API to get the macro list from the XWiki Preferences The macro list are the macros available from the Macro Mapping System
      MetaClass getMetaclass()
      Get the global MetaClass object
      Object getObjectFromRequest​(String className)
      API to create an object from the request The parameters are the ones that are created from doc.display("field","edit") calls
      String getPlainUserName​(DocumentReference userReference)
      Generate and return an unescaped user display name.
      Api getPlugin​(String name)
      Returns a plugin from the plugin API.
      PropertyClass getPropertyClassFromName​(String propPath)
      API to get the Property object from a class based on a property path A property path looks like XWiki.ArticleClass_fieldname
      String getRefererText​(String referer)
      API to retrieve a viewable referer text for a referer Referers are URL where users have clicked on a link to an XWiki page Search engine referer URLs are transformed to a nicer view (Google: search query string) For other URL the http:// part is stripped
      String getRelativeRequestURL()
      API Allowing to access the current request URL being requested as a relative URL.
      String getRequestURL()
      API Allowing to access the current request URL being requested.
      long getSectionEditingDepth()  
      String getServletPath()
      API to get the Servlet path for the current wiki.
      String getServletPath​(String wikiName)
      API to get the Servlet path for a given wiki.
      String getShortRefererText​(String referer, int length)
      API to retrieve a viewable referer text for a referer with a maximum length Referers are URL where users have clicked on a link to an XWiki page Search engine referer URLs are transformed to a nicer view (Google: search query string) For other URL the http:// part is stripped
      String getSkin()
      API to retrieve the current skin for this request and user The skin is first derived from the request "skin" parameter If this parameter does not exist, the user preference "skin" is looked up If this parameter does not exist or is empty, the space preference "skin" is looked up If this parameter does not exist or is empty, the XWiki preference "skin" is looked up If this parameter does not exist or is empty, the xwiki.cfg parameter xwiki.defaultskin is looked up If this parameter does not exist or is empty, the xwiki.cfg parameter xwiki.defaultbaseskin is looked up If this parameter does not exist or is empty, the skin is "colibri"
      String getSkinFile​(String filename)
      Return the URL of the static file provided by the current skin The file is first looked in the skin active for the user, the space or the wiki.
      String getSkinFile​(String filename, boolean forceSkinAction)
      Return the URL of the static file provided by the current skin The file is first looked in the skin active for the user, the space or the wiki.
      String getSkinPreference​(String preference)
      API to access a Skin Preference The skin object is the current user's skin
      String getSkinPreference​(String preference, String defaultValue)
      API to access a Skin Preference The skin object is the current user's skin
      String getSpaceCopyright()
      API to access the copyright for this space.
      List<String> getSpaceDocsName​(String spaceReference)
      Deprecated.
      use query service instead
      String getSpacePreference​(String preference)
      API to access an Space Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look in the XWiki Preferences
      String getSpacePreference​(String preference, String defaultValue)
      API to access an Space Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look in the XWiki Preferences
      int getSpacePreferenceAsInt​(String preference)
      API to access a Space Preference as a int number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
      int getSpacePreferenceAsInt​(String preference, int defaultValue)
      API to access a space Preference as a int number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
      long getSpacePreferenceAsLong​(String preference)
      API to access a Space Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
      long getSpacePreferenceAsLong​(String preference, long defaultValue)
      API to access a Space Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
      String getSpacePreferenceFor​(String preference, String space)
      Get the reference of the space and fallback on parent space or wiki in case nothing is found.
      String getSpacePreferenceFor​(String preference, String space, String defaultValue)
      Get the reference of the space and fallback on parent space or wiki in case nothing is found.
      String getSpacePreferenceFor​(String preference, SpaceReference spaceReference)
      Get the reference of the space and fallback on parent space or wiki in case nothing is found.
      String getSpacePreferenceFor​(String preference, SpaceReference spaceReference, String defaultValue)
      Get the reference of the space and fallback on parent space or wiki in case nothing is found.
      List<String> getSpaces()
      Deprecated.
      use query service instead
      StatsService getStatsService()
      Access statistics api
      String getTextArea​(String content)
      Output content in the edit content textarea
      String getUniquePageName​(String name)
      Generates a unique page name based on initial page name and already existing pages
      String getUniquePageName​(String space, String name)
      Generates a unique page name based on initial page name and already existing pages
      String getURL​(String fullname)
      API to retrieve the URL of an a Wiki Document in view mode The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object For compatibility with any target environment (and especially the portlet environment) It is important to always use the URL functions to generate URL and never hardcode URLs
      String getURL​(String fullname, String action)
      API to retrieve the URL of an a Wiki Document in any mode.
      String getURL​(String fullname, String action, String querystring)
      API to retrieve the URL of a Wiki Document in any mode, optionally adding a query string The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object.
      String getURL​(String fullname, String action, String querystring, String anchor)
      API to retrieve the URL of an a Wiki Document in any mode, optionally adding an anchor.
      String getURL​(DocumentReference reference)
      API to retrieve the URL of an a Wiki Document in view mode The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object For compatibility with any target environment (and especially the portlet environment) It is important to always use the URL functions to generate URL and never hardcode URLs
      String getURL​(DocumentReference reference, String action, String querystring)
      API to retrieve the URL of a Wiki Document in any mode, optionally adding a query string The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object.
      String getURL​(EntityReference reference)
      Retrieve the URL of an entity using the default mode/action for that entity type.
      String getURL​(EntityReference reference, String action, String querystring)
      API to retrieve the URL of an entity in any mode, optionally adding a query string The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object.
      String getURLContent​(String surl)
      Returns the content of an HTTP/HTTPS URL
      String getURLContent​(String surl, int timeout)
      Returns the content of an HTTP/HTTPS URL
      String getURLContent​(String surl, String username, String password)
      Returns the content of an HTTP/HTTPS URL protected using Basic Authentication
      String getURLContent​(String surl, String username, String password, int timeout)
      Returns the content of an HTTP/HTTPS URL protected using Basic Authentication
      byte[] getURLContentAsBytes​(String surl)
      Returns the content of an HTTP/HTTPS URL as Bytes
      byte[] getURLContentAsBytes​(String surl, String username, String password)
      Returns the content of an HTTP/HTTPS URL protected using Basic Authentication as Bytes
      User getUser()  
      User getUser​(String username)  
      User getUser​(DocumentReference userReference)
      Retrieve a user from its document reference.
      String getUserName​(String user)
      API to retrieve a link to the User Name page displayed for the first name and last name of the user.
      String getUserName​(String user, boolean link)
      API to retrieve a text representing the user with the first name and last name of the user.
      String getUserName​(String user, String format)
      API to retrieve a link to the User Name page displayed with a custom view.
      String getUserName​(String user, String format, boolean link)
      API to retrieve a text representing the user with a custom view With the link param set to false it will not link to the user page.
      String getUserPreference​(String preference)
      API to access a User Preference This function will look in the User profile for the preference If no preference is found it will look in the Space Preferences If no preference is found it will look in the XWiki Preferences
      String getUserPreferenceFromCookie​(String preference)
      API to access a User Preference from cookie This function will look in the session cookie for the preference
      String getUserTimeZone()  
      String getVersion()  
      String getWebAppPath()
      API to get the webapp path for the current wiki.
      List<String> getWikiNames()  
      String getWysiwygToolbars()
      API to check if using which toolbars in Wysiwyg editor
      XWiki getXWiki()
      Privileged API allowing to access the underlying main XWiki Object
      String getXWikiPreference​(String preference)
      API to access an XWiki Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale
      String getXWikiPreference​(String preference, String defaultValue)
      API to access an XWiki Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale
      int getXWikiPreferenceAsInt​(String preference)
      API to access an XWiki Preference as a int number There can be one preference object per locale This function will find the right preference object associated to the current active locale
      int getXWikiPreferenceAsInt​(String preference, int defaultValue)
      API to access an XWiki Preference as an int number There can be one preference object per locale This function will find the right preference object associated to the current active locale
      long getXWikiPreferenceAsLong​(String preference)
      API to access an XWiki Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale
      long getXWikiPreferenceAsLong​(String preference, long defaultValue)
      API to access an XWiki Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale
      boolean hasAccessLevel​(String level)
      API to check rights on the current document for the current user
      boolean hasAccessLevel​(String level, String user, String docname)
      API to check rights on a document for a given user
      boolean hasBacklinks()
      API to check if the backlinks feature is active Backlinks are activated in xwiki.cfg or in the XWiki Preferences
      boolean hasEditComment()
      API to check if the edit comment feature is active Edit comments are activated in xwiki.cfg or in the XWiki Preferences
      boolean hasMinorEdit()
      API to check if the minor edit feature is active minor edit is activated in xwiki.cfg or in the XWiki Preferences
      boolean hasRecycleBin()
      API to check if the recycle bin feature is active recycle bin is activated in xwiki.cfg or in the XWiki Preferences
      boolean hasSectionEdit()  
      boolean hasSubWikis()
      Convenience method to ask if the current XWiki instance contains subwikis (in addition to the main wiki)
      boolean hasTags()
      API to check if the tags feature is active.
      String includeForm​(String topic)
      API to execute a form in the context of an including topic The rendering is evaluated in the context of the including topic All velocity variables are the one of the including topic This api is usually called using #includeForm in a page, which modifies the behavior of "Edit this page" button to direct for Form mode (inline)
      String includeForm​(String topic, boolean pre)
      API to execute a form in the context of an including topic, optionnaly surrounding the content with {pre}{/pre} to avoid future wiki rendering The rendering is evaluated in the context of the including topic All velocity variables are the one of the including topic This api is usually called using #includeForm in a page, which modifies the behavior of "Edit this page" button to direct for Form mode (inline).
      String includeTopic​(String topic)
      API to include a topic into another The topic is rendered fully in the context of itself
      String includeTopic​(String topic, boolean pre)
      API to include a topic into another, optionally surrounding the content with {pre}{/pre} to avoid future wiki rendering.
      boolean isEditCommentFieldHidden()
      API to check if the edit comment field is shown in the edit form Edit comments are activated in xwiki.cfg or in the XWiki Preferences
      boolean isEditCommentMandatory()
      API to check if the edit comment is mandatory (prompted by Javascript if empty) Edit comments are activated in xwiki.cfg or in the XWiki Preferences
      boolean isEditCommentSuggested()
      API to check if the edit comment is suggested (prompted once by Javascript if empty) Edit comments are activated in xwiki.cfg or in the XWiki Preferences
      boolean isMultiLingual()
      API to check is wiki is multi-lingual
      boolean isReadOnly()
      returns true if xwiki.readonly is set in the configuration file
      boolean isTitleInCompatibilityMode()  
      String parseContent​(String content)
      Deprecated.
      Since 7.2M1.
      Object parseGroovyFromPage​(String fullname)
      Privileged API to retrieve an object instanciated from groovy code in a String Groovy scripts compilation is cached
      Object parseGroovyFromPage​(String script, String jarWikiPage)
      Privileged API to retrieve an object instantiated from groovy code in a String, using a classloader including all JAR files located in the passed page as attachments.
      Object parseGroovyFromString​(String script)
      Privileged API to retrieve an object instantiated from groovy code in a String.
      String parseTemplate​(String template)
      API to parse a velocity template provided by the current Skin The template is first looked in the skin active for the user, the space or the wiki.
      void refreshLinks()
      Priviledge API to regenerate the links/backlinks table Normally links and backlinks are stored when a page is modified This function will regenerate all the backlinks This function can be long to run
      boolean renameDocument​(DocumentReference sourceDocumentReference, DocumentReference targetDocumentReference, boolean overwrite, List<DocumentReference> backlinkDocumentReferences, List<DocumentReference> childDocumentReferences)
      API to rename a document to another document.
      String renderTemplate​(String template)
      API to render a velocity template provided by the current Skin The template is first looked in the skin active for the user, the space or the wiki.
      List<Attachment> searchAttachments​(String parametrizedSqlClause, int nb, int start, List<?> parameterValues)
      Search attachments by passing HQL where clause values as parameters.
      List<String> searchDocuments​(String wheresql)
      Deprecated.
      use query service instead
      List<Document> searchDocuments​(String wheresql, boolean distinctbylocale)
      API allowing to search for documents allowing to have mutliple entries per locale
      List<Document> searchDocuments​(String wheresql, boolean distinctbylocale, int nb, int start)
      API allowing to search for documents allowing to have multiple entries per locale
      List<String> searchDocuments​(String wheresql, int nb, int start)
      Deprecated.
      use query service instead
      List<String> searchDocuments​(String wheresql, int nb, int start, String selectColumns)
      Deprecated.
      use query service instead
      List<String> searchDocuments​(String parameterizedWhereClause, int maxResults, int startOffset, List<?> parameterValues)
      Deprecated.
      use query service instead
      List<String> searchDocuments​(String parameterizedWhereClause, List<?> parameterValues)
      Deprecated.
      use query service instead
      List<String> searchDocumentsNames​(String wikiName, String parameterizedWhereClause, int maxResults, int startOffset, List<?> parameterValues)
      Deprecated.
      use query service instead
      List<String> searchSpacesNames​(String parametrizedSqlClause, int nb, int start, List<?> parameterValues)
      Search spaces by passing HQL where clause values as parameters.
      void sendConfirmationMail​(String xwikiname, String password, String email, String contentfield)
      Privileged API to send a confirmation email to a user
      void sendConfirmationMail​(String xwikiname, String password, String email, String add_message, String contentfield)
      Privileged API to send a confirmation email to a user
      void setReadOnly​(boolean ro)
      Privileged API to set/unset the readonly status of the Wiki After setting this to true no writing to the database will be performed All Edit buttons will be removed and save actions disabled This is used for maintenance purposes
      int validateUser​(boolean withConfirmEmail)
      Privileged API to validate the return code given by a user in response to an email validation email The validation information are taken from the request object
      List<Document> wrapDocs​(List<?> docs)
      Function to wrap a list of XWikiDocument into Document objects
    • Field Detail

      • LOGGER

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

      • XWiki

        public XWiki​(XWiki xwiki,
                     XWikiContext context)
        XWiki API Constructor
        Parameters:
        xwiki - XWiki Main Object to wrap
        context - XWikiContext to wrap
    • Method Detail

      • getXWiki

        @Programming
        public XWiki getXWiki()
        Privileged API allowing to access the underlying main XWiki Object
        Returns:
        Privileged Main XWiki Object
      • getJobStatus

        public com.xpn.xwiki.internal.XWikiInitializerJobStatus getJobStatus()
        Returns:
        the status of the job initializing XWiki instance
        Since:
        6.1M1
      • getCurrentInitializerJobStatus

        public org.xwiki.job.event.status.JobStatus getCurrentInitializerJobStatus()
        Returns:
        the status of the job initializing the instance or the current wiki
        Since:
        8.4RC1
      • getVersion

        public String getVersion()
        Returns:
        XWiki's version in the format (version).(SVN build number), or "Unknown version" if it failed to be retrieved
      • getRequestURL

        public String getRequestURL()
                             throws XWikiException
        API Allowing to access the current request URL being requested.
        Returns:
        the URL
        Throws:
        XWikiException - failed to create the URL
      • getRelativeRequestURL

        public String getRelativeRequestURL()
                                     throws XWikiException
        API Allowing to access the current request URL being requested as a relative URL.
        Returns:
        the URL
        Throws:
        XWikiException - failed to create the URL
        Since:
        4.0M1
      • getEntityDocument

        public Document getEntityDocument​(String reference,
                                          EntityType type)
                                   throws XWikiException
        Loads an Document from the database. Rights are checked before sending back the document.
        Parameters:
        reference - the reference of the document to be loaded
        type - the type of the reference
        Returns:
        a Document object (if the document couldn't be found a new one is created in memory - but not saved, you can check whether it's a new document or not by using Document.isNew()
        Throws:
        XWikiException
        Since:
        10.6RC1
      • getDocument

        public Document getDocument​(DocumentReference reference)
                             throws XWikiException
        Loads a Document from the database. Rights are checked before sending back the document.
        Parameters:
        reference - the reference of the XWiki document to be loaded
        Returns:
        a Document object (if the document couldn't be found a new one is created in memory - but not saved, you can check whether it's a new document or not by using Document.isNew()
        Throws:
        XWikiException
        Since:
        2.3M1
      • getDocument

        public Document getDocument​(EntityReference reference)
                             throws XWikiException
        Loads a Document from the store. Rights are checked before sending back the document.

        The passed reference can be anything. If if a document child, the document reference will be extracted from it. If it's a document parent it will be completed with the necessary default references (for example if it's a space reference it will load the space home page).

        Parameters:
        reference - the reference close to the XWiki document to be loaded
        Returns:
        a Document object (if the document couldn't be found a new one is created in memory - but not saved, you can check whether it's a new document or not by using Document.isNew()
        Throws:
        XWikiException
        Since:
        7.1M2
      • getDocumentAsAuthor

        public Document getDocumentAsAuthor​(String fullName)
                                     throws XWikiException
        Loads an Document from the database. Rights are checked on the author (contentAuthor) of the document containing the currently executing script before sending back the loaded document.
        Parameters:
        fullName - the full name of the XWiki document to be loaded
        Returns:
        a Document object (if the document couldn't be found a new one is created in memory - but not saved, you can check whether it's a new document or not by using Document.isNew()
        Throws:
        XWikiException
        Since:
        2.3M2
      • getDocumentAsAuthor

        public Document getDocumentAsAuthor​(DocumentReference reference)
                                     throws XWikiException
        Loads an Document from the database. Rights are checked on the author (contentAuthor) of the document containing the currently executing script before sending back the loaded document.
        Parameters:
        reference - the reference of the XWiki document to be loaded
        Returns:
        a Document object (if the document couldn't be found a new one is created in memory - but not saved, you can check whether it's a new document or not by using Document.isNew()
        Throws:
        XWikiException
        Since:
        2.3M2
      • getDeletedDocuments

        public List<DeletedDocument> getDeletedDocuments​(String fullname,
                                                         String locale)
                                                  throws XWikiException
        Parameters:
        fullname - the name of the document to search for.
        locale - an optional locale to filter results.
        Returns:
        A list with all the deleted versions of a document in the recycle bin.
        Throws:
        XWikiException - if any error
      • getDeletedDocuments

        public List<DeletedDocument> getDeletedDocuments​(String batchId)
                                                  throws XWikiException
        Parameters:
        batchId - id of the operation that deleted multiple documents at the same time; useful when trying to revert the operation
        Returns:
        a list of all document versions that were deleted in the same batch, as part of the same operation
        Throws:
        XWikiException - if any error
        Since:
        9.4RC1
      • getDeletedAttachments

        public List<DeletedAttachment> getDeletedAttachments​(String docName)
        Retrieve all the deleted attachments that belonged to a certain document. Note that this does not distinguish between different incarnations of a document name, and it does not require that the document still exists, it returns all the attachments that at the time of their deletion had a document with the specified name as their owner.
        Parameters:
        docName - the name of the owner document
        Returns:
        A list with all the deleted attachments which belonged to the specified document. If no such attachments are found in the trash, an empty list is returned.
      • getDeletedAttachments

        public List<DeletedAttachment> getDeletedAttachments​(String docName,
                                                             String filename)
        Retrieve all the deleted attachments that belonged to a certain document and had the specified name. Multiple versions can be returned since the same file can be uploaded and deleted several times, creating different instances in the trash. Note that this does not distinguish between different incarnations of a document name, and it does not require that the document still exists, it returns all the attachments that at the time of their deletion had a document with the specified name as their owner.
        Parameters:
        docName - the name of the document the attachment belonged to
        filename - the name of the attachment to search for
        Returns:
        A list with all the deleted attachments which belonged to the specified document and had the specified filename. If no such attachments are found in the trash, an empty list is returned.
      • getDeletedAttachment

        public DeletedAttachment getDeletedAttachment​(String id)
        Retrieve a specific attachment from the trash.
        Parameters:
        id - the unique identifier of the entry in the trash
        Returns:
        specified attachment from the trash, null if not found
      • exists

        public boolean exists​(String fullname)
                       throws XWikiException
        Returns whether a document exists or not
        Parameters:
        fullname - Fullname of the XWiki document to be loaded
        Returns:
        true if the document exists, false if not
        Throws:
        XWikiException
      • exists

        public boolean exists​(DocumentReference reference)
                       throws XWikiException
        Returns whether a document exists or not
        Parameters:
        reference - the reference of the document to check for its existence
        Returns:
        true if the document exists, false if not
        Throws:
        XWikiException
        Since:
        2.3M2
      • exists

        @Unstable
        public boolean exists​(PageReference reference)
        Returns whether a page exists or not.
        Parameters:
        reference - the reference of the page to check for its existence
        Returns:
        true if the page exists, false if not
        Since:
        13.3RC1, 12.10.7
      • checkAccess

        public boolean checkAccess​(String docname,
                                   String right)
        Verify the rights the current user has on a document. If the document requires rights and the user is not authenticated he will be redirected to the login page.
        Parameters:
        docname - fullname of the document
        right - right to check ("view", "edit", "admin", "delete")
        Returns:
        true if it exists
      • getDocument

        public Document getDocument​(String space,
                                    String fullname)
                             throws XWikiException
        Loads an Document from the database. Rights are checked before sending back the document.
        Parameters:
        space - Space to use in case no space is defined in the provided fullname
        fullname - the full name or relative name of the document to load
        Returns:
        a Document object (if the document couldn't be found a new one is created in memory - but not saved, you can check whether it's a new document or not by using Document.isNew()
        Throws:
        XWikiException
      • getDocument

        public Document getDocument​(Document doc,
                                    String rev)
                             throws XWikiException
        Load a specific revision of a document
        Parameters:
        doc - Document for which to load a specific revision
        rev - Revision number
        Returns:
        Specific revision of a document
        Throws:
        XWikiException - is never thrown
      • getDocument

        public Document getDocument​(DocumentReference reference,
                                    String revision)
                             throws XWikiException
        Load a specific revision of a document
        Parameters:
        reference - Document for which to load a specific revision
        revision - Revision number
        Returns:
        Specific revision of a document
        Throws:
        XWikiException - is never thrown
        Since:
        9.4RC1
      • getTextArea

        public String getTextArea​(String content)
        Output content in the edit content textarea
        Parameters:
        content - content to output
        Returns:
        the textarea text content
      • getMetaclass

        public MetaClass getMetaclass()
        Get the global MetaClass object
        Returns:
        MetaClass object
      • searchDocuments

        @Deprecated
        public List<String> searchDocuments​(String wheresql)
                                     throws XWikiException
        Deprecated.
        use query service instead
        API allowing to search for document names matching a query. Examples:
        • Query: where doc.space='Main' order by doc.creationDate desc. Result: All the documents in space 'Main' ordered by the creation date from the most recent
        • Query: where doc.name like '%sport%' order by doc.name asc. Result: All the documents containing 'sport' in their name ordered by document name
        • Query: where doc.content like '%sport%' order by doc.author Result: All the documents containing 'sport' in their content ordered by the author
        • Query: where doc.creator = 'XWiki.LudovicDubost' order by doc.creationDate desc. Result: All the documents with creator LudovicDubost ordered by the creation date from the most recent
        • Query: where doc.author = 'XWiki.LudovicDubost' order by doc.date desc. Result: All the documents with last author LudovicDubost ordered by the last modification date from the most recent.
        • Query: ,BaseObject as obj where doc.fullName=obj.name and obj.className='XWiki.XWikiComments' order by doc.date desc. Result: All the documents with at least one comment ordered by the last modification date from the most recent
        • Query: ,BaseObject as obj, StringProperty as prop where doc.fullName=obj.name and obj.className='XWiki.XWikiComments' and obj.id=prop.id.id and prop.id.name='author' and prop.value='XWiki.LudovicDubost' order by doc.date desc. Result: All the documents with at least one comment from LudovicDubost ordered by the last modification date from the most recent
        Parameters:
        wheresql - Query to be run (either starting with ", BaseObject as obj where.." or by "where ..."
        Returns:
        List of document names matching (Main.Page1, Main.Page2)
        Throws:
        XWikiException
      • searchDocuments

        @Deprecated
        public List<String> searchDocuments​(String wheresql,
                                            int nb,
                                            int start)
                                     throws XWikiException
        Deprecated.
        use query service instead
        API allowing to search for document names matching a query return only a limited number of elements and skipping the first rows. The query part is the same as searchDocuments
        Parameters:
        wheresql - query to use similar to searchDocuments(wheresql)
        nb - return only 'nb' rows
        start - skip the first 'start' rows
        Returns:
        List of document names matching
        Throws:
        XWikiException
        See Also:
        searchDocuments(String where sql)
      • searchDocuments

        @Deprecated
        public List<String> searchDocuments​(String wheresql,
                                            int nb,
                                            int start,
                                            String selectColumns)
                                     throws XWikiException
        Deprecated.
        use query service instead
        Privileged API allowing to search for document names matching a query return only a limited number of elements and skipping the first rows. The return values contain the list of columns specified in addition to the document space and name The query part is the same as searchDocuments
        Parameters:
        wheresql - query to use similar to searchDocuments(wheresql)
        nb - return only 'nb' rows
        start - skip the first 'start' rows
        selectColumns - List of columns to add to the result
        Returns:
        List of Object[] with the column values of the matching rows
        Throws:
        XWikiException
      • searchDocuments

        public List<Document> searchDocuments​(String wheresql,
                                              boolean distinctbylocale)
                                       throws XWikiException
        API allowing to search for documents allowing to have mutliple entries per locale
        Parameters:
        wheresql - query to use similar to searchDocuments(wheresql)
        distinctbylocale - true to return multiple rows per locale
        Returns:
        List of Document object matching
        Throws:
        XWikiException
      • searchDocuments

        public List<Document> searchDocuments​(String wheresql,
                                              boolean distinctbylocale,
                                              int nb,
                                              int start)
                                       throws XWikiException
        API allowing to search for documents allowing to have multiple entries per locale
        Parameters:
        wheresql - query to use similar to searchDocuments(wheresql)
        distinctbylocale - true to return multiple rows per locale
        nb - return only 'nb' rows
        start - skip the first 'start' rows
        Returns:
        List of Document object matching
        Throws:
        XWikiException
      • searchDocuments

        @Deprecated
        public List<String> searchDocuments​(String parameterizedWhereClause,
                                            int maxResults,
                                            int startOffset,
                                            List<?> parameterValues)
                                     throws XWikiException
        Deprecated.
        use query service instead
        Search documents by passing HQL where clause values as parameters. This allows generating a Named HQL query which will automatically encode the passed values (like escaping single quotes). This API is recommended to be used over the other similar methods where the values are passed inside the where clause and for which you'll need to do the encoding/escaping yourself before calling them.

        Example

         <code>
         #set($orphans = $xwiki.searchDocuments(" where doc.fullName <> ?1 and (doc.parent = ?2 or "
             + "(doc.parent = ?3 and doc.space = ?4))",
             ["${doc.fullName}as", ${doc.fullName}, ${doc.name}, ${doc.space}]))
         </code>
         
        Parameters:
        parameterizedWhereClause - the HQL where clause. For example where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        maxResults - the number of rows to return. If 0 then all rows are returned
        startOffset - the number of rows to skip. If 0 don't skip any row
        parameterValues - the where clause values that replace the question marks (?1, ?2, etc.)
        Returns:
        a list of document names
        Throws:
        XWikiException - in case of error while performing the query
      • searchDocumentsNames

        @Deprecated
        public List<String> searchDocumentsNames​(String wikiName,
                                                 String parameterizedWhereClause,
                                                 int maxResults,
                                                 int startOffset,
                                                 List<?> parameterValues)
                                          throws XWikiException
        Deprecated.
        use query service instead
        Search documents in the provided wiki by passing HQL where clause values as parameters. See searchDocuments(String, int, int, java.util.List) for more details.
        Parameters:
        wikiName - the name of the wiki where to search.
        parameterizedWhereClause - the HQL where clause. For example where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        maxResults - the number of rows to return. If 0 then all rows are returned
        startOffset - the number of rows to skip. If 0 don't skip any row
        parameterValues - the where clause values that replace the question marks (?)
        Returns:
        a list of document full names (Space.Name).
        Throws:
        XWikiException - in case of error while performing the query
        See Also:
        searchDocuments(String, int, int, java.util.List)
      • searchSpacesNames

        public List<String> searchSpacesNames​(String parametrizedSqlClause,
                                              int nb,
                                              int start,
                                              List<?> parameterValues)
                                       throws XWikiException
        Search spaces by passing HQL where clause values as parameters. See searchDocuments(String, int, int, List) for more about parameterized hql clauses.
        Parameters:
        parametrizedSqlClause - the HQL where clause. For example where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        nb - the number of rows to return. If 0 then all rows are returned
        start - the number of rows to skip. If 0 don't skip any row
        parameterValues - the where clause values that replace the question marks (?)
        Returns:
        a list of spaces names.
        Throws:
        XWikiException - in case of error while performing the query
      • searchAttachments

        public List<Attachment> searchAttachments​(String parametrizedSqlClause,
                                                  int nb,
                                                  int start,
                                                  List<?> parameterValues)
                                           throws XWikiException
        Search attachments by passing HQL where clause values as parameters. See searchDocuments(String, int, int, List) for more about parameterized hql clauses. You can specify properties of attach (the attachment) or doc (the document it is attached to)
        Parameters:
        parametrizedSqlClause - The HQL where clause. For example where doc.fullName <> ?1 and (doc.parent = ?2 or (doc.parent = ?3 and doc.space = ?4))
        nb - The number of rows to return. If 0 then all rows are returned
        start - The number of rows to skip at the beginning.
        parameterValues - A List of the where clause values that replace the question marks (?)
        Returns:
        A List of Attachment objects.
        Throws:
        XWikiException - in case of error while performing the query
        Since:
        5.0M2
      • wrapDocs

        public List<Document> wrapDocs​(List<?> docs)
        Function to wrap a list of XWikiDocument into Document objects
        Parameters:
        docs - list of XWikiDocument
        Returns:
        list of Document objects
      • parseContent

        @Deprecated
        public String parseContent​(String content)
        Deprecated.
        Since 7.2M1. Use specific rendering/parsing options for the content type you want to parse/render.
        API allowing to parse a text content to evaluate velocity scripts
        Parameters:
        content -
        Returns:
        evaluated content if the content contains velocity scripts
      • parseTemplate

        public String parseTemplate​(String template)
        API to parse a velocity template provided by the current Skin The template is first looked in the skin active for the user, the space or the wiki. If the template does not exist in that skin, the template is looked up in the "parent skin" of the skin
        Parameters:
        template - Template name ("view", "edit", "comment")
        Returns:
        Evaluated content from the template
      • renderTemplate

        public String renderTemplate​(String template)
        API to render a velocity template provided by the current Skin The template is first looked in the skin active for the user, the space or the wiki. If the template does not exist in that skin, the template is looked up in the "parent skin" of the skin
        Parameters:
        template - Template name ("view", "edit", "comment")
        Returns:
        Evaluated content from the template
      • getSkinFile

        public String getSkinFile​(String filename)
        Return the URL of the static file provided by the current skin The file is first looked in the skin active for the user, the space or the wiki. If the file does not exist in that skin, the file is looked up in the "parent skin" of the skin. The file can be a CSS file, an image file, a javascript file, etc.
        Parameters:
        filename - Filename to be looked up in the skin (logo.gif, style.css)
        Returns:
        URL to access this file
      • getSkinFile

        public String getSkinFile​(String filename,
                                  boolean forceSkinAction)
        Return the URL of the static file provided by the current skin The file is first looked in the skin active for the user, the space or the wiki. If the file does not exist in that skin, the file is looked up in the "parent skin" of the skin. The file can be a CSS file, an image file, a javascript file, etc.
        Parameters:
        filename - Filename to be looked up in the skin (logo.gif, style.css)
        forceSkinAction - true to make sure that static files are retrieved through the skin action, to allow parsing of velocity on CSS files
        Returns:
        URL to access this file
      • getSkin

        public String getSkin()
        API to retrieve the current skin for this request and user The skin is first derived from the request "skin" parameter If this parameter does not exist, the user preference "skin" is looked up If this parameter does not exist or is empty, the space preference "skin" is looked up If this parameter does not exist or is empty, the XWiki preference "skin" is looked up If this parameter does not exist or is empty, the xwiki.cfg parameter xwiki.defaultskin is looked up If this parameter does not exist or is empty, the xwiki.cfg parameter xwiki.defaultbaseskin is looked up If this parameter does not exist or is empty, the skin is "colibri"
        Returns:
        The current skin for this request and user
      • getBaseSkin

        public String getBaseSkin()
        API to retrieve the current skin for this request and user. Each skin has a skin it is based on. If not the base skin is the xwiki.cfg parameter "xwiki.defaultbaseskin". If this parameter does not exist or is empty, the base skin is "colibri".
        Returns:
        The current baseskin for this request and user
      • getSpaceCopyright

        public String getSpaceCopyright()
        API to access the copyright for this space. The copyright is read in the space preferences. If it does not exist or is empty it is read from the XWiki preferences.
        Returns:
        the text for the copyright
      • getXWikiPreference

        public String getXWikiPreference​(String preference)
        API to access an XWiki Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale
      • getXWikiPreference

        public String getXWikiPreference​(String preference,
                                         String defaultValue)
        API to access an XWiki Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale
        Parameters:
        preference - Preference name
        defaultValue - default value to return if the preference does not exist or is empty
        Returns:
        The preference for this wiki and the current locale
      • getSpacePreference

        public String getSpacePreference​(String preference)
        API to access an Space Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look in the XWiki Preferences
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale
      • getSpacePreference

        public String getSpacePreference​(String preference,
                                         String defaultValue)
        API to access an Space Preference There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look in the XWiki Preferences
        Parameters:
        preference - Preference name
        defaultValue - default value to return if the preference does not exist or is empty
        Returns:
        The preference for this wiki and the current locale
      • getSkinPreference

        public String getSkinPreference​(String preference)
        API to access a Skin Preference The skin object is the current user's skin
        Parameters:
        preference - Preference name
        Returns:
        The preference for the current skin
      • getSkinPreference

        public String getSkinPreference​(String preference,
                                        String defaultValue)
        API to access a Skin Preference The skin object is the current user's skin
        Parameters:
        preference - Preference name
        defaultValue - default value to return if the preference does not exist or is empty
        Returns:
        The preference for the current skin
      • getSpacePreferenceFor

        public String getSpacePreferenceFor​(String preference,
                                            String space)
        Get the reference of the space and fallback on parent space or wiki in case nothing is found.

        If the property is not set on any level then empty String is returned.

        Parameters:
        preference - Preference name
        space - The space for which this preference is requested
        Returns:
        The preference for this wiki and the current locale
      • getSpacePreferenceFor

        public String getSpacePreferenceFor​(String preference,
                                            String space,
                                            String defaultValue)
        Get the reference of the space and fallback on parent space or wiki in case nothing is found.

        If the property is not set on any level then defaultValue is returned.

        Parameters:
        preference - Preference name
        space - The space for which this preference is requested
        defaultValue - default value to return if the preference does not exist or is empty
        Returns:
        The preference for this wiki and the current locale in long format
      • getSpacePreferenceFor

        public String getSpacePreferenceFor​(String preference,
                                            SpaceReference spaceReference)
        Get the reference of the space and fallback on parent space or wiki in case nothing is found.

        If the property is not set on any level then empty String is returned.

        Parameters:
        preference - the name of the preference key
        spaceReference - the reference of the space
        Returns:
        the value of the preference or empty String if it could not be found
        Since:
        7.4M1
      • getSpacePreferenceFor

        public String getSpacePreferenceFor​(String preference,
                                            SpaceReference spaceReference,
                                            String defaultValue)
        Get the reference of the space and fallback on parent space or wiki in case nothing is found.

        If the property is not set on any level then defaultValue is returned.

        Parameters:
        preference - the name of the preference key
        spaceReference - the reference of the space
        defaultValue - the value to return if the preference can't be found
        Returns:
        the value of the preference or defaultValue if it could not be found
        Since:
        7.4M1
      • getXWikiPreferenceAsLong

        public long getXWikiPreferenceAsLong​(String preference,
                                             long defaultValue)
        API to access an XWiki Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale
        Parameters:
        preference - Preference name
        defaultValue - default value to return if the preference does not exist or is empty
        Returns:
        The preference for this wiki and the current locale in long format
      • getXWikiPreferenceAsLong

        public long getXWikiPreferenceAsLong​(String preference)
        API to access an XWiki Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale in long format
      • getSpacePreferenceAsLong

        public long getSpacePreferenceAsLong​(String preference,
                                             long defaultValue)
        API to access a Space Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
        Parameters:
        preference - Preference name
        defaultValue - default value to return if the prefenrece does not exist or is empty
        Returns:
        The preference for this wiki and the current locale in long format
      • getSpacePreferenceAsLong

        public long getSpacePreferenceAsLong​(String preference)
        API to access a Space Preference as a long number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale in long format
      • getXWikiPreferenceAsInt

        public int getXWikiPreferenceAsInt​(String preference,
                                           int defaultValue)
        API to access an XWiki Preference as an int number There can be one preference object per locale This function will find the right preference object associated to the current active locale
        Parameters:
        preference - Preference name
        defaultValue - default value to return if the prefenrece does not exist or is empty
        Returns:
        The preference for this wiki and the current locale in int format
      • getXWikiPreferenceAsInt

        public int getXWikiPreferenceAsInt​(String preference)
        API to access an XWiki Preference as a int number There can be one preference object per locale This function will find the right preference object associated to the current active locale
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale in int format
      • getSpacePreferenceAsInt

        public int getSpacePreferenceAsInt​(String preference,
                                           int defaultValue)
        API to access a space Preference as a int number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
        Parameters:
        preference - Preference name
        defaultValue - default value to return if the prefenrece does not exist or is empty
        Returns:
        The preference for this wiki and the current locale in int format
      • getSpacePreferenceAsInt

        public int getSpacePreferenceAsInt​(String preference)
        API to access a Space Preference as a int number There can be one preference object per locale This function will find the right preference object associated to the current active locale If no preference is found it will look for the XWiki Preference
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale in int format
      • getUserPreference

        public String getUserPreference​(String preference)
        API to access a User Preference This function will look in the User profile for the preference If no preference is found it will look in the Space Preferences If no preference is found it will look in the XWiki Preferences
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale
      • getUserPreferenceFromCookie

        public String getUserPreferenceFromCookie​(String preference)
        API to access a User Preference from cookie This function will look in the session cookie for the preference
        Parameters:
        preference - Preference name
        Returns:
        The preference for this wiki and the current locale
      • getLocalePreference

        public Locale getLocalePreference()
        First try to find the current locale in use from the XWiki context. If none is used and if the wiki is not multilingual use the default locale defined in the XWiki preferences. If the wiki is multilingual try to get the locale passed in the request. If none was passed try to get it from a cookie. If no locale cookie exists then use the user default locale and barring that use the browser's "Accept-Language" header sent in HTTP request. If none is defined use the default locale.
        Returns:
        the locale to use
        Since:
        8.0M1
      • getInterfaceLocalePreference

        public Locale getInterfaceLocalePreference()
        API to access the interface locale preference for the request Order of evaluation is: locale of the wiki in mono-lingual mode locale request parameter locale in context locale user preference locale in cookie locale accepted by the navigator
        Returns:
        the document locale preference for the request
      • getAvailableLocales

        public List<Locale> getAvailableLocales()
        Get the available locales according to the preferences.
        Returns:
        the list of available locales
        Since:
        12.4RC1
      • getWikiNames

        public List<String> getWikiNames()
        Returns:
        the list of all wiki names, including the main wiki, corresponding to the available wiki descriptors. Example: the descriptor for the wiki wikiname is a document in the main wiki, named XWiki.XWikiServerWikiname, containing an XWiki.XWikiServerClass object.
        See Also:
        XWiki.getVirtualWikisDatabaseNames(XWikiContext)
      • hasSubWikis

        public boolean hasSubWikis()
        Convenience method to ask if the current XWiki instance contains subwikis (in addition to the main wiki)
        Returns:
        true if at least 1 subwiki exists; false otherwise
        See Also:
        getWikiNames()
      • isMultiLingual

        public boolean isMultiLingual()
        API to check is wiki is multi-lingual
        Returns:
        true for multi-lingual/false for mono-lingual
      • flushCache

        public void flushCache()
        Privileged API to flush the cache of the Wiki installation This flushed the cache of all wikis, all plugins, all renderers
      • createUser

        public int createUser()
                       throws XWikiException
        Privileged API to create a new user from the request This API is used by RegisterNewUser wiki page
        Returns:
        the integer status code
        • 1: ok
        • -2: passwords are different or password is empty
        • -3: user already exists
        • -4: invalid username provided
        • -8: user already exists
        Throws:
        XWikiException
      • createUser

        public int createUser​(boolean withValidation)
                       throws XWikiException
        Privileged API to create a new user from the request This API is used by RegisterNewUser wiki page This version sends a validation email to the user Configuration of validation email is in the XWiki Preferences
        Parameters:
        withValidation - true to send the validationemail
        Returns:
        the integer status code
        • 1: ok
        • -2: passwords are different or password is empty
        • -3: user already exists
        • -4: invalid username provided
        • -8: user already exists
        Throws:
        XWikiException
      • createUser

        public int createUser​(boolean withValidation,
                              String userRights)
                       throws XWikiException
        Privileged API to create a new user from the request.

        This API is used by the RegisterNewUser wiki page.

        This version sends a validation email to the user. Configuration of validation email is in the XWiki Preferences.

        Parameters:
        withValidation - true to send the validation email
        userRights - Rights to set for the user for it's own page(defaults to "edit")
        Returns:
        the integer status code
        • 1: ok
        • -2: passwords are different or password is empty
        • -3: user already exists
        • -4: invalid username provided
        • -8: user already exists
        Throws:
        XWikiException
      • validateUser

        public int validateUser​(boolean withConfirmEmail)
                         throws XWikiException
        Privileged API to validate the return code given by a user in response to an email validation email The validation information are taken from the request object
        Parameters:
        withConfirmEmail - true to send a account confirmation email/false to not send it
        Returns:
        Success of Failure code (0 for success, -1 for missing programming rights, > 0 for other errors
        Throws:
        XWikiException
      • addToAllGroup

        public void addToAllGroup​(String fullwikiname)
                           throws XWikiException
        Privileged API to add a user to the XWiki.XWikiAllGroup
        Parameters:
        fullwikiname - user name to add
        Throws:
        XWikiException
      • sendConfirmationMail

        public void sendConfirmationMail​(String xwikiname,
                                         String password,
                                         String email,
                                         String add_message,
                                         String contentfield)
                                  throws XWikiException
        Privileged API to send a confirmation email to a user
        Parameters:
        xwikiname - user to send the email to
        password - password to put in the mail
        email - email to send to
        add_message - Additional message to send to the user
        contentfield - Preference field to use as a mail template
        Throws:
        XWikiException - if the mail was not send successfully
      • sendConfirmationMail

        public void sendConfirmationMail​(String xwikiname,
                                         String password,
                                         String email,
                                         String contentfield)
                                  throws XWikiException
        Privileged API to send a confirmation email to a user
        Parameters:
        xwikiname - user to send the email to
        password - password to put in the mail
        email - email to send to
        contentfield - Preference field to use as a mail template
        Throws:
        XWikiException - if the mail was not send successfully
      • renameDocument

        public boolean renameDocument​(DocumentReference sourceDocumentReference,
                                      DocumentReference targetDocumentReference,
                                      boolean overwrite,
                                      List<DocumentReference> backlinkDocumentReferences,
                                      List<DocumentReference> childDocumentReferences)
                               throws XWikiException
        API to rename a document to another document. Note that the list of backlinks can be retrieved with Document.getBackLinkedReferences() and the list of children with Document.getChildrenReferences(). Warning: Be aware that this method never triggers any event related to the rename of the document. If you want the right events to be sent for the event, please use the dedicated Refactoring Module API (see RequestFactory.createRenameRequest(EntityReference, EntityReference) and MoveRequest).
        Parameters:
        sourceDocumentReference - the source document to rename.
        targetDocumentReference - the target reference to rename the document to.
        overwrite - if true the target document reference will be overwritten if it exists (deleted to the recycle bin before the rename). If false and the target document exist the rename won't be performed.
        backlinkDocumentReferences - the list of references of documents to parse and for which links will be modified to point to the new document reference
        childDocumentReferences - the list of references of document whose parent field will be set to the new document reference
        Returns:
        true if the rename succeeded. false if there was any issue.
        Throws:
        XWikiException - if the document cannot be renamed properly.
        Since:
        12.5RC1
      • copyDocument

        public boolean copyDocument​(String docname,
                                    String targetdocname)
                             throws XWikiException
        API to copy a document to another document in the same wiki
        Parameters:
        docname - source document
        targetdocname - target document
        Returns:
        true if the copy was sucessfull
        Throws:
        XWikiException - if the document was not copied properly
      • copyDocument

        public boolean copyDocument​(String docname,
                                    String targetdocname,
                                    String wikilocale)
                             throws XWikiException
        API to copy a translation of a document to another document in the same wiki
        Parameters:
        docname - source document
        targetdocname - target document
        wikilocale - locale to copy
        Returns:
        true if the copy was sucessfull
        Throws:
        XWikiException - if the document was not copied properly
      • copyDocument

        public boolean copyDocument​(String docname,
                                    String sourceWiki,
                                    String targetWiki,
                                    String wikilocale)
                             throws XWikiException
        API to copy a translation of a document to another document of the same name in another wiki
        Parameters:
        docname - source document
        sourceWiki - source wiki
        targetWiki - target wiki
        wikilocale - locale to copy
        Returns:
        true if the copy was sucessfull
        Throws:
        XWikiException - if the document was not copied properly
      • copyDocument

        public boolean copyDocument​(String docname,
                                    String targetdocname,
                                    String sourceWiki,
                                    String targetWiki,
                                    String wikilocale,
                                    boolean reset)
                             throws XWikiException
        API to copy a translation of a document to another document of the same name in another wiki additionally resetting the version
        Parameters:
        docname - source document
        sourceWiki - source wiki
        targetWiki - target wiki
        wikilocale - locale to copy
        reset - true to reset versions
        Returns:
        true if the copy was sucessfull
        Throws:
        XWikiException - if the document was not copied properly
      • copyDocument

        public boolean copyDocument​(String docname,
                                    String targetdocname,
                                    String sourceWiki,
                                    String targetWiki,
                                    String wikilocale,
                                    boolean reset,
                                    boolean force)
                             throws XWikiException
        API to copy a translation of a document to another document of the same name in another wiki additionally resetting the version and overwriting the previous document
        Parameters:
        docname - source document name
        targetdocname - target document name
        sourceWiki - source wiki
        targetWiki - target wiki
        wikilocale - locale to copy
        reset - true to reset versions
        force - true to overwrite the previous document
        Returns:
        true if the copy was sucessfull
        Throws:
        XWikiException - if the document was not copied properly
      • copyDocument

        public boolean copyDocument​(DocumentReference sourceDocumentReference,
                                    DocumentReference targetDocumentReference,
                                    String wikilocale,
                                    boolean resetHistory,
                                    boolean overwrite)
                             throws XWikiException
        API to copy a translation of a document to another document of the same name in another wiki additionally resetting the version and overwriting the previous document
        Parameters:
        sourceDocumentReference - the reference to the document to copy
        targetDocumentReference - the reference to the document to create
        wikilocale - locale to copy
        resetHistory - true to reset versions
        overwrite - true to overwrite the previous document
        Returns:
        true if the copy was sucessful
        Throws:
        XWikiException - if the document was not copied properly
        Since:
        3.0M3
      • copySpaceBetweenWikis

        public int copySpaceBetweenWikis​(String space,
                                         String sourceWiki,
                                         String targetWiki,
                                         String locale,
                                         boolean clean)
                                  throws XWikiException
        Privileged API to copy a space to another wiki, optionally deleting all document of the target space
        Parameters:
        space - source Space
        sourceWiki - source Wiki
        targetWiki - target Wiki
        locale - locale to copy
        clean - true to delete all document of the target space
        Returns:
        number of copied documents
        Throws:
        XWikiException - if the space was not copied properly
      • includeTopic

        public String includeTopic​(String topic)
                            throws XWikiException
        API to include a topic into another The topic is rendered fully in the context of itself
        Parameters:
        topic - page name of the topic to include
        Returns:
        the content of the included page
        Throws:
        XWikiException - if the include failed
      • includeForm

        public String includeForm​(String topic)
                           throws XWikiException
        API to execute a form in the context of an including topic The rendering is evaluated in the context of the including topic All velocity variables are the one of the including topic This api is usually called using #includeForm in a page, which modifies the behavior of "Edit this page" button to direct for Form mode (inline)
        Parameters:
        topic - page name of the form to execute
        Returns:
        the content of the included page
        Throws:
        XWikiException - if the include failed
      • includeTopic

        public String includeTopic​(String topic,
                                   boolean pre)
                            throws XWikiException
        API to include a topic into another, optionally surrounding the content with {pre}{/pre} to avoid future wiki rendering. The topic is rendered fully in the context of itself.
        Parameters:
        topic - page name of the topic to include
        pre - true to add {pre} {/pre} (only if includer document is 1.0 syntax)
        Returns:
        the content of the included page
        Throws:
        XWikiException - if the include failed
      • includeForm

        public String includeForm​(String topic,
                                  boolean pre)
                           throws XWikiException
        API to execute a form in the context of an including topic, optionnaly surrounding the content with {pre}{/pre} to avoid future wiki rendering The rendering is evaluated in the context of the including topic All velocity variables are the one of the including topic This api is usually called using #includeForm in a page, which modifies the behavior of "Edit this page" button to direct for Form mode (inline).
        Parameters:
        topic - page name of the form to execute
        pre - true to add {pre} {/pre} (only if includer document is 1.0 syntax)
        Returns:
        the content of the included page
        Throws:
        XWikiException - if the include failed
      • hasAccessLevel

        public boolean hasAccessLevel​(String level)
        API to check rights on the current document for the current user
        Parameters:
        level - right to check (view, edit, comment, delete)
        Returns:
        true if right is granted/false if not
      • hasAccessLevel

        public boolean hasAccessLevel​(String level,
                                      String user,
                                      String docname)
        API to check rights on a document for a given user
        Parameters:
        level - right to check (view, edit, comment, delete)
        user - user for which to check the right
        docname - document on which to check the rights
        Returns:
        true if right is granted/false if not
      • getSpaces

        @Deprecated
        public List<String> getSpaces()
                               throws XWikiException
        Deprecated.
        use query service instead
        API to list all spaces in the current wiki.

        Hidden spaces are filtered unless current user enabled them.

        Returns:
        a list of string representing all non-hidden spaces (ie spaces that have non-hidden pages) for the current wiki
        Throws:
        XWikiException - if something went wrong
      • getSpaceDocsName

        @Deprecated
        public List<String> getSpaceDocsName​(String spaceReference)
                                      throws XWikiException
        Deprecated.
        use query service instead
        API to list all documents in a space.

        Hidden spaces are filtered unless current user enabled them.

        Parameters:
        spaceReference - the local reference of the space for which to return all non-hidden documents
        Returns:
        the list of document names (in the format Space.Page) for non-hidden documents in the specified space
        Throws:
        XWikiException - if the loading went wrong
      • getEncoding

        public String getEncoding()
        API to retrieve the current encoding of the wiki engine The encoding is stored in xwiki.cfg Default encoding is ISO-8891-1
        Returns:
        encoding active in this wiki
      • getAttachmentURL

        public String getAttachmentURL​(String fullname,
                                       String filename)
                                throws XWikiException
        API to retrieve the URL of an attached file in a Wiki Document The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object For compatibility with any target environment (and especially the portlet environment) It is important to always use the URL functions to generate URL and never hardcode URLs
        Parameters:
        fullname - page name which includes the attached file
        filename - attached filename to create a link for
        Returns:
        a URL as a string pointing to the filename
        Throws:
        XWikiException - if the URL could not be generated properly
      • getURL

        public String getURL​(String fullname)
                      throws XWikiException
        API to retrieve the URL of an a Wiki Document in view mode The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object For compatibility with any target environment (and especially the portlet environment) It is important to always use the URL functions to generate URL and never hardcode URLs
        Parameters:
        fullname - the name of the document for which to return the URL for
        Returns:
        a URL as a string pointing to the wiki document in view mode
        Throws:
        XWikiException - if the URL could not be generated properly
      • getURL

        public String getURL​(EntityReference reference)
                      throws XWikiException
        Retrieve the URL of an entity using the default mode/action for that entity type. The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..). The URL generation can be modified by implementing a new XWikiURLFactory object. For compatibility with any target environment (and especially the portlet environment) it is important to always use the URL functions to generate URLs and never hardcode URLs.
        Parameters:
        reference - the reference to the entity for which to return the URL
        Returns:
        a URL as a string pointing to the specified entity, using the default mode/action for that entity type
        Throws:
        XWikiException - if the URL could not be generated properly
        Since:
        7.2M1
      • getURL

        public String getURL​(EntityReference reference,
                             String action,
                             String querystring)
                      throws XWikiException
        API to retrieve the URL of an entity in any mode, optionally adding a query string The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object. The query string will be modified to be added in the way the environment needs it. It is important to not add the query string parameter manually after a URL. Some environments will not accept this (like the Portlet environment).
        Parameters:
        reference - the reference to the entity for which to return the URL for
        action - the mode in which to access the entity (view/edit/save/..). Any valid XWiki action is possible
        querystring - the Query String to provide in the usual mode (name1=value1&name2=value=2) including encoding
        Returns:
        a URL as a string pointing to the entity
        Throws:
        XWikiException - if the URL could not be generated properly
        Since:
        7.2M1
      • getURL

        public String getURL​(DocumentReference reference)
                      throws XWikiException
        API to retrieve the URL of an a Wiki Document in view mode The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object For compatibility with any target environment (and especially the portlet environment) It is important to always use the URL functions to generate URL and never hardcode URLs
        Parameters:
        reference - the reference to the document for which to return the URL for
        Returns:
        a URL as a string pointing to the wiki document in view mode
        Throws:
        XWikiException - if the URL could not be generated properly
        Since:
        2.3M2
      • getURL

        public String getURL​(String fullname,
                             String action)
                      throws XWikiException
        API to retrieve the URL of an a Wiki Document in any mode. The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..). The URL generation can be modified by implementing a new XWikiURLFactory object For compatibility with any target environment (and especially the portlet environment). It is important to always use the URL functions to generate URL and never hardcode URLs.
        Parameters:
        fullname - the page name which includes the attached file
        action - the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible.
        Returns:
        a URL as a string pointing to the wiki document in view mode
        Throws:
        XWikiException - if the URL could not be generated properly
      • getURL

        public String getURL​(String fullname,
                             String action,
                             String querystring)
                      throws XWikiException
        API to retrieve the URL of a Wiki Document in any mode, optionally adding a query string The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object. The query string will be modified to be added in the way the environment needs it. It is important to not add the query string parameter manually after a URL. Some environments will not accept this (like the Portlet environment).
        Parameters:
        fullname - the page name which includes the attached file
        action - the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible
        querystring - the Query String to provide in the usual mode (name1=value1&name2=value=2) including encoding
        Returns:
        a URL as a string pointing to the wiki document in view mode
        Throws:
        XWikiException - if the URL could not be generated properly
      • getURL

        public String getURL​(DocumentReference reference,
                             String action,
                             String querystring)
                      throws XWikiException
        API to retrieve the URL of a Wiki Document in any mode, optionally adding a query string The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object. The query string will be modified to be added in the way the environment needs it. It is important to not add the query string parameter manually after a URL. Some environments will not accept this (like the Portlet environment).
        Parameters:
        reference - the reference to the document for which to return the URL for
        action - the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible
        querystring - the Query String to provide in the usual mode (name1=value1&name2=value=2) including encoding
        Returns:
        a URL as a string pointing to the wiki document in view mode
        Throws:
        XWikiException - if the URL could not be generated properly
        Since:
        3.0M3
      • getURL

        public String getURL​(String fullname,
                             String action,
                             String querystring,
                             String anchor)
                      throws XWikiException
        API to retrieve the URL of an a Wiki Document in any mode, optionally adding an anchor. The URL is generated differently depending on the environment (Servlet, Portlet, PDF, etc..) The URL generation can be modified by implementing a new XWikiURLFactory object. The anchor will be modified to be added in the way the environment needs it. It is important to not add the anchor parameter manually after a URL. Some environments will not accept this (like the Portlet environment).
        Parameters:
        fullname - the page name which includes the attached file
        action - the mode in which to access the document (view/edit/save/..). Any valid XWiki action is possible
        querystring - the Query String to provide in the usual mode (name1=value1&name2=value=2) including encoding
        anchor - the anchor that points at a location within the passed document name
        Returns:
        a URL as a string pointing to the wiki document in view mode
        Throws:
        XWikiException - if the URL could not be generated properly
      • getRefererText

        public String getRefererText​(String referer)
        API to retrieve a viewable referer text for a referer Referers are URL where users have clicked on a link to an XWiki page Search engine referer URLs are transformed to a nicer view (Google: search query string) For other URL the http:// part is stripped
        Parameters:
        referer - referer URL to transform
        Returns:
        A viewable string
      • getShortRefererText

        public String getShortRefererText​(String referer,
                                          int length)
        API to retrieve a viewable referer text for a referer with a maximum length Referers are URL where users have clicked on a link to an XWiki page Search engine referer URLs are transformed to a nicer view (Google: search query string) For other URL the http:// part is stripped
        Parameters:
        referer - referer URL to transform
        length - Maximum length. "..." is added to the end of the text
        Returns:
        A viewable string
      • getPlainUserName

        public String getPlainUserName​(DocumentReference userReference)
        Generate and return an unescaped user display name.
        Parameters:
        userReference - the user reference
        Returns:
        the unescaped display user name
        Since:
        6.4RC1
      • getUserName

        public String getUserName​(String user)
        API to retrieve a link to the User Name page displayed for the first name and last name of the user. The link will link to the page on the wiki where the user is registered
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getUserName

        public String getUserName​(String user,
                                  String format)
        API to retrieve a link to the User Name page displayed with a custom view. The link will link to the page on the wiki where the user is registered. The formating is done using the format parameter which can contain velocity scripting and access all properties of the User profile using variables ($first_name $last_name $email $city)
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        format - formatting to be used ("$first_name $last_name", "$first_name")
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getLocalUserName

        public String getLocalUserName​(String user)
        API to retrieve a link to the User Name page displayed for the first name and last name of the user. The link will link to the page on the local wiki even if the user is registered on a different wiki.
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getLocalUserName

        public String getLocalUserName​(String user,
                                       String format)
        API to retrieve a link to the User Name page displayed with a custom view. The link will link to the page on the local wiki even if the user is registered on a different wiki. The formating is done using the format parameter which can contain velocity scripting and access all properties of the User profile using variables ($first_name $last_name $email $city)
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        format - formatting to be used ("$first_name $last_name", "$first_name")
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getUserName

        public String getUserName​(String user,
                                  boolean link)
        API to retrieve a text representing the user with the first name and last name of the user. With the link param set to false it will not link to the user page With the link param set to true, the link will link to the page on the wiki where the user was registered.
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        link - false to not add an HTML link to the user profile
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getUserName

        public String getUserName​(String user,
                                  String format,
                                  boolean link)
        API to retrieve a text representing the user with a custom view With the link param set to false it will not link to the user page. With the link param set to true, the link will link to the page on the wiki where the user was registered. The formating is done using the format parameter which can contain velocity scripting and access all properties of the User profile using variables ($first_name $last_name $email $city)
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        format - formatting to be used ("$first_name $last_name", "$first_name")
        link - false to not add an HTML link to the user profile
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getLocalUserName

        public String getLocalUserName​(String user,
                                       boolean link)
        API to retrieve a text representing the user with the first name and last name of the user. With the link param set to false it will not link to the user page. With the link param set to true, the link will link to the page on the local wiki even if the user is registered on a different wiki.
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        link - false to not add an HTML link to the user profile
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getLocalUserName

        public String getLocalUserName​(String user,
                                       String format,
                                       boolean link)
        API to retrieve a text representing the user with a custom view. The formating is done using the format parameter which can contain velocity scripting and access all properties of the User profile using variables ($first_name $last_name $email $city). With the link param set to false it will not link to the user page. With the link param set to true, the link will link to the page on the local wiki even if the user is registered on a different wiki.
        Parameters:
        user - Fully qualified username as retrieved from $xcontext.user (XWiki.LudovicDubost)
        format - formatting to be used ("$first_name $last_name", "$first_name")
        link - false to not add an HTML link to the user profile
        Returns:
        The first name and last name fields surrounded with a link to the user page
      • getUser

        public User getUser()
      • getUser

        public User getUser​(String username)
      • getUser

        public User getUser​(DocumentReference userReference)
        Retrieve a user from its document reference.
        Parameters:
        userReference - the reference of the user.
        Returns:
        the user corresponding to the reference.
        Since:
        11.8RC1
      • formatDate

        public String formatDate​(Date date)
        API allowing to format a date according to the default Wiki setting The date format is provided in the 'dateformat' parameter of the XWiki Preferences
        Parameters:
        date - date object to format
        Returns:
        A string with the date formating from the default Wiki setting
      • formatDate

        public String formatDate​(Date date,
                                 String format)
        API allowing to format a date according to a custom format The date format is from java.text.SimpleDateFormat Example: "dd/MM/yyyy HH:mm:ss" or "d MMM yyyy" If the format is invalid the default format will be used to show the date
        Parameters:
        date - date to format
        format - format of the date to be used
        Returns:
        the formatted date
        See Also:
        SimpleDateFormat
      • getUserTimeZone

        public String getUserTimeZone()
      • get

        public Api get​(String name)
        Returns a plugin from the plugin API. Plugin Rights can be verified. Note that although this API is a duplicate of getPlugin(String) it used to provide an easy access from Velocity to XWiki plugins. Indeed Velocity has a feature in that if a class has a get method, using the dot notation will automatically call the get method for the class. See http://velocity.apache.org/engine/releases/velocity-1.5/user-guide.html#propertylookuprules. This this allows the following constructs: $xwiki.pluginName.somePluginMethod()
        Parameters:
        name - Name of the plugin to retrieve (either short of full class name)
        Returns:
        a plugin object
      • getPlugin

        public Api getPlugin​(String name)
        Returns a plugin from the plugin API. Plugin Rights can be verified.
        Parameters:
        name - Name of the plugin to retrieve (either short of full class name)
        Returns:
        a plugin object
      • getAdType

        public String getAdType()
        Returns the Advertisement system from the preferences
        Returns:
        "google" or "none"
      • getAdClientId

        public String getAdClientId()
        Returns the Advertisement client ID from the preferences
        Returns:
        an Ad affiliate ID
      • getURLContent

        @Programming
        public String getURLContent​(String surl,
                                    String username,
                                    String password)
                             throws IOException
        Returns the content of an HTTP/HTTPS URL protected using Basic Authentication
        Parameters:
        surl - url to retrieve
        username - username for the basic authentication
        password - password for the basic authentication
        Returns:
        Content of the specified URL
        Throws:
        IOException
      • getURLContent

        @Programming
        public String getURLContent​(String surl,
                                    String username,
                                    String password,
                                    int timeout)
                             throws IOException
        Returns the content of an HTTP/HTTPS URL protected using Basic Authentication
        Parameters:
        surl - url to retrieve
        username - username for the basic authentication
        password - password for the basic authentication
        timeout - manuel timeout in milliseconds
        Returns:
        Content of the specified URL
        Throws:
        IOException
      • getURLContent

        @Programming
        public String getURLContent​(String surl,
                                    int timeout)
                             throws IOException
        Returns the content of an HTTP/HTTPS URL
        Parameters:
        surl - url to retrieve
        timeout - manuel timeout in milliseconds
        Returns:
        Content of the specified URL
        Throws:
        IOException
      • getURLContentAsBytes

        @Programming
        public byte[] getURLContentAsBytes​(String surl,
                                           String username,
                                           String password)
                                    throws IOException
        Returns the content of an HTTP/HTTPS URL protected using Basic Authentication as Bytes
        Parameters:
        surl - url to retrieve
        username - username for the basic authentication
        password - password for the basic authentication
        Returns:
        Content of the specified URL
        Throws:
        IOException
      • getURLContentAsBytes

        @Programming
        public byte[] getURLContentAsBytes​(String surl)
                                    throws IOException
        Returns the content of an HTTP/HTTPS URL as Bytes
        Parameters:
        surl - url to retrieve
        Returns:
        Content of the specified URL
        Throws:
        IOException
      • getIncludedMacros

        public List<String> getIncludedMacros​(String defaultSpace,
                                              String content)
        Returns the list of Macros documents in the specified content
        Parameters:
        defaultSpace - Default space to use for relative path names
        content - Content to parse
        Returns:
        ArrayList of document names
      • isReadOnly

        public boolean isReadOnly()
        returns true if xwiki.readonly is set in the configuration file
        Returns:
        the value of xwiki.isReadOnly()
        See Also:
        XWiki
      • setReadOnly

        public void setReadOnly​(boolean ro)
        Privileged API to set/unset the readonly status of the Wiki After setting this to true no writing to the database will be performed All Edit buttons will be removed and save actions disabled This is used for maintenance purposes
        Parameters:
        ro - true to set read-only mode/false to unset
      • refreshLinks

        public void refreshLinks()
                          throws XWikiException
        Priviledge API to regenerate the links/backlinks table Normally links and backlinks are stored when a page is modified This function will regenerate all the backlinks This function can be long to run
        Throws:
        XWikiException - exception if the generation fails
      • hasBacklinks

        public boolean hasBacklinks()
                             throws XWikiException
        API to check if the backlinks feature is active Backlinks are activated in xwiki.cfg or in the XWiki Preferences
        Returns:
        true if the backlinks feature is active
        Throws:
        XWikiException - exception if the preference could not be retrieved
      • hasTags

        public boolean hasTags()
                        throws XWikiException
        API to check if the tags feature is active. Tags are activated in xwiki.cfg or in the XWiki Preferences
        Returns:
        true if the tags feature is active, false otherwise
        Throws:
        XWikiException - exception if the preference could not be retrieved
      • hasEditComment

        public boolean hasEditComment()
        API to check if the edit comment feature is active Edit comments are activated in xwiki.cfg or in the XWiki Preferences
        Returns:
      • isEditCommentFieldHidden

        public boolean isEditCommentFieldHidden()
        API to check if the edit comment field is shown in the edit form Edit comments are activated in xwiki.cfg or in the XWiki Preferences
        Returns:
      • isEditCommentSuggested

        public boolean isEditCommentSuggested()
        API to check if the edit comment is suggested (prompted once by Javascript if empty) Edit comments are activated in xwiki.cfg or in the XWiki Preferences
        Returns:
      • isEditCommentMandatory

        public boolean isEditCommentMandatory()
        API to check if the edit comment is mandatory (prompted by Javascript if empty) Edit comments are activated in xwiki.cfg or in the XWiki Preferences
        Returns:
      • hasMinorEdit

        public boolean hasMinorEdit()
        API to check if the minor edit feature is active minor edit is activated in xwiki.cfg or in the XWiki Preferences
      • hasRecycleBin

        public boolean hasRecycleBin()
        API to check if the recycle bin feature is active recycle bin is activated in xwiki.cfg or in the XWiki Preferences
      • getEditorPreference

        public String getEditorPreference()
        Retrieves the current editor preference for the request The preference is first looked up in the user preference and then in the space and wiki preference
        Returns:
        "wysiwyg" or "text"
      • parseGroovyFromString

        public Object parseGroovyFromString​(String script)
                                     throws XWikiException
        Privileged API to retrieve an object instantiated from groovy code in a String. Note that Groovy scripts compilation is cached.
        Parameters:
        script - the Groovy class definition string (public class MyClass { ... })
        Returns:
        An object instantiating this class
        Throws:
        XWikiException
      • parseGroovyFromPage

        public Object parseGroovyFromPage​(String script,
                                          String jarWikiPage)
                                   throws XWikiException
        Privileged API to retrieve an object instantiated from groovy code in a String, using a classloader including all JAR files located in the passed page as attachments. Note that Groovy scripts compilation is cached
        Parameters:
        script - the Groovy class definition string (public class MyClass { ... })
        Returns:
        An object instantiating this class
        Throws:
        XWikiException
      • parseGroovyFromPage

        public Object parseGroovyFromPage​(String fullname)
                                   throws XWikiException
        Privileged API to retrieve an object instanciated from groovy code in a String Groovy scripts compilation is cached
        Parameters:
        fullname - // script containing a Groovy class definition (public class MyClass { ... })
        Returns:
        An object instanciating this class
        Throws:
        XWikiException
      • getMacroList

        public String getMacroList()
        API to get the macro list from the XWiki Preferences The macro list are the macros available from the Macro Mapping System
        Returns:
        String with each macro on each line
      • getWysiwygToolbars

        public String getWysiwygToolbars()
        API to check if using which toolbars in Wysiwyg editor
        Returns:
        a string value
      • getObjectFromRequest

        public Object getObjectFromRequest​(String className)
                                    throws XWikiException
        API to create an object from the request The parameters are the ones that are created from doc.display("field","edit") calls
        Parameters:
        className - XWiki Class Name to create the object from
        Returns:
        a BaseObject wrapped in an Object
        Throws:
        XWikiException - exception if the object could not be read
      • createDocument

        public Document createDocument()
        API to create an empty document
        Returns:
        an XWikiDocument wrapped in a Document
      • convertUsername

        public String convertUsername​(String username)
        API to convert the username depending on the configuration The username can be converted from email to a valid XWiki page name hidding the email address The username can be then used to login and link to the right user page
        Parameters:
        username - username to use for login
        Returns:
        converted wiki page name for this username
      • getPropertyClassFromName

        public PropertyClass getPropertyClassFromName​(String propPath)
        API to get the Property object from a class based on a property path A property path looks like XWiki.ArticleClass_fieldname
        Parameters:
        propPath - Property path
        Returns:
        a PropertyClass object from a BaseClass object
      • getUniquePageName

        public String getUniquePageName​(String name)
        Generates a unique page name based on initial page name and already existing pages
        Parameters:
        name -
        Returns:
        a unique page name
      • getUniquePageName

        public String getUniquePageName​(String space,
                                        String name)
        Generates a unique page name based on initial page name and already existing pages
        Parameters:
        space -
        name -
        Returns:
        a unique page name
      • addTooltip

        public String addTooltip​(String html,
                                 String message,
                                 String params)
        Inserts a tooltip using toolTip.js
        Parameters:
        html - HTML viewed
        message - HTML Tooltip message
        params - Parameters in Javascropt added to the tooltip config
        Returns:
        HTML with working tooltip
      • addTooltip

        public String addTooltip​(String html,
                                 String message)
        Inserts a tooltip using toolTip.js
        Parameters:
        html - HTML viewed
        message - HTML Tooltip message
        Returns:
        HTML with working tooltip
      • addTooltipJS

        public String addTooltipJS()
        Inserts the tooltip Javascript
        Returns:
      • addMandatory

        public String addMandatory()
      • getClass

        public Class getClass​(String documentName)
                       throws XWikiException
        Get the XWiki Class object defined in the passed Document name.

        Note: This method doesn't require any rights for accessing the passed Document (as opposed to the Object.getClass() method which does require to get a Document object first. This is thus useful in cases where the calling code doesn't have the access right to the specified Document. It is safe because there are no sensitive data stored in a Class definition.

        Parameters:
        documentName - the name of the document for which to get the Class object. For example "XWiki.XWikiPreferences"
        Returns:
        the XWiki Class object defined in the passed Document name. If the passed Document name points to a Document with no Class defined then an empty Class object is returned (i.e. a Class object with no properties).
        Throws:
        XWikiException - if the passed document name doesn't point to a valid Document
      • getClass

        public Class getClass​(EntityReference docReference)
                       throws XWikiException
        Get the XWiki Class object defined in the passed Document name.

        Note: This method doesn't require any rights for accessing the passed Document (as opposed to the Object.getClass() method which does require to get a Document object first. This is thus useful in cases where the calling code doesn't have the access right to the specified Document. It is safe because there are no sensitive data stored in a Class definition.

        Parameters:
        docReference - the reference of the document for which to get the Class object.
        Returns:
        the XWiki Class object defined in the passed Document reference. If the passed Document name points to a Document with no Class defined then an empty Class object is returned (i.e. a Class object with no properties).
        Throws:
        XWikiException - if the reference doesn't exist.
        Since:
        10.11.10, 11.8RC1, 11.3.4
      • getCounter

        public String getCounter​(String name)
        Provides an absolute counter
        Parameters:
        name - Counter name
        Returns:
        String
      • checkAuth

        public XWikiUser checkAuth()
                            throws XWikiException
        Check authentication from request and set according persitent login information If it fails user is unlogged
        Returns:
        null if failed, non null XWikiUser if sucess
        Throws:
        XWikiException
      • checkAuth

        public XWikiUser checkAuth​(String username,
                                   String password,
                                   String rememberme)
                            throws XWikiException
        Check authentication from username and password and set according persitent login information If it fails user is unlogged
        Parameters:
        username - username to check
        password - password to check
        rememberme - "1" if you want to remember the login accross navigator restart
        Returns:
        null if failed, non null XWikiUser if sucess
        Throws:
        XWikiException
      • getStatsService

        public StatsService getStatsService()
        Access statistics api
        Returns:
        a StatsService instance that can be used to retrieve different xwiki statistics
      • getCriteriaService

        public CriteriaService getCriteriaService()
        API to get the xwiki criteria service which allow to create various criteria : integer ranges, date periods, date intervals, etc.
        Returns:
        the xwiki criteria service
      • getServletPath

        public String getServletPath​(String wikiName)
        API to get the Servlet path for a given wiki. In mono wiki this is "bin/" or "xwiki/". In virtual mode and if xwiki.virtual.usepath is enabled in xwiki.cfg, it is "wiki/wikiname/".
        Parameters:
        wikiName - wiki for which to get the path
        Returns:
        The servlet path
      • getServletPath

        public String getServletPath()
        API to get the Servlet path for the current wiki. In mono wiki this is "bin/" or "xwiki/". In virtual mode and if xwiki.virtual.usepath is enabled in xwiki.cfg, it is "wiki/wikiname/".
        Returns:
        The servlet path
      • getWebAppPath

        public String getWebAppPath()
        API to get the webapp path for the current wiki. This usually is "xwiki/". It can be configured in xwiki.cfg with the config xwiki.webapppath.
        Returns:
        The servlet path
      • getDefaultDocumentSyntax

        public String getDefaultDocumentSyntax()
        Returns:
        the syntax id of the syntax to use when creating new documents.
      • getAvailableRendererSyntax

        public org.xwiki.rendering.syntax.Syntax getAvailableRendererSyntax​(String syntaxType,
                                                                            String syntaxVersion)
        Find the corresponding available renderer syntax.

        If syntaxVersion is null the last version of the available provided syntax type is returned.

        Parameters:
        syntaxType - the syntax type
        syntaxVersion - the syntax version
        Returns:
        the available corresponding Syntax. Null if no available renderer can be found.
      • hasSectionEdit

        public boolean hasSectionEdit()
        Returns:
        true if section editing is enabled (can be configured through the xwiki.section.edit configuration property. Defaults to 1 (=enabled) when not defined
      • getSectionEditingDepth

        public long getSectionEditingDepth()
        Returns:
        the section depth for which section editing is available (can be configured through xwiki.section.depth configuration property. Defaults to 2 when not defined
      • isTitleInCompatibilityMode

        public boolean isTitleInCompatibilityMode()
        Returns:
        true if title handling should be using the compatibility mode or not. When the compatibility mode is active, if the document's content first header (level 1 or level 2) matches the document's title the first header is stripped.
      • getCurrentContentSyntaxId

        public String getCurrentContentSyntaxId()
        Get the syntax of the content currently being executed.

        The document currently being executed is not the same than the actual content syntax since the executed code might come from an included page or some macro that change the context syntax. The same logic used inside rendering macros is used (see MacroContentParser).

        If the current document can't be found, the method assume that the executed document is the context document (it's generally the case when a document is directly rendered with XWikiDocument.getRenderedContent(XWikiContext) for example).

        Returns:
        the syntax identifier