1 package org.sourceforge.vlibrary.user.actions;
2
3 import java.util.ArrayList;
4
5 import javax.servlet.http.HttpServletRequest;
6 import javax.servlet.http.HttpServletResponse;
7
8 import org.apache.struts.action.ActionForm;
9 import org.apache.struts.action.ActionForward;
10 import org.apache.struts.action.ActionMapping;
11 import org.apache.struts.util.MessageResources;
12
13 import org.apache.commons.beanutils.PropertyUtils;
14
15 import org.apache.log4j.Logger;
16
17 import org.sourceforge.vlibrary.Constants;
18 import org.sourceforge.vlibrary.exceptions.LibraryException;
19 import org.sourceforge.vlibrary.user.domain.Reader;
20 import org.sourceforge.vlibrary.user.forms.ReaderForm;
21
22 import java.lang.reflect.InvocationTargetException;
23
24
25
26
27
28 public class EditReaderAction extends LibraryAction {
29
30
31 private static Logger logger =
32 Logger.getLogger(EditReaderAction.class.getName());
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public ActionForward executeAction(ActionMapping mapping,
49 ActionForm form,
50 HttpServletRequest request,
51 HttpServletResponse response,
52 MessageResources messages)
53 throws Exception {
54
55 ArrayList errors = new ArrayList();
56 String action = request.getParameter(Constants.ACTION);
57
58
59
60
61 if (action == null) action = Constants.CREATE;
62
63 if (action.equals(Constants.UPDATE)) {
64 try {
65
66 Reader rd = new Reader();
67 ReaderForm frm = (ReaderForm)form;
68
69
70
71
72 if ((request.getParameter("uid") != null)
73 && (request.isUserInRole(Constants.ADMINISTRATOR))) {
74 rd.setUid(request.getParameter("uid"));
75 } else {
76 rd.setUid(request.getRemoteUser());
77 }
78
79 rd = libraryManager.retrieveByUid( rd.getUid());
80
81 logger.debug("propertyutils:" + frm + ", " + rd);
82
83 PropertyUtils.copyProperties(frm, rd);
84
85 } catch (InvocationTargetException e) {
86 Throwable t = e.getTargetException();
87 if (t == null)
88 t = e;
89 String errString = messages.getMessage
90 ("error.reader.reflection");
91 logger.error(errString,t);
92 errors.add(new LibraryException(errString,t));
93 } catch (Throwable t) {
94 String errString = messages.getMessage
95 ("error.reader.retrieve");
96 logger.error(errString,t);
97 errors.add(new LibraryException(errString,t));
98 }
99 }
100 return standardForward(mapping,request,errors);
101 }
102 }