1 16 17 package org.pentaho.ui.portlet; 18 19 import java.io.IOException ; 20 import java.io.PrintWriter ; 21 import javax.portlet.ActionRequest; 22 import javax.portlet.ActionResponse; 23 import javax.portlet.PortletException; 24 import javax.portlet.PortletPreferences; 25 import javax.portlet.RenderRequest; 26 import javax.portlet.RenderResponse; 27 import org.apache.commons.logging.Log; 28 import org.apache.commons.logging.LogFactory; 29 import org.pentaho.core.runtime.IBackgroundExecution; 30 import org.pentaho.core.solution.IOutputHandler; 31 import org.pentaho.core.system.PentahoSystem; 32 import org.pentaho.core.util.IUITemplater; 33 import org.pentaho.messages.Messages; 34 import org.pentaho.ui.component.ActionComponent; 35 36 public class ActionPortlet extends ViewPortlet { 37 38 private final static String ACTION = "action"; 40 private static final Log portletLogger = LogFactory.getLog(ActionPortlet.class); 41 42 public Log getLogger() { 43 return portletLogger; 44 } 45 46 public void processPortletAction(ActionRequest request, ActionResponse response, PentahoPortletSession userSession) throws PortletException, IOException { 47 49 } 50 51 public void doPortletView(RenderRequest request, RenderResponse response, PentahoPortletSession userSession) throws PortletException, IOException { 52 53 57 PortletRequestParameterProvider requestParameters = new PortletRequestParameterProvider(request); 58 59 doPortletView(IOutputHandler.OUTPUT_TYPE_DEFAULT, requestParameters, request, response, userSession); 60 61 } 62 63 public void doPortletView(int outputPreference, PortletRequestParameterProvider requestParameters, RenderRequest request, RenderResponse response, PentahoPortletSession userSession) throws IOException { 64 65 69 PortletUrlFactory urlFactory = new PortletUrlFactory(response, request.getWindowState(), request.getPortletMode()); 70 PortletPreferences prefs = request.getPreferences(); 74 PortletSessionParameterProvider sessionParameters = new PortletSessionParameterProvider(userSession); 75 76 String actionString = request.getParameter(ACTION); 77 if (actionString == null) { 78 actionString = prefs.getValue(ACTION, null); 80 if (actionString != null) { 81 requestParameters.setParameter(ACTION, actionString); 82 } 83 } 84 String backgroundExecution = request.getParameter("background"); if (backgroundExecution == null) { 86 backgroundExecution = prefs.getValue("background", null); if (backgroundExecution != null) { 88 requestParameters.setParameter("background", backgroundExecution); } 90 } 91 String solutionName = null; 92 String actionName = null; 93 String actionPath = null; 94 if (actionString != null) { 95 String info[] = PentahoSystem.parseActionString(actionString); 96 if (info != null && info.length == 3) { 97 solutionName = info[0]; 98 actionPath = info[1]; 99 actionName = info[2]; 100 } 101 102 } 103 if ("true".equals(backgroundExecution)) { IBackgroundExecution backgroundExecutionHandler = PentahoSystem.getBackgroundExecutionHandler(userSession); 105 if (backgroundExecutionHandler != null) { 106 PortletRequestParameterProvider parameterProvider = new PortletRequestParameterProvider(request); 107 parameterProvider.setParameter("solution", solutionName); parameterProvider.setParameter("path", actionPath); parameterProvider.setParameter("action", actionName); String backgroundResponse = backgroundExecutionHandler.backgroundExecuteAction(userSession, parameterProvider); 111 String intro = ""; String footer = ""; IUITemplater templater = PentahoSystem.getUITemplater( userSession ); 114 if( templater != null ) { 115 String sections[] = templater.breakTemplate( "template-dialog.html", "", userSession ); if( sections != null && sections.length > 0 ) { 117 intro = sections[0]; 118 } 119 if( sections != null && sections.length > 1 ) { 120 footer = sections[1]; 121 } 122 } else { 123 intro = Messages.getString( "UI.ERROR_0002_BAD_TEMPLATE_OBJECT" ); } 125 PrintWriter writer = response.getWriter(); 126 writer.print(intro); 127 writer.print(backgroundResponse); 128 writer.print(footer); 129 return; 130 } 131 } 132 133 if (actionString == null || solutionName == null || actionPath == null || actionName == null) { 134 error(Messages.getString("ActionPortlet.ERROR_0001_COULD_NOT_PARSE_ACTION")); PrintWriter writer = response.getWriter(); 136 writer.print(Messages.getString("ActionPortlet.ERROR_0001_COULD_NOT_PARSE_ACTION")); return; 138 139 } 140 141 ActionComponent component = new ActionComponent(solutionName, actionPath, actionName, null, outputPreference, urlFactory, null); 142 component.setParameterProvider("request", requestParameters); component.setParameterProvider("session", sessionParameters); component.validate(userSession, null); 145 146 String content = component.getContent("text/html"); if (content == null || content.equals("")) { content = " "; } 150 response.setContentType("text/html"); PrintWriter writer = response.getWriter(); 152 writer.print(content); 153 154 } 155 156 } 157 | Popular Tags |