Search in sources :

Example 6 with SimpleContentItem

use of org.pentaho.platform.engine.core.output.SimpleContentItem 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)

Example 7 with SimpleContentItem

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

the class SimpleOutputHandlerTest method testGetOutputContentItemObjectNameImportant.

public void testGetOutputContentItemObjectNameImportant() throws Exception {
    OutputStream out = new ByteArrayOutputStream();
    TestOutputHandler.contentItem = new SimpleContentItem(out);
    SimpleOutputHandler handler = new SimpleOutputHandler(out, false);
    StandaloneObjectFactory factory = new StandaloneObjectFactory();
    factory.defineObject("contentrepo", TestOutputHandler.class.getName(), StandaloneObjectFactory.Scope.GLOBAL);
    PentahoSystem.registerObjectFactory(factory);
    IContentItem contentItem = handler.getOutputContentItem("contentrepo", "myreport:contentrepo", null, null);
    assertNotNull(contentItem);
    assertEquals(out, contentItem.getOutputStream(null));
    contentItem = handler.getOutputContentItem("", "myreport:contentrepo", null, null);
    assertNull(contentItem);
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 8 with SimpleContentItem

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

the class ApacheVFSOutputHandler method getFileOutputContentItem.

@Override
public IContentItem getFileOutputContentItem() {
    String contentRef = getContentRef();
    try {
        // $NON-NLS-1$
        String contentName = getHandlerId().substring(4) + ":" + contentRef;
        FileSystemManager fsManager = getFileSystemManager();
        if (fsManager == null) {
            logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0001_CANNOT_GET_VFSMGR"));
            return null;
        }
        FileObject file = fsManager.resolveFile(contentName);
        if (file == null) {
            logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0002_CANNOT_GET_VF", contentName));
            return null;
        }
        if (!file.isWriteable()) {
            logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0003_CANNOT_WRITE", contentName));
            return null;
        }
        FileContent fileContent = file.getContent();
        if (fileContent == null) {
            logError(Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0004_CANNOT_GET_CTX", contentName));
            return null;
        }
        OutputStream outputStream = fileContent.getOutputStream();
        SimpleContentItem content = new SimpleContentItem(outputStream);
        return content;
    } catch (Throwable t) {
        Logger.error(ApacheVFSOutputHandler.class.getName(), Messages.getInstance().getString("ApacheVFSOutputHandler.ERROR_0005_CANNOT_GET_HANDLER", contentRef), // $NON-NLS-1$
        t);
    }
    return null;
}
Also used : FileContent(org.apache.commons.vfs2.FileContent) SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) OutputStream(java.io.OutputStream) FileObject(org.apache.commons.vfs2.FileObject) FileSystemManager(org.apache.commons.vfs2.FileSystemManager)

Example 9 with SimpleContentItem

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

the class OutputTest method testSimpleContentItem.

public void testSimpleContentItem() throws Exception {
    OutputStream out = new ByteArrayOutputStream();
    SimpleContentItem content = new SimpleContentItem();
    content.setMimeType("test/test");
    content.setOutputStream(out);
    content.setName("testname");
    // assertEquals("wrong value", null, content.getPath() );
    // SimpleContentItem changed to not return null for path.
    assertNotNull(content.getPath());
    assertEquals("wrong value", "test/test", content.getMimeType());
    assertEquals("wrong value", null, content.getInputStream());
    assertEquals("wrong value", out, content.getOutputStream(null));
    // these should not throw errors
    content.closeOutputStream();
    out = new MockExceptionOutputStream();
    content.setOutputStream(out);
    content.closeOutputStream();
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MultiOutputStream(org.pentaho.platform.engine.core.output.MultiOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream)

Example 10 with SimpleContentItem

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

the class SimpleOutputHandlerTest method test2.

public void test2() throws Exception {
    StandaloneSession session = new StandaloneSession();
    OutputStream out = new MockExceptionOutputStream();
    IContentItem content = new SimpleContentItem(out);
    SimpleOutputHandler handler = new SimpleOutputHandler(content, true);
    assertTrue(handler.allowFeedback());
    assertFalse(handler.contentDone());
    assertNotNull(handler.getFeedbackContentItem());
    assertTrue(handler.contentDone());
    IContentItem content2 = handler.getFeedbackContentItem();
    assertEquals(content.getOutputStream(null), content2.getOutputStream(null));
    IContentItem content3 = new BufferedContentItem(null);
    content3.getOutputStream(null).write("test data".getBytes());
    content3.closeOutputStream();
    try {
        handler.setOutput(IOutputHandler.CONTENT, content3);
        fail("Exception not detected.");
    } catch (Exception ex) {
    // Test passed.
    }
}
Also used : SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) BufferedContentItem(org.pentaho.platform.engine.core.output.BufferedContentItem)

Aggregations

SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)12 OutputStream (java.io.OutputStream)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 IContentItem (org.pentaho.platform.api.repository.IContentItem)5 MultiOutputStream (org.pentaho.platform.engine.core.output.MultiOutputStream)3 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)3 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 BufferedContentItem (org.pentaho.platform.engine.core.output.BufferedContentItem)2 MultiContentItem (org.pentaho.platform.engine.core.output.MultiContentItem)2 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)2 FileOutputStream (java.io.FileOutputStream)1 Method (java.lang.reflect.Method)1 BigDecimal (java.math.BigDecimal)1 URI (java.net.URI)1 URISyntaxException (java.net.URISyntaxException)1 Set (java.util.Set)1