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.util.UIUtil;
034: import org.pentaho.messages.Messages;
035: import org.pentaho.ui.component.DashboardWidgetComponent;
036:
037: public class WidgetPortlet extends ViewPortlet {
038:
039: private String WIDGET = "widget"; //$NON-NLS-1$
040:
041: private String WIDTH = "width"; //$NON-NLS-1$
042:
043: private String HEIGHT = "height"; //$NON-NLS-1$
044:
045: private String VALUE = "value"; //$NON-NLS-1$
046:
047: private String TITLE = "title"; //$NON-NLS-1$
048:
049: private static final Log portletLogger = LogFactory
050: .getLog(WidgetPortlet.class);
051:
052: public Log getLogger() {
053: return portletLogger;
054: }
055:
056: public void processPortletAction(ActionRequest request,
057: ActionResponse response, PentahoPortletSession userSession)
058: throws PortletException, IOException {
059:
060: }
061:
062: public void doPortletView(RenderRequest request,
063: RenderResponse response, PentahoPortletSession userSession)
064: throws PortletException, IOException {
065:
066: response.setContentType("text/html"); //$NON-NLS-1$
067:
068: PortletUrlFactory urlFactory = new PortletUrlFactory(response,
069: request.getWindowState(), request.getPortletMode());
070:
071: PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(
072: request);
073: PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(
074: userSession);
075: PortletPreferences prefs = request.getPreferences();
076: PortletPreferencesParameterProvider portletPrefsParameters = new PortletPreferencesParameterProvider(
077: prefs);
078:
079: String widgetDefinition = getSetting(WIDGET, null, request,
080: requestParameters);
081:
082: if (widgetDefinition == null) {
083: response
084: .getWriter()
085: .print(
086: Messages
087: .getString("Widget.USER_WIDGET_NOT_SPECIFIED")); //$NON-NLS-1$
088: return;
089: }
090:
091: int width = (int) getSetting(WIDTH, 150, request,
092: requestParameters);
093: int height = (int) getSetting(HEIGHT, 150, request,
094: requestParameters);
095:
096: ArrayList messages = new ArrayList();
097: DashboardWidgetComponent widget = new DashboardWidgetComponent(
098: DashboardWidgetComponent.TYPE_DIAL, widgetDefinition,
099: width, height, urlFactory, messages);
100: widget.validate(userSession, null);
101:
102: widget.setParameterProvider(
103: HttpRequestParameterProvider.SCOPE_REQUEST,
104: requestParameters);
105: widget.setParameterProvider(
106: HttpSessionParameterProvider.SCOPE_SESSION,
107: sessionParameters);
108: widget
109: .setParameterProvider(
110: PortletPreferencesParameterProvider.SCOPE_PORTLET_PREFERENCES,
111: portletPrefsParameters);
112:
113: // TODO provide different ways to get the value to display...
114: int value = (int) getSetting(VALUE, 0, request,
115: requestParameters);
116: widget.setValue(value);
117:
118: String widgetTitle = getSetting(TITLE,
119: "", request, requestParameters); //$NON-NLS-1$
120: widget.setTitle(widgetTitle);
121:
122: String content = widget.getContent("text/html"); //$NON-NLS-1$
123:
124: if (content == null) {
125: StringBuffer buffer = new StringBuffer();
126: UIUtil
127: .formatErrorMessage(
128: "text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
129: content = buffer.toString();
130: }
131:
132: if (content == null || content.equals("")) { //$NON-NLS-1$
133: content = " "; //$NON-NLS-1$
134: }
135: response.getWriter().print(content);
136:
137: }
138:
139: }
|