Search in sources :

Example 1 with WebSitemapUrl

use of com.redfin.sitemapgenerator.WebSitemapUrl 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;
}
Also used : SitemapIndexGenerator(com.redfin.sitemapgenerator.SitemapIndexGenerator) WebSitemapGenerator(com.redfin.sitemapgenerator.WebSitemapGenerator) WebSitemapUrl(com.redfin.sitemapgenerator.WebSitemapUrl) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) File(java.io.File) Date(java.util.Date)

Aggregations

SitemapIndexGenerator (com.redfin.sitemapgenerator.SitemapIndexGenerator)1 WebSitemapGenerator (com.redfin.sitemapgenerator.WebSitemapGenerator)1 WebSitemapUrl (com.redfin.sitemapgenerator.WebSitemapUrl)1 File (java.io.File)1 IOException (java.io.IOException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Date (java.util.Date)1