Author: chris.laprun(a)jboss.com
Date: 2011-08-01 11:03:18 -0400 (Mon, 01 Aug 2011)
New Revision: 6965
Modified:
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/NavigationPortlet.java
Log:
- Basic group navigation with node URIs.
Modified:
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/NavigationPortlet.java
===================================================================
---
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/NavigationPortlet.java 2011-08-01
15:00:03 UTC (rev 6964)
+++
portal/branches/api/examples/portlets/api/src/main/java/org/gatein/portal/samples/api/NavigationPortlet.java 2011-08-01
15:03:18 UTC (rev 6965)
@@ -23,6 +23,8 @@
package org.gatein.portal.samples.api;
import org.gatein.api.GateIn;
+import org.gatein.api.id.Id;
+import org.gatein.api.portal.Navigation;
import org.gatein.api.portal.Site;
import org.gatein.api.util.IterableIdentifiableCollection;
@@ -32,6 +34,7 @@
import javax.portlet.RenderRequest;
import javax.portlet.RenderResponse;
import java.io.IOException;
+import java.io.PrintWriter;
/** @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a> */
public class NavigationPortlet extends GenericPortlet
@@ -48,13 +51,43 @@
@Override
protected void doView(RenderRequest request, RenderResponse response) throws
PortletException, IOException
{
+ Id groupId = gateIn.groupId("platform", "administrators");
- IterableIdentifiableCollection<? extends Site> portals = gateIn.getSites();
- for (Site portal : portals)
+ Site adminSite = gateIn.getGroupSite(groupId);
+ Navigation navigation = adminSite.getNavigation();
+
+ IterableIdentifiableCollection<Navigation> adminNodes = navigation.getAll();
+
+ PrintWriter writer = response.getWriter();
+ String portalURI = request.getParameterMap().get("navigation_uri")[0];
+ writer.println("<ul>");
+
+ for (Navigation adminNode : adminNodes)
{
- String s = portal.toString();
- System.out.println(s);
- response.getWriter().println(s);
+ outputNode(writer, adminNode, portalURI);
}
+
+ writer.println("</ul>");
}
+
+ private void outputNode(PrintWriter writer, Navigation node, String portalURI)
+ {
+ IterableIdentifiableCollection<Navigation> children = node.getAll();
+ int size = children.size();
+ boolean isLeaf = size == 0;
+ writer.println("<li>"
+ + (isLeaf ? "<a href='" + node.getURI() + "'>"
: "")
+ + node.getDisplayName()
+ + (isLeaf ? "</a>" : "")
+ + "</li>");
+ if (size != 0)
+ {
+ writer.println("<ul>");
+ for (Navigation child : children)
+ {
+ outputNode(writer, child, portalURI);
+ }
+ writer.println("</ul>");
+ }
+ }
}