Package cz.jiripinkas.jsitemapgenerator
Class AbstractGenerator<I extends AbstractGenerator>
- java.lang.Object
-
- cz.jiripinkas.jsitemapgenerator.AbstractGenerator<I>
-
- Type Parameters:
I- Concrete implementation of AbstractGenerator, for example SitemapGenerator
- Direct Known Subclasses:
AbstractSitemapGenerator,RssGenerator
public abstract class AbstractGenerator<I extends AbstractGenerator> extends Object
Abstract Generator
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceAbstractGenerator.GeneratorConsumerWithException<T>static interfaceAbstractGenerator.RunnableWithExceptionstatic interfaceAbstractGenerator.StringSupplierWithException<S>
-
Constructor Summary
Constructors Constructor Description AbstractGenerator(String baseUrl)Construct web sitemap.AbstractGenerator(String baseUrl, boolean root)Construct web sitemap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description IaddPage(AbstractGenerator.StringSupplierWithException<String> supplier)Add single page to sitemap.IaddPage(WebPage webPage)Add single page to sitemapIaddPage(String name)Add single page to sitemap.<T> IaddPageNames(Collection<T> webPages, Function<T,String> mapper)Add collection of pages to sitemap<T> IaddPageNames(Supplier<Collection<T>> webPagesSupplier, Function<T,String> mapper)Add collection of pages to sitemapIaddPages(Collection<WebPage> webPages)Add collection of pages to sitemap<T> IaddPages(Collection<T> webPages, Function<T,WebPage> mapper)Add collection of pages to sitemapIaddPages(Supplier<Collection<WebPage>> webPagesSupplier)Add collection of pages to sitemap<T> IaddPages(Supplier<Collection<T>> webPagesSupplier, Function<T,WebPage> mapper)Add collection of pages to sitemapprotected voidbeforeAddPageEvent(WebPage webPage)This method is called before adding a page to urls.protected IgetThis()Irun(AbstractGenerator.GeneratorConsumerWithException<I> consumer)Run some method.Irun(AbstractGenerator.RunnableWithException runnable)Run some methodprotected StringtoPrettyXmlString(String xml, int indent)Method to prettify XML string
-
-
-
Constructor Detail
-
AbstractGenerator
public AbstractGenerator(String baseUrl, boolean root)
Construct web sitemap.- Parameters:
baseUrl- All URLs must start with this baseUrl, for example http://www.javavids.comroot- If Base URL is root (for example http://www.javavids.com or if it's some path like http://www.javalibs.com/blog)
-
AbstractGenerator
public AbstractGenerator(String baseUrl)
Construct web sitemap. Root = true.- Parameters:
baseUrl- All URLs must start with this baseUrl, for example http://www.javavids.com
-
-
Method Detail
-
addPage
public I addPage(WebPage webPage)
Add single page to sitemap- Parameters:
webPage- single page- Returns:
- this
-
addPage
public I addPage(String name)
Add single page to sitemap. This method calls addPage(WebPage.of(name))- Parameters:
name- single page- Returns:
- this
-
addPage
public I addPage(AbstractGenerator.StringSupplierWithException<String> supplier)
Add single page to sitemap.- Parameters:
supplier- Supplier method which sneaks any checked exception https://www.baeldung.com/java-sneaky-throws Allows for calling method which performs some operation and then returns name of page.- Returns:
- this
-
beforeAddPageEvent
protected void beforeAddPageEvent(WebPage webPage)
This method is called before adding a page to urls. It can be used to change webPage attributes- Parameters:
webPage- WebPage
-
addPages
public I addPages(Collection<WebPage> webPages)
Add collection of pages to sitemap- Parameters:
webPages- Collection of pages- Returns:
- this
-
addPages
public I addPages(Supplier<Collection<WebPage>> webPagesSupplier)
Add collection of pages to sitemap- Parameters:
webPagesSupplier- Collection of pages supplier- Returns:
- this
-
addPages
public <T> I addPages(Collection<T> webPages, Function<T,WebPage> mapper)
Add collection of pages to sitemap- Type Parameters:
T- This is the type parameter- Parameters:
webPages- Collection of pagesmapper- Mapper function which transforms some object to WebPage- Returns:
- this
-
addPageNames
public <T> I addPageNames(Collection<T> webPages, Function<T,String> mapper)
Add collection of pages to sitemap- Type Parameters:
T- This is the type parameter- Parameters:
webPages- Collection of pagesmapper- Mapper function which transforms some object to String. This will be passed to WebPage.of(name)- Returns:
- this
-
addPages
public <T> I addPages(Supplier<Collection<T>> webPagesSupplier, Function<T,WebPage> mapper)
Add collection of pages to sitemap- Type Parameters:
T- This is the type parameter- Parameters:
webPagesSupplier- Collection of pages suppliermapper- Mapper function which transforms some object to WebPage- Returns:
- this
-
addPageNames
public <T> I addPageNames(Supplier<Collection<T>> webPagesSupplier, Function<T,String> mapper)
Add collection of pages to sitemap- Type Parameters:
T- This is the type parameter- Parameters:
webPagesSupplier- Collection of pages suppliermapper- Mapper function which transforms some object to String. This will be passed to WebPage.of(name)- Returns:
- this
-
run
public I run(AbstractGenerator.RunnableWithException runnable)
Run some method- Parameters:
runnable- Runnable method which sneaks any checked exception https://www.baeldung.com/java-sneaky-throws Usage: SitemapIndexGenerator.of(homepage) .run(() -> methodToCall()) .addPage(WebPage.of("test)) .toString()- Returns:
- this
-
run
public I run(AbstractGenerator.GeneratorConsumerWithException<I> consumer)
Run some method. Argument is current generator, which allows to access current generator in run() method.- Parameters:
consumer- Consumer method which sneaks any checked exception https://www.baeldung.com/java-sneaky-throws Usage: SitemapIndexGenerator.of(homepage) .run(currentGenerator -> { ... }) .addPage(WebPage.of("test)) .toString()- Returns:
- this
-
getThis
protected I getThis()
-
-