use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.
the class ComponentImplementationExample method setFeedbackMimeType.
protected void setFeedbackMimeType(final String mimeType) {
IContentItem feedbackContentItem = runtimeContext.getFeedbackContentItem();
feedbackContentItem.setMimeType(mimeType);
}
use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.
the class SimpleOutputHandler method setOutput.
/*
* (non-Javadoc)
*
* @see org.pentaho.platform.api.engine.IOutputHandler#setOutput(java.lang.String, java.lang.Object)
*
* This implementation tries to write the data in "value" to the response outputstream managed by this output
* handler, or if "value" is null, adds it to a responseAttributes map for later retrieval.
*/
public void setOutput(final String name, final Object value) throws IOException {
if (value == null) {
// $NON-NLS-1$
SimpleOutputHandler.logger.info(Messages.getInstance().getString("SimpleOutputHandler.INFO_VALUE_IS_NULL"));
return;
}
if (IOutputHandler.CONTENT.equalsIgnoreCase(name)) {
// $NON-NLS-1$
IContentItem response = getOutputContentItem("response", IOutputHandler.CONTENT, null, null);
if (response != null) {
// of the response IContentItem managed by this output handler.
if (value instanceof IContentItem) {
IContentItem content = (IContentItem) value;
// See if we should process the input stream. If it's from
// the content repository, then there's an input stream.
// SimpleContentItem and HttpContentItem both return null from
// getInputStream().
InputStream inStr = content.getInputStream();
if (inStr != null) {
if ((response.getMimeType() == null) || (!response.getMimeType().equalsIgnoreCase(content.getMimeType()))) {
response.setMimeType(content.getMimeType());
}
try {
OutputStream outStr = response.getOutputStream(null);
int inCnt = 0;
byte[] buf = new byte[4096];
while (-1 != (inCnt = inStr.read(buf))) {
outStr.write(buf, 0, inCnt);
}
} finally {
try {
inStr.close();
} catch (Exception ignored) {
// ignore
}
}
contentGenerated = true;
}
} else {
// if "value" is not an IContentItem, assume it is a string and write it out
if (response.getMimeType() == null) {
// $NON-NLS-1$
response.setMimeType("text/html");
}
response.getOutputStream(null).write(value.toString().getBytes());
contentGenerated = true;
}
}
}
}
use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.
the class BaseXmlContentGenerator method createContent.
@Override
public void createContent() throws Exception {
requestParameters = this.parameterProviders.get(IParameterProvider.SCOPE_REQUEST);
sessionParameters = this.parameterProviders.get(IParameterProvider.SCOPE_SESSION);
String content = getContent();
if (content == null) {
StringBuffer buffer = new StringBuffer();
PentahoSystem.get(IMessageFormatter.class, userSession).formatErrorMessage("text/html", Messages.getInstance().getErrorString("UI.ERROR_0001_CONTENT_ERROR"), messages, // $NON-NLS-1$ //$NON-NLS-2$
buffer);
content = buffer.toString();
}
// $NON-NLS-1$
String intro = "";
// $NON-NLS-1$
String footer = "";
IUITemplater templater = PentahoSystem.get(IUITemplater.class, userSession);
if (templater != null) {
// $NON-NLS-1$ //$NON-NLS-2$
String[] sections = templater.breakTemplate("template.html", "", userSession);
if (sections != null && sections.length > 0) {
intro = sections[0];
}
if (sections != null && sections.length > 1) {
footer = sections[1];
}
} else {
// $NON-NLS-1$
intro = Messages.getInstance().getString("UI.ERROR_0002_BAD_TEMPLATE_OBJECT");
}
IContentItem contentItem = // $NON-NLS-1$
outputHandler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, "text/html");
OutputStream outputStream = contentItem.getOutputStream(null);
outputStream.write(intro.getBytes());
outputStream.write(content.getBytes());
outputStream.write(footer.getBytes());
}
use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.
the class AxisServiceExecutor method setContentType.
public void setContentType(String contentType) {
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IContentItem contentItem = outputHandler.getOutputContentItem("response", "content", instanceId, getMimeType());
contentItem.setMimeType(contentType);
}
Aggregations