<%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <% /* * * Copyright (c) 2005 Massachusetts Institute of Technology * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS * IN THE SOFTWARE. */ %> Hierarchy Viewer using OSID <%! org.osid.hierarchy.HierarchyManager hierarchyManager; org.osid.hierarchy.Hierarchy thisHierarchy; org.osid.id.IdManager idManager; org.osid.shared.Id hierId; // we passed the hierarchy ID as a parameter to this JSP String idString; %> <% idString = request.getParameter("idstr"); %>

Hierarchy Details

Hierarchy ID: <%=idString%> <% if (session.isNew()) { // if they didn't select a hierarchy from our main page, force them to go back. // if we were doing authentication, then we would send them to the login screen %> <% } else { idManager = (org.osid.id.IdManager)session.getAttribute("IdManager"); hierarchyManager= (org.osid.hierarchy.HierarchyManager)session.getAttribute("HierarchyManager"); } try { String displayName = ""; String desc = ""; String nid = ""; int level = 0; hierId = idManager.getId(idString); thisHierarchy=hierarchyManager.getHierarchy(hierId); %>
Name: <%=thisHierarchy.getDisplayName()%>
Description: <%=thisHierarchy.getDescription()%>

<% org.osid.hierarchy.NodeIterator rootNodeIterator = thisHierarchy.getRootNodes(); while (rootNodeIterator.hasNextNode()) { org.osid.hierarchy.Node nextNode = rootNodeIterator.nextNode(); org.osid.hierarchy.TraversalInfoIterator traversalInfoIterator = thisHierarchy.traverse( nextNode.getId(), org.osid.hierarchy.Hierarchy.TRAVERSE_MODE_DEPTH_FIRST, org.osid.hierarchy.Hierarchy.TRAVERSE_DIRECTION_DOWN, org.osid.hierarchy.Hierarchy.TRAVERSE_LEVELS_ALL); while (traversalInfoIterator.hasNextTraversalInfo()) { try { org.osid.hierarchy.TraversalInfo traversalInfo = traversalInfoIterator.nextTraversalInfo(); org.osid.hierarchy.Node n = thisHierarchy.getNode(traversalInfo.getNodeId()); displayName = n.getDisplayName(); desc = n.getDescription(); nid = n.getId().getIdString(); level = traversalInfo.getLevel(); String indent = ""; for (int i=0; i < level; i++) indent += "---"; if (n.isLeaf()) { %> <% } else { %> <% } } catch (Throwable t) { t.printStackTrace(); } } } } catch (Throwable t) { t.printStackTrace(); } %>

Back home