Class ExportURLFactory

  • All Implemented Interfaces:
    XWikiURLFactory

    public class ExportURLFactory
    extends XWikiServletURLFactory
    Handle URL generation in rendered wiki pages. This implementation makes sure that generated URLs will be file URLs pointing to the local filesystem, for exported content (like skin, attachment and pages). This is needed for example for the HTML export.
    Version:
    $Id: 2caf23e74c6d47ef4181ee05e4b028f27a3ce564 $
    • Field Detail

      • LOGGER

        protected static final org.slf4j.Logger LOGGER
        Logging tool.
      • exportedPages

        @Deprecated
        protected Set<String> exportedPages
        Deprecated.
        since 6.2RC1, use {link #getExportURLFactoryContext} instead
        Pages for which to convert URL to local.
      • exportDir

        @Deprecated
        protected File exportDir
        Deprecated.
        since 6.2RC1, use {link #getExportURLFactoryContext} instead
        Directory where to export attachment.
    • Constructor Detail

      • ExportURLFactory

        public ExportURLFactory()
        ExportURLFactory constructor.
    • Method Detail

      • init

        public void init​(Collection<DocumentReference> exportedPages,
                         File exportDir,
                         FilesystemExportContext exportContext,
                         XWikiContext context)
        Init the url factory.
        Parameters:
        exportedPages - the pages that will be exported.
        exportDir - the directory where to copy exported objects (attachments).
        exportContext - the context for the export
        context - the XWiki context.
        Since:
        8.4.5, 9.0
      • createSkinURL

        public URL createSkinURL​(String filename,
                                 String skin,
                                 XWikiContext context,
                                 Map<String,​Object> queryParameters)
        Description copied from interface: XWikiURLFactory
        Create an URL for the given filename in the given skin directory.
        Specified by:
        createSkinURL in interface XWikiURLFactory
        Overrides:
        createSkinURL in class XWikiServletURLFactory
        Parameters:
        filename - the file to reach.
        skin - the skin where the file should be loaded
        context - current context
        queryParameters - the parameters to put at the end of the URL
        Returns:
        a URL to load the given file with the given query parameters.
      • createSkinURL

        public URL createSkinURL​(String filename,
                                 String spaces,
                                 String name,
                                 XWikiContext context)
        Description copied from interface: XWikiURLFactory
        Create an URL for the filename located in the spaces and with given repository.
        Specified by:
        createSkinURL in interface XWikiURLFactory
        Overrides:
        createSkinURL in class XWikiDefaultURLFactory
        Parameters:
        filename - the path of the file to reach.
        spaces - the spaces where the file is located.
        name - the directory where the file is located.
        context - current context.
        Returns:
        an URL to load the given file.
      • createSkinURL

        public URL createSkinURL​(String fileName,
                                 String spaces,
                                 String name,
                                 String wikiId,
                                 XWikiContext context)
        Description copied from interface: XWikiURLFactory
        Create an URL for the filename located in the spaces and with given repository.
        Specified by:
        createSkinURL in interface XWikiURLFactory
        Overrides:
        createSkinURL in class XWikiDefaultURLFactory
        Parameters:
        fileName - the path of the file to reach.
        spaces - the spaces where the file is located.
        name - the directory where the file is located.
        wikiId - the wiki in which the file is located.
        context - current context.
        Returns:
        an URL to load the given file.
      • createSkinURL

        public URL createSkinURL​(String filename,
                                 String spaces,
                                 String name,
                                 String xwikidb,
                                 XWikiContext context,
                                 Map<String,​Object> queryParameters)
        Description copied from interface: XWikiURLFactory
        Create an URL for the filename located in the spaces and with given repository.
        Specified by:
        createSkinURL in interface XWikiURLFactory
        Overrides:
        createSkinURL in class XWikiServletURLFactory
        Parameters:
        filename - the path of the file to reach.
        spaces - the spaces where the file is located.
        name - the directory where the file is located.
        xwikidb - the wiki in which the file is located.
        context - current context.
        queryParameters - parameters to put at the end of the URL.
        Returns:
        an URL to load the given file.
      • createResourceURL

        public URL createResourceURL​(String filename,
                                     boolean forceSkinAction,
                                     XWikiContext context,
                                     Map<String,​Object> queryParameters)
        Description copied from interface: XWikiURLFactory
        Create an URL for the file resource.
        Specified by:
        createResourceURL in interface XWikiURLFactory
        Overrides:
        createResourceURL in class XWikiServletURLFactory
        Parameters:
        filename - the path of the file to load.
        forceSkinAction - if true specify the skin directory in the URL.
        context - the current context.
        queryParameters - the parameters to put at the end of the URL.
        Returns:
        an URL to load the given file
      • createURL

        public URL createURL​(String spaces,
                             String name,
                             String action,
                             String querystring,
                             String anchor,
                             String xwikidb,
                             XWikiContext context)
        Specified by:
        createURL in interface XWikiURLFactory
        Overrides:
        createURL in class XWikiServletURLFactory
        Parameters:
        spaces - a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"
        querystring - the URL-encoded Query String. It's important to realize that the implementation of this method cannot encode it automatically since the Query String is passed as a String (and it's not possible to differentiate between a '=' character that should be encoded and one that shouldn't. Imagine an input of 'a=&b=c' which can be understood either as 'a' = '&b=c' or as 'a' = '' and 'b' = 'c'). Ideally we would need an API signature that accepts a Map<String, String> for the Query String, for example
      • createAttachmentURL

        public URL createAttachmentURL​(String filename,
                                       String spaces,
                                       String name,
                                       String action,
                                       String querystring,
                                       String xwikidb,
                                       XWikiContext context)
        Specified by:
        createAttachmentURL in interface XWikiURLFactory
        Overrides:
        createAttachmentURL in class XWikiServletURLFactory
        spaces - a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"
        querystring - the URL-encoded Query String. It's important to realize that the implementation of this method cannot encode it automatically since the Query String is passed as a String (and it's not possible to differentiate between a '=' character that should be encoded and one that shouldn't. Imagine an input of 'a=&b=c' which can be understood either as 'a' = '&b=c' or as 'a' = '' and 'b' = 'c'). Ideally we would need an API signature that accepts a Map<String, String> for the Query String, for example
      • createAttachmentRevisionURL

        public URL createAttachmentRevisionURL​(String filename,
                                               String spaces,
                                               String name,
                                               String revision,
                                               String xwikidb,
                                               XWikiContext context)
        Specified by:
        createAttachmentRevisionURL in interface XWikiURLFactory
        Overrides:
        createAttachmentRevisionURL in class XWikiDefaultURLFactory
        spaces - a serialized space reference which can contain one or several spaces (e.g. "space1.space2"). If a space name contains a dot (".") it must be passed escaped as in "space1\.with\.dot.space2"
        xwikidb - the URL-encoded Query String. It's important to realize that the implementation of this method cannot encode it automatically since the Query String is passed as a String (and it's not possible to differentiate between a '=' character that should be encoded and one that shouldn't. Imagine an input of 'a=&b=c' which can be understood either as 'a' = '&b=c' or as 'a' = '' and 'b' = 'c'). Ideally we would need an API signature that accepts a Map<String, String> for the Query String, for example
      • getURL

        public String getURL​(URL url,
                             XWikiContext context)
        Description copied from class: XWikiServletURLFactory
        Converts a URL to a relative URL if it's a XWiki URL (keeping only the path + query string + anchor) and leave the URL unchanged if it's an external URL.

        An URL is considered to be external if its server component doesn't match the server of the current request URL. This means that URLs are made relative with respect to the current request URL rather than the current wiki set on the XWiki context. Let's take an example:

         
         request URL: http://playground.xwiki.org/xwiki/bin/view/Sandbox/TestURL
         current wiki: code (code.xwiki.org)
         URL (1): http://code.xwiki.org/xwiki/bin/view/Main/WebHome
         URL (2): http://playground.xwiki.org/xwiki/bin/view/Spage/Page
         
         The result will be:
         (1) http://code.xwiki.org/xwiki/bin/view/Main/WebHome
         (2) /xwiki/bin/view/Spage/Page
         
         
        Specified by:
        getURL in interface XWikiURLFactory
        Overrides:
        getURL in class XWikiServletURLFactory
        Parameters:
        url - the URL to convert
        Returns:
        the converted URL as a string
        See Also:
        XWikiDefaultURLFactory.getURL(java.net.URL, com.xpn.xwiki.XWikiContext)