Search in sources :

Example 1 with WebSitemapGenerator

use of com.redfin.sitemapgenerator.WebSitemapGenerator 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)

Example 2 with WebSitemapGenerator

use of com.redfin.sitemapgenerator.WebSitemapGenerator 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());
    }
}
Also used : SitemapIndexGenerator(com.redfin.sitemapgenerator.SitemapIndexGenerator) WebSitemapGenerator(com.redfin.sitemapgenerator.WebSitemapGenerator) MalformedURLException(java.net.MalformedURLException) DatabaseManager(massbank.db.DatabaseManager) SQLException(java.sql.SQLException) PreparedStatement(java.sql.PreparedStatement) ConfigurationException(org.apache.commons.configuration2.ex.ConfigurationException) ResultSet(java.sql.ResultSet) DatabaseTimestamp(massbank.db.DatabaseTimestamp) File(java.io.File)

Aggregations

SitemapIndexGenerator (com.redfin.sitemapgenerator.SitemapIndexGenerator)2 WebSitemapGenerator (com.redfin.sitemapgenerator.WebSitemapGenerator)2 File (java.io.File)2 WebSitemapUrl (com.redfin.sitemapgenerator.WebSitemapUrl)1 IOException (java.io.IOException)1 MalformedURLException (java.net.MalformedURLException)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Date (java.util.Date)1 DatabaseManager (massbank.db.DatabaseManager)1 DatabaseTimestamp (massbank.db.DatabaseTimestamp)1 ConfigurationException (org.apache.commons.configuration2.ex.ConfigurationException)1