01: /* ***** BEGIN LICENSE BLOCK *****
02: * Version: MPL 1.1
03: * The contents of this file are subject to the Mozilla Public License Version
04: * 1.1 (the "License"); you may not use this file except in compliance with
05: * the License. You may obtain a copy of the License at
06: * http://www.mozilla.org/MPL/
07: *
08: * Software distributed under the License is distributed on an "AS IS" basis,
09: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
10: * for the specific language governing rights and limitations under the
11: * License.
12: *
13: * The Original Code is Riot.
14: *
15: * The Initial Developer of the Original Code is
16: * Neteye GmbH.
17: * Portions created by the Initial Developer are Copyright (C) 2006
18: * the Initial Developer. All Rights Reserved.
19: *
20: * Contributor(s):
21: * Felix Gnass [fgnass at neteye dot de]
22: *
23: * ***** END LICENSE BLOCK ***** */
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: /**
45: * Controller that collects messages form all {@link StatusMonitor} beans
46: * and displays them.
47: *
48: * @author Felix Gnass [fgnass at neteye dot de]
49: */
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: public void setApplicationContext(ApplicationContext context) {
59: monitors = BeanFactoryUtils.beansOfTypeIncludingAncestors(
60: context, StatusMonitor.class).values();
61: }
62:
63: public ModelAndView handleRequest(HttpServletRequest request,
64: HttpServletResponse response) throws Exception {
65:
66: if (monitors.isEmpty()) {
67: return null;
68: }
69:
70: Locale locale = RequestContextUtils.getLocale(request);
71:
72: Iterator it = monitors.iterator();
73: List model = new ArrayList();
74: while (it.hasNext()) {
75: StatusMonitor monitor = (StatusMonitor) it.next();
76: Collection messages = monitor.getMessages(locale);
77: if (messages != null) {
78: model.addAll(messages);
79: }
80: }
81: return new ModelAndView(viewName, "messages", model);
82: }
83:
84: }
|