1 package com.dotmarketing.portlets.categories.action; 2 3 import javax.portlet.ActionRequest; 4 import javax.portlet.ActionResponse; 5 import javax.portlet.PortletConfig; 6 import javax.servlet.http.HttpServletRequest ; 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.Host; 13 import com.dotmarketing.factories.HostFactory; 14 import com.dotmarketing.factories.InodeFactory; 15 import com.dotmarketing.portal.struts.DotPortletAction; 16 import com.dotmarketing.portlets.categories.factories.CategoryFactory; 17 import com.dotmarketing.portlets.categories.model.Category; 18 import com.dotmarketing.portlets.categories.struts.CategoryForm; 19 import com.dotmarketing.portlets.folders.factories.FolderFactory; 20 import com.dotmarketing.portlets.folders.model.Folder; 21 import com.dotmarketing.util.Config; 22 import com.dotmarketing.util.Logger; 23 import com.dotmarketing.util.UtilMethods; 24 import com.dotmarketing.util.Validator; 25 import com.dotmarketing.util.WebKeys; 26 import com.liferay.portlet.ActionRequestImpl; 27 import com.liferay.util.servlet.SessionMessages; 28 29 30 public class EditCategoryAction extends DotPortletAction { 31 public void processAction(ActionMapping mapping, ActionForm form, PortletConfig config, ActionRequest req, 32 ActionResponse res) throws Exception { 33 String cmd = req.getParameter(com.liferay.portal.util.Constants.CMD); 34 35 ActionRequestImpl reqImpl = (ActionRequestImpl) req; 37 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 38 39 String referer = req.getParameter("referer"); 40 41 _viewCategory(form, req, res); 43 44 if (com.liferay.portal.util.Constants.ADD.equals(cmd)) { 46 Logger.debug(this, "Category: Saving Category"); 47 48 if (!Validator.validate(req, form, mapping)) { 50 Logger.debug(this, "Category: Validation Category Failed"); 51 setForward(req, mapping.getInput()); 52 53 return; 54 } else { 55 try { 56 _saveCategory(form, req, res); 57 } catch (Exception e) { 58 _handleException(e, req); 59 } 60 61 _sendToReferral(req, res, referer); 62 63 return; 64 } 65 } 66 else if (com.liferay.portal.util.Constants.DELETE.equals(cmd)) { 68 Logger.debug(this, "Category: Deleting Category"); 69 70 try { 71 _deleteCategory(form, req, res); 72 } catch (Exception e) { 73 _handleException(e, req); 74 } 75 76 _sendToReferral(req, res, referer); 77 78 return; 79 } 80 81 BeanUtils.copyProperties(form, req.getAttribute(WebKeys.CATEGORY_EDIT)); 82 setForward(req, "portlet.ext.categories.edit_category"); 83 } 84 85 86 87 private void _saveCategory(ActionForm form, ActionRequest req, ActionResponse res) 89 throws Exception { 90 91 ActionRequestImpl reqImpl = (ActionRequestImpl) req; 93 HttpServletRequest httpReq = reqImpl.getHttpServletRequest(); 94 Host host = HostFactory.getCurrentHost(httpReq); 95 96 BeanUtils.copyProperties(req.getAttribute(WebKeys.CATEGORY_EDIT), form); 97 98 Category cat = (Category) req.getAttribute(WebKeys.CATEGORY_EDIT); 99 Logger.debug(this, "_saveCategory: Inode = " + cat.getInode()); 100 InodeFactory.saveInode(cat); 101 102 if ((req.getParameter("parent") != null) && (!req.getParameter("parent").equals("0"))) { 103 Category parent = (Category) InodeFactory.getInode(req.getParameter("parent"), Category.class); 104 parent.addChild(cat); 105 InodeFactory.saveInode(parent); 106 } 107 108 109 CategoryForm cf = (CategoryForm) form; 111 112 SessionMessages.add(req, "message", "message.category.update"); 113 } 114 115 private void _deleteCategory(ActionForm form, ActionRequest req, ActionResponse res) 117 throws Exception { 118 Category cat = (Category) req.getAttribute(WebKeys.CATEGORY_EDIT); 119 InodeFactory.deleteInode(cat); 120 req.setAttribute(WebKeys.CATEGORY_EDIT, cat); 121 SessionMessages.add(req, "message", "message.category.delete"); 122 } 123 124 private void _viewCategory(ActionForm form, ActionRequest req, ActionResponse res) 126 throws Exception { 127 Category cat = (Category) InodeFactory.getInode(req.getParameter("inode"), Category.class); 128 req.setAttribute(WebKeys.CATEGORY_EDIT, cat); 129 req.setAttribute(WebKeys.CATEGORY_LIST_TOP, CategoryFactory.getTopLevelCategories()); 130 } 131 } 132 | Popular Tags |