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 24, 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.util.UIUtil;
034: import org.pentaho.messages.Messages;
035: import org.pentaho.ui.component.WidgetGridComponent;
036:
037: public class WidgetGridPortlet extends ViewPortlet {
038:
039: private String WIDGET = "widget"; //$NON-NLS-1$
040:
041: private String WIDGETGRID = "widget-grid"; //$NON-NLS-1$
042:
043: private static final Log portletLogger = LogFactory
044: .getLog(WidgetGridPortlet.class);
045:
046: public Log getLogger() {
047: return portletLogger;
048: }
049:
050: public void processPortletAction(ActionRequest request,
051: ActionResponse response, PentahoPortletSession userSession)
052: throws PortletException, IOException {
053:
054: }
055:
056: public void doPortletView(RenderRequest request,
057: RenderResponse response, PentahoPortletSession userSession)
058: throws PortletException, IOException {
059:
060: response.setContentType("text/html"); //$NON-NLS-1$
061:
062: PortletUrlFactory urlFactory = new PortletUrlFactory(response,
063: request.getWindowState(), request.getPortletMode());
064:
065: PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(
066: request);
067: PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(
068: userSession);
069: PortletPreferences prefs = request.getPreferences();
070: PortletPreferencesParameterProvider portletPrefsParameters = new PortletPreferencesParameterProvider(
071: prefs);
072:
073: String widgetDefinition = getSetting(WIDGET, null, request,
074: requestParameters);
075: String widgetGridDataDefinition = getSetting(WIDGETGRID, null,
076: request, requestParameters);
077:
078: if (widgetDefinition == null) {
079: response
080: .getWriter()
081: .print(
082: Messages
083: .getString("Widget.USER_WIDGET_NOT_SPECIFIED")); //$NON-NLS-1$
084: return;
085: }
086:
087: String urlDrillTemplate = getSetting(
088: "drill-url", null, request, null); //$NON-NLS-1$
089: ArrayList messages = new ArrayList();
090: WidgetGridComponent widget = null;
091: try {
092: widget = new WidgetGridComponent(widgetDefinition,
093: urlFactory, messages);
094: widget.validate(userSession, null);
095: widget.setDataAction(widgetGridDataDefinition);
096: widget.setDrillUrlTemplate(urlDrillTemplate);
097:
098: widget.setParameterProvider(
099: HttpRequestParameterProvider.SCOPE_REQUEST,
100: requestParameters);
101: widget.setParameterProvider(
102: HttpSessionParameterProvider.SCOPE_SESSION,
103: sessionParameters);
104: widget
105: .setParameterProvider(
106: PortletPreferencesParameterProvider.SCOPE_PORTLET_PREFERENCES,
107: portletPrefsParameters);
108:
109: String content = widget.getContent("text/html"); //$NON-NLS-1$
110:
111: if (content == null) {
112: StringBuffer buffer = new StringBuffer();
113: UIUtil
114: .formatErrorMessage(
115: "text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
116: content = buffer.toString();
117: }
118: if (content == null || content.equals("")) { //$NON-NLS-1$
119: content = " "; //$NON-NLS-1$
120: }
121: response.getWriter().print(content);
122: } finally {
123: if (widget != null)
124: widget.dispose();
125: }
126: }
127: }
|