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.log4j.Logger;
9 import org.apache.struts.action.Action;
10 import org.apache.struts.action.ActionForm;
11 import org.apache.struts.action.ActionForward;
12 import org.apache.struts.action.ActionMapping;
13 import org.apache.struts.util.MessageResources;
14 import org.sourceforge.vlibrary.Constants;
15 import org.sourceforge.vlibrary.exceptions.LibraryException;
16 import org.sourceforge.vlibrary.user.logic.LibraryManager;
17
18
19
20
21
22
23
24 public abstract class LibraryAction extends Action {
25
26
27 private static Logger logger =
28 Logger.getLogger(LibraryAction.class.getName());
29
30
31 private static MessageResources logMessages =
32 MessageResources.getMessageResources(Constants.APPLICATION_RESOURCES);
33
34 protected LibraryManager libraryManager = null;
35
36
37
38
39 public void setLibraryManager( LibraryManager libraryManager ) {
40 this.libraryManager = libraryManager;
41 }
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57 @Override
58 public ActionForward execute(ActionMapping mapping,
59 ActionForm form,
60 HttpServletRequest request,
61 HttpServletResponse response)
62 throws Exception {
63
64 if (logger.isDebugEnabled()) {
65 logger.debug(logMessages.getMessage("entering.execute")
66 + "--" + mapping.getType() + " Action = " + request.getParameter(Constants.ACTION));
67 }
68
69 logger.debug("libraryManager=" + libraryManager);
70
71 if (isCancelled(request)) {
72
73 if (mapping.getAttribute() != null) {
74 request.removeAttribute(mapping.getAttribute());
75 }
76
77 if (logger.isDebugEnabled()) {
78 logger.debug(logMessages.getMessage("action.cancelled")
79 + "--" + mapping.getType());
80 }
81
82 return (mapping.findForward(Constants.CANCEL));
83 }
84
85 final MessageResources messages = getResources(request);
86
87 final ActionForward result =
88 executeAction(mapping,form,request,response,messages);
89
90 if (logger.isDebugEnabled()) {
91 if (result.getName().equals(Constants.ERROR)) {
92 logger.debug(logMessages.getMessage("execute.failure")
93 + "--"+ mapping.getType());
94 } else {
95 logger.debug(logMessages.getMessage("execute.successful")
96 + "--" + mapping.getType());
97 }
98 }
99
100 return result;
101
102 }
103
104
105
106
107
108
109
110
111
112
113 protected ActionForward standardForward(ActionMapping mapping,
114 HttpServletRequest request,
115 ArrayList<LibraryException> errors) {
116
117 if (!errors.isEmpty()) {
118 request.setAttribute(Constants.ERRORS,errors);
119 return (mapping.findForward(Constants.ERROR));
120 } else {
121 return (mapping.findForward(Constants.SUCCESS));
122 }
123 }
124
125
126
127
128
129
130
131
132
133
134
135
136
137 abstract public ActionForward executeAction(ActionMapping mapping,
138 ActionForm form,
139 HttpServletRequest request,
140 HttpServletResponse response,
141 MessageResources messages)
142 throws Exception;
143
144 }