1 package org.contineo.actions.admin.user; 2 3 import java.util.Collection ; 4 import javax.servlet.http.HttpServletRequest ; 5 import javax.servlet.http.HttpServletResponse ; 6 import javax.servlet.http.HttpSession ; 7 import org.apache.log4j.Level; 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.contineo.admin.dao.MenuDAO; 14 import org.contineo.admin.dao.UserDAO; 15 import org.contineo.core.LoggingManager; 16 import org.contineo.core.SessionManagement; 17 import org.contineo.forms.SelectUserForm; 18 24 public class SelectUserAction extends Action { 25 26 30 private Logger logger; 31 32 33 34 public SelectUserAction() { 35 logger = LoggingManager.getLogger(this.getClass()); 36 } 37 38 public ActionForward execute(ActionMapping mapping, 39 ActionForm form, HttpServletRequest request, 40 HttpServletResponse response) { 41 ActionForward actionForward = new ActionForward(); 42 HttpSession session = request.getSession(); 43 if (SessionManagement.isValid(session)) { 44 try { 45 MenuDAO mdao = new MenuDAO(); 46 String uname = (String )session.getAttribute("authuser"); 47 if (mdao.isReadEnable(10, uname)) { 48 SelectUserForm suform = (SelectUserForm)form; 49 String username = suform.getUserName(); 50 String name = suform.getName(); 51 UserDAO dao = new UserDAO(); 52 Collection coll = null; 53 if ((username == null || username.trim().equals("")) && (name == null || name.trim().equals(""))) { 54 coll = dao.findAll(); 55 } else { 56 if (username == null || username.trim().equals("")) { 57 coll = dao.findByName(name); 58 } else { 59 if (name == null || name.trim().equals("")) { 60 coll = dao.findByUserName(username); 61 } else { 62 coll = dao.findByUserNameAndName(username, name); 63 } 64 } 65 } 66 request.setAttribute("users", coll); 67 actionForward = mapping.findForward("showuser"); 68 } else 69 actionForward = mapping.findForward("noaccess"); 70 } catch (Exception e) { 71 if (logger.isEnabledFor(Level.ERROR)) 72 logger.error(e.getMessage()); 73 actionForward = mapping.findForward("error"); 74 } 75 } else 76 actionForward = mapping.findForward("invalid"); 77 return actionForward; 78 } 79 } | Popular Tags |