Java 类net.sf.jasperreports.engine.data.JRMapCollectionDataSource 实例源码

项目:document-management-system    文件:ReportUtils.java   
/**
 * Generates a report based on a map collection (from stream)
 */
public static OutputStream generateReport(OutputStream out, JasperReport jr, Map<String, Object> params,
                                          int outputType) throws JRException, EvalError {
    JRQuery query = jr.getQuery();

    if (query != null) {
        Interpreter bsh = new Interpreter(null, System.out, System.err, false);

        // Set parameters
        for (Map.Entry<String, Object> entry : params.entrySet()) {
            bsh.set(entry.getKey(), entry.getValue());
        }

        @SuppressWarnings("rawtypes")
        Collection list = (Collection) bsh.eval(query.getText());
        JasperPrint print = JasperFillManager.fillReport(jr, params, new JRMapCollectionDataSource(list));
        export(out, outputType, print);
    } else {
        throw new JRException("Null report query string");
    }

    return out;
}
项目:4mila-1.0    文件:GenericTableDynamicReport.java   
@Override
public JRDataSource evaluate(ReportParameters reportParameters) {
  int masterRowNumber = reportParameters.getReportRowNumber();
  GenericTableReportContent reportContent = contents.get(masterRowNumber - 1);
  ITable table = reportContent.getTable();
  JRMapCollectionDataSource ds = new JRMapCollectionDataSource(DataSourceUtility.createCollectionFromTable(table, true, false));
  return ds;
}
项目:document-management-system    文件:ReportUtils.java   
/**
 * Generates a report based on a map collection (from stream)
 */
public static OutputStream generateReport(OutputStream out, InputStream report, Map<String, Object> params,
                                          int outputType, Collection<Map<String, ?>> list) throws JRException {
    JasperReport jasperReport = JasperCompileManager.compileReport(report);
    JasperPrint print = JasperFillManager.fillReport(jasperReport, params, new JRMapCollectionDataSource(list));
    export(out, outputType, print);
    return out;
}
项目:appverse-server    文件:ReportServiceImpl.java   
@Override
public byte[] generateExcel(List<ExcelSheetReportData> excelSheetsReportData)
        throws Exception {

    if (excelSheetsReportData == null || excelSheetsReportData.size() == 0) {
        throw new Exception("There are no data to make report.");
    }

    String[] sheetNamesArray = new String[excelSheetsReportData.size()];
    List<JasperPrint> jasperPrints = new ArrayList<JasperPrint>();
    int i = 0;
    for (ExcelSheetReportData excelSheetReportData : excelSheetsReportData) {
        sheetNamesArray[i] = excelSheetReportData.getSheetName();
        i++;

        JRDataSource reportDataSource = new JRMapCollectionDataSource(
                excelSheetReportData.getSheetData());
        JasperPrint jasperPrint = null;
        if (excelSheetReportData.getSheetReportLocation() != null
                && !excelSheetReportData.getSheetReportLocation()
                        .equals("")) {
            jasperPrint = JasperFillManager.fillReport(
                    excelSheetReportData.getSheetReportLocation(),
                    excelSheetReportData.getSheetParameters(),
                    reportDataSource);
        } else {
            jasperPrint = JasperFillManager.fillReport(
                    excelSheetReportData.getSheetReport(),
                    excelSheetReportData.getSheetParameters(),
                    reportDataSource);
        }
        jasperPrints.add(jasperPrint);
    }

    JasperPrint firstJasperPrint = jasperPrints.get(0);
    if (jasperPrints.size() > 1) {
        for (i = 1; i < jasperPrints.size(); i++) {
            List<JRPrintPage> additionalPages = new ArrayList<JRPrintPage>(
                    jasperPrints.get(i).getPages());
            int fistJasperPrintPages = firstJasperPrint.getPages().size();
            for (int count = 0; count < additionalPages.size(); count++) {
                firstJasperPrint.addPage(fistJasperPrintPages,
                        additionalPages.get(count));
            }
        }
    }

    JRExporter exporter = new JExcelApiExporter();
    exporter.setParameter(JRXlsExporterParameter.JASPER_PRINT,
            firstJasperPrint);
    exporter.setParameter(JRXlsExporterParameter.IS_DETECT_CELL_TYPE,
            Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_WHITE_PAGE_BACKGROUND,
            Boolean.FALSE);

    exporter.setParameter(
            JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS,
            Boolean.TRUE);
    exporter.setParameter(
            JRXlsExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_COLUMNS,
            Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.IS_ONE_PAGE_PER_SHEET,
            Boolean.TRUE);
    exporter.setParameter(JRXlsExporterParameter.SHEET_NAMES,
            sheetNamesArray);
    exporter.setParameter(JExcelApiExporterParameter.IS_COLLAPSE_ROW_SPAN,
            Boolean.TRUE);
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream(32768);
    exporter.setParameter(JRXlsExporterParameter.OUTPUT_STREAM,
            outputStream);
    // exporter.setParameter(JRXlsExporterParameter.OUTPUT_FILE_NAME,
    // "C:/development/workspaces/jasper/report1.xls");
    exporter.exportReport();
    return outputStream.toByteArray();
}
项目:TechnologyReadinessTool    文件:ReportExportPdf.java   
@Override
public byte[] getReport() throws Exception {

    if (data == null || columnKeys == null) {
        throw new Exception("No data to report.");
    }

    // build report
    DynamicReport report = buildReport();
    // build reporting data source

    // fill report
    JasperReport jasperReport = DynamicJasperHelper.generateJasperReport(report, new ClassicLayoutManager(), params);
    adjustTextMarkup(jasperReport);

    if (data == null || data.isEmpty()) {
        data = Lists.newArrayList();
        if (columnKeys.size() > 0) {
            Map<String, String> noData = Maps.newHashMap();
            noData.put(columnKeys.get(0), "No Results");
            data.add(noData);
        }
    }

    JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params, new JRMapCollectionDataSource(data));

    return JasperExportManager.exportReportToPdf(jasperPrint);
}
项目:4mila-1.0    文件:FMilaJrxmlReport.java   
@Override
protected JasperPrint createJasperPrint() throws ProcessingException {
  JasperPrint result = null;
  JRMapCollectionDataSource ds = new JRMapCollectionDataSource(list);

  try {
    // fill
    result = JasperFillManager.fillReport(getTemplateFilename(), parameters, ds);
  }
  catch (JRException e) {
    throw new ProcessingException("Failed creating template-based report", e);
  }
  return result;
}
项目:dynamicreports-jasper    文件:MapCollectionSubDatasourceExpression.java   
@Override
protected JRDataSource createSubDatasource(Collection<Map<String, ?>> data) {
    return new JRMapCollectionDataSource(data);
}
项目:dynamicreports-jasper    文件:ColumnSubreportDataReport.java   
@Override
public JRDataSource evaluate(ReportParameters reportParameters) {
    Collection<Map<String, ?>> value = reportParameters.getValue("comments");
    return new JRMapCollectionDataSource(value);
}
项目:carcv    文件:BasicReportGenerator.java   
/**
 * Constructs a basic report from the parameters.
 *
 * @param e the FileEntry from which to fill the data
 * @param templateFilename the template report to fill
 * @param reportBuilderLocation the place where report is being built (physical, real)
 * @param reportName the title of the report
 * @param hostURL URL of the domain that is generating the report
 * @param tz TimeZone of the returned date (it is stored in UTC)
 * @throws JRException if an error during the generation occurs
 */
