use of org.pentaho.platform.api.engine.IContentOutputHandler in project pentaho-platform by pentaho.
the class RepositoryFileOutputHandler method getOutputContentItem.
public IContentItem getOutputContentItem(final String outputName, final String contentName, final String instanceId, final String localMimeType) {
IContentItem outputContentItem = null;
if (outputName.equals(IOutputHandler.RESPONSE) && contentName.equals(IOutputHandler.CONTENT)) {
String requestedFileExtension = MimeHelper.getExtension(localMimeType);
String currentExtension = FilenameUtils.getExtension(outputStream.getFilePath());
if (requestedFileExtension == null) {
if (currentExtension != null) {
String tempFilePath = FilenameUtils.getFullPathNoEndSeparator(outputStream.getFilePath()) + "/" + FilenameUtils.getBaseName(outputStream.getFilePath());
outputStream.setFilePath(tempFilePath);
outputContentItem = new RepositoryFileContentItem(outputStream);
} else {
outputContentItem = new RepositoryFileContentItem(outputStream);
}
} else if (!requestedFileExtension.substring(1).equals(currentExtension.toLowerCase())) {
String tempFilePath = FilenameUtils.getFullPathNoEndSeparator(outputStream.getFilePath()) + "/" + FilenameUtils.getBaseName(outputStream.getFilePath()) + requestedFileExtension;
outputStream.setFilePath(tempFilePath);
outputContentItem = new RepositoryFileContentItem(outputStream);
} else {
outputContentItem = new RepositoryFileContentItem(outputStream);
}
responseExpected = true;
} else {
IContentOutputHandler output = PentahoSystem.getOutputDestinationFromContentRef(contentName, session);
// (This mirrors HttpOutputHandler's lookup logic)
if (output == null) {
// $NON-NLS-1$
output = PentahoSystem.getOutputDestinationFromContentRef(outputName + ":" + contentName, session);
}
if (output != null) {
output.setSession(PentahoSessionHolder.getSession());
output.setInstanceId(instanceId);
// $NON-NLS-1$
String filePath = "~/workspace/" + contentName;
if (contentName.startsWith("/")) {
filePath = contentName;
}
output.setSolutionPath(filePath);
output.setMimeType(localMimeType);
outputContentItem = output.getFileOutputContentItem();
}
}
return outputContentItem;
}
use of org.pentaho.platform.api.engine.IContentOutputHandler in project pentaho-platform by pentaho.
the class RuntimeContext method getOutputItem.
public IContentItem getOutputItem(final String outputName, final String mimeType, final String extension) {
// TODO support content output versions in the action definition
IActionParameter outputParameter = getOutputParameter(outputName);
if (outputParameter == null) {
warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
actionSequence.getSequenceName()));
return null;
}
// $NON-NLS-1$
String filePath = "~/workspace/" + FilenameUtils.getBaseName(getSolutionPath()) + extension;
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
String contentName = "contentrepo:" + filePath;
if (!IActionParameter.TYPE_CONTENT.equals(outputParameter.getType())) {
// $NON-NLS-1$
warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0023_INVALID_OUTPUT_STREAM", outputName));
return null;
}
try {
IContentOutputHandler output = PentahoSystem.getOutputDestinationFromContentRef(contentName, session);
if (output != null) {
// TODO get this info
output.setInstanceId(instanceId);
output.setSolutionPath(filePath);
output.setMimeType(mimeType);
output.setSession(session);
IContentItem contentItem = output.getFileOutputContentItem();
setOutputValue(outputName, contentItem);
return contentItem;
}
} catch (Exception e) {
// ignored
}
return null;
}
use of org.pentaho.platform.api.engine.IContentOutputHandler in project pentaho-platform by pentaho.
the class PentahoSystem method getOutputDestinationFromContentRef.
// TODO: is this method needed? See if we can use the factory directly and delete this method.
public static IContentOutputHandler getOutputDestinationFromContentRef(final String contentTag, final IPentahoSession session) {
int pos = contentTag.indexOf(':');
if (pos == -1) {
Logger.error(PentahoSystem.class.getName(), Messages.getInstance().getErrorString("PentahoSystem.ERROR_0029_OUTPUT_HANDLER_NOT_SPECIFIED", // $NON-NLS-1$
contentTag));
return null;
}
String handlerId = contentTag.substring(0, pos);
String contentRef = contentTag.substring(pos + 1);
IContentOutputHandler output = PentahoSystem.get(IContentOutputHandler.class, handlerId, session);
if (output != null) {
output.setHandlerId(handlerId);
output.setSession(session);
output.setContentRef(contentRef);
}
return output;
}
use of org.pentaho.platform.api.engine.IContentOutputHandler in project pentaho-platform by pentaho.
the class SimpleOutputHandler method getOutputContentItem.
/*
* (non-Javadoc)
*
* @see org.pentaho.platform.api.engine.IOutputHandler#getOutputContentItem(java.lang.String, java.lang.String,
* java.lang.String, java.lang.String, java.lang.String)
*/
public IContentItem getOutputContentItem(final String outputName, final String contentName, final String instanceId, final String localMimeType) {
if (outputName.equals(IOutputHandler.RESPONSE) && contentName.equals(IOutputHandler.CONTENT)) {
responseExpected = true;
}
// $NON-NLS-1$
String key = outputName + "." + contentName;
if (outputs.get(key) != null) {
return outputs.get(key);
} else {
IContentOutputHandler output = PentahoSystem.getOutputDestinationFromContentRef(contentName, session);
// (This mirrors HttpOutputHandler's lookup logic)
if (output == null) {
// $NON-NLS-1$
output = PentahoSystem.getOutputDestinationFromContentRef(outputName + ":" + contentName, session);
}
if (output != null) {
output.setInstanceId(instanceId);
output.setMimeType(localMimeType);
output.setContentRef(contentName);
if (contentName.indexOf(":") != -1) {
output.setSolutionPath(contentName.substring(contentName.indexOf(":") + 1));
} else {
output.setSolutionPath(null);
}
return output.getFileOutputContentItem();
}
}
return null;
}
use of org.pentaho.platform.api.engine.IContentOutputHandler in project pentaho-platform by pentaho.
the class HttpOutputHandler method getOutputContentItem.
/*
* (non-Javadoc)
*
* @see org.pentaho.core.solution.IOutputHandler#getContentStream()
*/
public IContentItem getOutputContentItem(final String objectName, final String contentName, final String instanceId, final String mimeType) {
if (objectName.equals(IOutputHandler.RESPONSE) && contentName.equals(IOutputHandler.CONTENT)) {
// change the content type if necessary
if (mimeType != null) {
outputContent.setMimeType(mimeType);
}
contentGenerated = true;
/*
* if someone is requesting an outputContentItem, they are intending to write to the response output stream.
*/
responseExpected = true;
return outputContent;
} else {
IContentOutputHandler output = null;
// this code allows us to stay backwards compatible
if ((contentName != null) && (contentName.indexOf(":") == -1)) {
// $NON-NLS-1$
// $NON-NLS-1$
output = PentahoSystem.getOutputDestinationFromContentRef(objectName + ":" + contentName, session);
} else {
output = PentahoSystem.getOutputDestinationFromContentRef(contentName, session);
if (output == null) {
// $NON-NLS-1$
output = PentahoSystem.getOutputDestinationFromContentRef(objectName + ":" + contentName, session);
}
}
if (output != null) {
output.setInstanceId(instanceId);
// $NON-NLS-1$
String filePath = "~/workspace/" + contentName;
if (contentName.startsWith("/")) {
filePath = contentName;
}
output.setSolutionPath(filePath);
output.setMimeType(mimeType);
output.setSession(session);
return output.getFileOutputContentItem();
}
}
return null;
}
Aggregations