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;
}
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);
}
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);
}
Aggregations