Sitemap generator


The sitemap is an XML file which helps bots and search engines know all pages that our web site have.

References, Sitemap on Wikipedia


Check the link below to see the sitemap of Tapestry5 dev-util:

View sitemap

Source codes

package es.carlosmontero.webapp.t5devutil.pages;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Locale;

import org.apache.commons.lang3.StringUtils;
import org.apache.tapestry5.SymbolConstants;
import org.apache.tapestry5.annotations.ContentType;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.Messages;
import org.apache.tapestry5.ioc.annotations.Inject;
import org.apache.tapestry5.ioc.annotations.Symbol;

import es.carlosmontero.webapp.t5devutil.pages.IndexPage.MenuGroup;
import es.carlosmontero.webapp.t5devutil.pages.IndexPage.MenuItem;

@ContentType(value = "text/xml")
public class Sitemap {

   private Messages messages;

   private PageRenderLinkSource pageRenderLinkSource;

   private PersistentLocale persistentLocale;

   private List<Object> pages;

   private Object page;

   private List<String> locales;

   private String locale, otherLocale;

   private String supportedLocales;

   public void setupRender() {

      locales = Arrays.asList(supportedLocales.split(","));

      pages = new ArrayList<Object>();


      for (final MenuGroup menuGroup : IndexPage.MENU_GROUPS) {
         for (final MenuItem menuItem : menuGroup.items) {
            if (StringUtils.isNotBlank( {


   public String getURL(final String pageName, final String locale) {

      persistentLocale.set(new Locale(locale));

      return pageRenderLinkSource.createPageRenderLinkWithContext(pageName).toAbsoluteURI();

   public String getLink(final String pageName, final String locale) {
      return messages.format("SitemapLink", locale, getURL(pageName, locale));

   public String getURL() {
      return getURL(locale);

   public String getURL(final String locale) {

      persistentLocale.set(new Locale(locale));

      if (page instanceof String) {
         return pageRenderLinkSource.createPageRenderLinkWithContext((String) page).toAbsoluteURI();
      return pageRenderLinkSource.createPageRenderLinkWithContext((Class) page).toAbsoluteURI();

   public String getLink() {
      return messages.format("SitemapLink", otherLocale, getURL(otherLocale));

   public String getLink2() {
      return messages.format("SitemapLink", locale, getURL(locale));

   public List<String> getOtherLocales() {

      final List<String> otherLocales = new ArrayList<String>(locales);
      return otherLocales;


    * Optional. For debug.
   public String getXmlComment() {
      String pageName = null;
      if (page instanceof String) {
         pageName = (String) page;
      else if (page instanceof Class) {
         pageName = ((Class) page).getCanonicalName().toLowerCase();
         pageName = pageName.substring(21, pageName.length() - 4);
      return new StringBuilder("<!-- ").append(pageName.replace(".", "/"))
              .append(" -->").toString();