Class CmsDefaultLinkSubstitutionHandler

    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String ATTR_IS_IMAGE_LINK
      Request context attribute name to make the link substitution handler treat the link like an image link.
      static java.lang.String DONT_USE_CURRENT_SITE_FOR_WORKPLACE_REQUESTS
      Key for a request context attribute to control whether the getRootPath method uses the current site root for workplace requests.
      static java.lang.String OVERRIDE_SITEROOT_PREFIX
      Prefix used for request context attributes to control whether a different site root should be used in appendServerPrefix.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected CmsPair<java.lang.String,​java.lang.String> addVfsPrefix​(CmsObject cms, java.lang.String vfsName, CmsSite targetSite, java.lang.String parameters)
      Adds the VFS prefix to the VFS name and potentially adjusts request parameters
      protected java.lang.String generateCacheKey​(CmsObject cms, java.lang.String targetSiteRoot, java.lang.String detailPagePart, java.lang.String absoluteLink)
      Generates the cache key for Online links.
      java.lang.String getLink​(CmsObject cms, java.lang.String link, java.lang.String siteRoot, boolean forceSecure)
      Returns the resource root path in the OpenCms VFS for the given link, or null in case the link points to an external site.
      java.lang.String getLink​(CmsObject cms, java.lang.String link, java.lang.String siteRoot, java.lang.String targetDetailPage, boolean forceSecure)
      Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given link and siteRoot, for use on web pages.
      java.lang.String getRootPath​(CmsObject cms, java.lang.String targetUri, java.lang.String basePath)
      Returns the resource root path in the OpenCms VFS for the given target URI link, or null in case the link points to an external site.
      protected java.lang.String getRootPathForSite​(CmsObject cms, java.lang.String path, java.lang.String siteRoot, boolean isRootPath)
      Returns the root path for given site.
      protected java.lang.String getSimpleRootPath​(CmsObject cms, java.lang.String targetUri, java.lang.String basePath)
      Gets the root path without taking into account detail page links.
      protected boolean isDetailPageLinkSecure​(CmsObject cms, java.lang.String detailPage, CmsResource detailContent, CmsSite targetSite, boolean secureRequest)
      Checks whether a link to a detail page should be secure.
      protected boolean isSecureLink​(CmsObject cms, java.lang.String vfsName, CmsSite targetSite, boolean secureRequest)
      Checks if the link target is a secure link.
      protected java.lang.String prepareExportParameters​(CmsObject cms, java.lang.String vfsName, java.lang.String parameters)
      Prepares the request parameters for the given resource.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • ATTR_IS_IMAGE_LINK

        public static final java.lang.String ATTR_IS_IMAGE_LINK
        Request context attribute name to make the link substitution handler treat the link like an image link.

        See Also:
        Constant Field Values
      • DONT_USE_CURRENT_SITE_FOR_WORKPLACE_REQUESTS

        public static final java.lang.String DONT_USE_CURRENT_SITE_FOR_WORKPLACE_REQUESTS
        Key for a request context attribute to control whether the getRootPath method uses the current site root for workplace requests. The getRootPath method clears this attribute when called.
        See Also:
        Constant Field Values
      • OVERRIDE_SITEROOT_PREFIX

        public static final java.lang.String OVERRIDE_SITEROOT_PREFIX
        Prefix used for request context attributes to control whether a different site root should be used in appendServerPrefix.
        See Also:
        Constant Field Values
    • Method Detail

      • getLink

        public java.lang.String getLink​(CmsObject cms,
                                        java.lang.String link,
                                        java.lang.String siteRoot,
                                        boolean forceSecure)
        Returns the resource root path in the OpenCms VFS for the given link, or null in case the link points to an external site.

        If the target URI contains no site information, but starts with the opencms context, the context is removed:

         /opencms/opencms/system/further_path -> /system/further_path
        If the target URI contains no site information, the path will be prefixed with the current site from the provided OpenCms user context:
         /folder/page.html -> /sites/mysite/folder/page.html
        If the path of the target URI is relative, i.e. does not start with "/", the path will be prefixed with the current site and the given relative path, then normalized. If no relative path is given, null is returned. If the normalized path is outsite a site, null is returned.
         page.html -> /sites/mysite/page.html
         ../page.html -> /sites/mysite/page.html
         ../../page.html -> null
        If the target URI contains a scheme/server name that denotes an opencms site, it is replaced by the appropriate site path:
         http://www.mysite.de/folder/page.html -> /sites/mysite/folder/page.html

        If the target URI contains a scheme/server name that does not match with any site, or if the URI is opaque or invalid, null is returned:

         http://www.elsewhere.com/page.html -> null
         mailto:someone@elsewhere.com -> null
        Specified by:
        getLink in interface I_CmsLinkSubstitutionHandler
        Parameters:
        cms - the current OpenCms user context
        link - the link to process which is assumed to point to a VFS resource, with optional parameters
        siteRoot - the site root of the link
        forceSecure - if true generates always an absolute URL (with protocol and server name) for secure links
        Returns:
        a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given link and siteRoot
        See Also:
        I_CmsLinkSubstitutionHandler.getLink(org.opencms.file.CmsObject, java.lang.String, java.lang.String, boolean)
      • getLink

        public java.lang.String getLink​(CmsObject cms,
                                        java.lang.String link,
                                        java.lang.String siteRoot,
                                        java.lang.String targetDetailPage,
                                        boolean forceSecure)
        Description copied from interface: I_CmsLinkSubstitutionHandler
        Returns a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given link and siteRoot, for use on web pages.

        The result should be an absolute link that contains the configured context path and servlet name, and in the case of the "online" project it will also be rewritten according to to the configured static export settings.

        In case link is a relative URI, the current URI contained in the provided OpenCms user context cms is normally used to make the relative link absolute.

        The provided siteRoot is assumed to be the "home" of the link. In case the current site of the given OpenCms user context cms is different from the provided siteRoot, the full server prefix is appended to the result link.

        A server prefix is also added if

        • the link is contained in a normal document and the link references a secure document
        • the link is contained in a secure document and the link references a normal document
        Please note the above text describes the default behavior as implemented by CmsDefaultLinkSubstitutionHandler, which can be fully customized using this handler interface.

        Specified by:
        getLink in interface I_CmsLinkSubstitutionHandler
        Parameters:
        cms - the current OpenCms user context
        link - the link to process which is assumed to point to a VFS resource, with optional parameters
        siteRoot - the site root of the link
        targetDetailPage - the target detail page, in case of linking to a specific detail page
        forceSecure - if true generates always an absolute URL (with protocol and server name) for secure links
        Returns:
        a link from the URI stored in the provided OpenCms user context to the VFS resource indicated by the given link and siteRoot
        See Also:
        I_CmsLinkSubstitutionHandler.getLink(org.opencms.file.CmsObject, java.lang.String, java.lang.String, java.lang.String, boolean)
      • getRootPath

        public java.lang.String getRootPath​(CmsObject cms,
                                            java.lang.String targetUri,
                                            java.lang.String basePath)
        Description copied from interface: I_CmsLinkSubstitutionHandler
        Returns the resource root path in the OpenCms VFS for the given target URI link, or null in case the link points to an external site.

        The default implementation applies the following transformations to the link:

        • In case the link starts with a VFS prefix (for example /opencms/opencms, this prefix is removed from the result
        • In case the link is not a root path, the current site root is appended to the result.

        • In case the link is relative, it will be made absolute using the given absolute basePath as starting point.

        • In case the link contains a server schema (for example http://www.mysite.de/), which points to a configured site in OpenCms, the server schema is replaced with the root path of the site.

        • In case the link points to an external site, or in case it is not a valid URI, then null is returned.

        Please note the above text describes the default behavior as implemented by CmsDefaultLinkSubstitutionHandler, which can be fully customized using this handler interface.

        Specified by:
        getRootPath in interface I_CmsLinkSubstitutionHandler
        Parameters:
        cms - the current users OpenCms context
        targetUri - the target URI link
        basePath - path to use as base in case the target URI is relative (can be null)
        Returns:
        the resource root path in the OpenCms VFS for the given target URI link, or null in case the link points to an external site
        See Also:
        I_CmsLinkSubstitutionHandler.getRootPath(org.opencms.file.CmsObject, java.lang.String, java.lang.String)
      • addVfsPrefix

        protected CmsPair<java.lang.String,​java.lang.String> addVfsPrefix​(CmsObject cms,
                                                                                java.lang.String vfsName,
                                                                                CmsSite targetSite,
                                                                                java.lang.String parameters)
        Adds the VFS prefix to the VFS name and potentially adjusts request parameters

        This method is required as a hook used in CmsLocalePrefixLinkSubstitutionHandler.

        Parameters:
        cms - the cms context
        vfsName - the VFS name
        targetSite - the target site
        parameters - the request parameters
        Returns:
        the path and the (adjusted) request parameters.
      • generateCacheKey

        protected java.lang.String generateCacheKey​(CmsObject cms,
                                                    java.lang.String targetSiteRoot,
                                                    java.lang.String detailPagePart,
                                                    java.lang.String absoluteLink)
        Generates the cache key for Online links.
        Parameters:
        cms - the current CmsObject
        targetSiteRoot - the target site root
        detailPagePart - the detail page part
        absoluteLink - the absolute (site-relative) link to the resource
        Returns:
        the cache key
      • getRootPathForSite

        protected java.lang.String getRootPathForSite​(CmsObject cms,
                                                      java.lang.String path,
                                                      java.lang.String siteRoot,
                                                      boolean isRootPath)
        Returns the root path for given site.

        This method is required as a hook used in CmsLocalePrefixLinkSubstitutionHandler.

        Parameters:
        cms - the cms context
        path - the path
        siteRoot - the site root, will be null in case of the root site
        isRootPath - in case the path is already a root path
        Returns:
        the root path
      • getSimpleRootPath

        protected java.lang.String getSimpleRootPath​(CmsObject cms,
                                                     java.lang.String targetUri,
                                                     java.lang.String basePath)
        Gets the root path without taking into account detail page links.

        Parameters:
        cms - - see the getRootPath() method
        targetUri - - see the getRootPath() method
        basePath - - see the getRootPath() method
        Returns:
        - see the getRootPath() method
      • isDetailPageLinkSecure

        protected boolean isDetailPageLinkSecure​(CmsObject cms,
                                                 java.lang.String detailPage,
                                                 CmsResource detailContent,
                                                 CmsSite targetSite,
                                                 boolean secureRequest)
        Checks whether a link to a detail page should be secure.

        Parameters:
        cms - the current CMS context
        detailPage - the detail page path
        detailContent - the detail content resource
        targetSite - the target site containing the detail page
        secureRequest - true if the currently running request is secure
        Returns:
        true if the link should be a secure link
      • isSecureLink

        protected boolean isSecureLink​(CmsObject cms,
                                       java.lang.String vfsName,
                                       CmsSite targetSite,
                                       boolean secureRequest)
        Checks if the link target is a secure link.
        Parameters:
        cms - the current CMS context
        vfsName - the path of the link target
        targetSite - the target site containing the detail page
        secureRequest - true if the currently running request is secure
        Returns:
        true if the link should be a secure link
      • prepareExportParameters

        protected java.lang.String prepareExportParameters​(CmsObject cms,
                                                           java.lang.String vfsName,
                                                           java.lang.String parameters)
        Prepares the request parameters for the given resource.

        This method is required as a hook used in CmsLocalePrefixLinkSubstitutionHandler.

        Parameters:
        cms - the cms context
        vfsName - the vfs name
        parameters - the parameters to prepare
        Returns:
        the root path