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