Search in sources :

Example 31 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class ComponentBase 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 32 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class RuntimeContext method getOutputItem.

public IContentItem getOutputItem(final String outputName, final String mimeType, final String extension) {
    // TODO support content output versions in the action definition
    IActionParameter outputParameter = getOutputParameter(outputName);
    if (outputParameter == null) {
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
        actionSequence.getSequenceName()));
        return null;
    }
    // $NON-NLS-1$
    String filePath = "~/workspace/" + FilenameUtils.getBaseName(getSolutionPath()) + extension;
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    String contentName = "contentrepo:" + filePath;
    if (!IActionParameter.TYPE_CONTENT.equals(outputParameter.getType())) {
        // $NON-NLS-1$
        warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0023_INVALID_OUTPUT_STREAM", outputName));
        return null;
    }
    try {
        IContentOutputHandler output = PentahoSystem.getOutputDestinationFromContentRef(contentName, session);
        if (output != null) {
            // TODO get this info
            output.setInstanceId(instanceId);
            output.setSolutionPath(filePath);
            output.setMimeType(mimeType);
            output.setSession(session);
            IContentItem contentItem = output.getFileOutputContentItem();
            setOutputValue(outputName, contentItem);
            return contentItem;
        }
    } catch (Exception e) {
    // ignored
    }
    return null;
}
Also used : IContentOutputHandler(org.pentaho.platform.api.engine.IContentOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) InvalidParameterException(org.pentaho.platform.api.engine.InvalidParameterException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) ActionSequencePromptException(org.pentaho.platform.api.engine.ActionSequencePromptException) FileNotFoundException(java.io.FileNotFoundException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IOException(java.io.IOException)

Example 33 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem 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 34 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class RuntimeContext method setOutputValue.

public void setOutputValue(final String name, final Object output) {
    IActionParameter actionParameter = paramManager.getCurrentOutput(name);
    if (actionParameter == null) {
        throw new InvalidParameterException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", name, // $NON-NLS-1$
        actionSequence.getSequenceName()));
    }
    actionParameter.setValue(output);
    if (output instanceof String) {
        runtimeData.setStringProperty(name, (String) output);
    } else if (output instanceof Date) {
        runtimeData.setDateProperty(name, (Date) output);
    } else if (output instanceof Long) {
        runtimeData.setLongProperty(name, (Long) output);
    } else if (output instanceof List) {
        runtimeData.setListProperty(name, (List) output);
    } else if (output instanceof Map) {
        runtimeData.setMapProperty(name, (Map) output);
    } else if (output instanceof IContentItem) {
        runtimeData.setStringProperty(name, ((IContentItem) output).getPath());
    }
}
Also used : InvalidParameterException(org.pentaho.platform.api.engine.InvalidParameterException) IContentItem(org.pentaho.platform.api.repository.IContentItem) List(java.util.List) ArrayList(java.util.ArrayList) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Map(java.util.Map) HashMap(java.util.HashMap) Date(java.util.Date)

Example 35 with IContentItem

use of org.pentaho.platform.api.repository.IContentItem in project pentaho-platform by pentaho.

the class SimpleContentGenerator method createContent.

@Override
public void createContent() throws Exception {
    OutputStream out = null;
    if (outputHandler == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SimpleContentGenerator.ERROR_0001_NO_OUTPUT_HANDLER"));
        throw new InvalidParameterException(Messages.getInstance().getString(// $NON-NLS-1$
        "SimpleContentGenerator.ERROR_0001_NO_OUTPUT_HANDLER"));
    }
    if (instanceId == null) {
        setInstanceId(UUIDUtil.getUUIDAsString());
    }
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IContentItem contentItem = outputHandler.getOutputContentItem("response", "content", instanceId, getMimeType());
    if (contentItem == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SimpleContentGenerator.ERROR_0002_NO_CONTENT_ITEM"));
        throw new InvalidParameterException(Messages.getInstance().getString(// $NON-NLS-1$
        "SimpleContentGenerator.ERROR_0002_NO_CONTENT_ITEM"));
    }
    contentItem.setMimeType(getMimeType());
    out = contentItem.getOutputStream(itemName);
    if (out == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SimpleContentGenerator.ERROR_0003_NO_OUTPUT_STREAM"));
        throw new InvalidParameterException(Messages.getInstance().getString(// $NON-NLS-1$
        "SimpleContentGenerator.ERROR_0003_NO_OUTPUT_STREAM"));
    }
    createContent(out);
    try {
        // we created the output stream, let's be sure it's closed
        // do not leave it up to the implementations of SimpleContentGenerator
        // do do this or not
        out.flush();
        out.close();
    } catch (Exception ignored) {
    // this is cleanup code anyway, the output stream was probably
    // closed by the impl
    }
}
Also used : InvalidParameterException(java.security.InvalidParameterException) OutputStream(java.io.OutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) InvalidParameterException(java.security.InvalidParameterException)

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