KickJava   Java API By Example, From Geeks To Geeks.

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


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 import javax.portlet.ActionRequest;
22 import javax.portlet.ActionResponse;
23 import javax.portlet.PortletException;
24 import javax.portlet.RenderRequest;
25 import javax.portlet.RenderResponse;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28 import org.pentaho.core.util.UIUtil;
29 import org.pentaho.messages.Messages;
30 import org.pentaho.ui.component.DashboardWidgetComponent;
31
32 public class WidgetPortlet extends ViewPortlet {
33
34     private String JavaDoc WIDGET = "widget"; //$NON-NLS-1$
35

36     private String JavaDoc WIDTH = "width"; //$NON-NLS-1$
37

38     private String JavaDoc HEIGHT = "height"; //$NON-NLS-1$
39

40     private String JavaDoc VALUE = "value"; //$NON-NLS-1$
41

42     private String JavaDoc TITLE = "title"; //$NON-NLS-1$
43

44     private static final Log portletLogger = LogFactory.getLog(WidgetPortlet.class);
45
46     public Log getLogger() {
47         return portletLogger;
48     }
49
50     public void processPortletAction(ActionRequest request, ActionResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
51
52     }
53
54     public void doPortletView(RenderRequest request, RenderResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
55
56         response.setContentType("text/html"); //$NON-NLS-1$
57

58         PortletUrlFactory urlFactory = new PortletUrlFactory(response, request.getWindowState(), request.getPortletMode());
59
60         PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(request);
61         PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(userSession);
62
63         String JavaDoc widgetDefinition = getSetting(WIDGET, null, request, requestParameters);
64
65         if (widgetDefinition == null) {
66             response.getWriter().print(Messages.getString("Widget.USER_WIDGET_NOT_SPECIFIED")); //$NON-NLS-1$
67
return;
68         }
69
70         int width = (int) getSetting(WIDTH, 150, request, requestParameters);
71         int height = (int) getSetting(HEIGHT, 150, request, requestParameters);
72
73         ArrayList JavaDoc messages = new ArrayList JavaDoc();
74         DashboardWidgetComponent widget = new DashboardWidgetComponent(DashboardWidgetComponent.TYPE_DIAL, widgetDefinition, width, height, urlFactory, messages);
75         widget.validate(userSession, null);
76
77         widget.setParameterProvider("request", requestParameters); //$NON-NLS-1$
78
widget.setParameterProvider("session", sessionParameters); //$NON-NLS-1$
79

80         // TODO provide different ways to get the value to display...
81
int value = (int) getSetting(VALUE, 0, request, requestParameters);
82         widget.setValue(value);
83
84         String JavaDoc widgetTitle = getSetting(TITLE, "", request, requestParameters); //$NON-NLS-1$
85
widget.setTitle(widgetTitle);
86
87         String JavaDoc content = widget.getContent("text/html"); //$NON-NLS-1$
88

89         if (content == null) {
90             StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
91             UIUtil.formatErrorMessage("text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
92
content = buffer.toString();
93         }
94
95         if (content == null || content.equals("")) { //$NON-NLS-1$
96
content = " "; //$NON-NLS-1$
97
}
98         response.getWriter().print(content);
99
100     }
101
102 }
103
Popular Tags