1 24 package org.riotfamily.riot.workflow.notification.ui; 25 26 import java.util.List ; 27 28 import javax.servlet.http.HttpServletRequest ; 29 import javax.servlet.http.HttpServletResponse ; 30 31 import org.riotfamily.common.util.ResourceUtils; 32 import org.riotfamily.common.web.util.ServletUtils; 33 import org.riotfamily.common.web.view.JsonView; 34 import org.riotfamily.riot.security.AccessController; 35 import org.riotfamily.riot.workflow.notification.NotificationDao; 36 import org.springframework.web.bind.ServletRequestUtils; 37 import org.springframework.web.servlet.ModelAndView; 38 import org.springframework.web.servlet.mvc.Controller; 39 40 public class NotificationListController implements Controller { 41 42 private static final String ID_PARAMETER = "id"; 43 44 private String viewName = ResourceUtils.getPath( 45 NotificationListController.class, "NotificationView.ftl"); 46 47 private NotificationDao dao; 48 49 public NotificationListController(NotificationDao dao) { 50 this.dao = dao; 51 } 52 53 public ModelAndView handleRequest(HttpServletRequest request, 54 HttpServletResponse response) throws Exception { 55 56 if (dao == null) { 57 return null; 58 } 59 60 String userId = AccessController.getCurrentUser().getUserId(); 61 if (request.getParameter(ID_PARAMETER) != null) { 62 Long notificationId = ServletRequestUtils.getLongParameter( 63 request, ID_PARAMETER); 64 65 dao.markAsRead(userId, notificationId); 66 return null; 67 } 68 69 List notifications = dao.getNotifications(userId); 70 71 if (ServletUtils.isXmlHttpRequest(request)) { 72 return new ModelAndView(new JsonView(), 73 "notifications", notifications); 74 } 75 else if (notifications != null && !notifications.isEmpty()) { 76 return new ModelAndView(viewName); 77 } 78 return null; 79 80 } 81 82 } 83 | Popular Tags |