[opencms-dev] howto get the current file name
Martin Kuba
makub at ics.muni.cz
Wed Sep 15 21:05:35 CEST 2004
David Causse wrote:
> Hello,
>
> I'm writing a JSP Template and I have some difficulties to find the way
> to obtain the current file name or better the current CmsJspNavElement.
>
> I'm working under OpenCMS 5.0.1
I am using version 5.3.5, but I think that this part was not changed.
You can do:
CmsJspActionElement cms = new CmsJspActionElement(pageContext,
request, response);
CmsJspNavBuilder nav = cms.getNavigation();
CmsJspNavElement current = nav.getNavigationForResource();
Here is my jsp for generating a tree menu:
<%@ page import="org.opencms.jsp.*" %>
<%@ page import="java.util.*" %>
<%@ page import="org.opencms.flex.CmsFlexController" %>
<%!
void showFolder(CmsJspActionElement cms, JspWriter
out,CmsJspNavBuilder nav,CmsJspNavElement ne,CmsJspNavElement current)
throws java.io.IOException {
Iterator i =
nav.getNavigationForFolder(ne.getResourceName()).iterator();
while (i.hasNext()) {
CmsJspNavElement sub = (CmsJspNavElement)i.next();
if(sub.isFolderLink()) {
out.print("<li><a href=\"" +
cms.link(sub.getResourceName()) + "index.html\">"+sub.getNavText()+"</a>");
if(current.getResourceName().startsWith(sub.getResourceName())) {
out.print("<ol>");
showFolder(cms,out,nav,sub,current);
out.print("</ol>");
}
out.print("</li>");
} else {
if(sub.getFileName().startsWith("index.")) continue;
out.print("<li><a href=\"" +
cms.link(sub.getResourceName()) + "\">" + sub.getNavText() + "</a></li>");
}
}
}
%>
<%
CmsFlexController controller =
(CmsFlexController)request.getAttribute(CmsFlexController.ATTRIBUTE_NAME);
String locale =
controller.getCmsObject().readPropertyObject(controller.getCmsObject().getRequestContext().getUri(),
"locale", true).getValue();
CmsJspActionElement cms = new CmsJspActionElement(pageContext,
request, response);
CmsJspNavBuilder nav = cms.getNavigation();
CmsJspNavElement top = nav.getNavigationForResource("/"+locale+"/");
CmsJspNavElement current = nav.getNavigationForResource();
%>
<ul>
<%
showFolder(cms,out,nav,top,current);
%>
</ul>
Martin
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Supercomputing Center Brno Martin Kuba
Institute of Computer Science email: makub at ics.muni.cz
Masaryk University http://www.ics.muni.cz/~makub/
Botanicka 68a, 60200 Brno, CZ mobil: +420-603-533775
--------------------------------------------------------------
More information about the opencms-dev
mailing list