Search in sources :

Example 46 with IContentItem

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);
}
Also used : IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 47 with IContentItem

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;
            }
        }
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) IOException(java.io.IOException)

Example 48 with IContentItem

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());
}
Also used : IUITemplater(org.pentaho.platform.api.engine.IUITemplater) IMessageFormatter(org.pentaho.platform.api.engine.IMessageFormatter) OutputStream(java.io.OutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 49 with IContentItem

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);
}
Also used : IContentItem(org.pentaho.platform.api.repository.IContentItem)

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