[opencms-dev] SiteMap / Navigation

Pedro Huitema Pedro.Huitema at wwu.edu
Fri Jun 10 19:50:10 CEST 2005


Here is a script that is in use on our instance of OpenCMS (we're still
running 5, but the code should work fine under 6). This will output a
site map to the screen:

<%@ page session="false" import="com.opencms.flex.jsp.*" %>
<%@ taglib prefix="cms" uri="http://www.opencms.org/taglib/cms" %>
<%
	
	// Change this variable to the root folder of the project
	String rootFolder = "/WWU.CS/";

	// Obtain some page information
	com.opencms.flex.jsp.CmsJspActionElement cms = new
CmsJspActionElement(pageContext, request, response);
	String filename, foldername, filenameparam;
	filename = cms.getRequestContext().getUri();
	
	// Retrieve the folder that the file is stored in
	if ((filenameparam = request.getParameter("filename")) == null)
{
		foldername = com.opencms.file.CmsFile.getPath(filename);

	} else {
		foldername =
com.opencms.file.CmsResource.getPath(filenameparam);
		String foldernameprop = cms.property("target",
filename);
		if (foldernameprop != null) foldername = foldernameprop
+ foldername;  
	}
	
	// Setup some page constants
	String moduleFolder = "/system/modules/wwutemplates/";
	String showsource = cms.property("showsource", filename, "no");
	String targetframe = request.getParameter("targetframe");
	if (targetframe == null || "".equals(targetframe) ||
"null".equals(targetframe)) {
		targetframe = "_self";
	}
	
%>

<%!	

	String printNavigation(String navFolderName,
com.opencms.flex.jsp.CmsJspActionElement cms) {

		String returnString = "";

		java.util.ArrayList navList =
cms.getNavigation().getNavigationForFolder(navFolderName); 
		java.util.Iterator n = navList.iterator();
		
		returnString = "<ul>";
		
		while (n.hasNext()) {
		
			CmsJspNavElement ni =
(CmsJspNavElement)n.next();
			
			if (ni.getResourceName().indexOf("index.html")
== -1) {
				returnString += "<li><p><a href=\"" +
cms.link(ni.getResourceName()) + "\">" + ni.getNavText() + "</a></p>";
		
				// Display a folder   
				if (ni.isFolderLink()) {
			
					returnString +=
printNavigation(ni.getResourceName(), cms);
				
				}
			
				returnString += "</li>";
			}
			
		}		
		
		returnString += "</ul>";

		return returnString;
	
	}
%>
<%
	
	out.println("<ul><li><p><a href=\"" + cms.link(rootFolder) +
"\">Home</a></p>" + printNavigation(rootFolder, cms) + "</li></ul>");
	
%>

I hope this helps...

 
Pedro Huitema
(360) 650-7229
Pedro.Huitema at wwu.edu
Web Services, MH182
Western Washington University
Bellingham, WA 98225-9009

-----Original Message-----
From: opencms-dev-bounces at opencms.org
[mailto:opencms-dev-bounces at opencms.org] On Behalf Of Marius Oancea
Sent: Thursday, June 09, 2005 5:36 AM
To: The OpenCms mailing list
Subject: Re: [opencms-dev] SiteMap / Navigation

Hi,
    I'm not and expert in OpenCms yet but i think the api only returns 
the current navigation level. You have to recursivelly browse the tree. 
Create a java class for that propose, or (i do not recomand) make a 
metod in jsp.

Regards
    Marius

John Crickett wrote:

>I'm trying to build a sitemap / navigation system for my site I've had
a
>look at the documentation and the following messages in the archive:
>
>http://mail.opencms.org/pipermail/opencms-dev/2005q2/017277.html
>
>However like this chap:
>
>http://mail.opencms.org/pipermail/opencms-dev/2005q1/014744.html
>
>My list returned from getSiteNavigation is incomplete. My code is:
>
><%@ page import="java.util.*" %>
><%@ page import="org.opencms.jsp.*" %>
><%	
>	CmsJspActionElement cms = new CmsJspActionElement(pageContext,
>request, response);
>
>	CmsJspNavBuilder builder = cms.getNavigation();
>
>	List list = builder.getSiteNavigation("/mysite/", -1);
>
>	java.util.Iterator i = list.iterator();
>
>	while (i.hasNext()) 
>	{
>		CmsJspNavElement ne = (CmsJspNavElement)i.next();
>
>		out.println(ne.getNavText());
>	}
>%>
>
>Which results in the print out of the 3 html files in the dir
>/sites/default/mysite/ but nothing from the subdirectories any pointers
>as to what I'm doing wrong would be much appreciated.
>
>Regards, John
>
>
>
>
>_______________________________________________
>This mail is send to you from the opencms-dev mailing list
>To change your list options, or to unsubscribe from the list, please
visit
>http://mail.opencms.org/mailman/listinfo/opencms-dev
>
>  
>


-- 
Let your workings remain a mystery.
Just show people the results,
	Lao-Tsu,Tao Te Ching


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


_______________________________________________
This mail is send to you from the opencms-dev mailing list
To change your list options, or to unsubscribe from the list, please
visit
http://mail.opencms.org/mailman/listinfo/opencms-dev



More information about the opencms-dev mailing list