public BasicReportGenerator(FileEntry e, String templateFilename, String reportBuilderLocation, String reportName,
        String hostURL, TimeZone tz) throws JRException {

    Map<String, Object> values = new HashMap<>();
    Map<String, Object> parameters = new HashMap<>();

    CarData data = e.getCarData();

    Long entryId = e.getId() == null ? 0 : e.getId();
    String reportId = entryId + "-" + System.currentTimeMillis();

    // TimeZone:

    DateFormat dateFormat = new SimpleDateFormat("dd. MM. yyyy");
    dateFormat.setTimeZone(tz);
    DateFormat timeFormat = new SimpleDateFormat("HH:mm");
    timeFormat.setTimeZone(tz);

    // report
    parameters.put("reportid", reportId);
    parameters.put("reportname", reportName);
    parameters.put("reportlocation", reportBuilderLocation);
    parameters.put("reportdate", dateFormat.format(new Date(System.currentTimeMillis())));

    // data
    Address add = data.getAddress();
    String dataLocation = add.print();

    // parameters.put("id", Long.toString(data.getId()));

    Path imagePath = e.getCarImages().get(0).getFilepath().toAbsolutePath();

    if (Files.exists(imagePath) && Files.isRegularFile(imagePath)) {
        parameters.put("previewURL", imagePath.toString());
    } else {
        parameters.put("previewURL", "/reports/OpenCV_Logo_with_text.png");
    }

    parameters.put("date", dateFormat.format(data.getTimestamp()));
    parameters.put("location", dataLocation);
    parameters.put("LPNumber", data.getNumberPlate().getText());
    parameters.put("videoURL", hostURL + "/servlet/GenerateVideo?entry_id=" + e.getId().toString());
    parameters.put("time", timeFormat.format(data.getTimestamp()));
    parameters
            .put("speed", Double.toString(data.getSpeed().getSpeed()) + " " + data.getSpeed().getUnit().toString());

    // parameters.put

    Collection<Map<String, ?>> mapList = new ArrayList<>();
    mapList.add(values);

    JRMapCollectionDataSource mapDataSource = new JRMapCollectionDataSource(mapList);

    // compile template - already precompiled
    // JasperCompileManager.compileReportToFile(templateFilename + ".jrxml",
    // templateFilename + ".jasper");

    // fill with data
    InputStream templateInputStream = getClass().getResourceAsStream(templateFilename);

    filledReportPrint = JasperFillManager.fillReport(templateInputStream, parameters, mapDataSource);

}