01: package com.technoetic.xplanner.actions;
02:
03: import com.technoetic.xplanner.domain.repository.ObjectRepository;
04: import org.apache.struts.action.ActionForm;
05: import org.apache.struts.action.ActionForward;
06: import org.apache.struts.action.ActionMapping;
07:
08: import java.net.URLEncoder;
09: import java.io.UnsupportedEncodingException;
10: import javax.servlet.ServletException;
11: import javax.servlet.http.HttpServletRequest;
12: import javax.servlet.http.HttpServletResponse;
13:
14: public class ViewObjectAction extends AbstractAction {
15: private boolean authorizationRequired = true;
16:
17: protected ActionForward doExecute(ActionMapping actionMapping,
18: ActionForm form, HttpServletRequest request,
19: HttpServletResponse reply) throws Exception {
20: ObjectRepository objectRepository = getRepository(
21: actionMapping, request);
22: String forwardPath = getForwardPath(actionMapping, request);
23: if (isSecure(actionMapping)) {
24: Object object = objectRepository.load(Integer
25: .parseInt(request.getParameter("oid")));
26: setDomainContext(request, object, actionMapping);
27: }
28: return new ActionForward(forwardPath);
29: }
30:
31: private String getForwardPath(ActionMapping actionMapping,
32: HttpServletRequest request)
33: throws UnsupportedEncodingException {
34: String forwardPath = actionMapping.findForward("display")
35: .getPath();
36: String returnto = request.getParameter("returnto");
37: if (returnto != null) {
38: forwardPath += (forwardPath.indexOf("?") != -1 ? "&" : "?")
39: + "returnto="
40: + URLEncoder.encode(returnto, "UTF-8");
41: }
42: return forwardPath;
43: }
44:
45: protected ObjectRepository getRepository(
46: ActionMapping actionMapping, HttpServletRequest request)
47: throws ClassNotFoundException, ServletException {
48: Class objectClass = getObjectType(actionMapping, request);
49: ObjectRepository objectRepository = getRepository(objectClass);
50: return objectRepository;
51: }
52:
53: private boolean isSecure(ActionMapping actionMapping) {
54: return authorizationRequired;
55: }
56:
57: public void setAuthorizationRequired(boolean authorizationRequired) {
58: this.authorizationRequired = authorizationRequired;
59: }
60: }
|