Class ResourceTreeSitemapGenerator
- java.lang.Object
-
- org.apache.sling.sitemap.spi.generator.ResourceTreeSitemapGenerator
-
- All Implemented Interfaces:
SitemapGenerator
@ConsumerType public abstract class ResourceTreeSitemapGenerator extends Object implements SitemapGenerator
A default implementation ofSitemapGenerator
that traverses a resource tree.Implementations may change the traversal behaviour by overriding
shouldFollow(Resource)
orshouldInclude(Resource)
but it is recommended to always consider the default implementation. The default implementation includes onlyResource
s 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.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.apache.sling.sitemap.spi.generator.SitemapGenerator
SitemapGenerator.Context
-
-
Field Summary
Fields Modifier and Type Field Description protected static String
PROPERTY_LAST_PATH
-
Constructor Summary
Constructors Constructor Description ResourceTreeSitemapGenerator()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract void
addResource(@NotNull String name, @NotNull Sitemap sitemap, @NotNull org.apache.sling.api.resource.Resource resource)
Implementations add the givenResource
to the givenSitemap
.void
generate(@NotNull org.apache.sling.api.resource.Resource sitemapRoot, @NotNull String name, @NotNull Sitemap sitemap, SitemapGenerator.Context context)
Generates aSitemap
with the given name at the givenResource
.protected boolean
shouldFollow(@NotNull org.apache.sling.api.resource.Resource resource)
When implementations return true, the children of the givenResource
will be followed through by the traversal.protected boolean
shouldInclude(@NotNull org.apache.sling.api.resource.Resource resource)
When implementations return true, the given resource will be passed toaddResource(String, Sitemap, Resource)
to be added to theSitemap
.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.apache.sling.sitemap.spi.generator.SitemapGenerator
getNames, getOnDemandNames
-
-
-
-
Field Detail
-
PROPERTY_LAST_PATH
protected static final String PROPERTY_LAST_PATH
- See Also:
- Constant Field Values
-
-
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 aSitemap
with the given name at the givenResource
.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 lastResource
added to theSitemap
.- Specified by:
generate
in interfaceSitemapGenerator
- Parameters:
sitemapRoot
- the root at which the sitemap should be createdname
- the name, one of the names returned bySitemapGenerator.getNames(Resource)
for the given sitemapRootsitemap
- theSitemap
object to add locations tocontext
- 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 givenResource
to the givenSitemap
.- Parameters:
name
- the name of the sitemap currently being generatedsitemap
-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 toaddResource(String, Sitemap, Resource)
to be added to theSitemap
.- Parameters:
resource
-- Returns:
-
shouldFollow
protected boolean shouldFollow(@NotNull @NotNull org.apache.sling.api.resource.Resource resource)
When implementations return true, the children of the givenResource
will be followed through by the traversal.- Parameters:
resource
-- Returns:
-
-