use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.
the class JFreeReportComponent method getReportFromResource.
private MasterReport getReportFromResource() throws ResourceException, IOException {
JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
MasterReport report = null;
Object reportDefinition = jFreeReportAction.getReportDefinition();
IActionSequenceResource resource = null;
if (reportDefinition instanceof ActionResource) {
resource = getResource(((ActionResource) reportDefinition).getName());
}
if (resource != null) {
if (resource.getSourceType() == IActionResource.XML) {
String repDef = resource.getAddress();
ReportGenerator generator = ReportGenerator.createInstance();
// add the runtime context so that PentahoResourceData class can get access to the solution repo
// generator.setObject(PentahoResourceData.PENTAHO_RUNTIME_CONTEXT_KEY, getRuntimeContext());
// Read the encoding from the XML file - see BISERVER-895
final String encoding = XmlHelper.getEncoding(repDef, null);
ByteArrayInputStream inStream = new ByteArrayInputStream(repDef.getBytes(encoding));
InputSource repDefInputSource = new InputSource(inStream);
repDefInputSource.setEncoding(encoding);
report = generator.parseReport(repDefInputSource, getDefinedResourceURL(null));
} else {
report = parseReport(resource);
}
}
return report;
}
use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.
the class JFreeReportComponent method initReportConfigParameters.
private boolean initReportConfigParameters(final MasterReport report) {
JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
boolean result = true;
if (isDefinedInput(AbstractJFreeReportComponent.DATACOMPONENT_REPORTTEMP_OBJINPUT)) {
Object reportConfigParams = jFreeReportAction.getReportConfig().getValue();
if (reportConfigParams != null) {
if (reportConfigParams instanceof IPentahoResultSet) {
setReportConfigParameters(report, (IPentahoResultSet) reportConfigParams);
} else if (reportConfigParams instanceof Map) {
setReportConfigParameters(report, (Map) reportConfigParams);
} else if (reportConfigParams instanceof JFreeReportAction.StaticReportConfig) {
setReportConfigParameters(report, (JFreeReportAction.StaticReportConfig) reportConfigParams);
} else {
error(Messages.getInstance().getErrorString(// $NON-NLS-1$
"JFreeReport.ERROR_0026_UNKNOWN_REPORT_CONFIGURATION_PARAMETERS"));
result = false;
}
}
}
return result;
}
use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.
the class JFreeReportComponent method getInputParamDataFactory.
private PentahoTableDataFactory getInputParamDataFactory() {
PentahoTableDataFactory factory = null;
JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
ActionInput reportDataParam = (ActionInput) jFreeReportAction.getData();
Object dataObject = reportDataParam != null ? reportDataParam.getValue() : null;
if ((dataObject instanceof IPentahoResultSet) || (dataObject instanceof TableModel)) {
factory = new PentahoTableDataFactory();
if (dataObject instanceof IPentahoResultSet) {
IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
if (resultset.isScrollable()) {
resultset.beforeFirst();
} else {
// $NON-NLS-1$
debug("ResultSet is not scrollable. Copying into memory");
IPentahoResultSet memSet = resultset.memoryCopy();
resultset.close();
resultset = memSet;
}
factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, new PentahoTableModel(resultset));
} else if (dataObject instanceof TableModel) {
factory.addTable(AbstractJFreeReportComponent.DATACOMPONENT_DEFAULTINPUT, (TableModel) dataObject);
}
IActionInput[] subreportQueries = jFreeReportAction.getSubreportQueryParams();
for (IActionInput element : subreportQueries) {
dataObject = element.getValue();
if (dataObject instanceof IPreparedComponent) {
factory.addPreparedComponent(element.getName(), (IPreparedComponent) dataObject);
} else if (dataObject instanceof IPentahoResultSet) {
final IPentahoResultSet resultset = (IPentahoResultSet) dataObject;
resultset.beforeFirst();
factory.addTable(element.getName(), new PentahoTableModel(resultset));
} else if (dataObject instanceof TableModel) {
factory.addTable(element.getName(), (TableModel) dataObject);
}
}
}
return factory;
}
use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.
the class JFreeReportComponent method getContentItem.
protected IContentItem getContentItem(final String mimeType, final String extension) {
JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
// Try to get the output from the action-sequence document.
IContentItem contentItem = null;
IActionOutput actionOutput = jFreeReportAction.getOutputReport();
if (actionOutput != null) {
contentItem = getOutputItem(actionOutput.getName(), mimeType, extension);
contentItem.setMimeType(mimeType);
} else if (getOutputNames().size() == 1) {
String outputName = (String) getOutputNames().iterator().next();
contentItem = getOutputContentItem(outputName, mimeType);
contentItem.setMimeType(mimeType);
}
return contentItem;
}
use of org.pentaho.actionsequence.dom.actions.JFreeReportAction in project pentaho-platform by pentaho.
the class JFreeReportComponent method generateReport.
private boolean generateReport(final MasterReport report, final PentahoTableDataFactory factory) throws IOException {
JFreeReportAction jFreeReportAction = (JFreeReportAction) getActionDefinition();
boolean result = false;
try {
applyThreadPriority();
// this might be invalid in case the action is contained in a sub-directory.
final String baseName = IOUtils.getInstance().stripFileExtension(getActionName());
final String path = getSolutionPath();
final PentahoResourceBundleFactory bundleFactory = new PentahoResourceBundleFactory(path, baseName, getSession());
report.setResourceBundleFactory(bundleFactory);
// set the default resourcebundle. This allows users to override the
// resource-bundle in case they want to keep common strings in a common
// collection.
report.getReportConfiguration().setConfigProperty(ResourceBundleFactory.DEFAULT_RESOURCE_BUNDLE_CONFIG_KEY, baseName);
if (factory != null) {
report.setDataFactory(factory);
}
String printerName = jFreeReportAction.getPrinterName().getStringValue();
String outputFormat = jFreeReportAction.getOutputType().getStringValue();
if (printerName != null) {
result = print(report, getActionTitle(), printerName);
} else if (AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_SWING.equals(outputFormat)) {
if (GraphicsEnvironment.isHeadless()) {
result = writeSwingPreview(report);
}
// $NON-NLS-1$
warn(Messages.getInstance().getString("JFreeReportAllContentComponent.WARN_HEADLESSMODE_ACTIVE"));
} else if (AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_HTML.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_PDF.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_XLS.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_CSV.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_RTF.equals(outputFormat) || AbstractJFreeReportComponent.REPORTALLCONTENT_OUTPUTTYPE_XML.equals(outputFormat)) {
String mimeType = getMimeType(outputFormat);
String fileExtention = getFileExtension(outputFormat);
IContentItem contentItem = getContentItem(mimeType, fileExtention);
OutputStream outputStream = null;
if (contentItem != null) {
outputStream = contentItem.getOutputStream(getActionName());
} else {
outputStream = getDefaultOutputStream(mimeType);
}
result = writeReport(outputFormat, report, outputStream, jFreeReportAction.getReportGenerationYieldRate().getIntValue(0), jFreeReportAction.getHtmlContentHandlerUrlPattern().getStringValue());
if (contentItem != null) {
contentItem.closeOutputStream();
}
} else {
// $NON-NLS-1$
warn(Messages.getInstance().getString("JFreeReportAllContentComponent.WARN_NO_PRINTER_GIVEN"));
}
} finally {
if (factory != null) {
// force close the factory
factory.closeTables();
}
}
return result;
}
Aggregations