Search in sources :

Example 1 with ActionSequencePromptException

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

the class RuntimeContext method sendFeedbackForm.

// Feebdack form handling
public void sendFeedbackForm() throws ActionSequencePromptException {
    try {
        if (!feedbackAllowed()) {
            return;
        }
        // add the standard parameters that we need
        // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        createFeedbackParameter("path", "path", "", getSolutionPath(), false);
        // ProSolutionEngine proSolutionEngine = (ProSolutionEngine) solutionEngine;
        // $NON-NLS-1$
        IParameterProvider parameterProvider = (IParameterProvider) parameterProviders.get("PRO_EDIT_SUBSCRIPTION");
        if (parameterProvider == null) {
            // Then we are not editing subscriptions
            parameterProvider = (IParameterProvider) parameterProviders.get(IParameterProvider.SCOPE_REQUEST);
        } else {
            // $NON-NLS-1$
            parameterProvider.getStringParameter("subscribe-id", null);
        }
        Iterator parameterNameIterator = parameterProvider.getParameterNames();
        while (parameterNameIterator.hasNext()) {
            String name = (String) parameterNameIterator.next();
            if (!"path".equals(name) && (xformFields.get(name) == null)) {
                // TODO we need to check to see if this has been handled as
                // a control before adding a hidden field
                Object value = parameterProvider.getParameter(name);
                if (value != null) {
                    // $NON-NLS-1$
                    createFeedbackParameter(name, name, "", value, false);
                }
            }
        }
        SolutionURIResolver resolver = new SolutionURIResolver();
        if (parameterXsl == null) {
            // Generate XForm for the parameters needed, transform into
            // HTML, and float it down the feedback stream
            // $NON-NLS-1$
            xformBody.append("<tr><td>");
            XForm.createXFormSubmit(RuntimeContext.PARAMETER_FORM, xformBody, Messages.getInstance().getString(// $NON-NLS-1$
            "RuntimeContext.USER_PARAMETER_FORM_SUBMIT"));
            // $NON-NLS-1$
            xformBody.append("</td></tr></table></body>");
            String html = XForm.completeXForm(XForm.OUTPUT_HTML_PAGE, RuntimeContext.PARAMETER_FORM, xformHeader, xformBody, getSession(), resolver);
            if (RuntimeContext.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("RuntimeContext.DEBUG_PARAMETER_HTML", html));
            }
            // $NON-NLS-1$
            outputHandler.getFeedbackContentItem().setMimeType("text/html");
            OutputStream os = outputHandler.getFeedbackContentItem().getOutputStream(getActionName());
            os.write(html.getBytes());
        } else if (parameterTemplate != null) {
            String html = XForm.completeXForm(XForm.OUTPUT_HTML_PAGE, RuntimeContext.PARAMETER_FORM, xformHeader, new StringBuffer(parameterTemplate), getSession(), resolver);
            if (RuntimeContext.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("RuntimeContext.DEBUG_PARAMETER_HTML", html));
            }
            IContentItem contentItem = outputHandler.getFeedbackContentItem();
            // $NON-NLS-1$
            contentItem.setMimeType("text/html");
            OutputStream os = contentItem.getOutputStream(getActionName());
            os.write(html.getBytes(LocaleHelper.getSystemEncoding()));
            os.close();
        } else if (parameterXsl.endsWith(".xsl")) {
            // $NON-NLS-1$
            String id = actionSequence.getSequenceName();
            int pos = id.indexOf('.');
            if (pos > -1) {
                id = id.substring(0, pos);
            }
            // make sure the id can form a valid javascript variable or
            // function name
            id = id.replace('-', '_');
            id = id.replace(' ', '_');
            String actionUrl = urlFactory.getActionUrlBuilder().getUrl();
            String displayUrl = urlFactory.getDisplayUrlBuilder().getUrl();
            // String target = (parameterTarget == null) ? "" : parameterTarget; //$NON-NLS-1$
            XForm.completeXFormHeader(RuntimeContext.PARAMETER_FORM, xformHeader);
            Document document = XmlDom4JHelper.getDocFromString(// $NON-NLS-1$ //$NON-NLS-2$
            "<?xml version=\"1.0\" encoding=\"" + LocaleHelper.getSystemEncoding() + "\" ?><filters xmlns:xf=\"http://www.w3.org/2002/xforms\">" + xformHeader + // $NON-NLS-1$
            "<id><![CDATA[" + id + // $NON-NLS-1$
            "]]></id><title><![CDATA[" + Messages.getInstance().getEncodedString(actionSequence.getTitle()) + // $NON-NLS-1$
            "]]></title><description><![CDATA[" + Messages.getInstance().getEncodedString(actionSequence.getDescription()) + // $NON-NLS-1$
            "]]></description><icon><![CDATA[" + actionSequence.getIcon() + // $NON-NLS-1$
            "]]></icon><help><![CDATA[" + Messages.getInstance().getEncodedString(actionSequence.getHelp()) + // $NON-NLS-1$
            "]]></help>" + "<action><![CDATA[" + actionUrl + // $NON-NLS-1$ //$NON-NLS-2$
            "]]></action>" + "<display><![CDATA[" + displayUrl + // $NON-NLS-1$ //$NON-NLS-2$
            "]]></display>" + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            ((parameterTarget != null) ? "<target>" + parameterTarget + "</target>" : "") + xformBody.toString() + "</filters>", // $NON-NLS-1$
            null);
            // add any subscription information here
            Element root = document.getRootElement();
            // notify the xsl whether we're in parameter view or not.
            root.addAttribute("parameterView", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            (getOutputPreference() == IOutputHandler.OUTPUT_TYPE_PARAMETERS) ? "true" : "false");
            Map<String, String> parameters = new HashMap<String, String>();
            // $NON-NLS-1$
            parameters.put("baseUrl", PentahoSystem.getApplicationContext().getBaseUrl());
            // $NON-NLS-1$
            parameters.put("actionUrl", this.getUrlFactory().getActionUrlBuilder().getUrl());
            // $NON-NLS-1$
            parameters.put("displayUrl", this.getUrlFactory().getDisplayUrlBuilder().getUrl());
            // Uncomment this line for troubleshooting the XSL.
            StringBuffer content = XmlHelper.transformXml(parameterXsl, getSolutionPath(), document.asXML(), parameters, resolver);
            IContentItem contentItem = outputHandler.getFeedbackContentItem();
            // $NON-NLS-1$
            contentItem.setMimeType("text/html");
            OutputStream os = contentItem.getOutputStream(getActionName());
            try {
                os.write(content.toString().getBytes(LocaleHelper.getSystemEncoding()));
            } finally {
                if (os != null) {
                    os.close();
                }
            }
        }
    /*
       * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
       * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
       * prevent valuable feedback in the log or response.
       */
    } catch (Throwable e) {
        throw new ActionSequencePromptException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0030_SEND_FEEDBACKFORM"), // $NON-NLS-1$
        e, session.getName(), instanceId, getActionSequence().getSequenceName(), null);
    }
}
Also used : HashMap(java.util.HashMap) ActionSequencePromptException(org.pentaho.platform.api.engine.ActionSequencePromptException) OutputStream(java.io.OutputStream) IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) Element(org.dom4j.Element) Document(org.dom4j.Document) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) Iterator(java.util.Iterator) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Aggregations

OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 Document (org.dom4j.Document)1 Element (org.dom4j.Element)1 ActionSequencePromptException (org.pentaho.platform.api.engine.ActionSequencePromptException)1 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1 IRuntimeElement (org.pentaho.platform.api.repository.IRuntimeElement)1 SolutionURIResolver (org.pentaho.platform.engine.services.SolutionURIResolver)1