Search in sources :

Example 26 with IActionSequenceResource

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

the class JFreeReportLoadComponent method validateAction.

@Override
protected boolean validateAction() {
    if (isDefinedResource(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN)) {
        return true;
    }
    if (isDefinedInput(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN)) {
        IActionParameter o = getInputParameter(AbstractJFreeReportComponent.REPORTGENERATEDEFN_REPORTDEFN);
        if ((o != null) && (o.getValue() instanceof String)) {
            return true;
        }
        return false;
    }
    // Handle late-bind of report resource name
    if (isDefinedInput(AbstractJFreeReportComponent.REPORTLOAD_RESOURCENAME)) {
        if (isDefinedResource(getInputStringValue(AbstractJFreeReportComponent.REPORTLOAD_RESOURCENAME))) {
            return true;
        } else {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0004_REPORT_DEFINITION_UNREADABLE"));
            return false;
        }
    }
    if (isDefinedResource(AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT)) {
        if (!isDefinedInput(AbstractJFreeReportComponent.REPORTLOAD_REPORTLOC)) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0011_REPORT_LOCATION_MISSING"));
            return false;
        }
        final IActionSequenceResource resource = getResource(AbstractJFreeReportComponent.DATACOMPONENT_JARINPUT);
        final InputStream in;
        in = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
        try {
            // not being able to read a single char is definitly a big boo ..
            if (in.read() == -1) {
                // $NON-NLS-1$
                error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
                return false;
            }
        } catch (Exception e) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0009_REPORT_JAR_UNREADABLE"));
            return false;
        }
        if (!isDefinedInput(AbstractJFreeReportComponent.REPORTLOAD_REPORTLOC)) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("JFreeReport.ERROR_0012_CLASS_LOCATION_MISSING"));
            return false;
        }
        return true;
    }
    return false;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) ResourceException(org.pentaho.reporting.libraries.resourceloader.ResourceException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 27 with IActionSequenceResource

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

the class TestComponent method validateAction.

@Override
protected boolean validateAction() {
    // describe the inputs, outputs and resources available to us
    Set inputNames = getInputNames();
    Iterator inputNamesIterator = inputNames.iterator();
    String inputName;
    IActionParameter actionParameter;
    while (inputNamesIterator.hasNext()) {
        inputName = (String) inputNamesIterator.next();
        actionParameter = getInputParameter(inputName);
        message(Messages.getInstance().getString("TestComponent.DEBUG_INPUT_DESCRIPTION", inputName, // $NON-NLS-1$
        actionParameter.getType()));
    }
    Set outputNames = getOutputNames();
    Iterator outputNamesIterator = outputNames.iterator();
    String outputName;
    while (outputNamesIterator.hasNext()) {
        outputName = (String) outputNamesIterator.next();
        actionParameter = getOutputItem(outputName);
        message(Messages.getInstance().getString("TestComponent.DEBUG_OUTPUT_DESCRIPTION", outputName, // $NON-NLS-1$
        actionParameter.getType()));
    }
    Set resourceNames = getResourceNames();
    Iterator resourceNamesIterator = resourceNames.iterator();
    String resourceName;
    IActionSequenceResource actionResource;
    while (resourceNamesIterator.hasNext()) {
        resourceName = (String) resourceNamesIterator.next();
        actionResource = getResource(resourceName);
        message(Messages.getInstance().getString("TestComponent.DEBUG_RESOURCE_DESCRIPTION", resourceName, actionResource.getMimeType(), // $NON-NLS-1$
        actionResource.getAddress()));
        try {
            String content = getResourceAsString(actionResource);
            message(Messages.getInstance().getString("TestComponent.DEBUG_RESOURCE_CONTENTS", // $NON-NLS-1$ //$NON-NLS-2$
            ((content == null) ? "null" : content.substring(0, 100))));
        } catch (Exception e) {
            // $NON-NLS-1$
            message(Messages.getInstance().getString("TestComponent.ERROR_0005_RESOURCE_NOT_LOADED", e.getMessage()));
        }
    }
    return true;
}
Also used : Set(java.util.Set) Iterator(java.util.Iterator) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Example 28 with IActionSequenceResource

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

the class PentahoResourceData method getResourceAsStream.

/**
 * gets a resource stream from the runtime context.
 *
 * @param caller
 *          resource manager
 * @return input stream
 */
public InputStream getResourceAsStream(final ResourceManager caller) throws ResourceLoadingException {
    int resourceType = IActionResource.SOLUTION_FILE_RESOURCE;
    if (filename.contains("://")) {
        resourceType = IActionResource.URL_RESOURCE;
    }
    final IActionSequenceResource resource = // $NON-NLS-1$ //$NON-NLS-2$
    new ActionSequenceResource("", resourceType, "application/binary", (String) key.getIdentifier());
    return resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
}
Also used : IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource) ActionSequenceResource(org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource) IActionSequenceResource(org.pentaho.platform.api.engine.IActionSequenceResource)

Aggregations

IActionSequenceResource (org.pentaho.platform.api.engine.IActionSequenceResource)28 InputStream (java.io.InputStream)10 IOException (java.io.IOException)9 ActionSequenceResource (org.pentaho.platform.engine.services.actionsequence.ActionSequenceResource)7 OutputStream (java.io.OutputStream)5 FileInputStream (java.io.FileInputStream)4 Set (java.util.Set)4 Document (org.dom4j.Document)4 Node (org.dom4j.Node)4 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)4 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)4 MasterReport (org.pentaho.reporting.engine.classic.core.MasterReport)4 ReportGenerator (org.pentaho.reporting.engine.classic.core.modules.parser.base.ReportGenerator)4 BufferedInputStream (java.io.BufferedInputStream)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 File (java.io.File)3 FileNotFoundException (java.io.FileNotFoundException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URL (java.net.URL)3 Iterator (java.util.Iterator)3