1 16 17 package org.pentaho.ui.component; 18 19 import java.io.ByteArrayOutputStream ; 20 import java.io.File ; 21 import java.util.List ; 22 import org.apache.commons.logging.Log; 23 import org.apache.commons.logging.LogFactory; 24 import org.pentaho.messages.Messages; 25 import org.pentaho.core.runtime.IRuntimeContext; 26 import org.pentaho.core.session.IPentahoSession; 27 import org.pentaho.core.solution.ISolutionEngine; 28 import org.pentaho.core.solution.SimpleOutputHandler; 29 import org.pentaho.core.system.PentahoSystem; 30 import org.pentaho.core.ui.IPentahoUrlFactory; 31 import org.pentaho.messages.util.LocaleHelper; 32 import org.pentaho.ui.BaseUIComponent; 33 34 public class ActionComponent extends BaseUIComponent { 35 36 private static final long serialVersionUID = 1217363866006312765L; 37 38 private static final Log logger = LogFactory.getLog(ActionComponent.class); 39 40 private String solutionName; 41 42 private String actionPath; 43 44 private String actionName; 45 46 private String instanceId; 47 48 private int outputPreference; 49 50 public ActionComponent(String solutionName, String actionPath, String actionName, String instanceId, int outputPreference, IPentahoUrlFactory urlFactory, List messages) { 51 super(urlFactory, messages, solutionName + File.separator + actionPath); 52 this.solutionName = solutionName; 53 this.actionName = actionName; 54 this.actionPath = actionPath; 55 this.instanceId = instanceId; 56 this.outputPreference = outputPreference; 57 } 58 59 public ActionComponent(String actionString, String instanceId, int outputPreference, IPentahoUrlFactory urlFactory, List messages) { 60 super(urlFactory, messages, null); 61 String info[] = PentahoSystem.parseActionString(actionString); 62 if (info != null && info.length == 3) { 63 solutionName = info[0]; 64 actionPath = info[1]; 65 actionName = info[2]; 66 } 67 setSourcePath(solutionName + File.separator + actionPath); 68 this.instanceId = instanceId; 69 this.outputPreference = outputPreference; 70 } 71 72 public Log getLogger() { 73 return logger; 74 } 75 76 public boolean validate() { 77 return true; 78 } 79 80 public String getContent(String mimeType) { 81 IPentahoSession userSession = getSession(); 82 83 ByteArrayOutputStream outputStream = new ByteArrayOutputStream (); 84 85 SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); 86 outputHandler.setOutputPreference(outputPreference); 87 88 ISolutionEngine solutionEngine = PentahoSystem.getSolutionEngineInstance(getSession()); 89 solutionEngine.setLoggingLevel(getLoggingLevel()); 90 solutionEngine.init(userSession); 91 92 IRuntimeContext context = null; 93 try { 94 context = solutionEngine.execute(solutionName, actionPath, actionName, Messages.getString("BaseTest.DEBUG_JUNIT_TEST"), false, true, instanceId, false, getParameterProviders(), outputHandler, null, urlFactory, getMessages()); } finally { 96 if (context != null) { 97 context.dispose(); 98 } 99 } 100 101 String result = ""; try { 104 result = outputStream.toString(LocaleHelper.getSystemEncoding()); 105 } catch (Exception e) { 106 return outputStream.toString(); 107 } 108 return result; 109 110 } 111 112 } 113 | Popular Tags |