Class CmsXmlSitemapGenerator

    • Constructor Detail

      • CmsXmlSitemapGenerator

        public CmsXmlSitemapGenerator​(java.lang.String folderRootPath)
                               throws CmsException
        Creates a new sitemap generator instance.

        Parameters:
        folderRootPath - the root folder for the XML sitemap to generate
        Throws:
        CmsException - if something goes wrong
    • Method Detail

      • replaceServerUri

        public static java.lang.String replaceServerUri​(java.lang.String link,
                                                        java.lang.String server)
        Replaces the protocol/host/port of a link with the ones from the given server URI, if it's not empty.

        Parameters:
        link - the link to change
        server - the server URI string
        Returns:
        the changed link
      • getChangeFrequency

        protected static java.lang.String getChangeFrequency​(java.util.List<CmsProperty> properties)
        Gets the change frequency for a sitemap entry from a list of properties.

        If the change frequency is not defined in the properties, this method will return null.

        Parameters:
        properties - the properties from which the change frequency should be obtained
        Returns:
        the change frequency string
      • getPriority

        protected static double getPriority​(java.util.List<CmsProperty> properties)
        Gets the page priority from a list of properties.

        If the page priority can't be found among the properties, -1 will be returned.

        Parameters:
        properties - the properties of a resource
        Returns:
        the page priority read from the properties, or -1
      • removeInternalFiles

        protected static void removeInternalFiles​(java.util.List<CmsResource> resources)
        Removes files marked as internal from a resource list.

        Parameters:
        resources - the list which should be replaced
      • renderSitemap

        public java.lang.String renderSitemap()
                                       throws CmsException
        Generates a sitemap and formats it as a string.

        Returns:
        the sitemap XML data
        Throws:
        CmsException - if something goes wrong
      • setComputeContainerPageDates

        public void setComputeContainerPageDates​(boolean computeContainerPageDates)
        Enables or disables computation of container page dates.

        Parameters:
        computeContainerPageDates - the new value
      • setServerUrl

        public void setServerUrl​(java.lang.String serverUrl)
        Sets the replacement server URL.

        The replacement server URL will replace the scheme/host/port from the URLs returned by getOnlineLink.

        Parameters:
        serverUrl - the server URL
      • addDetailLinks

        protected void addDetailLinks​(CmsResource containerPage,
                                      java.util.Locale locale)
                               throws CmsException
        Adds the detail page links for a given page to the results.

        Parameters:
        containerPage - the container page resource
        locale - the locale of the container page
        Throws:
        CmsException - if something goes wrong
      • addResult

        protected void addResult​(CmsXmlSitemapUrlBean result,
                                 int resultPriority)
        Adds an URL bean to the internal map of results, but only if there is no existing entry with higher internal priority than the priority given as an argument.

        Parameters:
        result - the result URL bean to add
        resultPriority - the internal priority to use for updating the map of results
      • computeContainerPageModificationDate

        protected long computeContainerPageModificationDate​(CmsResource containerPage)
                                                     throws CmsException
        Computes the container the container page modification date from its referenced contents.

        Parameters:
        containerPage - the container page
        Returns:
        the computed modification date
        Throws:
        CmsException - if something goes wrong
      • getDetailLink

        protected java.lang.String getDetailLink​(CmsResource pageRes,
                                                 CmsResource detailRes,
                                                 java.util.Locale locale)
        Gets the detail link for a given container page and detail content.

        Note: The actual container page used for the result link is not necessarily the container page passed in as parameter - the default detail page in the sitemap containing the page is used.

        Parameters:
        pageRes - the container page
        detailRes - the detail content
        locale - the locale for which we want the link
        Returns:
        the detail page link
      • getDetailTypesForPage

        protected java.util.List<I_CmsResourceTypegetDetailTypesForPage​(CmsResource resource)
        Gets the types for which a given resource is configured as a detail page.

        Parameters:
        resource - a resource for which we want to find the detail page types
        Returns:
        the list of resource types for which the given page is configured as a detail page
      • getDirectPages

        protected java.util.List<CmsResourcegetDirectPages()
                                                      throws CmsException
        Gets the list of pages which should be directly added to the XML sitemap.

        Returns:
        the list of resources which should be directly added to the XML sitemap
        Throws:
        CmsException - if something goes wrong
      • getInnerXmlForEntry

        protected java.lang.String getInnerXmlForEntry​(CmsXmlSitemapUrlBean entry)
        Writes the inner node content for an url element to a buffer.

        Parameters:
        entry - the entry for which the content should be written
        Returns:
        the inner XML
      • getNavigationPages

        protected java.util.List<CmsResourcegetNavigationPages()
        Gets the list of pages from the navigation which should be directly added to the XML sitemap.

        Returns:
        the list of pages to add to the XML sitemap
      • getUrlSetOpenTag

        protected java.lang.String getUrlSetOpenTag()
        Gets the opening tag for the urlset element (can be overridden to add e.g. more namespaces.

        Returns:
        the opening tag
      • getXmlForEntry

        protected java.lang.String getXmlForEntry​(CmsXmlSitemapUrlBean entry)
        Writes the XML for an URL entry to a buffer.

        Parameters:
        entry - the XML sitemap entry bean
        Returns:
        an XML representation of this bean
      • isAliasBelowBaseFolder

        protected boolean isAliasBelowBaseFolder​(CmsAlias alias)
        Checks whether the given alias is below the base folder.

        Parameters:
        alias - the alias to check
        Returns:
        true if the alias is below the base folder
      • isValidDetailPageCombination

        protected boolean isValidDetailPageCombination​(CmsResource page,
                                                       java.util.Locale locale,
                                                       CmsResource detailRes)
        Checks whether the page/detail content combination is a valid detail page.

        Parameters:
        page - the container page
        locale - the locale
        detailRes - the detail content resource
        Returns:
        true if this is a valid detail page combination
      • replaceServerUri

        protected java.lang.String replaceServerUri​(java.lang.String link)
        Replaces the protocol/host/port of a link with the ones from the configured server URI, if it's not empty.

        Parameters:
        link - the link to change
        Returns:
        the changed link