Search in sources :

Example 6 with SolutionURIResolver

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

Example 7 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class FilterPanelComponent method init.

public boolean init() {
    if (filterPanel == null) {
        // load the XML document that defines the dial
        Document filterDocument = null;
        try {
            org.dom4j.io.SAXReader reader = XMLParserFactoryProducer.getSAXReader(new SolutionURIResolver());
            filterDocument = reader.read(ActionSequenceResource.getInputStream(definitionPath, LocaleHelper.getLocale()));
        } catch (Throwable t) {
            FilterPanelComponent.logger.error(Messages.getInstance().getString("FilterPanelComponent.ERROR_0002_CREATE_XML"), // $NON-NLS-1$
            t);
            return false;
        }
        try {
            filterPanel = getFilterPanel(filterDocument);
        } catch (FilterPanelException e) {
            // TODO sbarkdull localize
            FilterPanelComponent.logger.error(Messages.getInstance().getString("FilterPanelComponent.ERROR_0003_CREATE"), // $NON-NLS-1$
            e);
            return false;
        }
    }
    return true;
}
Also used : Document(org.dom4j.Document) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver)

Example 8 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class WidgetGridComponent method getXmlContent.

@Override
public Document getXmlContent() {
    // get the data to populate the widgets
    IPentahoResultSet resultSet = null;
    if (solution != null) {
        resultSet = getActionData();
    }
    // create the widget to use
    // load the XML document that defines the dial
    Document dialDefinition = null;
    try {
        org.dom4j.io.SAXReader reader = new org.dom4j.io.SAXReader();
        reader.setEntityResolver(new SolutionURIResolver());
        dialDefinition = reader.read(ActionSequenceResource.getInputStream(definitionPath, LocaleHelper.getLocale()));
    } catch (Throwable t) {
    // XML document can't be read. We'll just return a null document.
    }
    // create a dial definition from the XML definition
    WidgetDefinition widgetDefinition = new DialWidgetDefinition(dialDefinition, 0, widgetWidth, widgetHeight, getSession());
    return createDials(resultSet, widgetDefinition);
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) DialWidgetDefinition(org.pentaho.platform.uifoundation.chart.DialWidgetDefinition) WidgetDefinition(org.pentaho.platform.uifoundation.chart.WidgetDefinition) DialWidgetDefinition(org.pentaho.platform.uifoundation.chart.DialWidgetDefinition) Document(org.dom4j.Document) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver)

Example 9 with SolutionURIResolver

use of org.pentaho.platform.engine.services.SolutionURIResolver in project pentaho-platform by pentaho.

the class XmlComponent method getContent.

@Override
public String getContent(final String mimeType) {
    if ("text/xml".equalsIgnoreCase(mimeType)) {
        // $NON-NLS-1$
        Document content = getXmlContent();
        return content.asXML();
    } else {
        Document document = getXmlContent();
        if (document != null) {
            String xslName = (String) contentTypes.get(mimeType);
            if (xslName == null) {
                // $NON-NLS-1$
                error(Messages.getInstance().getString("BaseUI.ERROR_0002_XSL_NOT_FOUND") + mimeType);
                return null;
            }
            StringBuffer sb = null;
            try {
                sb = XmlHelper.transformXml(xslName, getSourcePath(), document.asXML(), getXslProperties(), new SolutionURIResolver());
            } catch (TransformerException e) {
                // $NON-NLS-1$
                XmlComponent.log.error(Messages.getInstance().getString("XmlComponent.ERROR_0000_XML_XFORM_FAILED"), e);
                return null;
            }
            if (sb == null) {
                // $NON-NLS-1$
                XmlComponent.log.error(Messages.getInstance().getString("XmlComponent.ERROR_0000_XML_XFORM_FAILED"));
                return null;
            }
            if (BaseUIComponent.debug) {
                debug(sb.toString());
            }
            return sb.toString();
        } else {
            return null;
        }
    }
}
Also used : Document(org.dom4j.Document) TransformerException(javax.xml.transform.TransformerException) SolutionURIResolver(org.pentaho.platform.engine.services.SolutionURIResolver)

Aggregations

Document (org.dom4j.Document)9 SolutionURIResolver (org.pentaho.platform.engine.services.SolutionURIResolver)9 File (java.io.File)2 IOException (java.io.IOException)2 Element (org.dom4j.Element)2 Node (org.dom4j.Node)2 FilenameFilter (java.io.FilenameFilter)1 OutputStream (java.io.OutputStream)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 List (java.util.List)1 TransformerException (javax.xml.transform.TransformerException)1 NameFileFilter (org.apache.commons.io.filefilter.NameFileFilter)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 ActionSequencePromptException (org.pentaho.platform.api.engine.ActionSequencePromptException)1 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)1 IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)1 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)1