Search in sources :

Example 1 with JasperReportsExporter

use of com.archimatetool.jasperreports.JasperReportsExporter in project archi by archimatetool.

the class JasperReportsProvider method run.

@Override
public void run(CommandLine commandLine) throws Exception {
    if (!hasCorrectOptions(commandLine)) {
        return;
    }
    IArchimateModel model = CommandLineState.getModel();
    if (model == null) {
        throw new IOException(Messages.JasperReportsProvider_1);
    }
    // Folder
    String path = commandLine.getOptionValue(OPTION_JASPER_CREATE_REPORT);
    if (!StringUtils.isSet(path)) {
        logError(Messages.JasperReportsProvider_2);
        return;
    }
    File folderOutput = new File(path);
    folderOutput.mkdirs();
    if (!folderOutput.exists()) {
        logError(NLS.bind(Messages.JasperReportsProvider_3, folderOutput.getPath()));
        return;
    }
    // Filename
    String filename = commandLine.getOptionValue(OPTION_JASPER_FILENAME);
    if (!StringUtils.isSet(filename)) {
        logError(Messages.JasperReportsProvider_4);
        return;
    }
    // Template file
    // $NON-NLS-1$
    File templateFile = new File(JasperReportsPlugin.INSTANCE.getJasperReportsFolder(), "Customizable Report/main.jrxml");
    String template = commandLine.getOptionValue(OPTION_JASPER_TEMPLATE);
    if (StringUtils.isSet(template)) {
        templateFile = new File(template);
        if (!templateFile.exists()) {
            logError(NLS.bind(Messages.JasperReportsProvider_5, templateFile.getPath()));
            return;
        }
    }
    // Title
    String title = commandLine.getOptionValue(OPTION_JASPER_TITLE);
    if (!StringUtils.isSet(title)) {
        logError(Messages.JasperReportsProvider_6);
        return;
    }
    // Locale
    Locale locale = null;
    String loc = commandLine.getOptionValue(OPTION_JASPER_LOCALE);
    if (StringUtils.isSet(loc)) {
        locale = Locale.forLanguageTag(loc.replace('_', '-'));
    }
    // Export options
    int exportOptions = JasperReportsExporter.EXPORT_PDF;
    String format = commandLine.getOptionValue(OPTION_JASPER_FORMAT).toLowerCase();
    // $NON-NLS-1$
    exportOptions |= format.contains("pdf") ? JasperReportsExporter.EXPORT_PDF : 0;
    // $NON-NLS-1$
    exportOptions |= format.contains("html") ? JasperReportsExporter.EXPORT_HTML : 0;
    // $NON-NLS-1$
    exportOptions |= format.contains("rtf") ? JasperReportsExporter.EXPORT_RTF : 0;
    // $NON-NLS-1$
    exportOptions |= format.contains("ppt") ? JasperReportsExporter.EXPORT_PPT : 0;
    // $NON-NLS-1$
    exportOptions |= format.contains("odt") ? JasperReportsExporter.EXPORT_ODT : 0;
    // $NON-NLS-1$
    exportOptions |= format.contains("docx") ? JasperReportsExporter.EXPORT_DOCX : 0;
    logMessage(NLS.bind(Messages.JasperReportsProvider_7, model.getName(), folderOutput.getPath()));
    JasperReportsExporter exporter = new JasperReportsExporter(model, folderOutput, filename, templateFile, title, locale, exportOptions);
    exporter.export(new NullProgressMonitor() {

        @Override
        public void subTask(String name) {
            logMessage(name);
        }
    });
    logMessage(Messages.JasperReportsProvider_8);
}
Also used : Locale(java.util.Locale) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) JasperReportsExporter(com.archimatetool.jasperreports.JasperReportsExporter) IOException(java.io.IOException) IArchimateModel(com.archimatetool.model.IArchimateModel) File(java.io.File)

Aggregations

JasperReportsExporter (com.archimatetool.jasperreports.JasperReportsExporter)1 IArchimateModel (com.archimatetool.model.IArchimateModel)1 File (java.io.File)1 IOException (java.io.IOException)1 Locale (java.util.Locale)1 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)1