net.sf.jasperreports.engine.JasperReport Java Examples
The following examples show how to use
net.sf.jasperreports.engine.JasperReport.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JRReportUtil.java From opencps-v2 with GNU Affero General Public License v3.0 | 6 votes |
/** * @param jrxmlTemplate * @param jsonData * @param parameters * @param outputDestination * @param exportName * @return */ public static String createReportPDFFile(String jrxmlTemplate, String jsonData, Map<String, Object> parameters, String outputDestination, String exportName) { String sourceFileName = outputDestination + exportName; try { // fix json enter char jsonData = quoteHTML(jsonData); JasperReport reportTemplate = JRReportTemplate.getJasperReport(jrxmlTemplate); JRJSONDataSource dataSource = JRJSONDataSource.getInstance(jsonData); JasperPrint jasperPrint = getJasperPrint(reportTemplate, parameters, dataSource); return exportPdfFile(jasperPrint, sourceFileName); } catch (Exception e) { _log.error(e); return StringPool.BLANK; } }
Example #2
Source File: JasperEngine.java From nextreports-server with Apache License 2.0 | 6 votes |
public Map<String, Serializable> getReportUserParametersForEdit(Report report) throws Exception { Map<String, Serializable> result = new LinkedHashMap<String, Serializable>(); JasperReport jr = getJasperReport(report); Map<String, Serializable> map = JasperReportsUtil.getJasperReportUserParameters(jr); for (String key : map.keySet()) { JasperParameter jp = (JasperParameter) map.get(key); JasperParameterSource sp = getParameterSources(report, jp); // this parameter is not defined inside the file if (sp == null) { sp = new JasperParameterSource(jp.getName()); sp.setValueClassName(JasperReportsUtil.getValueClassName(storageService, report.getDataSource(), jp)); } result.put(sp.getName(), sp); } return result; }
Example #3
Source File: TravelReportFactoryServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * Create a subreport {@link JRDesignSubreport}. Since all kinds of reports are created through the {@link TravelReportFactoryServiceImpl} class, * even sub report instances will be considered normal reports and created individually. This method just marks where in the * parent report to place the sub report. This does not actually create another report. * * @param report is the parent report * @field is the field that is a {@link SubReport} * @return {@link JRDesignSubreport} to be added to report */ protected JRDesignSubreport createSubreport(final ReportInfo report, final Field field) throws Exception { final JRDesignSubreport retval = new JRDesignSubreport(new JasperDesign()); final JRDesignExpression dsExpression = new JRDesignExpression(); final String getterName = "get" + field.getName().substring(0, 1).toUpperCase() + field.getName().substring(1); dsExpression.setText("$P{report}." + getterName + "()"); dsExpression.setValueClass(JRDataSource.class); retval.setDataSourceExpression(dsExpression); final JRDesignExpression expression = new JRDesignExpression(); expression.setValueClass(JasperReport.class); expression.setText("$P{" + field.getName() + "Subreport}"); retval.setExpression(expression); retval.setHeight(SUBREPORT_HEIGHT); return retval; }
Example #4
Source File: AbstractTest.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * This method is used for compiling subreports. */ public JasperReport compileReport(String jrxmlFileName) throws JRException, IOException { JasperReport jasperReport = null; InputStream jrxmlInput = JRLoader.getResourceInputStream(jrxmlFileName); if (jrxmlInput != null) { JasperDesign design; try { design = JRXmlLoader.load(jrxmlInput); } finally { jrxmlInput.close(); } jasperReport = JasperCompileManager.compileReport(design); } return jasperReport; }
Example #5
Source File: JRFillCrosstab.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
protected void loadEvaluator(JasperReport jasperReport) { try { JREvaluator evaluator = JasperCompileManager.getInstance(filler.getJasperReportsContext()).getEvaluator(jasperReport, parentCrosstab); crosstabEvaluator = new JRCrosstabExpressionEvaluator(evaluator); } catch (JRException e) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_EVALUATOR_LOADING_ERROR, (Object[])null, e); } }
Example #6
Source File: JasperEngine.java From nextreports-server with Apache License 2.0 | 6 votes |
private JasperReport getJasperReport(Report report) throws Exception { JasperContent reportContent = (JasperContent) report.getContent(); String name = reportContent.getMaster().getName(); Settings settings = storageService.getSettings(); name = settings.getJasper().getHome() + File.separator + JasperUtil.getUnique(name, report.getId()) + "." + JasperUtil.JASPER_COMPILED_EXT; //System.out.println("name="+name); File f = new File(name); JasperReport jr; if (!f.exists()) { // byte[] xml = reportContent.getMaster().getXml(); JasperReportsUtil.compileReport(storageService, reportContent, report.getId()); } jr = JasperReportsUtil.getJasper(name); JasperReportsUtil.copyImages(settings.getJasper().getHome(), reportContent.getImageFiles()); return jr; }
Example #7
Source File: JRFillContext.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
public void registerReportStyles(JasperReport jasperReport, UUID id, List<JRStyle> styles) { JasperDesignCache designCache = JasperDesignCache.getExistingInstance(reportContext); if (designCache != null) { String reportURI = designCache.locateReport(jasperReport); if (reportURI == null) { if (log.isDebugEnabled()) { log.debug("Did not find report " + jasperReport.getName() + " " + jasperReport.getUUID()); } return; } designCache.setStyles(reportURI, id, styles); } }
Example #8
Source File: SubreportFillPart.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
@Override public void evaluate(byte evaluation) throws JRException { jasperReportSource = evaluateReportSource(evaluation); JRFillDataset parentDataset = expressionEvaluator.getFillDataset(); datasetPosition = new FillDatasetPosition(parentDataset.getFillPosition()); datasetPosition.addAttribute("subreportPartUUID", fillContext.getPart().getUUID()); parentDataset.setCacheRecordIndex(datasetPosition, evaluation); String cacheIncludedProp = JRPropertiesUtil.getOwnProperty(fillContext.getPart(), DataCacheHandler.PROPERTY_INCLUDED); cacheIncluded = JRPropertiesUtil.asBoolean(cacheIncludedProp, true);// default to true //FIXMEBOOK do not evaluate REPORT_DATA_SOURCE JasperReport jasperReport = getReport(); parameterValues = JRFillSubreport.getParameterValues(fillContext.getFiller(), expressionEvaluator, subreportPart.getParametersMapExpression(), subreportPart.getParameters(), evaluation, false, jasperReport.getResourceBundle() != null, jasperReport.getFormatFactoryClass() != null); setBookmarksParameter(); }
Example #9
Source File: JasperEngine.java From nextreports-server with Apache License 2.0 | 6 votes |
private JasperReport getJasperReport(ExportContext exportContext) throws Exception { JasperContent reportContent = (JasperContent) exportContext.getReportContent(); String name = reportContent.getMaster().getName(); Settings settings = storageService.getSettings(); name = settings.getJasper().getHome() + ReportUtil.FILE_SEPARATOR + JasperUtil.getUnique(name, exportContext.getId()) + "." + JasperUtil.JASPER_COMPILED_EXT; File jasperFile = new File(name); if (!jasperFile.exists()) { JasperReportsUtil.compileReport(storageService, reportContent, exportContext.getId()); } if (LOG.isDebugEnabled()) { LOG.debug("jasperFile = " + jasperFile); } JasperReportsUtil.copyImages(settings.getJasper().getHome(), reportContent.getImageFiles()); return JasperReportsUtil.getJasper(name); }
Example #10
Source File: SubreportApp.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * */ public void fill() throws JRException { long start = System.currentTimeMillis(); JasperReport subreport = (JasperReport)JRLoader.loadObjectFromFile("build/reports/ProductReport.jasper"); //Preparing parameters Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ProductsSubreport", subreport); JasperFillManager.fillReportToFile("build/reports/MasterReport.jasper", parameters, getDemoHsqldbConnection()); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); }
Example #11
Source File: JasperReportsUtil.java From nextreports-server with Apache License 2.0 | 6 votes |
public static LinkedHashMap<String, Serializable> getJasperReportUserParameters(JasperReport jr) { LinkedHashMap<String, Serializable> result = new LinkedHashMap<String, Serializable>(); JRParameter[] params = jr.getParameters(); for (JRParameter p : params) { if (!p.isSystemDefined() && p.isForPrompting()) { JasperParameter jp = new JasperParameter(); jp.setDescription(p.getDescription()); jp.setName(p.getName()); jp.setSystemDefined(p.isSystemDefined()); jp.setValueClassName(p.getValueClassName()); result.put(p.getName(), jp); } } return result; }
Example #12
Source File: JRFillSubreport.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
/** * */ protected JRFillSubreport( JRBaseFiller filler, JRSubreport subreport, JRFillObjectFactory factory ) { super(filler, subreport, factory); parameters = subreport.getParameters(); returnValues = new FillReturnValues(subreport.getReturnValues(), factory, filler); loadedEvaluators = new HashMap<JasperReport,JREvaluator>(); checkedReports = new HashSet<JasperReport>(); this.defaultGenerateRectangle = filler.getPropertiesUtil().getProperty( PROPERTY_SUBREPORT_GENERATE_RECTANGLE, subreport, filler.getJasperReport()); // property expression does not work, // but even if we would call filler.getMainDataset(), it would be too early as it is null here for subreport elements placed in group bands this.dynamicGenerateRectangle = hasDynamicProperty(PROPERTY_SUBREPORT_GENERATE_RECTANGLE); }
Example #13
Source File: TravelReportFactoryServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 5 votes |
/** * Create a subreport for the specified field. {@link Field} instance must have {@link SubReport} annotation * * @return JasperReport as a subreport */ @Override public JasperReport processReportForField(final ReportInfo report, final Field field) throws Exception { final JasperDesign design = designReport(report, field); if (design == null) { return null; } final JasperReport retval = JasperCompileManager.compileReport(design); retval.setWhenNoDataType(JasperReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL); return retval; }
Example #14
Source File: JRHorizontalFiller.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ protected JRHorizontalFiller( JasperReportsContext jasperReportsContext, JasperReport jasperReport ) throws JRException { this(jasperReportsContext, jasperReport, null); }
Example #15
Source File: JRAbstractCompiler.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
@Override public JREvaluator loadEvaluator(JasperReport jasperReport, JRCrosstab crosstab) throws JRException { JRReportCompileData reportCompileData = (JRReportCompileData) jasperReport.getCompileData(); String unitName = reportCompileData.getUnitName(jasperReport, crosstab); Serializable compileData = reportCompileData.getCrosstabCompileData(crosstab); return createEvaluator(compileData, unitName); }
Example #16
Source File: JRFillSubreport.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected JasperReportSource loadReportSource(Object reportSource, String contextLocation) throws JRException { JasperReport jasperReport = loadReport(reportSource, filler); JasperReportSource report = null; if (jasperReport != null) { RepositoryResourceContext currentContext = filler.getRepositoryContext().getResourceContext(); RepositoryResourceContext reportContext = SimpleRepositoryResourceContext.of(contextLocation, currentContext == null ? null : currentContext.getDerivedContextFallback()); report = SimpleJasperReportSource.from(jasperReport, reportSource instanceof String ? (String) reportSource : null, reportContext); } return report; }
Example #17
Source File: JRReportUtils.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
public static JRDataset findSubdataset(JRDatasetRun datasetRun, JasperReport report) { JRDataset[] datasets = report.getDatasets(); JRDataset reportDataset = null; if (datasets != null) { for (int i = 0; i < datasets.length; i++) { if (datasetRun.getDatasetName().equals( datasets[i].getName())) { reportDataset = datasets[i]; break; } } } if (reportDataset == null) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_REPORT_SUBDATASET_NOT_FOUND, new Object[]{datasetRun.getDatasetName(), report.getName()}); } return reportDataset; }
Example #18
Source File: ScriptletFactoryContext.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public ScriptletFactoryContext( JasperReportsContext jasperReportsContext, JRDataset dataset, Map<String,Object> parameterValues ) { this.jasperReportsContext = jasperReportsContext; this.jasperReport = (JasperReport)parameterValues.get(JRParameter.JASPER_REPORT); this.dataset = dataset; this.parameterValues = parameterValues; }
Example #19
Source File: FillDatasetRun.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
private static JRFillDataset createFillDataset(JRDatasetRun datasetRun, JRFillObjectFactory factory) throws JRException { JasperReport jasperReport = factory.getReportFiller().getJasperReport(); JRDataset reportDataset = JRReportUtils.findSubdataset(datasetRun, jasperReport); FillListDatasetFactory datasetFactory = new FillListDatasetFactory(factory); JRFillDataset fillDataset = datasetFactory.getDataset(reportDataset); fillDataset.createCalculator(jasperReport); fillDataset.inheritFromMain(); return fillDataset; }
Example #20
Source File: JasperDesignCache.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public JasperReport getJasperReport(String uri) { JasperDesignReportResource resource = getResource(uri); if (resource != null) { return resource.getReport(); } return null; }
Example #21
Source File: FillTable.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected JRReportCompileData createTableReportCompileData( JasperReport parentReport, JRDataset reportSubdataset) throws JRException { Serializable reportCompileDataObj = parentReport.getCompileData(); if (!(reportCompileDataObj instanceof JRReportCompileData)) { throw new JRRuntimeException( EXCEPTION_MESSAGE_KEY_UNSUPPORTED_REPORT_DATA_TYPE, new Object[]{reportCompileDataObj.getClass().getName()} ); } JRReportCompileData reportCompileData = (JRReportCompileData) reportCompileDataObj; Serializable datasetCompileData = reportCompileData.getDatasetCompileData( reportSubdataset); TableReportCompileData tableReportCompileData = new TableReportCompileData( parentReport); tableReportCompileData.setMainDatasetCompileData(datasetCompileData); JRDataset[] datasets = parentReport.getDatasets(); if (datasets != null) { for (JRDataset dataset : datasets) { Serializable compileData = reportCompileData.getDatasetCompileData(dataset); tableReportCompileData.setDatasetCompileData(dataset, compileData); } } tableReportCompileData.copyCrosstabCompileData(reportCompileData); return tableReportCompileData; }
Example #22
Source File: SimpleJasperReportSource.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
public static SimpleJasperReportSource from(JasperReport report, String reportLocation, RepositoryResourceContext reportContext) { SimpleJasperReportSource source = new SimpleJasperReportSource(); source.setReport(report); source.setReportLocation(reportLocation); source.setRepositoryReportContext(reportContext); return source; }
Example #23
Source File: JasperReportsUtil.java From nextreports-server with Apache License 2.0 | 5 votes |
public static String getMasterQuery(Report report) { String sql = "NA"; JasperContent jrc = (JasperContent) report.getContent(); byte[] xml = jrc.getMaster().getDataProvider().getBytes(); try { JasperReport jr = JasperReportsUtil.compileReport(xml); sql = jr.getQuery().getText(); } catch (JRException e) { e.printStackTrace(); LOG.error(e.getMessage(), e); } return sql; }
Example #24
Source File: AsynchronousFillHandle.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected AsynchronousFillHandle ( JasperReportsContext jasperReportsContext, JasperReport jasperReport, Map<String,Object> parameters, Connection conn ) throws JRException { this(jasperReportsContext, jasperReport, parameters, null, conn); }
Example #25
Source File: AsynchronousFillHandle.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * @see #createHandle(JasperReportsContext, JasperReport, Map, JRDataSource) */ public static AsynchronousFillHandle createHandle( JasperReport jasperReport, Map<String,Object> parameters, JRDataSource dataSource ) throws JRException { return createHandle(DefaultJasperReportsContext.getInstance(), jasperReport, parameters, dataSource); }
Example #26
Source File: AlterDesignApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void fill() throws JRException { long start = System.currentTimeMillis(); File sourceFile = new File("build/reports/AlterDesignReport.jasper"); System.err.println(" : " + sourceFile.getAbsolutePath()); JasperReport jasperReport = (JasperReport)JRLoader.loadObject(sourceFile); JRRectangle rectangle = (JRRectangle)jasperReport.getTitle().getElementByKey("first.rectangle"); rectangle.setForecolor(new Color((int)(16000000 * Math.random()))); rectangle.setBackcolor(new Color((int)(16000000 * Math.random()))); rectangle = (JRRectangle)jasperReport.getTitle().getElementByKey("second.rectangle"); rectangle.setForecolor(new Color((int)(16000000 * Math.random()))); rectangle.setBackcolor(new Color((int)(16000000 * Math.random()))); rectangle = (JRRectangle)jasperReport.getTitle().getElementByKey("third.rectangle"); rectangle.setForecolor(new Color((int)(16000000 * Math.random()))); rectangle.setBackcolor(new Color((int)(16000000 * Math.random()))); JRStyle style = jasperReport.getStyles()[0]; style.setFontSize(16f); style.setItalic(Boolean.TRUE); JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, null, (JRDataSource)null); File destFile = new File(sourceFile.getParent(), jasperReport.getName() + ".jrprint"); JRSaver.saveObject(jasperPrint, destFile); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); }
Example #27
Source File: SubreportApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void jsonMetadata() throws JRException { long start = System.currentTimeMillis(); JasperReport subreport = (JasperReport)JRLoader.loadObjectFromFile("build/reports/ProductReport.jasper"); //Preparing parameters Map<String, Object> parameters = new HashMap<String, Object>(); parameters.put("ProductsSubreport", subreport); parameters.put(JRParameter.IS_IGNORE_PAGINATION, true); JasperPrint jasperPrint = JasperFillManager.fillReport("build/reports/MasterReport.jasper", parameters, getDemoHsqldbConnection()); System.err.println("Filling time : " + (System.currentTimeMillis() - start)); start = System.currentTimeMillis(); File destFile = new File(new File("build/reports"), jasperPrint.getName() + ".json"); JsonMetadataExporter exporter = new JsonMetadataExporter(); exporter.setExporterInput(new SimpleExporterInput(jasperPrint)); exporter.setExporterOutput(new SimpleWriterExporterOutput(destFile)); exporter.exportReport(); System.err.println("JSON creation time : " + (System.currentTimeMillis() - start)); }
Example #28
Source File: AsynchronousFillHandle.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
protected AsynchronousFillHandle ( JasperReportsContext jasperReportsContext, JasperReport jasperReport, Map<String,Object> parameters, JRDataSource dataSource, Connection conn ) throws JRException { this(jasperReportsContext, SimpleJasperReportSource.from(jasperReport), parameters, dataSource, conn); }
Example #29
Source File: AsynchronousFillHandle.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * @see #createHandle(JasperReportsContext, JasperReport, Map) */ public static AsynchronousFillHandle createHandle( JasperReport jasperReport, Map<String,Object> parameters ) throws JRException { return createHandle(DefaultJasperReportsContext.getInstance(), jasperReport, parameters); }
Example #30
Source File: ShowReport.java From Hotel-Properties-Management-System with GNU General Public License v2.0 | 5 votes |
public void loadReport(String reportName, ReportObject reportObject) { logging = LoggingEngine.getInstance(); try { final InputStream inputStream = ShowReport.class .getResourceAsStream("/com/coder/hms/reportTemplates/" + reportName + ".jrxml"); JasperReport report = JasperCompileManager.compileReport(inputStream); HashMap<String, Object> parameters = new HashMap<String, Object>(); List<ReportObject> list = new ArrayList<ReportObject>(); list.add(reportObject); JRBeanCollectionDataSource beanColDataSource = new JRBeanCollectionDataSource(list); JasperPrint jasperPrint = JasperFillManager.fillReport(report, parameters, beanColDataSource); final JRViewer viewer = new JRViewer(jasperPrint); setType(Type.POPUP); setResizable(false); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); this.setTitle("Reservation [Report]"); this.setExtendedState(Frame.MAXIMIZED_BOTH); this.setAlwaysOnTop(isAlwaysOnTopSupported()); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); getContentPane().setLayout(new BorderLayout()); this.setIconImage(Toolkit.getDefaultToolkit(). getImage(LoginWindow.class.getResource(LOGOPATH))); this.setResizable(false); getContentPane().add(viewer, BorderLayout.CENTER); } catch (JRException e) { logging.setMessage("JRException report error!"); } }