KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > dotmarketing > portlets > mailinglists > action > EditSubscriberAction


1 package com.dotmarketing.portlets.mailinglists.action;
2
3 import javax.portlet.ActionRequest;
4 import javax.portlet.ActionResponse;
5 import javax.portlet.PortletConfig;
6 import javax.servlet.jsp.PageContext JavaDoc;
7
8 import org.apache.commons.beanutils.BeanUtils;
9 import org.apache.struts.action.ActionForm;
10 import org.apache.struts.action.ActionMapping;
11
12 import com.dotmarketing.beans.UserProxy;
13 import com.dotmarketing.cms.factories.PublicUserFactory;
14 import com.dotmarketing.factories.InodeFactory;
15 import com.dotmarketing.portal.struts.DotPortletAction;
16 import com.dotmarketing.portlets.mailinglists.model.MailingList;
17 import com.dotmarketing.util.Logger;
18 import com.dotmarketing.util.UtilMethods;
19 import com.dotmarketing.util.Validator;
20 import com.dotmarketing.util.WebKeys;
21 import com.liferay.portal.model.User;
22 import com.liferay.portal.util.Constants;
23 import com.liferay.util.servlet.SessionMessages;
24 /**
25  * @author Maria
26  */

27
28 public class EditSubscriberAction extends DotPortletAction {
29
30     public void processAction(
31             ActionMapping mapping, ActionForm form, PortletConfig config,
32             ActionRequest req, ActionResponse res)
33         throws Exception JavaDoc {
34     
35         String JavaDoc cmd = req.getParameter(Constants.CMD);
36         String JavaDoc referer = req.getParameter("referer");
37
38         //get the user
39
User user = null;
40         try {
41             user = com.liferay.portal.util.PortalUtil.getUser(req);
42         }
43         catch (Exception JavaDoc e) {
44             req.setAttribute(PageContext.EXCEPTION, e);
45             setForward(req, Constants.COMMON_ERROR);
46         }
47
48         /*
49          * get the mainglist object, stick it in request
50          *
51          */

52         try {
53             _retrieveSubscriber(req, res, config, form);
54         }
55         catch (Exception JavaDoc ae) {
56             Logger.error(this, "Error retrieving the list", ae);
57             req.setAttribute(PageContext.EXCEPTION, ae);
58             setForward(req, Constants.COMMON_ERROR);
59         }
60
61
62         /*
63          * if we are saving
64          *
65          */

66         if ((cmd != null) && cmd.equals(Constants.ADD)) {
67             try {
68
69                 if (Validator.validate(req,form,mapping)) {
70                     _saveSubscriber(req, res, config, form, user);
71                 }
72                 _sendToReferral(req,res,referer);
73                 return;
74             }
75             catch (Exception JavaDoc ae) {
76                 Logger.error(this, "Error Saving Subscriber", ae);
77                 req.setAttribute(PageContext.EXCEPTION, ae);
78                 setForward(req, Constants.COMMON_ERROR);
79             }
80         }
81
82         /*
83          * deleting the list, return to listing page
84          *
85          */

86         else if ((cmd != null) && cmd.equals(com.dotmarketing.util.Constants.DELETE_LIST)) {
87             try {
88                 _deleteSubscriber(req, res, config, form,user);
89                 _sendToReferral(req,res,referer);
90                 return;
91             }
92             catch (Exception JavaDoc ae) {
93                 Logger.error(this, ae.toString(), ae);
94                 req.setAttribute(PageContext.EXCEPTION, ae);
95                 setForward(req, Constants.COMMON_ERROR);
96             }
97         }
98
99         /*
100          * Copy copy props from the db to the form bean
101          *
102          */

103         if ((cmd != null) && cmd.equals(Constants.EDIT)) {
104             BeanUtils.copyProperties(form, req.getAttribute(WebKeys.SUBSCRIBER_EDIT));
105         }
106         
107         /*
108          * return to edit page
109          *
110          */

111         setForward(req, "portlet.ext.mailinglists.edit_subscriber");
112     }
113
114     private void _retrieveSubscriber(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form)
115     throws Exception JavaDoc {
116         UserProxy up = (UserProxy) InodeFactory.getInode(req.getParameter("inode"),UserProxy.class);
117         User s = PublicUserFactory.getUserByUserId(up.getUserId());
118         if (UtilMethods.isSet(req.getParameter("email"))) {
119             s = PublicUserFactory.getUserByEmail(req.getParameter("email"));
120         }
121         req.setAttribute(WebKeys.SUBSCRIBER_EDIT, s);
122     }
123
124     private void _saveSubscriber(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user)
125     throws Exception JavaDoc {
126
127     }
128
129     private void _deleteSubscriber(ActionRequest req, ActionResponse res,PortletConfig config, ActionForm form , User user)
130     throws Exception JavaDoc {
131
132     }
133
134 }
135
Popular Tags