public abstract class AbstractGenerator extends Object
Provides most of the required functionality, subclasses need just implement a few methods that specify the "boilerplate" and text for including URLs.
Typical usage:
AbstractGenerator g = new FooGenerator(...);
while (...) {
g.addURL(url, date);
}
g.finish();
| Modifier and Type | Field and Description |
|---|---|
protected int |
bytesWritten
Number of bytes written to current file
|
protected PrintStream |
currentOutput
Current output
|
protected int |
fileCount
Number of files written so far
|
protected File |
outputDir
Directory files are written to
|
protected int |
urlsWritten
Number of URLs written to current file
|
| Constructor and Description |
|---|
AbstractGenerator(File outputDirIn)
Initialize this generator to write to the given directory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addURL(String url,
Date lastMod)
Add the given URL to the sitemap.
|
protected void |
closeCurrentFile()
Finish with the current sitemap file.
|
int |
finish()
Complete writing sitemap files and write the index files.
|
abstract String |
getFilename(int number)
Return the filename a sitemap at the given index should be stored at.
|
abstract String |
getIndexFilename()
Get the filename the index should be written to.
|
abstract String |
getLeadingBoilerPlate()
Return the boilerplate at the top of a sitemap file.
|
abstract int |
getMaxSize()
Return the maximum size in bytes that an individual sitemap file should
be.
|
abstract int |
getMaxURLs()
Return the maximum number of URLs that an individual sitemap file should
contain.
|
abstract String |
getTrailingBoilerPlate()
Return the boilerplate at the end of a sitemap file.
|
abstract String |
getURLText(String url,
Date lastMod)
Return marked-up text to be included in a sitemap about a given URL.
|
protected void |
startNewFile()
Start writing a new sitemap file.
|
abstract boolean |
useCompression()
Return whether the written sitemap files and index should be
GZIP-compressed.
|
abstract void |
writeIndex(PrintStream output,
int sitemapCount)
Write the index file.
|
protected int fileCount
protected int bytesWritten
protected int urlsWritten
protected File outputDir
protected PrintStream currentOutput
public AbstractGenerator(File outputDirIn)
outputDirIn - directory to write sitemap files toprotected void startNewFile()
throws IOException
IOException - if an error occurs creating the filepublic void addURL(String url, Date lastMod) throws IOException
url - Full URL to addlastMod - Date URL was last modified, or nullIOException - if an error occurs writingprotected void closeCurrentFile()
throws IOException
IOException - if an error occurs writingpublic int finish()
throws IOException
addURL(String, Date) have
been completed, and invalidates the generator.IOException - if an error occurs writingpublic abstract String getURLText(String url, Date lastMod)
url - URL to add information aboutlastMod - date URL was last modified, or null if unknown or not
applicablepublic abstract String getLeadingBoilerPlate()
public abstract String getTrailingBoilerPlate()
public abstract int getMaxSize()
public abstract int getMaxURLs()
public abstract boolean useCompression()
true if GZIP compression should be used, false
otherwise.public abstract String getFilename(int number)
number - index of the sitemap file (zero is first).public abstract String getIndexFilename()
public abstract void writeIndex(PrintStream output, int sitemapCount) throws IOException
output - stream to write the index tositemapCount - number of sitemaps that were generatedIOException - if an IO error occursCopyright © 2013 DuraSpace. All Rights Reserved.