1 16 17 package org.pentaho.plugin.core; 18 19 import java.io.ByteArrayOutputStream ; 20 import java.io.File ; 21 import java.util.HashMap ; 22 import java.util.Iterator ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.pentaho.core.runtime.IActionParameter; 27 import org.pentaho.core.runtime.IRuntimeContext; 28 import org.pentaho.core.session.IPentahoSession; 29 import org.pentaho.core.session.UserSession; 30 import org.pentaho.core.solution.ISolutionEngine; 31 import org.pentaho.core.solution.SolutionHelper; 32 import org.pentaho.messages.util.LocaleHelper; 33 import org.pentaho.plugin.ComponentBase; 34 35 public class SubActionComponent extends ComponentBase { 36 37 private static final long serialVersionUID = 3557732430102823611L; 38 39 private static final String SESSION_PROXY = "session-proxy"; 41 public Log getLogger() { 42 return LogFactory.getLog(SubActionComponent.class); 43 } 44 45 protected boolean validateAction() { 46 47 return isDefinedInput(StandardSettings.SOLUTION) && isDefinedInput(StandardSettings.PATH) && isDefinedInput(StandardSettings.ACTION); 48 49 } 50 51 protected boolean validateSystemSettings() { 52 return true; 53 } 54 55 public void done() { 56 } 57 58 protected boolean executeAction() throws Throwable { 59 60 String solution = getInputStringValue(StandardSettings.SOLUTION); 61 String path = getInputStringValue(StandardSettings.PATH); 62 String action = getInputStringValue(StandardSettings.ACTION); 63 String actionPath; 64 if (path == null || path.equals("")) { actionPath = solution + File.separator + action; 66 } else { 67 actionPath = solution + File.separator + path + File.separator + action; 68 } 69 70 IPentahoSession session = getSession(); 72 if (isDefinedInput(SESSION_PROXY)) { 73 String sessionProxy = getInputStringValue(SESSION_PROXY); 74 if (isDefinedInput(sessionProxy)) { 75 String sessionName = getInputStringValue(sessionProxy); 76 session = new UserSession(sessionName, LocaleHelper.getLocale()); 78 } 79 } 80 81 HashMap parameters = new HashMap (); 83 Iterator iterator = getInputNames().iterator(); 84 while (iterator.hasNext()) { 85 String inputName = (String ) iterator.next(); 86 if (!StandardSettings.SOLUTION.equals(inputName) && !StandardSettings.PATH.equals(inputName) && !StandardSettings.ACTION.equals(inputName)) { 87 Object value = getInputValue(inputName); 88 parameters.put(inputName, value); 89 } 90 } 91 92 ByteArrayOutputStream outputStream = new ByteArrayOutputStream (); 96 ISolutionEngine solutionEngine = SolutionHelper.execute(getProcessId(), session, actionPath, parameters, outputStream); 97 if ( outputStream.size() > 0 ) { 98 getDefaultOutputStream().write( outputStream.toByteArray() ); 99 } 100 101 int status = solutionEngine.getStatus(); 102 if (status == IRuntimeContext.RUNTIME_STATUS_SUCCESS) { 103 Iterator it = this.getOutputNames().iterator(); 105 while (it.hasNext()) { 106 String outputName = (String ) it.next(); 107 IActionParameter param = solutionEngine.getExecutionContext().getOutputParameter(outputName); 108 if ( param != null ) { 109 setOutputValue( outputName, param.getValue() ); 110 } 111 } 112 return true; 113 } else { 114 return false; 115 } 116 } 117 118 public boolean init() { 119 return true; 120 } 121 122 } 123 | Popular Tags |