1 16 17 package org.pentaho.ui.portlet; 18 19 import java.io.IOException ; 20 import java.util.ArrayList ; 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 WIDGET = "widget"; 36 private String WIDTH = "width"; 38 private String HEIGHT = "height"; 40 private String VALUE = "value"; 42 private String TITLE = "title"; 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 { 51 52 } 53 54 public void doPortletView(RenderRequest request, RenderResponse response, PentahoPortletSession userSession) throws PortletException, IOException { 55 56 response.setContentType("text/html"); 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 widgetDefinition = getSetting(WIDGET, null, request, requestParameters); 64 65 if (widgetDefinition == null) { 66 response.getWriter().print(Messages.getString("Widget.USER_WIDGET_NOT_SPECIFIED")); return; 68 } 69 70 int width = (int) getSetting(WIDTH, 150, request, requestParameters); 71 int height = (int) getSetting(HEIGHT, 150, request, requestParameters); 72 73 ArrayList messages = new ArrayList (); 74 DashboardWidgetComponent widget = new DashboardWidgetComponent(DashboardWidgetComponent.TYPE_DIAL, widgetDefinition, width, height, urlFactory, messages); 75 widget.validate(userSession, null); 76 77 widget.setParameterProvider("request", requestParameters); widget.setParameterProvider("session", sessionParameters); 80 int value = (int) getSetting(VALUE, 0, request, requestParameters); 82 widget.setValue(value); 83 84 String widgetTitle = getSetting(TITLE, "", request, requestParameters); widget.setTitle(widgetTitle); 86 87 String content = widget.getContent("text/html"); 89 if (content == null) { 90 StringBuffer buffer = new StringBuffer (); 91 UIUtil.formatErrorMessage("text/html", Messages.getString("Widget.ERROR_0001_COULD_NOT_CREATE_WIDGET"), messages, buffer); content = buffer.toString(); 93 } 94 95 if (content == null || content.equals("")) { content = " "; } 98 response.getWriter().print(content); 99 100 } 101 102 } 103 | Popular Tags |