Search in sources :

Example 21 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class PojoComponent method callMethods.

protected void callMethods(List<Method> methods, Object value) throws Throwable {
    if (value instanceof String) {
        callMethodWithString(methods, value.toString());
        return;
    }
    boolean done = false;
    for (Method method : methods) {
        Class<?>[] paramClasses = method.getParameterTypes();
        if (paramClasses.length != 1) {
            // we don't know how to handle this
            throw new GenericSignatureFormatError();
        }
        Class<?> paramclass = paramClasses[0];
        // do some type safety. this would be the point to do automatic type conversions
        if (value instanceof IPentahoResultSet && paramclass.equals(IPentahoResultSet.class)) {
            done = true;
            method.invoke(pojo, new Object[] { (IPentahoResultSet) value });
            break;
        } else if (value instanceof java.lang.Boolean && (paramclass.equals(Boolean.class) || paramclass.equals(boolean.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Integer && (paramclass.equals(Integer.class) || paramclass.equals(int.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Long && (paramclass.equals(Long.class) || paramclass.equals(long.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Double && (paramclass.equals(Double.class) || paramclass.equals(double.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof java.lang.Float && (paramclass.equals(Float.class) || paramclass.equals(float.class))) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof IPentahoStreamSource && paramclass.equals(IPentahoStreamSource.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof Date && paramclass.equals(Date.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof BigDecimal && paramclass.equals(BigDecimal.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof IContentItem && paramclass.equals(IContentItem.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value });
            break;
        } else if (value instanceof IContentItem && paramclass.equals(String.class)) {
            done = true;
            method.invoke(pojo, new Object[] { value.toString() });
            break;
        } else if (paramclass.equals(IPentahoSession.class)) {
            done = true;
            method.invoke(pojo, new Object[] { (IPentahoSession) value });
            break;
        } else if (paramclass.equals(Log.class)) {
            done = true;
            method.invoke(pojo, new Object[] { (Log) value });
            break;
        }
    }
    if (!done) {
        // Try invoking the first instance with what we have
        try {
            methods.get(0).invoke(pojo, new Object[] { value });
        } catch (Exception ex) {
            throw new IllegalArgumentException(// $NON-NLS-1$ //$NON-NLS-2$
            "No implementation of method \"" + Method.class.getName() + "\" takes a " + value.getClass());
        }
    }
}
Also used : IPentahoStreamSource(org.pentaho.commons.connection.IPentahoStreamSource) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Method(java.lang.reflect.Method) Date(java.util.Date) BigDecimal(java.math.BigDecimal) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) GenericSignatureFormatError(java.lang.reflect.GenericSignatureFormatError) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 22 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class ApacheVFSOutputHandlerTest method getOutputContentWrongFileNameTest.

@Test
public void getOutputContentWrongFileNameTest() {
    setupMockObjectsDefaults("bogus", true, true);
    IContentItem contentItem = apacheVFSOutputHandler.getFileOutputContentItem();
    assertNull(contentItem);
    verify(apacheVFSOutputHandler).logError("Cannot get virtual file: 1:bogus");
}
Also used : IContentItem(org.pentaho.platform.api.repository.IContentItem) Test(org.junit.Test)

Example 23 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class ApacheVFSOutputHandlerTest method getOutputContentFileNoContentTest.

@Test
public void getOutputContentFileNoContentTest() {
    setupMockObjectsDefaults(CONTENT_NAME, true, false);
    IContentItem contentItem = apacheVFSOutputHandler.getFileOutputContentItem();
    assertNull(contentItem);
    verify(apacheVFSOutputHandler).logError("Cannot get virtal file content: 1:filecontent");
}
Also used : IContentItem(org.pentaho.platform.api.repository.IContentItem) Test(org.junit.Test)

Example 24 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class ActionSequenceActionTest method testGetActionOutputContents.

@Test
public void testGetActionOutputContents() throws Exception {
    OutputStream outputStream = mock(OutputStream.class);
    ActionSequenceAction action = new ActionSequenceAction();
    action.setOutputStream(outputStream);
    action.execute();
    List<IContentItem> outputContents = action.getActionOutputContents();
    assertNotNull(outputContents);
    assertEquals(expectedContentItem, outputContents);
}
Also used : OutputStream(java.io.OutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) Test(org.junit.Test)

Example 25 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class ViewAction method handleActionRequest.

@SuppressWarnings("unchecked")
protected void handleActionRequest(final HttpServletRequest request, final HttpServletResponse response, final IOutputHandler outputHandler, final HttpServletRequestHandler requestHandler, OutputStream outputStream, final IContentItem contentItem) throws ServletException, IOException {
    IRuntimeContext runtime = null;
    try {
        runtime = requestHandler.handleActionRequest(0, 0);
        if (runtime == null) {
            StringBuffer buffer = new StringBuffer();
            for (String message : (List<String>) requestHandler.getMessages()) {
                buffer.append(message);
            }
            outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
            return;
        }
        /*
       * the flag "hasResponse" should be set if the outputHandler is expected to serve a response back via either the
       * "response.content" output (a final content output), or an intermediate response such as a form to request
       * parameters such as from a SecureFilterComponent.
       */
        boolean hasResponse = outputHandler.isResponseExpected();
        IContentItem responseContentItem = outputHandler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
        boolean success = (runtime != null && runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS);
        boolean debugMessages = doMessages(request);
        boolean printSuccess = (runtime != null) && success && (!hasResponse || debugMessages);
        boolean printError = (runtime != null) && !success && !response.isCommitted();
        if (printSuccess || printError) {
            // $NON-NLS-1$
            final String htmlMimeType = "text/html";
            responseContentItem.setMimeType(htmlMimeType);
            // this is going to be the response output stream unless you are in debug mode
            outputStream = responseContentItem.getOutputStream(null);
            response.setContentType(htmlMimeType);
            StringBuffer buffer = new StringBuffer();
            if (printSuccess) {
                // $NON-NLS-1$ //$NON-NLS-2$
                boolean doWrapper = !("false".equals(request.getParameter("wrapper")));
                MessageFormatUtils.formatSuccessMessage(htmlMimeType, runtime, buffer, debugMessages, doWrapper);
            } else {
                response.resetBuffer();
                MessageFormatUtils.formatFailureMessage(htmlMimeType, runtime, buffer, requestHandler.getMessages());
            }
            outputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
            responseContentItem.closeOutputStream();
        }
    } finally {
        if (runtime != null) {
            runtime.dispose();
        }
    }
}
Also used : IContentItem(org.pentaho.platform.api.repository.IContentItem) List(java.util.List) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Aggregations

IContentItem (org.pentaho.platform.api.repository.IContentItem)49 OutputStream (java.io.OutputStream)20 Test (org.junit.Test)8 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 Iterator (java.util.Iterator)5 List (java.util.List)5 Element (org.dom4j.Element)5 SimpleContentItem (org.pentaho.platform.engine.core.output.SimpleContentItem)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 Document (org.dom4j.Document)4 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)4 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)4 InvalidParameterException (org.pentaho.platform.api.engine.InvalidParameterException)4 Set (java.util.Set)3 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)3