1 package org.paneris.bibliomania;
2
3 import java.util.Enumeration;
4 import java.util.Vector;
5
6 import org.melati.Melati;
7 import org.webmacro.servlet.WebContext;
8
9 public class AllMessageboards extends BibliomaniaServlet {
10
11
12
13
14 private static final long serialVersionUID = 1L;
15
16 protected String bibliomaniaHandle(Melati melati, WebContext context)
17 throws Exception {
18
19 BibliomaniaDatabase db = (BibliomaniaDatabase) melati.getDatabase();
20 db.setupContext(melati, context, null, null);
21
22 Vector sectionGroups = load(db.getSectionGroupTable().selection());
23 Vector sections = load(db.getSectionTable().selection());
24 Vector authors = load(db.getAuthorTable().selection());
25 Vector books = load(db.getBookTable().selection());
26
27 authors = ensure(authors, books);
28 sections = ensure(sections, authors);
29 sectionGroups = ensure(sectionGroups, sections);
30
31 context.put("sectionGroups",sectionGroups);
32 context.put("sections",sections);
33 context.put("authors",authors);
34 context.put("books",books);
35
36 return "AllMessageboards.wm";
37 }
38
39 private Vector ensure(Vector a, Vector b) {
40 for (Enumeration e = b.elements(); e.hasMoreElements();) {
41 Unit u = (Unit)e.nextElement();
42 if (!a.contains(u.getParentUnit())) {
43 a.add(u.getParentUnit());
44 }
45 }
46 return a;
47 }
48
49 private Vector load(Enumeration e) {
50 Vector v = new Vector();
51 while (e.hasMoreElements()) {
52 Unit u = (Unit)e.nextElement();
53 if (u.getMessageboard() != null && u.getMessageboard().isActive()) {
54 v.add(u);
55 }
56 }
57 return v;
58 }
59 }