View Javadoc

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   * Action used to view (read only) boooks
20   * @version $Revision$ $Date$
21   */
22  
23  public class ViewBookAction extends LibraryAction {
24      
25      /** log4j Logger */
26      private static Logger logger =
27       Logger.getLogger(ViewBookAction.class.getName());
28      
29      
30      /**
31       * Sets up Book view page
32       *
33       * Loads all book data
34       *
35       * @param mapping The ActionMapping used to select this instance
36       * @param form The optional ActionForm bean for this request (if any)
37       * @param request The HTTP request we are processing
38       * @param response The HTTP response we are creating
39       * @param messages message resources
40       *
41       * @exception Exception
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              // Retrieve book
54              Book bk = new Book();
55              bk.setId(frm.getId());
56              bk = libraryManager.retrieveBook(bk.getId());
57              
58              // Populate form with basic Book data
59              PropertyUtils.copyProperties(frm, bk);
60              
61              // Add Authors and Subjects
62              frm.setAuthors(libraryManager.getAuthors( bk));
63              frm.setSubjects(libraryManager.getSubjects( bk ));
64              
65              // Set Owner's desk phone
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  }