Class XWikiResource

  • All Implemented Interfaces:
    org.xwiki.component.phase.Initializable, XWikiRestComponent
    Direct Known Subclasses:
    XWikiJobResource

    @InstantiationStrategy(PER_LOOKUP)
    public class XWikiResource
    extends Object
    implements XWikiRestComponent, org.xwiki.component.phase.Initializable
    Base class for all XWiki-related JAX-RS resources. This class provides to subclasses a set of protected fields to access the XWiki API and a method for retrieving documents in their different incarnations.
    Version:
    $Id: 40b6686e40648716dc6df74c2f0bb78a192022b6 $
    • Field Detail

      • uriInfo

        @Context
        protected javax.ws.rs.core.UriInfo uriInfo
        The actual URI information about the JAX-RS resource being called. This variable is useful when generating links to other resources in representations.
      • slf4Jlogger

        @Inject
        protected org.slf4j.Logger slf4Jlogger
        The logger to be used to output log messages.
        Since:
        7.4.5, 8.3C1
      • objectFactory

        protected ObjectFactory objectFactory
        The object factory for model objects to be used when creating representations.
      • componentManager

        @Inject
        @Named("context")
        protected org.xwiki.component.manager.ComponentManager componentManager
        The XWiki component manager that is used to lookup XWiki components and context.
      • xcontextProvider

        @Inject
        protected javax.inject.Provider<XWikiContext> xcontextProvider
      • queryManager

        @Inject
        protected QueryManager queryManager
        The query manager to be used to perform low-level queries for retrieving information about wiki content.
    • Constructor Detail

      • XWikiResource

        public XWikiResource()
    • Method Detail

      • initialize

        public void initialize()
                        throws org.xwiki.component.phase.InitializationException
        Resource initialization.
        Specified by:
        initialize in interface org.xwiki.component.phase.Initializable
        Throws:
        org.xwiki.component.phase.InitializationException
      • parseSpaceSegments

        public List<String> parseSpaceSegments​(String spaceSegments)
                                        throws XWikiRestException
        Parameters:
        spaceSegments - the space segments of the URL (the URL-encoded value of the /spaces/... URL path parameter)
        Returns:
        the list of parent spaces
        Throws:
        XWikiRestException - if the URL is malformed
      • getDocumentInfo

        public XWikiResource.DocumentInfo getDocumentInfo​(String wikiName,
                                                          String spaceName,
                                                          String pageName,
                                                          String language,
                                                          String version,
                                                          boolean failIfDoesntExist,
                                                          boolean failIfLocked)
                                                   throws XWikiException,
                                                          XWikiRestException
        Retrieve a document. This method never returns null. If something goes wrong with respect to some precondition an exception is thrown.
        Parameters:
        wikiName - The wiki name. Cannot be null.
        spaceName - The space name. Cannot be null.
        pageName - The page name. Cannot be null.
        language - The language. Null for the default language.
        version - The version. Null for the latest version.
        failIfDoesntExist - True if an exception should be raised whenever the page doesn't exist.
        failIfLocked - True if an exception should be raised whenever the page is locked.
        Returns:
        A DocumentInfo structure containing the actual document and additional information about it.
        Throws:
        IllegalArgumentException - If a parameter has an incorrect value (e.g. null)
        javax.ws.rs.WebApplicationException - NOT_FOUND if failIfDoesntExist is true and the page doesn't exist.
        XWikiRestException - if the URL is malformed PRECONDITION_FAILED if failIfLocked is true and the document is locked.
        XWikiException
      • getDocumentInfo

        public XWikiResource.DocumentInfo getDocumentInfo​(String wikiName,
                                                          List<String> spaces,
                                                          String pageName,
                                                          String localeString,
                                                          String version,
                                                          boolean failIfDoesntExist,
                                                          boolean failIfLocked)
                                                   throws XWikiException
        Retrieve a document. This method never returns null. If something goes wrong with respect to some precondition an exception is thrown.
        Parameters:
        wikiName - The wiki name. Cannot be null.
        spaces - The space hierarchy. Cannot be null.
        pageName - The page name. Cannot be null.
        localeString - The language. Null for the default language.
        version - The version. Null for the latest version.
        failIfDoesntExist - True if an exception should be raised whenever the page doesn't exist.
        failIfLocked - True if an exception should be raised whenever the page is locked.
        Returns:
        A DocumentInfo structure containing the actual document and additional information about it.
        Throws:
        IllegalArgumentException - If a parameter has an incorrect value (e.g. null)
        javax.ws.rs.WebApplicationException - NOT_FOUND if failIfDoesntExist is true and the page doesn't exist. PRECONDITION_FAILED if failIfLocked is true and the document is locked.
        XWikiException
      • getUriTemplate

        public String getUriTemplate()
        A special GET method that produces the ad-hoc "uritemplate" media type used for retrieving the URI template associated to a resource. This is an auxiliary method that is used for documenting the REST API.
        Returns:
        the URI template string associated to the requested resource
      • getXWikiContext

        protected XWikiContext getXWikiContext()
        Retrieve the XWiki context from the current execution context.
        Returns:
        the XWiki context
      • getLogger

        protected org.slf4j.Logger getLogger()
        Returns:
        the logger
        Since:
        9.1RC1