Project

General

Profile

« Previous | Next » 

Revision 3244

Added by Matt Jones about 17 years ago

Added a new class called Sitemap that is used to generate a series of XML documents representing the URLs of metacat documents following the sitemap protocol. The Sitemap class extends TimerTask so that it can be scheduled to run once a day or so. New configuration options were added to metacat.properties to control where the sitemaps are written and hw often they are updated. By default we do it once a day, as more often is overkill for search engines.

Included a JUnit unit test to test the Sitemap generation functionality.

Included changes to MetaCatServlet to schedule the Sitemap task the first time Metacat is called.

View differences:

MetaCatServlet.java
126 126
{
127 127
    private static Hashtable sessionHash = new Hashtable();
128 128
    private Timer timer = null;
129
    private static boolean sitemapScheduled;
129 130
    
130 131
    // Constants -- these should be final in a servlet
131 132
    private static final String PROLOG = "<?xml version=\"1.0\"?>";
......
244 245
	    } else {
245 246
                logMetacat.info(" \n **** Spatial cache is not set to regenerate on restart");
246 247
            }
247
           
248
           
248
            
249
            sitemapScheduled = false;
250
            
249 251
            logMetacat.info("Metacat (" + Version.getVersion()
250 252
                               + ") initialized.");
251 253

  
......
829 831
            //util.closeConnections();
830 832
            // Close the stream to the client
831 833
            //out.close();
834
            
835
            // Schedule the sitemap generator to run periodically
836
            scheduleSitemapGeneration(request);
832 837
        }
833 838
    }
834 839

  
......
3456 3461
            }
3457 3462
        }
3458 3463
    }
3464
    
3465
    /**
3466
     * Schedule the sitemap generator to run periodically and update all
3467
     * of the sitemap files for search indexing engines.
3468
     * 
3469
     * @param request a servlet request, from which we determine the context
3470
     */
3471
    private void scheduleSitemapGeneration(HttpServletRequest request) {
3472
    	if (!sitemapScheduled) {
3473
	    	String directoryName = MetaCatUtil.getOption("sitemapDirectory");
3474
			File directory = new File(directoryName);
3475
			directory.mkdirs();
3476
			String urlRoot = request.getRequestURL().toString();
3477
			String skin = MetaCatUtil.getOption("default-style");
3478
			Sitemap smap = new Sitemap(directory, urlRoot, skin);
3479
			long sitemapInterval = Integer.parseInt(
3480
					MetaCatUtil.getOption("sitemapInterval"));
3481
			long firstDelay = 60*1000;   // 60 seconds delay
3482
			timer.schedule(smap, firstDelay, sitemapInterval);
3483
			sitemapScheduled = true;
3484
    	}
3485
    }
3459 3486
}

Also available in: Unified diff