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; } }
/** * collects all inlinks or outlinks of the journal in linkTable if direction is < 0 or > 0 * respectively */ public void collectLinks(Hashtable linkTable, String linkLabel, int direction) throws ZenoException { StringBuffer buf = new StringBuffer(); buf.append( "select label, source_alias, target_alias, source, target, flag from link, resource"); if (direction < 0) buf.append(" where target=id"); else buf.append(" where source=id"); if (collection instanceof Topic) buf.append(" and part="); else buf.append(" and parent="); buf.append(DBClient.format(this.id)); if (!"".equals(linkLabel)) { buf.append(" and label = "); buf.append(DBClient.format(linkLabel)); } buf.append(" and source_mark='false' and target_mark='false'"); List allLinks = LinkImpl.getLinksWhere(factory, buf.toString()); Iterator it = allLinks.iterator(); while (it.hasNext()) { LinkImpl link = (LinkImpl) it.next(); Integer keyId = new Integer((direction < 0) ? link.getTargetId() : link.getSourceId()); List links = (List) linkTable.get(keyId); if (links == null) { links = new ArrayList(); linkTable.put(keyId, links); } links.add(link); } }
protected void collectLinksBut(Hashtable linkTable, String linkLabel) throws ZenoException { StringBuffer buf = new StringBuffer(); buf.append( "select distinct label, source_alias, target_alias, source,target, flag from link, resource"); buf.append(" where (target=id or source =id) "); if (collection instanceof Topic) buf.append(" and part="); else buf.append(" and parent="); buf.append(DBClient.format(this.id)); if (linkLabel != null && !linkLabel.equals("")) { buf.append(" and label<>"); buf.append(DBClient.format(linkLabel)); } // heg buf.append(" and source_mark='false' and target_mark='false'"); List alllinks = LinkImpl.getLinksWhere(factory, buf.toString()); Iterator it = alllinks.iterator(); while (it.hasNext()) { LinkImpl link = (LinkImpl) it.next(); Integer targetId = new Integer(link.getTargetId()); List links = (List) linkTable.get(targetId); if (links == null) { links = new ArrayList(); linkTable.put(targetId, links); } links.add(link); Integer sourceId = new Integer(link.getSourceId()); links = (List) linkTable.get(sourceId); if (links == null) { links = new ArrayList(); linkTable.put(sourceId, links); } links.add(link); } }
protected List getXOutline(Hashtable mainLinkTable, List articles) throws ZenoException { comparator = new NodeComparator2(); List result = new ArrayList(); Iterator artit = articles.iterator(); List outlineLinks = new ArrayList(); Hashtable resTable = new Hashtable(); Hashtable visited = new Hashtable(); 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); collectOutlineLinks(mainLinkTable, art.id, outlineLinks); resTable.put(new Integer(art.getId()), art); result.add(artNode); } LinkImpl.fillLinks(factory, outlineLinks, resTable, false); Iterator resit = result.iterator(); while (resit.hasNext()) { OutlineNode artNode = (OutlineNode) resit.next(); Article root = (Article) artNode.getResource(); genChildren(mainLinkTable, artNode, visited, root); } return result; }
protected static void collectOutlineLinks(Hashtable linkTable, int id, List outlineLinks) { List links = (List) linkTable.get(new Integer(id)); if (links != null) { Iterator it = links.iterator(); while (it.hasNext()) { LinkImpl link = (LinkImpl) it.next(); if (!outlineLinks.contains(link)) { outlineLinks.add(link); int otherId; if (link.getSourceId() == id) { otherId = link.getTargetId(); } else { otherId = link.getSourceId(); } collectOutlineLinks(linkTable, otherId, outlineLinks); } } } }
public List getFullOutline(Hashtable mainLinkTable, List articles) throws ZenoException { comparator = new NodeComparator2(); List result = new ArrayList(); Iterator artit = articles.iterator(); Hashtable resTable = genResTable(articles); Hashtable visited = new Hashtable(); int nr = 1; while (artit.hasNext()) { ArticleImpl art = (ArticleImpl) artit.next(); if (art instanceof Topic || visited.get(new Integer(art.getId())) == null) { OutlineNode artNode = new OutlineNode("", Integer.toString(art.getId()), art.getAlias()); artNode.setPosition(Integer.toString(nr++)); artNode.setResource(art); result.add(artNode); List outlineLinks = new ArrayList(); collectOutlineLinks(mainLinkTable, art.id, outlineLinks); LinkImpl.fillLinks(factory, outlineLinks, resTable, false); genChildren(mainLinkTable, artNode, visited, art); } } return result; }
protected void collectOutlineLinks(Hashtable linkTable, ZenoResource res, List outlineLinks) { int id = ((ResourceImpl) res).id; List links = (List) linkTable.get(new Integer(id)); if (links != null) { Iterator it = links.iterator(); while (it.hasNext()) { LinkImpl link = (LinkImpl) it.next(); if (!outlineLinks.contains(link)) { outlineLinks.add(link); int otherId; if (link.getSourceId() == id) { link.setSourceResource(res); otherId = link.getTargetId(); } else { link.setTargetResource(res); otherId = link.getSourceId(); } collectOutlineLinks(linkTable, otherId, outlineLinks); } } } }