use of com.redfin.sitemapgenerator.SitemapIndexGenerator in project eol-globi-data by jhpoelen.
the class SiteMapUtils method generateSiteMapFor.
public static List<File> generateSiteMapFor(String queryParamName, Set<String> queryParamValues, File baseDir, String siteMapLocation) throws IOException {
final String hostname = "www.globalbioticinteractions.org";
final String baseUrl = "http://" + hostname;
WebSitemapGenerator wsg = WebSitemapGenerator.builder(baseUrl, baseDir).gzip(true).build();
for (String accordingTo : queryParamValues) {
URI uri;
try {
uri = new URI("http", hostname, "/", queryParamName + accordingTo, null);
} catch (URISyntaxException e) {
throw new IOException("unexpected malformed uri", e);
}
WebSitemapUrl url = new WebSitemapUrl.Options(StringEscapeUtils.escapeXml10(uri.toString())).lastMod(new Date()).priority(1.0).changeFreq(ChangeFreq.WEEKLY).build();
wsg.addUrl(url);
}
final List<File> maps = wsg.write();
File outFile = new File(baseDir, "sitemap_index.xml");
SitemapIndexGenerator sig = (new SitemapIndexGenerator.Options(siteMapLocation, outFile)).build();
if (maps.size() > 1) {
sig.addUrls(siteMapLocation + "sitemap", ".xml.gz", maps.size()).write();
} else {
sig.addUrl(siteMapLocation + "sitemap.xml.gz");
}
sig.write();
return maps;
}
use of com.redfin.sitemapgenerator.SitemapIndexGenerator in project MassBank-web by MassBank.
the class SiteMapServlet method init.
public void init() throws ServletException {
logger.trace("ServletContext.TEMPDIR: " + getServletContext().getAttribute(ServletContext.TEMPDIR));
File tmpdir = (File) getServletContext().getAttribute(ServletContext.TEMPDIR);
// remove old index
for (File file : tmpdir.listFiles()) {
if (file.getName().matches("sitemap.*\\.xml$")) {
logger.trace("Remove old sitemap: " + file.toString());
file.delete();
}
}
try {
// create sitemap generator
String sitemapbaseurl = Config.get().SitemapBaseURL();
if (!sitemapbaseurl.endsWith("/"))
sitemapbaseurl = sitemapbaseurl + "/";
WebSitemapGenerator wsg = new WebSitemapGenerator(sitemapbaseurl, tmpdir);
// add static content
wsg.addUrl(sitemapbaseurl);
wsg.addUrl(sitemapbaseurl + "Index");
wsg.addUrl(sitemapbaseurl + "Search");
wsg.addUrl(sitemapbaseurl + "RecordIndex");
// add dynamic content
DatabaseManager databaseManager = new DatabaseManager("MassBank");
PreparedStatement stmnt = databaseManager.getConnection().prepareStatement("SELECT ACCESSION FROM RECORD");
ResultSet res = stmnt.executeQuery();
while (res.next()) {
wsg.addUrl(sitemapbaseurl + "RecordDisplay?id=" + res.getString(1));
}
databaseManager.closeConnection();
// write new sitemaps
List<File> sitemaps = wsg.write();
logger.trace("File(s) written:\n" + sitemaps);
// write sitemap index
SitemapIndexGenerator sig = new SitemapIndexGenerator(sitemapbaseurl, new File(tmpdir, "sitemapindex.xml"));
for (File sitemap : sitemaps) {
sig.addUrl(sitemapbaseurl + "sitemap/" + sitemap.getName());
}
sig.write();
// get the current database timestamp
timestamp = new DatabaseTimestamp();
} catch (ConfigurationException | MalformedURLException | SQLException e) {
logger.error(e.getMessage());
}
}
Aggregations