Package cz.jiripinkas.jsitemapgenerator
Class AbstractSitemapGenerator<T extends AbstractGenerator>
- java.lang.Object
-
- cz.jiripinkas.jsitemapgenerator.AbstractGenerator<T>
-
- cz.jiripinkas.jsitemapgenerator.AbstractSitemapGenerator<T>
-
- Direct Known Subclasses:
SitemapGenerator,SitemapIndexGenerator
public abstract class AbstractSitemapGenerator<T extends AbstractGenerator> extends AbstractGenerator<T>
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class cz.jiripinkas.jsitemapgenerator.AbstractGenerator
AbstractGenerator.GeneratorConsumerWithException<T>, AbstractGenerator.RunnableWithException, AbstractGenerator.StringSupplierWithException<S>
-
-
Field Summary
Fields Modifier and Type Field Description protected W3CDateFormatdateFormat-
Fields inherited from class cz.jiripinkas.jsitemapgenerator.AbstractGenerator
baseUrl, urls
-
-
Constructor Summary
Constructors Constructor Description AbstractSitemapGenerator(String baseUrl)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidbeforeAddPageEvent(WebPage webPage)This method is called before adding a page to urls.TdefaultChangeFreq(ChangeFreq changeFreq)Sets default changeFreq for all subsequent WebPagesTdefaultChangeFreqAlways()Sets default changeFreq to ALWAYS for all subsequent WebPagesTdefaultChangeFreqDaily()Sets default changeFreq to DAILY for all subsequent WebPagesTdefaultChangeFreqHourly()Sets default changeFreq to HOURLY for all subsequent WebPagesTdefaultChangeFreqMonthly()Sets default changeFreq to MONTHLY for all subsequent WebPagesTdefaultChangeFreqNever()Sets default changeFreq to NEVER for all subsequent WebPagesTdefaultChangeFreqWeekly()Sets default changeFreq to WEEKLY for all subsequent WebPagesTdefaultChangeFreqYearly()Sets default changeFreq to YEARLY for all subsequent WebPagesTdefaultDir(String dirName)Sets default prefix dir to name for all subsequent WebPages.TdefaultDir(String... dirNames)Sets default prefix dirs to name for all subsequent WebPages.TdefaultExtension(String extension)Sets default suffix extension for all subsequent WebPages.TdefaultLastMod(LocalDateTime lastMod)Sets default lastMod for all subsequent WebPagesTdefaultLastMod(Date lastMod)Sets default lastMod for all subsequent WebPagesTdefaultLastModNow()Sets default lastMod = new Date() for all subsequent WebPagesTdefaultPriority(Double priority)Sets default priority for all subsequent WebPagesTdefaultPriorityMax()Sets default priority for all subsequent WebPages to maximum (1.0)protected StringgetAbsoluteUrl(String webPageName)Get absolute URL: If webPageName is null, return baseUrl.protected StringgetAbsoluteUrl(String webPageName, boolean escapeSpecialCharacters)Get absolute URL: If webPageName is null, return baseUrl.PingResponseping(Ping ping)Ping search engine(s) that sitemap has changed.voidpingBing()Deprecated.Useping(Ping)booleanpingBing(boolean doNotThrowExceptionOnFailure)Deprecated.Useping(Ping)voidpingBing(String sitemapUrl)Deprecated.Useping(Ping)booleanpingBing(String sitemapUrl, boolean doNotThrowExceptionOnFailure)Deprecated.Useping(Ping)voidpingGoogle()Deprecated.Useping(Ping)booleanpingGoogle(boolean doNotThrowExceptionOnFailure)Deprecated.Useping(Ping)voidpingGoogle(String sitemapUrl)Deprecated.Useping(Ping)booleanpingGoogle(String sitemapUrl, boolean doNotThrowExceptionOnFailure)Deprecated.Useping(Ping)TresetDefaultChangeFreq()Reset default changeFreqTresetDefaultDir()Reset default dir valueTresetDefaultExtension()Reset default extension valueTresetDefaultLastMod()Reset default lastModTresetDefaultPriority()Reset default priorityvoidsetHttpClient(HttpClient httpClient)TtoFile(File file)Construct and save sitemap to output fileTtoFile(File parent, String child)Construct and save sitemap to output fileTtoFile(String first, String... more)Construct and save sitemap to output fileTtoFile(Path path)Construct and save sitemap to output fileTtoFile(Supplier<File> fileSupplier)Construct and save sitemap to output filebyte[]toGzipByteArray()Construct sitemap into gzipped fileTtoGzipByteArray(Consumer<byte[]> byteArrayConsumer)Construct sitemap into gzipped byte array which is consumed by supplied ConsumerStringtoPrettyString(int indent)Construct sitemap into prettified StringTtoPrettyString(int indent, Consumer<String> stringConsumer)Construct sitemap into prettified String which is consumed by supplied ConsumerStringtoString()Construct sitemap into StringTtoString(Consumer<String> stringConsumer)Construct sitemap into String which is consumed by supplied Consumerabstract String[]toStringArray()-
Methods inherited from class cz.jiripinkas.jsitemapgenerator.AbstractGenerator
addPage, addPage, addPage, addPageNames, addPageNames, addPages, addPages, addPages, addPages, getThis, run, run, toPrettyXmlString
-
-
-
-
Field Detail
-
dateFormat
protected W3CDateFormat dateFormat
-
-
Constructor Detail
-
AbstractSitemapGenerator
public AbstractSitemapGenerator(String baseUrl)
-
-
Method Detail
-
toStringArray
public abstract String[] toStringArray()
-
toString
public String toString()
Construct sitemap into String
-
toString
public T toString(Consumer<String> stringConsumer)
Construct sitemap into String which is consumed by supplied Consumer- Parameters:
stringConsumer- Consumer which consumes generated String- Returns:
- this
-
toPrettyString
public String toPrettyString(int indent)
Construct sitemap into prettified String- Parameters:
indent- Indentation- Returns:
- sitemap
-
toPrettyString
public T toPrettyString(int indent, Consumer<String> stringConsumer)
Construct sitemap into prettified String which is consumed by supplied Consumer- Parameters:
indent- IndentationstringConsumer- Consumer which consumes generated String- Returns:
- this
-
toGzipByteArray
public byte[] toGzipByteArray()
Construct sitemap into gzipped file- Returns:
- byte array
-
toGzipByteArray
public T toGzipByteArray(Consumer<byte[]> byteArrayConsumer)
Construct sitemap into gzipped byte array which is consumed by supplied Consumer- Parameters:
byteArrayConsumer- Consumer which consumes generated byte array- Returns:
- this
-
toFile
public T toFile(File file) throws IOException
Construct and save sitemap to output file- Parameters:
file- Output file- Returns:
- this
- Throws:
IOException- when error
-
toFile
public T toFile(Supplier<File> fileSupplier) throws IOException
Construct and save sitemap to output file- Parameters:
fileSupplier- Supplier which supplies output file- Returns:
- this
- Throws:
IOException- when error
-
toFile
public T toFile(Path path) throws IOException
Construct and save sitemap to output file- Parameters:
path- Output file- Returns:
- this
- Throws:
IOException- when error
-
toFile
public T toFile(String first, String... more) throws IOException
Construct and save sitemap to output file- Parameters:
first- The path string or initial part of the path stringmore- Additional strings to be joined to form the path string- Returns:
- this
- Throws:
IOException- when error
-
toFile
public T toFile(File parent, String child) throws IOException
Construct and save sitemap to output file- Parameters:
parent- The parent abstract pathnamechild- The child pathname string- Returns:
- this
- Throws:
IOException- when error
-
ping
public PingResponse ping(Ping ping)
Ping search engine(s) that sitemap has changed.- Parameters:
ping- Ping object- Returns:
- true if operation succeeded. If ping.isThrowExceptionOnFailure() == false and operation doesn't succeed, returns false.
-
pingGoogle
@Deprecated public void pingGoogle(String sitemapUrl)
Deprecated.Useping(Ping)Ping Google that sitemap has changed. Will call this URL: https://www.google.com/ping?sitemap=URL_Encoded_sitemapUrl- Parameters:
sitemapUrl- sitemap url
-
pingGoogle
@Deprecated public boolean pingGoogle(String sitemapUrl, boolean doNotThrowExceptionOnFailure)
Deprecated.Useping(Ping)Ping Google that sitemap has changed. Will call this URL: https://www.google.com/ping?sitemap=URL_Encoded_sitemapUrl- Parameters:
sitemapUrl- sitemap urldoNotThrowExceptionOnFailure- If this is true and it's not possible to ping google, this method won't throw any exception, but will return false.- Returns:
- If operation succeeded
-
pingBing
@Deprecated public void pingBing(String sitemapUrl)
Deprecated.Useping(Ping)Ping Bing that sitemap has changed. Will call this URL: https://www.bing.com/ping?sitemap=URL_Encoded_sitemapUrl- Parameters:
sitemapUrl- sitemap url
-
pingBing
@Deprecated public boolean pingBing(String sitemapUrl, boolean doNotThrowExceptionOnFailure)
Deprecated.Useping(Ping)Ping Bing that sitemap has changed. Will call this URL: https://www.bing.com/ping?sitemap=URL_Encoded_sitemapUrl- Parameters:
sitemapUrl- sitemap urldoNotThrowExceptionOnFailure- If this is true and it's not possible to ping google, this method won't throw any exception, but will return false.- Returns:
- If operation succeeded
-
pingGoogle
@Deprecated public void pingGoogle()
Deprecated.Useping(Ping)Ping Google that sitemap has changed. Sitemap must be on this location: baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)
-
pingGoogle
@Deprecated public boolean pingGoogle(boolean doNotThrowExceptionOnFailure)
Deprecated.Useping(Ping)Ping Google that sitemap has changed. Sitemap must be on this location: baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)- Parameters:
doNotThrowExceptionOnFailure- If this is true and it's not possible to ping google, this method won't throw any exception, but will return false.- Returns:
- If operation succeeded
-
pingBing
@Deprecated public void pingBing()
Deprecated.Useping(Ping)Ping Google that sitemap has changed. Sitemap must be on this location: baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)
-
pingBing
@Deprecated public boolean pingBing(boolean doNotThrowExceptionOnFailure)
Deprecated.Useping(Ping)Ping Bing that sitemap has changed. Sitemap must be on this location: baseUrl/sitemap.xml (for example http://www.javavids.com/sitemap.xml)- Parameters:
doNotThrowExceptionOnFailure- If this is true and it's not possible to ping google, this method won't throw any exception, but will return false.- Returns:
- If operation succeeded
-
beforeAddPageEvent
protected void beforeAddPageEvent(WebPage webPage)
Description copied from class:AbstractGeneratorThis method is called before adding a page to urls. It can be used to change webPage attributes- Overrides:
beforeAddPageEventin classAbstractGenerator<T extends AbstractGenerator>- Parameters:
webPage- WebPage
-
defaultDir
public T defaultDir(String dirName)
Sets default prefix dir to name for all subsequent WebPages. Final name will be "dirName/name"- Parameters:
dirName- Dir name- Returns:
- this
-
defaultDir
public T defaultDir(String... dirNames)
Sets default prefix dirs to name for all subsequent WebPages. For dirs: ["a", "b", "c"], the final name will be "a/b/c/name"- Parameters:
dirNames- Dir names- Returns:
- this
-
resetDefaultDir
public T resetDefaultDir()
Reset default dir value- Returns:
- this
-
defaultExtension
public T defaultExtension(String extension)
Sets default suffix extension for all subsequent WebPages. Final name will be "name.extension"- Parameters:
extension- Extension- Returns:
- this
-
resetDefaultExtension
public T resetDefaultExtension()
Reset default extension value- Returns:
- this
-
defaultPriorityMax
public T defaultPriorityMax()
Sets default priority for all subsequent WebPages to maximum (1.0)- Returns:
- this
-
defaultPriority
public T defaultPriority(Double priority)
Sets default priority for all subsequent WebPages- Parameters:
priority- Default priority- Returns:
- this
-
resetDefaultPriority
public T resetDefaultPriority()
Reset default priority- Returns:
- this
-
defaultChangeFreq
public T defaultChangeFreq(ChangeFreq changeFreq)
Sets default changeFreq for all subsequent WebPages- Parameters:
changeFreq- ChangeFreq- Returns:
- this
-
defaultChangeFreqAlways
public T defaultChangeFreqAlways()
Sets default changeFreq to ALWAYS for all subsequent WebPages- Returns:
- this
-
defaultChangeFreqHourly
public T defaultChangeFreqHourly()
Sets default changeFreq to HOURLY for all subsequent WebPages- Returns:
- this
-
defaultChangeFreqDaily
public T defaultChangeFreqDaily()
Sets default changeFreq to DAILY for all subsequent WebPages- Returns:
- this
-
defaultChangeFreqWeekly
public T defaultChangeFreqWeekly()
Sets default changeFreq to WEEKLY for all subsequent WebPages- Returns:
- this
-
defaultChangeFreqMonthly
public T defaultChangeFreqMonthly()
Sets default changeFreq to MONTHLY for all subsequent WebPages- Returns:
- this
-
defaultChangeFreqYearly
public T defaultChangeFreqYearly()
Sets default changeFreq to YEARLY for all subsequent WebPages- Returns:
- this
-
defaultChangeFreqNever
public T defaultChangeFreqNever()
Sets default changeFreq to NEVER for all subsequent WebPages- Returns:
- this
-
resetDefaultChangeFreq
public T resetDefaultChangeFreq()
Reset default changeFreq- Returns:
- this
-
defaultLastMod
public T defaultLastMod(Date lastMod)
Sets default lastMod for all subsequent WebPages- Parameters:
lastMod- lastMod- Returns:
- this
-
defaultLastMod
public T defaultLastMod(LocalDateTime lastMod)
Sets default lastMod for all subsequent WebPages- Parameters:
lastMod- lastMod- Returns:
- this
-
defaultLastModNow
public T defaultLastModNow()
Sets default lastMod = new Date() for all subsequent WebPages- Returns:
- this
-
resetDefaultLastMod
public T resetDefaultLastMod()
Reset default lastMod- Returns:
- this
-
setHttpClient
public void setHttpClient(HttpClient httpClient)
-
getAbsoluteUrl
protected String getAbsoluteUrl(String webPageName)
Get absolute URL: If webPageName is null, return baseUrl. If webPageName is not null, check if webPageName is absolute (can be URL from CDN) or relative URL. If it's relative URL, prepend baseUrl and return result. This method escapes webPageName's special characters, thus it must not be called for ping Google / Bing functionality!- Parameters:
webPageName- WebPageName- Returns:
- Correct URL
-
getAbsoluteUrl
protected String getAbsoluteUrl(String webPageName, boolean escapeSpecialCharacters)
Get absolute URL: If webPageName is null, return baseUrl. If webPageName is not null, check if webPageName is absolute (can be URL from CDN) or relative URL. If it's relative URL, prepend baseUrl and return result- Parameters:
webPageName- WebPageNameescapeSpecialCharacters- Escape special characters? Special characters must be escaped if the URL will be stored to sitemap. If this method is called for ping Google / Bing functionality, special characters must not be escaped.- Returns:
- Correct URL
-
-