Skip to content

Latest commit

 

History

History
85 lines (71 loc) · 2.98 KB

README.md

File metadata and controls

85 lines (71 loc) · 2.98 KB

Java sitemap generator

This library generates a web sitemap and can ping Google that it has changed. This project has been inspired by sitemapgen4j, but is much more focused on traditional web sitemap and ease of use.

Typical usage:

First add this library to classpath:


<dependency>
  <groupId>cz.jiripinkas</groupId>
  <artifactId>jsitemapgenerator</artifactId>
  <version>2.1</version>
</dependency>

If you want to use "ping google / bing" functionality, also add this library to classpath:


<dependency>
  <groupId>org.apache.httpcomponents</groupId>
  <artifactId>httpclient</artifactId>
  <version>4.2.2</version>
</dependency>

How to create a sitemap:


// create web sitemap for web http://www.javavids.com
SitemapGenerator sitemapGenerator = new SitemapGenerator("http://www.javavids.com");
// add some URLs
sitemapGenerator.addPage(new WebPageBuilder().name("index.php")
   .priorityMax().changeFreqNever().lastModNow().build());
sitemapGenerator.addPage(new WebPageBuilder().name("latest.php").build());
sitemapGenerator.addPage(new WebPageBuilder().name("contact.php").build());
// generate sitemap and save it to file /var/www/sitemap.xml
File file = new File("/var/www/sitemap.xml");
sitemapGenerator.constructAndSaveSitemap(file);
// inform Google that this sitemap has changed
sitemapGenerator.pingGoogle();

How to create a sitemap index:


SitemapIndexGenerator sitemapIndexGenerator = new SitemapIndexGenerator("http://javalibs.com");
sitemapIndexGenerator.addPage(new WebPageBuilder().name("sitemap-plugins.xml").build());
sitemapIndexGenerator.addPage(new WebPageBuilder().name("sitemap-archetypes.xml").build());
System.out.println(sitemapIndexGenerator.constructSitemapString());

How to create RSS channel:


RssGenerator rssGenerator = new RssGenerator("http://www.topjavablogs", 
                                             "Top Java Blogs", "Best Java Blogs");
rssGenerator.addPage(new RssItemBuilder().pubDate(new Date()).title("News Title")
                        .description("News Description").name("page-name").build());
System.out.println(rssGenerator.constructRss());

My other projects: