Search in sources :

Example 1 with MultiContentItem

use of org.pentaho.platform.engine.core.output.MultiContentItem in project pentaho-platform by pentaho.

the class RuntimeContext method getOutputContentItem.

public IContentItem getOutputContentItem(final String outputName, final String mimeType) {
    IContentItem contentItem = null;
    IActionParameter parameter = (IActionParameter) actionSequence.getOutputDefinitions().get(outputName);
    if (parameter == null) {
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
        actionSequence.getSequenceName()));
    } else {
        List destinationsList = parameter.getVariables();
        Iterator destinationsIterator = destinationsList.iterator();
        if (destinationsList.size() > 1) {
            contentItem = new MultiContentItem();
        }
        while (destinationsIterator.hasNext()) {
            ActionParameterSource destination = (ActionParameterSource) destinationsIterator.next();
            String objectName = destination.getSourceName();
            String contentName = destination.getValue();
            contentName = TemplateUtil.applyTemplate(contentName, this);
            outputHandler.setSession(session);
            IContentItem tmpContentItem = outputHandler.getOutputContentItem(objectName, contentName, instanceId, mimeType);
            addOutputContentItem(tmpContentItem);
            if (contentItem instanceof MultiContentItem) {
                ((MultiContentItem) contentItem).addContentItem(tmpContentItem);
            } else {
                contentItem = tmpContentItem;
                break;
            }
        }
    }
    return contentItem;
}
Also used : ActionParameterSource(org.pentaho.platform.engine.services.actionsequence.ActionParameterSource) MultiContentItem(org.pentaho.platform.engine.core.output.MultiContentItem) IContentItem(org.pentaho.platform.api.repository.IContentItem) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 2 with MultiContentItem

use of org.pentaho.platform.engine.core.output.MultiContentItem in project pentaho-platform by pentaho.

the class OutputTest method testMultiContentItem.

public void testMultiContentItem() {
    ByteArrayOutputStream out1 = new ByteArrayOutputStream();
    ByteArrayOutputStream out2 = new ByteArrayOutputStream();
    SimpleContentItem item1 = new SimpleContentItem(out1);
    SimpleContentItem item2 = new SimpleContentItem(out2);
    MultiContentItem multiContent = new MultiContentItem();
    multiContent.addContentItem(item1);
    multiContent.addContentItem(item2);
    byte[] in = "abcd".getBytes();
    String outStr1 = "";
    String outStr2 = "";
    try {
        OutputStream multi = multiContent.getOutputStream("");
        multi.write('a');
        multi.write(in, 1, 2);
        multi.write(in);
        multiContent.closeOutputStream();
    } catch (IOException e) {
        // we should not get here
        assertEquals("IOException", null, e);
    }
    outStr1 = new String(out1.toByteArray());
    outStr2 = new String(out2.toByteArray());
    assertEquals("Output stream 1", "abcabcd", outStr1);
    assertEquals("Output stream 2", "abcabcd", outStr2);
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) MultiContentItem(org.pentaho.platform.engine.core.output.MultiContentItem) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 3 with MultiContentItem

use of org.pentaho.platform.engine.core.output.MultiContentItem in project pentaho-platform by pentaho.

the class OutputTest method testMultiContentItemErrors.

public void testMultiContentItemErrors() {
    ByteArrayOutputStream out1 = new ByteArrayOutputStream();
    OutputStream out2 = new MockExceptionOutputStream();
    SimpleContentItem item1 = new SimpleContentItem(out1);
    SimpleContentItem item2 = new SimpleContentItem(out2);
    MultiContentItem multiContent = new MultiContentItem();
    multiContent.addContentItem(item1);
    multiContent.addContentItem(item2);
    byte[] in = "abcd".getBytes();
    String outStr1 = "";
    String outStr2 = "";
    try {
        OutputStream multi = multiContent.getOutputStream("");
        multi.write('a');
        // we should not get here
        assertFalse("IOException expected", true);
    } catch (IOException e) {
        assertNotNull("IOException expected", e);
    }
    try {
        multiContent.closeOutputStream();
    } catch (Exception e) {
        // we should not get here
        assertEquals("IOException", null, e);
    }
    outStr1 = new String(out1.toByteArray());
    assertEquals("Output stream 1", "a", outStr1);
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) MultiContentItem(org.pentaho.platform.engine.core.output.MultiContentItem) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) IOException(java.io.IOException)

Aggregations

MultiContentItem (org.pentaho.platform.engine.core.output.MultiContentItem)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 IOException (java.io.IOException)2 OutputStream (java.io.OutputStream)2 MultiOutputStream (org.pentaho.platform.engine.core.output.MultiOutputStream)2 SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)2 ArrayList (java.util.ArrayList)1 Iterator (java.util.Iterator)1 List (java.util.List)1 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1 ActionParameterSource (org.pentaho.platform.engine.services.actionsequence.ActionParameterSource)1