1 package com.dotmarketing.portlets.user.action; 2 3 import java.net.URLDecoder ; 4 5 import javax.portlet.ActionRequest; 6 import javax.portlet.ActionResponse; 7 import javax.portlet.PortletConfig; 8 9 import org.apache.struts.action.ActionForm; 10 import org.apache.struts.action.ActionMapping; 11 12 import com.dotmarketing.db.DotHibernate; 13 import com.dotmarketing.portal.struts.DotPortletAction; 14 import com.dotmarketing.portlets.user.factories.UserPreferencesFactory; 15 import com.dotmarketing.portlets.user.model.UserPreference; 16 import com.dotmarketing.util.Logger; 17 import com.dotmarketing.util.WebKeys; 18 import com.liferay.portal.model.User; 19 import com.liferay.portal.struts.ActionException; 20 import com.liferay.portal.util.Constants; 21 22 25 26 public class EditUserPreferenceAction extends DotPortletAction 27 { 28 29 public static boolean debug = false; 30 31 public void processAction( 32 ActionMapping mapping, ActionForm form, PortletConfig config, 33 ActionRequest req, ActionResponse res) 34 throws Exception { 35 36 37 String cmd = req.getParameter(Constants.CMD); 38 39 String referer = req.getParameter("referer"); 40 41 if ((referer!=null) && (referer.length()!=0)) { 42 referer = URLDecoder.decode(referer,"UTF-8"); 43 } 44 45 DotHibernate.startTransaction(); 46 47 User user = _getUser(req); 48 49 try { 50 _retrieveUserPreference(req, res, config, form, user); 51 } catch (ActionException ae) { 52 } 54 55 58 if ((cmd != null) && cmd.equals(Constants.EDIT)) { 59 } 60 61 if ((cmd != null) && cmd.equals(Constants.SAVE)) { 62 try { 63 _saveUserPreference(req, res, config, form, user); 64 } catch (ActionException ae) { 65 Logger.error(this, "ERROR SAVING!!!!", ae); 66 } 67 68 } 69 70 DotHibernate.commitTransaction(); 71 } 72 73 75 public void _retrieveUserPreference(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 76 throws Exception { 77 String userId = req.getParameter("userId"); 78 String preference = req.getParameter("preference"); 79 80 UserPreference u = UserPreferencesFactory.getUserPreferenceValue(userId, preference); 81 req.setAttribute(WebKeys.USER_PREFERENCE_EDIT, u); 82 } 83 84 public void _saveUserPreference(ActionRequest req, ActionResponse res,PortletConfig config,ActionForm form, User user) 85 throws Exception { 86 UserPreference up = (UserPreference) req.getAttribute(WebKeys.USER_PREFERENCE_EDIT); 87 88 if (up.getId()>0) { 89 up.setValue(req.getParameter("value")); 90 } 91 else { 92 up.setUserId(req.getParameter("userId")); 93 up.setPreference(req.getParameter("preference")); 94 up.setValue(req.getParameter("value")); 95 } 96 97 UserPreferencesFactory.saveUserPreference(up); 98 99 } 100 101 102 } 103 | Popular Tags |