KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.nextime.ion.backoffice.bean.SectionTypes;
15 import org.nextime.ion.commons.PublicationSorter;
16
17 import org.nextime.ion.framework.business.Section;
18 import org.nextime.ion.framework.mapping.Mapping;
19
20 public class ViewSectionAction extends BaseAction {
21     
22     static public final int pageSize = 5;
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 highlightId = request.getSession().getAttribute("highlightId")+"";
35         request.getSession().removeAttribute("highlightId");
36         request.setAttribute("highlightId", highlightId);
37
38         if (request.getSession().getAttribute("pageInfos") == null) {
39             request.getSession().setAttribute("pageInfos", new Hashtable JavaDoc());
40         }
41         if (request.getSession().getAttribute("versionDisplayInfos") == null) {
42             request.getSession().setAttribute(
43                 "versionDisplayInfos",
44                 new Hashtable JavaDoc());
45         }
46
47         if (request.getParameter("expand") != null) {
48             Hashtable JavaDoc ht =
49                 (Hashtable JavaDoc) request.getSession().getAttribute(
50                     "versionDisplayInfos");
51             ht.put(request.getParameter("expand"), "true");
52         }
53         if (request.getParameter("collapse") != null) {
54             Hashtable JavaDoc ht =
55                 (Hashtable JavaDoc) request.getSession().getAttribute(
56                     "versionDisplayInfos");
57             ht.remove(request.getParameter("collapse"));
58         }
59
60         // fill data
61
try {
62             Mapping.begin();
63
64             Vector JavaDoc sections;
65             Vector JavaDoc publications;
66
67             Section section = Section.getInstance(request.getParameter("id"));
68
69             int startPublications;
70             try {
71                 startPublications =
72                     Integer.parseInt(request.getParameter("start"));
73                 (
74                     (Hashtable JavaDoc)
75                         (request.getSession().getAttribute("pageInfos"))).put(
76                     section.getId(),
77                     new Integer JavaDoc(startPublications));
78             } catch (NumberFormatException JavaDoc e) {
79                 try {
80                     startPublications =
81                         (
82                             (Integer JavaDoc) (((Hashtable JavaDoc) (request
83                                 .getSession()
84                                 .getAttribute("pageInfos")))
85                             .get(section.getId())))
86                             .intValue();
87                 } catch (Exception JavaDoc ex) {
88                     startPublications = 0;
89                     (
90                         (Hashtable JavaDoc)
91                             (
92                                 request.getSession().getAttribute(
93                                     "pageInfos"))).put(
94                         section.getId(),
95                         new Integer JavaDoc(startPublications));
96
97                 }
98             }
99
100             sections = section.listSubSections();
101             publications = PublicationSorter.sortPublications(section);
102             
103             // ------------------------------
104

105             request.setAttribute("section", section);
106             request.setAttribute("sectionName", section.getMetaData("name"));
107             try {
108                 String JavaDoc description =
109                     SectionTypes
110                         .getSectionBean(
111                             servlet,
112                             section.getMetaData("template") + "",
113                             request)
114                         .getDescription();
115                 request.setAttribute("sectionDescription", description);
116             } catch (Exception JavaDoc e) {
117                 //e.printStackTrace();
118
}
119
120             // list subsections
121
request.setAttribute("sections", sections);
122             request.setAttribute("sectionsSize", new Integer JavaDoc(sections.size()));
123
124             Vector JavaDoc publicationPage = new Vector JavaDoc();
125
126             int stopPublications = -1;
127
128             for (int i = startPublications;
129                 i < startPublications + pageSize;
130                 i++) {
131                 if (i < publications.size()) {
132                     publicationPage.add(publications.get(i));
133                     stopPublications = i;
134                 }
135             }
136
137             // list publications
138
request.setAttribute("pageSize", new Integer JavaDoc(pageSize));
139             request.setAttribute("start", new Integer JavaDoc(startPublications));
140             request.setAttribute("stop", new Integer JavaDoc(stopPublications));
141             request.setAttribute("publications", publicationPage);
142             request.setAttribute(
143                 "publicationsSize",
144                 new Integer JavaDoc(publications.size()));
145
146         } catch (Exception JavaDoc e) {
147             throw new ServletException JavaDoc(e);
148         } finally {
149             Mapping.rollback();
150         }
151
152         // Forward to the next page
153
return (mapping.findForward("view"));
154
155     }
156
157 }
158
Popular Tags