Example #1
0
 // 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;
 }
Example #2
0
  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;
    }
  }
Example #3
0
  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;
  }
Example #4
0
 public List groupNodes(List nodes) {
   List result = new ArrayList();
   List nodegroup = null;
   int ltopid = -1;
   Iterator nit = nodes.iterator();
   while (nit.hasNext()) {
     OutlineNode node = (OutlineNode) nit.next();
     int ctopid = ((ArticleImpl) node.getResource()).getTopicId();
     if (ctopid != ltopid) {
       nodegroup = new ArrayList();
       result.add(nodegroup);
     }
     nodegroup.add(node);
   }
   return result;
 }
Example #5
0
 protected OutlineNode genOutlineNode(Link link, int parentId) {
   String linkLabel, id, alias;
   ZenoResource res;
   if (link.getSourceId() == parentId) {
     linkLabel = link.getLabel();
     id = Integer.toString(link.getTargetId());
     alias = link.getTargetAlias();
     res = ((LinkImpl) link).getTargetResource();
   } else {
     linkLabel = "-" + link.getLabel();
     id = Integer.toString(link.getSourceId());
     alias = link.getSourceAlias();
     res = ((LinkImpl) link).getSourceResource();
   }
   OutlineNode node = new OutlineNode(linkLabel, id, alias);
   node.setResource(res);
   return node;
 }
Example #6
0
  public List getOutline(Hashtable mainLinkTable, List articles) throws ZenoException {

    comparator = new NodeComparator();
    List result = new ArrayList();
    Iterator artit = articles.iterator();
    List outlineLinks = new ArrayList();
    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);
      result.add(artNode);
    }
    Iterator resit = result.iterator();
    while (resit.hasNext()) {
      OutlineNode artNode = (OutlineNode) resit.next();
      genChildren(mainLinkTable, artNode, visited, null);
    }
    return result;
  }
Example #7
0
  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;
  }
Example #8
0
 public int compare(Object o1, Object o2) {
   int result = 0;
   if (o1 instanceof OutlineNode && o2 instanceof OutlineNode) {
     OutlineNode n1 = (OutlineNode) o1;
     OutlineNode n2 = (OutlineNode) o2;
     result = stringCompare(n1.getLabel(), n2.getLabel());
     if (result == 0) {
       result = stringCompare(n1.getAlias(), n2.getAlias());
     }
   }
   return result;
 }
Example #9
0
  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);
    }
  }