public abstract class AbstractGenerator
extends java.lang.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 java.io.PrintStream |
currentOutput
Current output
|
protected int |
fileCount
Number of files written so far
|
protected java.io.File |
outputDir
Directory files are written to
|
protected int |
urlsWritten
Number of URLs written to current file
|
| Constructor and Description |
|---|
AbstractGenerator(java.io.File outputDirIn)
Initialize this generator to write to the given directory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addURL(java.lang.String url,
java.util.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 java.lang.String |
getFilename(int number)
Return the filename a sitemap at the given index should be stored at.
|
abstract java.lang.String |
getIndexFilename()
Get the filename the index should be written to.
|
abstract java.lang.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 java.lang.String |
getTrailingBoilerPlate()
Return the boilerplate at the end of a sitemap file.
|
abstract java.lang.String |
getURLText(java.lang.String url,
java.util.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(java.io.PrintStream output,
int sitemapCount)
Write the index file.
|
protected int fileCount
protected int bytesWritten
protected int urlsWritten
protected java.io.File outputDir
protected java.io.PrintStream currentOutput
public AbstractGenerator(java.io.File outputDirIn)
outputDirIn - directory to write sitemap files toprotected void startNewFile()
throws java.io.IOException
java.io.IOException - if an error occurs creating the filepublic void addURL(java.lang.String url,
java.util.Date lastMod)
throws java.io.IOException
url - Full URL to addlastMod - Date URL was last modified, or nulljava.io.IOException - if an error occurs writingprotected void closeCurrentFile()
throws java.io.IOException
java.io.IOException - if an error occurs writingpublic int finish()
throws java.io.IOException
addURL(String, Date) have
been completed, and invalidates the generator.java.io.IOException - if an error occurs writingpublic abstract java.lang.String getURLText(java.lang.String url,
java.util.Date lastMod)
url - URL to add information aboutlastMod - date URL was last modified, or null if unknown or not
applicablepublic abstract java.lang.String getLeadingBoilerPlate()
public abstract java.lang.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 java.lang.String getFilename(int number)
number - index of the sitemap file (zero is first).public abstract java.lang.String getIndexFilename()
public abstract void writeIndex(java.io.PrintStream output,
int sitemapCount)
throws java.io.IOException
output - stream to write the index tositemapCount - number of sitemaps that were generatedjava.io.IOException - if an IO error occursCopyright © 2013 DuraSpace. All Rights Reserved.