1 package org.sourceforge.vlibrary.user.actions;
2
3 import java.util.ArrayList;
4 import javax.servlet.http.HttpServletRequest;
5 import javax.servlet.http.HttpServletResponse;
6 import org.apache.struts.action.ActionForm;
7 import org.apache.struts.action.ActionForward;
8 import org.apache.struts.action.ActionMapping;
9 import org.apache.struts.util.MessageResources;
10 import org.apache.commons.beanutils.PropertyUtils;
11 import org.apache.log4j.Logger;
12
13 import org.sourceforge.vlibrary.user.domain.Book;
14 import org.sourceforge.vlibrary.user.domain.Reader;
15 import org.sourceforge.vlibrary.user.forms.BookForm;
16
17
18
19
20
21
22
23 public class ViewBookAction extends LibraryAction {
24
25
26 private static Logger logger =
27 Logger.getLogger(ViewBookAction.class.getName());
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public ActionForward executeAction(ActionMapping mapping,
44 ActionForm form,
45 HttpServletRequest request,
46 HttpServletResponse response,
47 MessageResources messages)
48 throws Exception {
49
50 BookForm frm = (BookForm) form;
51
52 try {
53
54 Book bk = new Book();
55 bk.setId(frm.getId());
56 bk = libraryManager.retrieveBook(bk.getId());
57
58
59 PropertyUtils.copyProperties(frm, bk);
60
61
62 frm.setAuthors(libraryManager.getAuthors( bk));
63 frm.setSubjects(libraryManager.getSubjects( bk ));
64
65
66 Reader rd = libraryManager.retrieveReader(bk.getOwner());
67 frm.setOwnerPhone(rd.getDeskPhone());
68 rd = null;
69 } catch (Throwable t){
70 String errString = messages.getMessage("error.book.retrieve");
71 logger.error(messages.getMessage(errString,t));
72 }
73
74 return standardForward(mapping,request, new ArrayList());
75 }
76 }