Class ResourceTreeSitemapGenerator

  • All Implemented Interfaces:
    SitemapGenerator

    @ConsumerType
    public abstract class ResourceTreeSitemapGenerator
    extends Object
    implements SitemapGenerator
    A default implementation of SitemapGenerator that traverses a resource tree.

    Implementations may change the traversal behaviour by overriding shouldFollow(Resource) or shouldInclude(Resource) but it is recommended to always consider the default implementation. The default implementation includes only Resources that have a "jcr:content" child and follows through only on content that is not below the "jcr:content" or any other sitemap root.

    This implementation keeps track of the traversal's state in the SitemapGenerator.Context. It is capable to continue from a previous persisted state, when the generation got aborted.

    • Constructor Detail

      • ResourceTreeSitemapGenerator

        public ResourceTreeSitemapGenerator()
    • Method Detail

      • generate

        public final void generate​(@NotNull
                                   @NotNull org.apache.sling.api.resource.Resource sitemapRoot,
                                   @NotNull
                                   @NotNull String name,
                                   @NotNull
                                   @NotNull Sitemap sitemap,
                                   @NotNull
                                   SitemapGenerator.Context context)
                            throws SitemapException
        Description copied from interface: SitemapGenerator
        Generates a Sitemap with the given name at the given Resource.

        This process may be stateful and the given SitemapGenerator.Context can be used to keep track of the state. For example a traversal that keeps track on the last Resource added to the Sitemap.

        Specified by:
        generate in interface SitemapGenerator
        Parameters:
        sitemapRoot - the root at which the sitemap should be created
        name - the name, one of the names returned by SitemapGenerator.getNames(Resource) for the given sitemapRoot
        sitemap - the Sitemap object to add locations to
        context - the context under which the sitemap is generated
        Throws:
        SitemapException - may be thrown in unrecoverable exceptional cases
      • addResource

        protected abstract void addResource​(@NotNull
                                            @NotNull String name,
                                            @NotNull
                                            @NotNull Sitemap sitemap,
                                            @NotNull
                                            @NotNull org.apache.sling.api.resource.Resource resource)
                                     throws SitemapException
        Implementations add the given Resource to the given Sitemap.
        Parameters:
        name - the name of the sitemap currently being generated
        sitemap -
        resource -
        Throws:
        SitemapException
      • shouldInclude

        protected boolean shouldInclude​(@NotNull
                                        @NotNull org.apache.sling.api.resource.Resource resource)
        When implementations return true, the given resource will be passed to addResource(String, Sitemap, Resource) to be added to the Sitemap.
        Parameters:
        resource -
        Returns:
      • shouldFollow

        protected boolean shouldFollow​(@NotNull
                                       @NotNull org.apache.sling.api.resource.Resource resource)
        When implementations return true, the children of the given Resource will be followed through by the traversal.
        Parameters:
        resource -
        Returns: