KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > ui > portlet > NavigationPortlet


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Aug 2, 2005
14  * @author James Dixon
15  */

16
17 package org.pentaho.ui.portlet;
18
19 import java.io.IOException JavaDoc;
20 import java.util.ArrayList JavaDoc;
21
22 import javax.portlet.ActionRequest;
23 import javax.portlet.ActionResponse;
24 import javax.portlet.PortletException;
25 import javax.portlet.PortletPreferences;
26 import javax.portlet.RenderRequest;
27 import javax.portlet.RenderResponse;
28
29 import org.apache.commons.logging.Log;
30 import org.apache.commons.logging.LogFactory;
31 import org.pentaho.core.system.PentahoSystem;
32 import org.pentaho.ui.component.INavigationComponent;
33 import org.pentaho.ui.component.NavigationComponentFactory;
34
35 public class NavigationPortlet extends ViewPortlet {
36
37     private String JavaDoc SOLUTION = "solution"; //$NON-NLS-1$
38

39     private String JavaDoc PATH = "path"; //$NON-NLS-1$
40

41     private String JavaDoc XSL = "xsl"; //$NON-NLS-1$
42

43     private static final Log portletLogger = LogFactory.getLog(NavigationPortlet.class);
44
45     public Log getLogger() {
46         return portletLogger;
47     }
48
49     public void processPortletAction(ActionRequest request, ActionResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
50         // TODO Auto-generated method stub
51

52     }
53
54     public void doPortletView(RenderRequest request, RenderResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
55
56         PortletUrlFactory urlFactory = new PortletUrlFactory(response, request.getWindowState(), request.getPortletMode());
57
58         PortletPreferences prefs = request.getPreferences();
59         PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(request);
60         PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(userSession);
61
62         boolean allowNavigation = true;
63         String JavaDoc solution = request.getParameter(SOLUTION);
64         if (solution == null) {
65             // get the default value from the preferences
66
solution = prefs.getValue(SOLUTION, null);
67             if (solution != null) {
68                 requestParameters.setParameter(SOLUTION, solution);
69                 allowNavigation = false;
70             } else {
71                 solution = ""; //$NON-NLS-1$
72
}
73         }
74         String JavaDoc path = request.getParameter(PATH);
75         if (path == null) {
76             // get the default value from the preferences
77
path = prefs.getValue(PATH, null);
78             if (path != null) {
79                 requestParameters.setParameter(PATH, path);
80                 allowNavigation = false;
81             } else {
82                 path = null;
83             }
84         }
85
86         String JavaDoc hrefUrl = PentahoSystem.getApplicationContext().getBaseUrl();
87         String JavaDoc onClick = ""; //$NON-NLS-1$
88
ArrayList JavaDoc messages = new ArrayList JavaDoc();
89
90         INavigationComponent navigate = NavigationComponentFactory.getNavigationComponent();
91         navigate.setHrefUrl(hrefUrl);
92         navigate.setOnClick(onClick);
93         navigate.setSolutionParamName(SOLUTION);
94         navigate.setPathParamName(PATH);
95         navigate.setAllowNavigation(new Boolean JavaDoc(allowNavigation));
96         navigate.setOptions(""); //$NON-NLS-1$
97
navigate.setUrlFactory(urlFactory);
98         navigate.setMessages(messages);
99         navigate.validate(userSession, null);
100         String JavaDoc xslName = prefs.getValue(XSL, null);
101         if (xslName != null) {
102             navigate.setXsl("text/html", xslName); //$NON-NLS-1$
103
}
104         navigate.setParameterProvider("request", requestParameters); //$NON-NLS-1$
105
navigate.setParameterProvider("session", sessionParameters); //$NON-NLS-1$
106

107         String JavaDoc content = navigate.getContent("text/html"); //$NON-NLS-1$
108
if (content == null || content.equals("")) { //$NON-NLS-1$
109
content = " "; //$NON-NLS-1$
110
}
111
112         response.setContentType("text/html"); //$NON-NLS-1$
113
response.getWriter().print(content);
114     }
115 }
116
Popular Tags