1 package org.paneris.bibliomania;
2
3 import org.melati.Melati;
4 import org.melati.poem.AccessToken;
5 import org.melati.poem.Persistent;
6 import org.melati.poem.PoemTask;
7 import org.melati.poem.PoemThread;
8 import org.melati.poem.UnexpectedExceptionPoemException;
9 import org.paneris.melati.boards.BoardUtils;
10 import org.webmacro.servlet.WebContext;
11
12
13 public class CreateBoard extends BibliomaniaServlet {
14
15
16
17
18 private static final long serialVersionUID = 1L;
19
20 protected String bibliomaniaHandle(final Melati melati, WebContext context)
21 throws Exception {
22
23 final BibliomaniaDatabase db = (BibliomaniaDatabase)PoemThread.database();
24 Persistent o = melati.getObject();
25
26 if (o instanceof Chapter) {
27 o = ((Chapter)o).getParentUnit();
28 }
29 final Persistent object = o;
30 final Board board = (Board)db.getBoardTable().newPersistent();
31 PoemThread.withAccessToken(
32 AccessToken.root,
33 new PoemTask() {
34 public void run() {
35 try {
36 if (object instanceof Chapter) {
37 board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).chapter());
38 } else if (object instanceof Book) {
39 board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).book());
40 } else if (object instanceof Author) {
41 board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).author());
42 } else if (object instanceof Section) {
43 board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).section());
44 } else if (object instanceof SectionGroup) {
45 board.setType(((org.paneris.bibliomania.BoardTypeTable)(db.getBoardTypeTable())).sectionGroup());
46 } else {
47 System.err.println("Unexpected Object in CreateBoard:" + object);
48 }
49 board.setName(((Unit)object).getBoardName());
50 board.setDisplayname(((Unit)object).getDisplayName());
51 board.setPurpose("Discussion of " + ((Unit)object).getDisplayName() + ".");
52 board.setArchived(false);
53 board.setOpensubscription(true);
54 board.setModeratedsubscription(false);
55 board.setOpenposting(false);
56 board.setAnonymousposting(false);
57 board.setModeratedposting(false);
58 board.setOpenmessageviewing(true);
59 board.setOpenmemberlist(false);
60 board.setAttachmentsallowed(false);
61 board.setAttachmentspath("");
62 board.setAttachmentsurl("");
63 board.makePersistent(((org.paneris.bibliomania.UserTable)db.getUserTable()).boardManager());
64 }
65 catch (Exception e) {
66 throw new UnexpectedExceptionPoemException(e);
67 }
68 try {
69 ((Unit)object).setMessageboard(board);
70 }
71 catch (Exception e) {
72 throw new UnexpectedExceptionPoemException(e);
73 }
74 }
75 }
76 );
77
78 BoardUtils bu = new BoardUtils("/b/org.paneris.melati.boards.BoardAdmin","bibliomania");
79 melati.getResponse().sendRedirect(bu.BoardURL(board,"0"));
80 return null;
81 }
82
83 }
84
85
86
87