Search in sources :

Example 1 with IContentOutputHandler

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;
}
Also used : IContentOutputHandler(org.pentaho.platform.api.engine.IContentOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 2 with IContentOutputHandler

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;
}
Also used : IContentOutputHandler(org.pentaho.platform.api.engine.IContentOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) InvalidParameterException(org.pentaho.platform.api.engine.InvalidParameterException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) ActionSequencePromptException(org.pentaho.platform.api.engine.ActionSequencePromptException) FileNotFoundException(java.io.FileNotFoundException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IOException(java.io.IOException)

Example 3 with IContentOutputHandler

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;
}
Also used : IContentOutputHandler(org.pentaho.platform.api.engine.IContentOutputHandler)

Example 4 with IContentOutputHandler

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;
}
Also used : IContentOutputHandler(org.pentaho.platform.api.engine.IContentOutputHandler)

Example 5 with IContentOutputHandler

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;
}
Also used : IContentOutputHandler(org.pentaho.platform.api.engine.IContentOutputHandler)

Aggregations

IContentOutputHandler (org.pentaho.platform.api.engine.IContentOutputHandler)5 IContentItem (org.pentaho.platform.api.repository.IContentItem)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)1 ActionInitializationException (org.pentaho.platform.api.engine.ActionInitializationException)1 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)1 ActionSequencePromptException (org.pentaho.platform.api.engine.ActionSequencePromptException)1 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)1 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)1 InvalidParameterException (org.pentaho.platform.api.engine.InvalidParameterException)1 PluginBeanException (org.pentaho.platform.api.engine.PluginBeanException)1 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)1 XmlParseException (org.pentaho.platform.api.util.XmlParseException)1