[opencms-dev] Google Site Maps

Isaac R. Higgins isaac.higgins at isaacray.com
Mon Feb 26 23:20:20 CET 2007


I have been searching for an basic opencms google sitemap XML generator all day.  I know no one asked for this, but I'm going to send it to the list anyway just in case someone is looking for one in the future.

https://www.google.com/webmasters/tools/docs/en/protocol.html#sitemapXMLFormat

I just created a file "sitemap.xml" in the root of my site with the following source:

-----------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %><%@ 
    taglib prefix="c" uri="http://java.sun.com/jstl/core" %><%@ 
    page import="com.opencms.flex.jsp.*,com.opencms.file.*,java.util.*" %>
<jsp:useBean id="cmsbean" class="org.opencms.jsp.CmsJspBean">
  <% cmsbean.init(pageContext, request, response); %>
</jsp:useBean><%

java.util.List alist = (new org.opencms.jsp.CmsJspNavBuilder()).getSiteNavigation(cmsbean.getCmsObject(), "/" ,-1);

%>
  <urlset xmlns="http://www.google.com/schemas/sitemap/0.84">
<% for (int i=0;i<alist.size();++i){%>
<%
	org.opencms.file.CmsResource ress = null;
	java.util.Date date1 = new java.util.Date();
	try{
		ress = org.opencms.main.OpenCms.initResource(cmsbean.getCmsObject(),
			(((org.opencms.jsp.CmsJspNavElement)alist.get(i)).getResourceName()),
			request,
			response);
		date1 = new java.util.Date(ress.getDateLastModified());
	}catch(Exception e){}
	
	int year = date1.getYear()+1900;
	int day = date1.getDate();
	int month = date1.getMonth()+1;
%>
   <url>
    <loc><%= ((org.opencms.jsp.CmsJspNavElement) alist.get(i)).getResourceName() %></loc>
    <lastmod><%= year %>-<%= month %>-<%= day %></lastmod>
    <changefreq>weekly</changefreq>
    <priority>0.5</priority>
   </url>  
<%}%>
  </urlset> 
------------------------------------------------------
-------------- next part --------------
A non-text attachment was scrubbed...
Name: winmail.dat
Type: application/ms-tnef
Size: 3357 bytes
Desc: not available
URL: <https://webmail.opencms.org/pipermail/opencms-dev/attachments/20070226/a0c414f4/attachment.bin>


More information about the opencms-dev mailing list