KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > nextime > ion > backoffice > action > content > HighlightAction


1 package org.nextime.ion.backoffice.action.content;
2
3 import java.io.IOException JavaDoc;
4 import java.util.Hashtable JavaDoc;
5 import java.util.Vector JavaDoc;
6
7 import javax.servlet.ServletException JavaDoc;
8 import javax.servlet.http.HttpServletRequest JavaDoc;
9 import javax.servlet.http.HttpServletResponse JavaDoc;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionForward;
12 import org.apache.struts.action.ActionMapping;
13 import org.nextime.ion.backoffice.action.BaseAction;
14
15 import org.nextime.ion.framework.business.Publication;
16 import org.nextime.ion.framework.business.Section;
17 import org.nextime.ion.framework.mapping.Mapping;
18 import org.nextime.ion.backoffice.tree.TreeControl;
19 import org.nextime.ion.backoffice.tree.TreeControlNode;
20 import org.nextime.ion.commons.PublicationSorter;
21
22 public class HighlightAction extends BaseAction {
23
24     public ActionForward perform(
25         ActionMapping mapping,
26         ActionForm form,
27         HttpServletRequest JavaDoc request,
28         HttpServletResponse JavaDoc response)
29         throws IOException JavaDoc, ServletException JavaDoc {
30
31         // check if user is correctly logged
32
checkUser(request);
33
34         String JavaDoc id = request.getParameter("id");
35
36         try {
37
38             Mapping.begin();
39
40             Publication p = Publication.getInstance(id);
41             Section section = (Section) p.listSections().firstElement();
42
43             // faire un bel arbre
44
TreeControl control =
45                 (TreeControl) request.getSession().getAttribute(
46                     "treeControlTest");
47             collapse(control.getRoot());
48
49             control.selectNode(section.getId());
50
51             // expand all
52
while (section != null) {
53                 TreeControlNode node = control.findNode(section.getId());
54                 node.setExpanded(true);
55                 section = section.getParent();
56             }
57
58             // trouve la page
59
section = (Section) p.listSections().firstElement();
60             Vector JavaDoc ps = PublicationSorter.sortPublications(section);
61             int pos = ps.indexOf(p);
62             int page = pos / ViewSectionAction.pageSize;
63             ((Hashtable JavaDoc) (request.getSession().getAttribute("pageInfos"))).put(
64                 section.getId(),
65                 new Integer JavaDoc(page * ViewSectionAction.pageSize));
66
67         } catch (Exception JavaDoc e) {
68             e.printStackTrace();
69         } finally {
70             Mapping.rollback();
71         }
72
73         request.getSession().setAttribute("highlightId", id);
74
75         // Forward to the next page
76
return (mapping.findForward("ok"));
77
78     }
79
80     private void collapse(TreeControlNode n) {
81         for (int i = 0; i < n.findChildren().length; i++) {
82             n.findChildren()[i].setExpanded(false);
83             collapse(n.findChildren()[i]);
84         }
85     }
86
87 }
88
Popular Tags