protected OutlineNode getNode( Hashtable linkTable, Link link, int parentId, String linkLabel, Set visited) throws ZenoException { Integer otherId = new Integer((link.getSourceId() == parentId) ? link.getTargetId() : link.getSourceId()); OutlineNode node = genOutlineNode(link, parentId); if (visited.contains(otherId)) { node.setDuplicate(true); return node; } else { visited.add(otherId); List links = (List) linkTable.get(otherId); if (links != null) { Iterator it = links.iterator(); while (it.hasNext()) { LinkImpl link1 = (LinkImpl) it.next(); if ("".equals(linkLabel) || link1.getLabel().equals(linkLabel)) node.add(getNode(linkTable, link1, otherId.intValue(), linkLabel, visited)); else node.add(genOutlineNode(link1, otherId.intValue())); } Collections.sort(node.getChildren(), new NodeComparator()); } return node; } }
// obsolete public List getOutline0(List articles) throws ZenoException { List result = new ArrayList(); NodeComparator nodeComparator = new NodeComparator(); Hashtable mainLinkTable = new Hashtable(); collectLinks(mainLinkTable, "", -1); Iterator artit = articles.iterator(); int nr = 1; while (artit.hasNext()) { ArticleImpl art = (ArticleImpl) artit.next(); OutlineNode artNode = new OutlineNode("", Integer.toString(art.getId()), art.getAlias()); artNode.setPosition(Integer.toString(nr++)); artNode.setResource(art); Integer artId = new Integer(art.getId()); HashSet visited = new HashSet(); List links = (List) mainLinkTable.get(artId); if (links != null) { Iterator it = links.iterator(); while (it.hasNext()) { LinkImpl link = (LinkImpl) it.next(); artNode.add(getNode(mainLinkTable, link, art.getId(), "", visited)); } Collections.sort(artNode.getChildren(), nodeComparator); } result.add(artNode); } return result; }
protected void genChildren(Hashtable linkTable, OutlineNode node, Hashtable visited, Article root) throws ZenoException { Integer nodeId = new Integer(node.getId()); OutlineNode rnode = (OutlineNode) visited.get(nodeId); if (rnode != null) { node.setDuplicate(true); node.setOriginalPosition(rnode.getPosition()); rnode.setDuplicated(true); return; } visited.put(nodeId, node); List links = (List) linkTable.get(nodeId); if (links != null) { Iterator it = links.iterator(); while (it.hasNext()) { LinkImpl link1 = (LinkImpl) it.next(); OutlineNode cnode = genOutlineNode(link1, nodeId.intValue()); if (root != null) cnode.genMark(root); if (!extended || cnode.getResource() != null) node.add(cnode); } Collections.sort(node.getChildren(), comparator); } Iterator cit = node.getChildren().iterator(); int nr = 1; while (cit.hasNext()) { OutlineNode cnode = (OutlineNode) cit.next(); String newPosition = node.getPosition() + "." + nr++; cnode.setPosition(newPosition); genChildren(linkTable, cnode, visited, root); } }