use of org.pentaho.platform.engine.services.runtime.ParameterManager.ReturnParameter in project pentaho-platform by pentaho.
the class MessageFormatter method formatSuccessMessage.
@SuppressWarnings({ "deprecation", "null" })
public void formatSuccessMessage(final String mimeType, final IRuntimeContext context, final StringBuffer messageBuffer, final boolean doMessages, final boolean doWrapper) {
if (context == null) {
// something went badly wrong
formatFailureMessage(mimeType, context, messageBuffer);
} else if (mimeType.equalsIgnoreCase(MessageFormatter.HTML_MIME_TYPE)) {
// TODO make this template or XSL based
if (doWrapper) {
messageBuffer.append(// $NON-NLS-1$
"<html><head><title>").append(// $NON-NLS-1$
Messages.getInstance().getString("MessageFormatter.USER_START_ACTION")).append(// $NON-NLS-1$
"</title><link rel=\"stylesheet\" type=\"text/css\" href=\"/pentaho-style/active/default.css\"></head>").append("<body dir=\"").append(LocaleHelper.getTextDirection()).append(// $NON-NLS-1$ //$NON-NLS-2$
"\"><table cellspacing=\"10\"><tr><td class=\"portlet-section\" colspan=\"3\">").append(// $NON-NLS-1$
Messages.getInstance().getString("MessageFormatter.USER_ACTION_SUCCESSFUL")).append(// $NON-NLS-1$
"<hr size=\"1\"/></td></tr><tr><td class=\"portlet-font\" valign=\"top\">");
}
// hmm do we need this to be ordered?
Set outputNames = context.getOutputNames();
Iterator outputNameIterator = outputNames.iterator();
while (outputNameIterator.hasNext()) {
String outputName = (String) outputNameIterator.next();
Object value = context.getOutputParameter(outputName).getValue();
if (value == null) {
// $NON-NLS-1$
value = "";
} else if (value instanceof IPentahoResultSet) {
formatResultSetAsHTMLRows((IPentahoResultSet) value, messageBuffer);
} else {
// Temporary fix for BISERVER-3348
ReturnParameter rpm = (ReturnParameter) context.getParameterManager().getReturnParameters().get(outputName);
// CHECKSTYLE IGNORE EmptyBlock FOR NEXT 3 LINES
if (// $NON-NLS-1$
(rpm != null) && ("response".equalsIgnoreCase(rpm.destinationName)) && ("header".equalsIgnoreCase(rpm.destinationParameter))) {
// $NON-NLS-1$
// we don't want to output response header parameters to the browser...
} else {
if (doWrapper) {
// $NON-NLS-1$
messageBuffer.append(outputName).append("=");
}
messageBuffer.append(value.toString());
if (doWrapper) {
// $NON-NLS-1$
messageBuffer.append("<br/>");
}
}
}
}
if (doMessages) {
if (doWrapper) {
// $NON-NLS-1$
messageBuffer.append("<p><br size=\"1\">");
}
List messages = context.getMessages();
Iterator messageIterator = messages.iterator();
while (messageIterator.hasNext()) {
messageBuffer.append((String) messageIterator.next());
if (doWrapper) {
// $NON-NLS-1$
messageBuffer.append("<br/>");
}
}
}
if (doWrapper) {
// $NON-NLS-1$
messageBuffer.append("</td></tr></table></body></html>");
}
} else if (mimeType.equalsIgnoreCase(MessageFormatter.TEXT_MIME_TYPE)) {
// $NON-NLS-1$ //$NON-NLS-2$
messageBuffer.append(Messages.getInstance().getString("MessageFormatter.USER_START_ACTION" + "\n")).append(// $NON-NLS-1$ //$NON-NLS-2$
Messages.getInstance().getString("MessageFormatter.USER_ACTION_SUCCESSFUL" + "\n"));
// hmm do we need this to be ordered?
Set outputNames = context.getOutputNames();
Iterator outputNameIterator = outputNames.iterator();
while (outputNameIterator.hasNext()) {
String outputName = (String) outputNameIterator.next();
Object value = context.getOutputParameter(outputName).getValue();
if (value == null) {
// $NON-NLS-1$
value = "";
} else if (value instanceof IPentahoResultSet) {
IPentahoResultSet resultSet = (IPentahoResultSet) value;
Object[][] columnHeaders = resultSet.getMetaData().getColumnHeaders();
Object[][] rowHeaders = resultSet.getMetaData().getRowHeaders();
boolean hasColumnHeaders = columnHeaders != null;
boolean hasRowHeaders = rowHeaders != null;
if (hasColumnHeaders) {
for (Object[] element : columnHeaders) {
for (int column = 0; column < element.length; column++) {
if (hasRowHeaders) {
for (int indent = 0; indent < rowHeaders[0].length; indent++) {
// $NON-NLS-1$
messageBuffer.append("\t");
}
}
// $NON-NLS-1$
messageBuffer.append(element[column]).append("\t");
}
// $NON-NLS-1$
messageBuffer.append("\n");
}
}
int headerRow = 0;
Object[] dataRow = resultSet.next();
int currentRow = 0;
while ((dataRow != null) && (currentRow < MessageFormatter.MAX_RESULT_THRESHOLD)) {
if (hasRowHeaders) {
for (int rowHeaderCol = 0; rowHeaderCol < rowHeaders[headerRow].length; rowHeaderCol++) {
// $NON-NLS-1$
messageBuffer.append(rowHeaders[headerRow][rowHeaderCol].toString()).append("\t");
}
}
for (Object element : dataRow) {
// $NON-NLS-1$
messageBuffer.append(element.toString()).append("\t");
}
dataRow = resultSet.next();
currentRow++;
}
} else {
// Temporary fix for BISERVER-3348
ReturnParameter rpm = (ReturnParameter) context.getParameterManager().getReturnParameters().get(outputName);
// CHECKSTYLE IGNORE EmptyBlock FOR NEXT 3 LINES
if (// $NON-NLS-1$
(rpm != null) && ("response".equalsIgnoreCase(rpm.destinationName)) && ("header".equalsIgnoreCase(rpm.destinationParameter))) {
// $NON-NLS-1$
// we don't want to output response header parameters to the browser...
} else {
// $NON-NLS-1$ //$NON-NLS-2$
messageBuffer.append(outputName).append("=").append(value.toString()).append("\n");
}
}
}
if (doMessages) {
List messages = context.getMessages();
Iterator messageIterator = messages.iterator();
while (messageIterator.hasNext()) {
// $NON-NLS-1$
messageBuffer.append((String) messageIterator.next()).append("\n");
}
}
}
}
Aggregations