KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > controller > DashboardController


1 /*********************************************************************************
2  * The contents of this file are subject to the OpenI Public License Version 1.0
3  * ("License"); You may not use this file except in compliance with the
4  * License. You may obtain a copy of the License at
5  * http://www.openi.org/docs/LICENSE.txt
6  *
7  * Software distributed under the License is distributed on an "AS IS" basis,
8  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
9  * the specific language governing rights and limitations under the License.
10  *
11  * The Original Code is: OpenI Open Source
12  *
13  * The Initial Developer of the Original Code is Loyalty Matrix, Inc.
14  * Portions created by Loyalty Matrix, Inc. are
15  * Copyright (C) 2005 Loyalty Matrix, Inc.; All Rights Reserved.
16  *
17  * Contributor(s): i18n : Pedro Casals Fradera (2006/05/17)
18  *
19  ********************************************************************************/

20 package org.openi.web.controller;
21
22 import java.io.FileInputStream JavaDoc;
23 import java.io.IOException JavaDoc;
24 import java.io.InputStream JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.Iterator JavaDoc;
27 import java.util.LinkedList JavaDoc;
28 import java.util.List JavaDoc;
29 import java.util.Map JavaDoc;
30 import java.util.TreeMap JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35
36 import org.apache.log4j.Logger;
37 import org.openi.analysis.Analysis;
38 import org.openi.menu.AnalysisCollectionMenuVisitor;
39 import org.openi.menu.Menu;
40 import org.openi.menu.MenuBuilder;
41 import org.openi.menu.MenuItem;
42 import org.openi.project.Overview;
43 import org.openi.project.ProjectContext;
44 import org.openi.xml.BeanStorage;
45 import org.openi.xml.RssFeedGenerator;
46 import org.openi.xml.XMLTransformer;
47 import org.springframework.web.servlet.ModelAndView;
48 import org.springframework.web.servlet.mvc.AbstractController;
49
50
51 /**
52  * Uses the RssFeedGenerator which retrieves rss feeds (including openi internal feeds),
53  * puts them into the model object for use in the view layer.
54  */

55 public class DashboardController extends AbstractController {
56     private static Logger logger = Logger.getLogger(DashboardController.class);
57     
58     /**
59      * Model contents:
60      * "model" (Map)
61      * "channels" (List)
62      * channel (ChannelIF)
63      *
64      * @param httpServletRequest HttpServletRequest
65      * @param httpServletResponse HttpServletResponse
66      * @return ModelAndView
67      * @throws Exception
68      */

69     protected ModelAndView handleRequestInternal(HttpServletRequest JavaDoc request,
70         HttpServletResponse JavaDoc response) throws Exception JavaDoc {
71     
72             ModelAndView modelAndView = null;
73             Map JavaDoc model = new HashMap JavaDoc();
74             ProjectContext projectContext = (ProjectContext)request.getSession().getAttribute("projectContext");
75             
76             String JavaDoc menuName = request.getParameter("menu");
77             String JavaDoc overviewKey = request.getParameter("overviewKey");
78             
79             if( (menuName==null || menuName.length()<1) &&
80                 (overviewKey == null || overviewKey.length()<1)){
81                 
82                 // return the choose overview page, which accesses overviews
83
// from the project in session (configured)
84
// and from the projectContext in session (dynamic overviews)
85
modelAndView = new ModelAndView("chooseOverviewView", model);
86             }else if(overviewKey != null){
87                 // Map analyses = new TreeMap();
88
List JavaDoc analyses = new LinkedList JavaDoc();
89                 Overview overview = projectContext.getProject().getOverview(overviewKey);
90                 Iterator JavaDoc links = overview.getLinks().iterator();
91                 
92                 // need analysis object for description
93
while(links.hasNext()){
94                     String JavaDoc config = (String JavaDoc)links.next();
95                     try{
96                         //try to restore
97
projectContext.restoreAnalysis(config);
98                         analyses.add(new MenuItem(MenuBuilder.constructDisplayName(config), config));
99                     }catch(IOException JavaDoc e){
100                         // need to trap the exception otherwise the whole analysis fails
101
logger.warn("Trapping IOException - missing analysis in overview, probably need to reconfigure overview", e);
102                         analyses.add(new MenuItem(MenuBuilder.constructDisplayName(config) + " - Missing", "broken") );
103                     }
104                 }
105                 model.put("title", overviewKey);
106                 // try just putting in the links
107
model.put("analyses", analyses);
108                 model.put("overview", overview);
109                 modelAndView = new ModelAndView("dashboardView", "model", model);
110             }else if(menuName!= null){
111                 logger.debug("building overview for submenu: " + menuName);
112                 
113                 Menu menu = projectContext.buildMenu().getSubMenu(menuName);
114                 AnalysisCollectionMenuVisitor visitor = new AnalysisCollectionMenuVisitor(projectContext);
115                 menu.accept(visitor);
116                 List JavaDoc analyses = new LinkedList JavaDoc();
117                 Iterator JavaDoc links = visitor.getAnalyses().keySet().iterator();
118                  while(links.hasNext()){
119                         String JavaDoc config = (String JavaDoc)links.next();
120                         try{
121                             //try to restore
122
projectContext.restoreAnalysis(config);
123                             analyses.add(new MenuItem(MenuBuilder.constructDisplayName(config), config));
124                         }catch(IOException JavaDoc e){
125                             // need to trap the exception otherwise the whole analysis fails
126
logger.warn("Trapping IOException - missing analysis in overview, probably need to reconfigure overview", e);
127                             analyses.add(new MenuItem(MenuBuilder.constructDisplayName(config) + " - Missing", "broken") );
128                         }
129                     }
130                 
131                 model.put("title", menuName);
132                 model.put("analyses", analyses);
133                 
134                 // create a shell overview, to store preferences
135
// ResourceBundle res = ResourceBundle.getBundle("org.openi.labels", projectContext.getUser().getLocale());
136
Overview overview = new Overview();
137                 // overview.setDescription(res.getString("java_DashboardController.message") + " " + menuName);
138
overview.setDescription(menuName);
139                 model.put("overview", overview);
140                 modelAndView = new ModelAndView("dashboardView", "model", model);
141             }
142         
143         return modelAndView;
144     }
145
146
147
148 }
149
Popular Tags