KickJava   Java API By Example, From Geeks To Geeks.

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


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 24, 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.WidgetGridComponent;
31
32 public class WidgetGridPortlet extends ViewPortlet {
33
34     private String JavaDoc WIDGET = "widget"; //$NON-NLS-1$
35

36     private String JavaDoc WIDGETGRID = "widget-grid"; //$NON-NLS-1$
37

38     private static final Log portletLogger = LogFactory.getLog(WidgetGridPortlet.class);
39
40     public Log getLogger() {
41         return portletLogger;
42     }
43
44     public void processPortletAction(ActionRequest request, ActionResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
45
46     }
47
48     public void doPortletView(RenderRequest request, RenderResponse response, PentahoPortletSession userSession) throws PortletException, IOException JavaDoc {
49
50         response.setContentType("text/html"); //$NON-NLS-1$
51

52         PortletUrlFactory urlFactory = new PortletUrlFactory(response, request.getWindowState(), request.getPortletMode());
53
54         PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(request);
55         PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(userSession);
56
57         String JavaDoc widgetDefinition = getSetting(WIDGET, null, request, requestParameters);
58         String JavaDoc widgetGridDataDefinition = getSetting(WIDGETGRID, null, request, requestParameters);
59
60         if (widgetDefinition == null) {
61             response.getWriter().print(Messages.getString("Widget.USER_WIDGET_NOT_SPECIFIED")); //$NON-NLS-1$
62
return;
63         }
64
65         String JavaDoc urlDrillTemplate = getSetting("drill-url", null, request, null); //$NON-NLS-1$
66
ArrayList JavaDoc messages = new ArrayList JavaDoc();
67         WidgetGridComponent widget = null;
68         try {
69             widget = new WidgetGridComponent(widgetDefinition, urlFactory, messages);
70             widget.validate(userSession, null);
71             widget.setDataAction(widgetGridDataDefinition);
72             widget.setDrillUrlTemplate(urlDrillTemplate);
73
74             widget.setParameterProvider("request", requestParameters); //$NON-NLS-1$
75
widget.setParameterProvider("session", sessionParameters); //$NON-NLS-1$
76

77             String JavaDoc content = widget.getContent("text/html"); //$NON-NLS-1$
78

79             if (content == null) {
80                 StringBuffer JavaDoc buffer = new StringBuffer JavaDoc();
81                 UIUtil.formatErrorMessage("text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); //$NON-NLS-1$ //$NON-NLS-2$
82
content = buffer.toString();
83             }
84             if (content == null || content.equals("")) { //$NON-NLS-1$
85
content = " "; //$NON-NLS-1$
86
}
87             response.getWriter().print(content);
88         } finally {
89             if (widget != null)
90                 widget.dispose();
91         }
92     }
93 }
94
Popular Tags