use of org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputHandler in project pentaho-platform by pentaho.
the class ActionSequenceAction method execute.
public void execute() throws Exception {
IOutputHandler outputHandler = null;
if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
outputHandler = new RepositoryFileOutputHandler(((RepositoryFileOutputStream) xactionResultsOutputStream));
} else {
outputHandler = new SimpleOutputHandler(xactionResultsOutputStream, false);
}
IRuntimeContext rt = null;
try {
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, null);
solutionEngine.setCreateFeedbackParameterCallback(null);
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.setForcePrompt(false);
ArrayList messages = new ArrayList();
HashMap<String, Object> parameterProviders = new HashMap<String, Object>();
parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider(xActionInputParams));
parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(PentahoSessionHolder.getSession()));
String xactionPath = null;
if (xactionDefInputStream instanceof RepositoryFileInputStream) {
xactionPath = ((RepositoryFileInputStream) xactionDefInputStream).getFile().getPath();
}
rt = solutionEngine.execute(xactionPath, this.getClass().getName(), false, true, null, true, parameterProviders, outputHandler, null, null, messages);
if (!outputHandler.contentDone()) {
if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
// set content which generated by sequence for pass it to caller
List<IContentItem> components = new ArrayList<IContentItem>(rt.getOutputContentItems());
setActionOutputContents(components);
boolean isFlushed = false;
boolean isEmpty;
if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
RepositoryFileOutputStream repositoryFileOutputStream = (RepositoryFileOutputStream) xactionResultsOutputStream;
isFlushed = repositoryFileOutputStream.isFlushed();
isEmpty = repositoryFileOutputStream.size() > 0 ? false : true;
String extension = RepositoryFilenameUtils.getExtension(repositoryFileOutputStream.getFilePath());
String mimeTypeFromExtension = MimeHelper.getMimeTypeFromExtension("." + extension);
if (mimeTypeFromExtension == null) {
// unknown type, treat it not as an extension but part of the name
extension = "";
}
if (extension.isEmpty() && xactionResultsOutputStream.toString().isEmpty()) {
repositoryFileOutputStream.setFilePath(repositoryFileOutputStream.getFilePath() + ".html");
}
} else {
isEmpty = xactionResultsOutputStream.toString().isEmpty();
}
if (!isFlushed) {
if (isEmpty) {
StringBuffer buffer = new StringBuffer();
// $NON-NLS-1$
MessageFormatUtils.formatSuccessMessage("text/html", rt, buffer, false);
xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
}
xactionResultsOutputStream.close();
}
} else {
// we need an error message...
StringBuffer buffer = new StringBuffer();
// $NON-NLS-1$
MessageFormatUtils.formatFailureMessage("text/html", rt, buffer, messages);
xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
xactionResultsOutputStream.close();
}
}
} finally {
if (rt != null) {
rt.dispose();
}
}
}
Aggregations