001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Aug 2, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.ui.portlet;
018:
019: import java.io.IOException;
020: import java.util.ArrayList;
021:
022: import javax.portlet.ActionRequest;
023: import javax.portlet.ActionResponse;
024: import javax.portlet.PortletException;
025: import javax.portlet.PortletPreferences;
026: import javax.portlet.RenderRequest;
027: import javax.portlet.RenderResponse;
028:
029: import org.apache.commons.logging.Log;
030: import org.apache.commons.logging.LogFactory;
031: import org.pentaho.core.solution.HttpRequestParameterProvider;
032: import org.pentaho.core.solution.HttpSessionParameterProvider;
033: import org.pentaho.core.system.PentahoSystem;
034: import org.pentaho.ui.component.INavigationComponent;
035: import org.pentaho.ui.component.NavigationComponentFactory;
036:
037: public class NavigationPortlet extends ViewPortlet {
038:
039: private String SOLUTION = "solution"; //$NON-NLS-1$
040:
041: private String PATH = "path"; //$NON-NLS-1$
042:
043: private String XSL = "xsl"; //$NON-NLS-1$
044:
045: private static final Log portletLogger = LogFactory
046: .getLog(NavigationPortlet.class);
047:
048: public Log getLogger() {
049: return portletLogger;
050: }
051:
052: public void processPortletAction(ActionRequest request,
053: ActionResponse response, PentahoPortletSession userSession)
054: throws PortletException, IOException {
055: // TODO Auto-generated method stub
056:
057: }
058:
059: public void doPortletView(RenderRequest request,
060: RenderResponse response, PentahoPortletSession userSession)
061: throws PortletException, IOException {
062:
063: PortletUrlFactory urlFactory = new PortletUrlFactory(response,
064: request.getWindowState(), request.getPortletMode());
065:
066: PortletPreferences prefs = request.getPreferences();
067: PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(
068: request);
069: PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(
070: userSession);
071: PortletPreferencesParameterProvider portletPrefsParameters = new PortletPreferencesParameterProvider(
072: prefs);
073:
074: boolean allowNavigation = true;
075: String solution = request.getParameter(SOLUTION);
076: if (solution == null) {
077: // get the default value from the preferences
078: solution = prefs.getValue(SOLUTION, null);
079: if (solution != null) {
080: requestParameters.setParameter(SOLUTION, solution);
081: allowNavigation = false;
082: } else {
083: solution = ""; //$NON-NLS-1$
084: }
085: }
086: String path = request.getParameter(PATH);
087: if (path == null) {
088: // get the default value from the preferences
089: path = prefs.getValue(PATH, null);
090: if (path != null) {
091: requestParameters.setParameter(PATH, path);
092: allowNavigation = false;
093: } else {
094: path = null;
095: }
096: }
097:
098: String hrefUrl = PentahoSystem.getApplicationContext()
099: .getBaseUrl();
100: String onClick = ""; //$NON-NLS-1$
101: ArrayList messages = new ArrayList();
102:
103: INavigationComponent navigate = NavigationComponentFactory
104: .getNavigationComponent();
105: navigate.setHrefUrl(hrefUrl);
106: navigate.setOnClick(onClick);
107: navigate.setSolutionParamName(SOLUTION);
108: navigate.setPathParamName(PATH);
109: navigate.setAllowNavigation(new Boolean(allowNavigation));
110: navigate.setOptions(""); //$NON-NLS-1$
111: navigate.setUrlFactory(urlFactory);
112: navigate.setMessages(messages);
113: navigate.validate(userSession, null);
114: String xslName = prefs.getValue(XSL, null);
115: if (xslName != null) {
116: navigate.setXsl("text/html", xslName); //$NON-NLS-1$
117: }
118: navigate.setParameterProvider(
119: HttpRequestParameterProvider.SCOPE_REQUEST,
120: requestParameters);
121: navigate.setParameterProvider(
122: HttpSessionParameterProvider.SCOPE_SESSION,
123: sessionParameters);
124: navigate
125: .setParameterProvider(
126: PortletPreferencesParameterProvider.SCOPE_PORTLET_PREFERENCES,
127: portletPrefsParameters);
128:
129: String content = navigate.getContent("text/html"); //$NON-NLS-1$
130: if (content == null || content.equals("")) { //$NON-NLS-1$
131: content = " "; //$NON-NLS-1$
132: }
133:
134: response.setContentType("text/html"); //$NON-NLS-1$
135: response.getWriter().print(content);
136: }
137: }
|