Search in sources :

Example 1 with IUITemplater

use of org.pentaho.platform.api.engine.IUITemplater in project pentaho-platform by pentaho.

the class ViewAction method doBackgroundExecution.

protected boolean doBackgroundExecution(final HttpServletRequest request, final HttpServletResponse response, final IPentahoSession userSession) throws ServletException, IOException {
    if ("true".equals(request.getParameter("background"))) {
        // $NON-NLS-1$ //$NON-NLS-2$
        IBackgroundExecution backgroundExecutionHandler = PentahoSystem.get(IBackgroundExecution.class, userSession);
        if (backgroundExecutionHandler != null) {
            HttpRequestParameterProvider parameterProvider = new HttpRequestParameterProvider(request);
            // $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-dialog.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("ViewAction.ERROR_0002_BAD_TEMPLATE_OBJECT");
            }
            response.getWriter().print(intro);
            String backgroundResponse = null;
            try {
                backgroundResponse = backgroundExecutionHandler.backgroundExecuteAction(userSession, parameterProvider);
            } catch (BackgroundExecutionException bex) {
                backgroundResponse = bex.getLocalizedMessage();
                response.getWriter().print(backgroundResponse);
                response.getWriter().print(footer);
                error(Messages.getInstance().getErrorString("ViewAction.ERROR_0004_UNABLE_TO_PERFORM_BACKGROUND_EXECUTION"), // $NON-NLS-1$
                bex);
                return false;
            }
            response.setHeader("background_execution", "true");
            response.getWriter().print(backgroundResponse);
            response.getWriter().print(footer);
            return true;
        } else {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("ViewAction.ERROR_0001_BACKGROUND_EXECUTE_NOT_SUPPORTED"));
        }
    }
    return false;
}
Also used : BackgroundExecutionException(org.pentaho.platform.api.scheduler.BackgroundExecutionException) IUITemplater(org.pentaho.platform.api.engine.IUITemplater) HttpRequestParameterProvider(org.pentaho.platform.web.http.request.HttpRequestParameterProvider) IBackgroundExecution(org.pentaho.platform.api.engine.IBackgroundExecution)

Example 2 with IUITemplater

use of org.pentaho.platform.api.engine.IUITemplater 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)

Aggregations

IUITemplater (org.pentaho.platform.api.engine.IUITemplater)2 OutputStream (java.io.OutputStream)1 IBackgroundExecution (org.pentaho.platform.api.engine.IBackgroundExecution)1 IMessageFormatter (org.pentaho.platform.api.engine.IMessageFormatter)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1 BackgroundExecutionException (org.pentaho.platform.api.scheduler.BackgroundExecutionException)1 HttpRequestParameterProvider (org.pentaho.platform.web.http.request.HttpRequestParameterProvider)1