KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openi > web > controller > menu > TreeNavigationController


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): ______________________________________.
18  *
19  ********************************************************************************/

20 package org.openi.web.controller.menu;
21
22 import org.apache.log4j.Logger;
23 import org.openi.application.Application;
24 import org.openi.menu.Menu;
25 import org.openi.project.ProjectContext;
26 import org.openi.util.Util;
27 import org.openi.xml.BeanStorage;
28 import org.openi.xml.XMLTransformer;
29 import org.springframework.web.servlet.ModelAndView;
30 import org.springframework.web.servlet.mvc.AbstractController;
31 import java.util.*;
32 import javax.servlet.http.HttpServletRequest JavaDoc;
33 import javax.servlet.http.HttpServletResponse JavaDoc;
34 import javax.servlet.http.HttpSession JavaDoc;
35
36
37 /**
38  * @author Uddhab Pant <br>
39  *
40  * Controller for handling <strong>treenavigation</strong> request. This class does following
41  * tasks:
42  * <ul>
43  * <li> reads menu xsl file.
44  * <li> builds menu for the project using project context in xml format.
45  * <li> transforms muenu xml with menu xsl and generates menu in html list format.
46  * <li> gets powered by logo from application configuration
47  * <li> gets project logo from project.
48  * </ul>
49  */

50 public class TreeNavigationController extends AbstractController {
51     private static Logger logger = Logger.getLogger(TreeNavigationController.class);
52     private String JavaDoc xslFileName;
53     
54     /**
55      * Process the request and return a ModelAndView object which the DispatcherServlet will render.
56      * It indicates that this object completed request processing itself, thus there is no ModelAndView to render.
57      * Handles treenavigation request
58      * @param request HttpServletRequest
59      * @param response HttpServletResponse
60      * @return ModelAndView
61      * @throws Exception
62      */

63     public ModelAndView handleRequestInternal(HttpServletRequest JavaDoc request,
64             HttpServletResponse JavaDoc response) throws Exception JavaDoc {
65         String JavaDoc view = null;
66         String JavaDoc xmlMenu = null;
67         String JavaDoc xslMenu = null;
68         String JavaDoc htmlMenu = null;
69         String JavaDoc poweredByLogoName = null;
70         String JavaDoc logoUrl = null;
71         String JavaDoc showPropertiesTab = "false";
72         Map model = new HashMap();
73         
74         try {
75             xslMenu = Util.getFileContents(this.getServletContext()
76                     .getRealPath(xslFileName));
77             
78             HttpSession JavaDoc session = request.getSession();
79             
80             // if request attribute contains 'analysisPage', use tree navigation view
81
// created for analaysis page.
82
// attribute 'exception' is added by spring and 'javax.servlet.jsp.jspException'
83
// attribute is added by jPivot.
84
if ("true".equalsIgnoreCase(
85                     (String JavaDoc) request.getAttribute("analysisPage"))
86                     && (request.getAttribute("javax.servlet.jsp.jspException") == null)
87                     && (request.getAttribute("exception") == null)) {
88                 view = "treeNavigationAnalysisView";
89                 logger.debug("view:treeNavigationAnalysisView");
90             } else {
91                 view = "treeNavigationView";
92                 logger.debug("view: treeNavigationView");
93             }
94             
95             //get project context from session and build menu
96
ProjectContext projectContext = (ProjectContext) session
97             .getAttribute("projectContext");
98             Menu root = projectContext.buildMenu();
99             
100             BeanStorage store = new BeanStorage();
101             
102             xmlMenu = store.toXmlString(root);
103             
104             //transform xml with xsl.
105
htmlMenu = XMLTransformer.transform(xslMenu, xmlMenu);
106             
107             model.put("htmlMenu", htmlMenu);
108             
109             //get powered by logo.
110
poweredByLogoName = Application.getInstance()
111             .getPoweredByLogoName();
112             
113             model.put("poweredByLogoName", poweredByLogoName);
114             
115             //get project logo
116
logoUrl = request.getContextPath() + "-projects/"
117             + projectContext.getProject().getProjectId() + "/"
118             + projectContext.getProject().getLogoUrl();
119             
120             model.put("logoUrl", logoUrl);
121             
122             /* Using hack (button name) to check whether print properties or chart properties or MDX editor or short
123              button is clicked. If any of these button is clicked, set showPropertiesTab value to true,
124              which is used in view to show properties tab.
125              */

126             if ((request.getParameter("toolbar01.printPropertiesButton01.x") != null)
127                     || (request.getParameter(
128                     "toolbar01.chartPropertiesButton01.x") != null)
129                     || (request.getParameter("toolbar01.mdxEditButton.x") != null)
130                     || (request.getParameter("toolbar01.sortConfigButton.x") != null)
131                     || (request.getParameter("toolbar01.sqlEditButton.x") != null)) {
132                 model.put("showPropertiesTab", Boolean.TRUE);
133             }
134         } catch (Exception JavaDoc e) {
135             logger.error("Exception:", e);
136             
137             //shouldn't throw exception to avoid recursive throw.
138
//throw e;
139
}
140         
141         return new ModelAndView(view, "model", model);
142     }
143     
144     public void setXslFileName(String JavaDoc xslFileName) {
145         this.xslFileName = xslFileName;
146     }
147     
148     public String JavaDoc getXslFileName() {
149         return xslFileName;
150     }
151 }
152
Popular Tags