Beat me to it. Here is a segment from my *-objects.xml file related to my version of the NavbarPortlet and the code.
| <page> | <page-name>default</page-name> | <properties> | <property> | <name>navbar.DisplayName</name> | <value>Home</value> | </property> | <property> | <name>navbar.SortOrder</name> | <value>1</value> | </property> | </properties> | | import org.jboss.portal.core.api.JBossPortalNode; | import org.jboss.portal.core.impl.model.portal.PortalObjectImpl; | import org.jboss.portal.core.model.portal.Context; | import org.jboss.portal.core.model.portal.Page; | import org.jboss.portal.core.model.portal.Portal; | import org.jboss.portal.core.model.portal.PortalObject; | import org.jboss.portal.core.model.portal.PortalObjectContainer; | import org.jboss.portal.core.model.portal.Window; | import org.jboss.portal.security.PortalPermissionFactory; | import org.jboss.portal.security.PortalPolicyException; | import org.jboss.portlet.JBossPortlet; | import org.jboss.portlet.JBossRenderRequest; | import org.jboss.portlet.JBossRenderResponse; | import org.jboss.portlet.PortalNode; | import org.jboss.portlet.PortalNodeURL; | | import javax.portlet.PortletException; | import javax.portlet.PortletPreferences; | import java.io.IOException; | import java.util.ArrayList; | import java.util.Collections; | import java.util.Comparator; | import java.util.HashMap; | import java.util.Iterator; | import java.util.List; | import java.util.Map; | | /** | * | * @author Vince Marco | */ | public class NavbarPortlet extends JBossPortlet | { | private PortalPermissionFactory permissionFactory; | private PortalObjectContainer container; | private Map nodemap = new HashMap(); | private static final String NAME_PROPERTY = "navbar.DisplayName"; | private static final String ORDER_PROPERTY = "navbar.SortOrder"; | | public NavbarPortlet() | { | super(); | } | | public void init() throws PortletException | { | permissionFactory = (PortalPermissionFactory) this.getPortletContext().getAttribute("PortalPermissionFactory"); | container = (PortalObjectContainer) this.getPortletContext().getAttribute("PortalObjectContainer"); | if (permissionFactory == null) | { | throw new PortletException("No portal permission factory"); | } | if (container == null) | { | throw new PortletException("No portal object container"); | } | } | | public void destroy() | { | super.destroy(); | | // | permissionFactory = null; | container = null; | } | | public void render(JBossRenderRequest req, JBossRenderResponse resp) throws IOException, | PortletException | { | resp.setContentType("text/html"); | resp.setTitle("Portals"); | try | { | PortletPreferences prefs = req.getPreferences(); | String rootLevel = prefs.getValue("navigation-root-level", "page"); | Context context = container.getContext(); | List navElements = new ArrayList(); | | // get the list of portal nodes to display (portals or pages, based on | // preference) | Iterator portalObjectIterator; | if ("page".equalsIgnoreCase(rootLevel)) | { | // if the pages of the current portal are requested, then read up | // the hierarchie to the current portal, to | // get the children from there (which are the pages to display) | PortalNode current = req.getPortalNode(); | while (current != null && current.getType() != PortalNode.TYPE_PORTAL) | { | current = current.getParent(); | } | if (current != null && current.getType() == PortalNode.TYPE_PORTAL) | { | PortalObject root = context.getChild(current.getName()); | portalObjectIterator = root.getChildren().iterator(); | } | else | { | throw new PortletException("the current node has no parent of type 'portal'"); | } | } | else | { | // ok, we are to display portals then; they are the children of the | // container root | portalObjectIterator = context.getChildren().iterator(); | } | // now build the list | while (portalObjectIterator.hasNext()) | { | PortalObject child = (PortalObject) portalObjectIterator.next(); | if (child.getType() == PortalNode.TYPE_PAGE || child.getType() == PortalNode.TYPE_PORTAL) | { | PortalObjectImpl portalObject = (PortalObjectImpl) child; | if (allowed(portalObject.getPortalNode())) | { | navElements.add(portalObject); | } | } | } | | Collections.sort(navElements, new PortalNodeComparator()); | | // find the selected item in the level that was selected to be the root | // from the current portal node walk up the hierarchie until the node | // type matches | // that of the nav elements; if there is a match, hold on to it to mark | // the selected item later on | PortalNode selectedNode = null; | if (navElements.size() > 0) | { | PortalObject first = (PortalObject) navElements.get(0); | int navElementType = first.getType(); | PortalNode current = req.getPortalNode(); | while (current != null && current.getType() != navElementType) | { | current = current.getParent(); | } | | // now read up the hierarchie within the same node type until the | // type changes, to find the top level node of that type | if (current.getParent() != null) | { | PortalNode sameTypeLevelUp = current; | while (sameTypeLevelUp != null && sameTypeLevelUp.getType() == current.getType()) | { | current = sameTypeLevelUp; | sameTypeLevelUp = current.getParent(); | } | } | | if (current != null && current.getType() == navElementType) | { | selectedNode = current; | } | } | | StringBuffer html = new StringBuffer(); | html.append("<ul id=\"tabsHeader\">"); | for (Iterator i = navElements.iterator(); i.hasNext();) | { | PortalObjectImpl navElement = (PortalObjectImpl) i.next(); | | // build up Marks markup for the navigation , based on these nodes | String name = navElement.getDeclaredProperty(NAME_PROPERTY); | if (name == null) | name = navElement.getName(); | JBossPortalNode urlNode = null; | if (navElement instanceof Portal) | { | // get the default page node for this portal to get a valid URL | // from it | Page defaultPage = ((Portal) navElement).getDefaultPage(); | if (defaultPage != null) | { | PortalObject node = navElement.getChild(defaultPage.getName()); | if (node instanceof PortalObjectImpl) | { | urlNode = ((PortalObjectImpl) node).getPortalNode(); | } | } | } | else if (navElement instanceof Page) | { | urlNode = navElement.getPortalNode(); | } | | if (urlNode != null) | { | PortalNodeURL childURL = resp.createRenderURL(urlNode); | html.append("<li"); | if (selectedNode != null && selectedNode.equals(navElement.getPortalNode())) | { | html.append(" id=\"current\""); | } | html.append(" onmouseover=\"this.className='hoverOn'\""); | html.append(" onmouseout=\"this.className='hoverOff'\"><a href='"); | html.append(childURL).append("'>").append(name).append("</a></li>"); | } | } | html.append("</ul>"); | resp.getWriter().write(html.toString()); | } | catch (Exception e) | { | // todo: handle error case : write it out | e.printStackTrace(); | } | | } | | private boolean allowed(JBossPortalNode node) throws PortalPolicyException | { | return permissionFactory.checkPermission("portalobject", node.getHandle(), "view"); | } | | private static int getOrder(Object o) | { | if (o instanceof Context) | { | return 0; | } | if (o instanceof Portal) | { | return 1; | } | if (o instanceof Page) | { | return 2; | } | if (o instanceof Window) | { | return 3; | } | return 4; | } | | class PortalNodeComparator implements Comparator | { | public int compare(Object arg0, Object arg1) | { | int result = 0; | int high1 = getOrder(arg0); | int high2 = getOrder(arg1); | if (high1 == high2) | { | PortalObject p0 = (PortalObject)arg0; | PortalObject p1 = (PortalObject)arg1; | String sort0 = p0.getDeclaredProperty(ORDER_PROPERTY); | String sort1 = p1.getDeclaredProperty(ORDER_PROPERTY); | if (sort0 == null) | sort0 = p0.getName(); | if (sort1 == null) | sort1 = p1.getName(); | result = (sort0.compareTo(sort1)); | } | else | result = high1 - high2; | return result; | } | } | } | | View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3919492#3919492 Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3919492 ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=103432&bid=230486&dat=121642 _______________________________________________ JBoss-user mailing list JBoss-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/jboss-user