1 24 package org.riotfamily.riot.workflow.status.ui; 25 26 import java.util.ArrayList ; 27 import java.util.Collection ; 28 import java.util.Iterator ; 29 import java.util.List ; 30 import java.util.Locale ; 31 32 import javax.servlet.http.HttpServletRequest ; 33 import javax.servlet.http.HttpServletResponse ; 34 35 import org.riotfamily.common.util.ResourceUtils; 36 import org.riotfamily.riot.workflow.status.StatusMonitor; 37 import org.springframework.beans.factory.BeanFactoryUtils; 38 import org.springframework.context.ApplicationContext; 39 import org.springframework.context.ApplicationContextAware; 40 import org.springframework.web.servlet.ModelAndView; 41 import org.springframework.web.servlet.mvc.Controller; 42 import org.springframework.web.servlet.support.RequestContextUtils; 43 44 50 public class StatusController implements Controller, 51 ApplicationContextAware { 52 53 private Collection monitors; 54 55 private String viewName = ResourceUtils.getPath( 56 StatusController.class, "StatusView.ftl"); 57 58 59 public void setApplicationContext(ApplicationContext context) { 60 monitors = BeanFactoryUtils.beansOfTypeIncludingAncestors( 61 context, StatusMonitor.class).values(); 62 } 63 64 public ModelAndView handleRequest(HttpServletRequest request, 65 HttpServletResponse response) throws Exception { 66 67 if (monitors.isEmpty()) { 68 return null; 69 } 70 71 Locale locale = RequestContextUtils.getLocale(request); 72 73 Iterator it = monitors.iterator(); 74 List model = new ArrayList (); 75 while (it.hasNext()) { 76 StatusMonitor monitor = (StatusMonitor) it.next(); 77 Collection messages = monitor.getMessages(locale); 78 if (messages != null) { 79 model.addAll(messages); 80 } 81 } 82 return new ModelAndView(viewName, "messages", model); 83 } 84 85 } 86 | Popular Tags |