net.sf.jasperreports.engine.JasperCompileManager Java Examples
The following examples show how to use
net.sf.jasperreports.engine.JasperCompileManager.
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: Report.java From jasperreports with GNU Lesser General Public License v3.0 | 6 votes |
public JasperReport compileReport() throws JRException, IOException { InputStream jrxmlInput = JRLoader.getResourceInputStream(jrxml); JasperDesign design; try { design = JRXmlLoader.load(jrxmlInput); } finally { jrxmlInput.close(); } report = JasperCompileManager.compileReport(design); //TODO do we need this here? fillManager = JasperFillManager.getInstance(jasperReportsContext); return report; }
Example #2
Source File: JReportUtils.java From bamboobsc with Apache License 2.0 | 6 votes |
/** * jasperreport compile jrxml 成 jasper * * @param sourceFile 如: File[] * @param destDir 如: C:/report/ 產生一個 test.jasper 到 C:/report/ 中 * @return * @throws JRException */ public static String compileReportToJasperFile(File sourceFile[], String destDir) throws JRException { String jasperFirst = ""; for (int ix=0; sourceFile!=null && ix<sourceFile.length; ix++) { File srcFile = sourceFile[ix]; if (!srcFile.exists() || srcFile.getName().indexOf(".jrxml")==-1) { srcFile=null; continue; } //String destFileName=srcFile.getName().replaceAll(".jrxml", ".jasper"); String destFileName=srcFile.getPath().replaceAll(".jrxml", ".jasper"); if ("".equals(jasperFirst)) { jasperFirst = destFileName; } JasperCompileManager.compileReportToFile(srcFile.getPath(), destFileName); logger.info("out process : " + destFileName); } return jasperFirst; }
Example #3
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 #4
Source File: ShikoPunetPunetoret.java From Automekanik with GNU General Public License v3.0 | 6 votes |
private void krijoRaport(String pnt){ btnRaporti.setOnAction(e -> { Thread t = new Thread(new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(CON_STR, "test", "test"); HashMap hm = new HashMap(); hm.put("Folderi", folderi); hm.put("punetori", pnt); JasperReport jreport = JasperCompileManager.compileReport(raportiPunetor); JasperPrint jprint = JasperFillManager.fillReport(jreport, hm, conn); JasperViewer.viewReport(jprint, false); conn.close(); }catch (Exception ex){ex.printStackTrace();} } }); t.start(); }); }
Example #5
Source File: JReportUtils.java From bamboobsc with Apache License 2.0 | 6 votes |
/** * jasperreport compile jrxml 成 jasper * * @param sourceFileName 如: new String[]{ "C:/report-source/test.jrxml" } * @param destDir 如: C:/report/ 產生一個 test.jasper 到 C:/report/ 中 * @return * @throws JRException */ public static String compileReportToJasperFile(String sourceFileName[], String destDir) throws JRException { String jasperFirst = ""; for (int ix=0; sourceFileName!=null && ix<sourceFileName.length; ix++) { File srcFile = new File(sourceFileName[ix]); if (!srcFile.exists() || srcFile.getName().indexOf(".jrxml")==-1) { srcFile=null; continue; } //String destFileName=srcFile.getName().replaceAll(".jrxml", ".jasper"); String destFileName=srcFile.getPath().replaceAll(".jrxml", ".jasper"); if ("".equals(jasperFirst)) { jasperFirst = destFileName; } JasperCompileManager.compileReportToFile(srcFile.getPath(), destFileName); logger.info("out process : " + destFileName); } return jasperFirst; }
Example #6
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 #7
Source File: ReportGenerationServiceImpl.java From kfs with GNU Affero General Public License v3.0 | 6 votes |
/** * complie the report template xml file into a Jasper report file if the compiled file does not exist or is out of update * * @param template the name of the template file, without an extension * @return an input stream where the intermediary report was written */ protected File compileReportTemplate(String template) throws JRException, IOException { ClassPathResource designTemplateResource = new ClassPathResource(template); if (!designTemplateResource.exists()) { throw new RuntimeException("The design template file does not exist: "+template); } File tempJasperDir = new File(System.getProperty("java.io.tmpdir")+File.separator+template.replaceAll("\\/[^\\/]+$", "")); if (!tempJasperDir.exists()) { FileUtils.forceMkdir(tempJasperDir); } File tempJasperFile = new File(System.getProperty("java.io.tmpdir")+File.separator+template.replace(ReportGeneration.DESIGN_FILE_EXTENSION,"").concat(ReportGeneration.JASPER_REPORT_EXTENSION)); if (!tempJasperFile.exists()) { JasperCompileManager.compileReportToStream(designTemplateResource.getInputStream(), new FileOutputStream(tempJasperFile)); } return tempJasperFile; }
Example #8
Source File: HyperlinkApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void writeXml() throws JRException { long start = System.currentTimeMillis(); JasperCompileManager.writeReportToXmlFile("build/reports/HyperlinkReport.jasper"); System.err.println("XML design creation time : " + (System.currentTimeMillis() - start)); }
Example #9
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 #10
Source File: IconLabelApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void print() throws JRException { long start = System.currentTimeMillis(); JasperDesign jasperDesign = JRXmlLoader.load("reports/FirstJasper.jrxml"); int i = 0; for (; i < 100; i++) { JasperCompileManager.compileReport(jasperDesign); } System.err.println("Average compile time : " + (System.currentTimeMillis() - start) / i); }
Example #11
Source File: NoXmlDesignApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void writeXml() throws JRException { long start = System.currentTimeMillis(); JasperCompileManager.writeReportToXmlFile("build/reports/NoXmlDesignReport.jasper"); System.err.println("XML design creation time : " + (System.currentTimeMillis() - start)); }
Example #12
Source File: NoXmlDesignApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void compile() throws JRException { long start = System.currentTimeMillis(); JasperDesign jasperDesign = getJasperDesign(); JasperCompileManager.compileReportToFile(jasperDesign, "build/reports/NoXmlDesignReport.jasper"); System.err.println("Compile time : " + (System.currentTimeMillis() - start)); }
Example #13
Source File: QueryApp.java From jasperreports with GNU Lesser General Public License v3.0 | 5 votes |
/** * */ public void compile() throws JRException { long start = System.currentTimeMillis(); JasperCompileManager.compileReportToFile("reports/QueryReport.jrxml", "build/reports/QueryReport.jasper"); System.err.println("Compile time : " + (System.currentTimeMillis() - start)); }
Example #14
Source File: JasperReportExample.java From dctb-utfpr-2018-1 with Apache License 2.0 | 5 votes |
public void generate(String layout) throws JRException , SQLException, ClassNotFoundException{ //gerando o jasper design JasperDesign drawing = JRXmlLoader.load(layout); //compila o relatório JasperReport report = JasperCompileManager.compileReport(drawing); //estabelece conexão Class.forName(driver); Connection con = DriverManager.getConnection(url, user, password); Statement stm = con.createStatement(); String query = "SELECT * from java_item"; ResultSet rs = stm.executeQuery(query); //implementação da interface JRDataSource para DataSource ResultSet JRResultSetDataSource jrRS = new JRResultSetDataSource(rs); //executa o relatório Map params = new HashMap(); params.put("HEADER", "Relatório de Clientes"); params.put("FOOTER", "Final do Relatório - 2018 - UTFPR"); JasperPrint print = JasperFillManager.fillReport(report, params, jrRS); //exibe o resultado JasperViewer viewer = new JasperViewer(print, true); viewer.show(); }
Example #15
Source File: ShikoPunetoret.java From Automekanik with GNU General Public License v3.0 | 5 votes |
private void raporti(){ new Thread(new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(CON_STR, "test", "test"); JasperReport jreport = JasperCompileManager.compileReport(raporti); JasperPrint jprint = JasperFillManager.fillReport(jreport, new HashMap(), conn); JasperViewer.viewReport(jprint, false); conn.close(); }catch (Exception ex){ex.printStackTrace();} } }).start(); }
Example #16
Source File: ShikoKonsumatoret.java From Automekanik with GNU General Public License v3.0 | 5 votes |
private void raporti(){ Thread t = new Thread(new Runnable() { @Override public void run() { try { Connection conn = DriverManager.getConnection(CON_STR, "test", "test"); JasperReport jreport = JasperCompileManager.compileReport(raporti); JasperPrint jprint = JasperFillManager.fillReport(jreport, new HashedMap(), conn); JasperViewer.viewReport(jprint, false); conn.close(); }catch (Exception ex){ex.printStackTrace();} } }); btnRaport.setOnAction(e -> t.start()); }
Example #17
Source File: JRReportTemplate.java From opencps-v2 with GNU Affero General Public License v3.0 | 5 votes |
public static JRReportTemplate getJRReportTemplate(String jrxmlTemplate) throws JRException, IOException { InputStream isTemplate = new ByteArrayInputStream(jrxmlTemplate.getBytes(StandardCharsets.UTF_8)); JRReportTemplate reportTemplate = (JRReportTemplate) JasperCompileManager.compileReport(isTemplate); if (isTemplate != null) { isTemplate.close(); } return reportTemplate; }
Example #18
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!"); } }
Example #19
Source File: JasperReportsUtil.java From nextreports-server with Apache License 2.0 | 4 votes |
public static void compileReportToFile(byte[] xml, File file) throws Exception { ByteArrayInputStream bais = new ByteArrayInputStream(xml); FileOutputStream fos = new FileOutputStream(file); JasperCompileManager.compileReportToStream(bais, fos); }
Example #20
Source File: JasperReportsUtil.java From nextreports-server with Apache License 2.0 | 4 votes |
public static JasperReport compileReport(byte[] xmlContent) throws JRException { ByteArrayInputStream bais = new ByteArrayInputStream(xmlContent); return JasperCompileManager.compileReport(bais); }
Example #21
Source File: DefaultReportService.java From dhis2-core with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override @Transactional(readOnly = true) public JasperPrint renderReport( OutputStream out, String reportUid, Period period, String organisationUnitUid, String type ) { I18nFormat format = i18nManager.getI18nFormat(); Report report = getReport( reportUid ); Map<String, Object> params = new HashMap<>(); params.putAll( constantService.getConstantParameterMap() ); Date reportDate = new Date(); if ( period != null ) { params.put( PARAM_PERIOD_NAME, format.formatPeriod( period ) ); reportDate = period.getStartDate(); } OrganisationUnit orgUnit = organisationUnitService.getOrganisationUnit( organisationUnitUid ); if ( orgUnit != null ) { int level = orgUnit.getLevel(); params.put( PARAM_ORGANISATIONUNIT_COLUMN_NAME, orgUnit.getName() ); params.put( PARAM_ORGANISATIONUNIT_LEVEL, level ); params.put( PARAM_ORGANISATIONUNIT_LEVEL_COLUMN, ORGUNIT_LEVEL_COLUMN_PREFIX + level ); params.put( PARAM_ORGANISATIONUNIT_UID_LEVEL_COLUMN, ORGUNIT_UID_LEVEL_COLUMN_PREFIX + level ); } JasperPrint print; log.debug( String.format( "Get report for report date: '%s', org unit: '%s'", DateUtils.getMediumDateString( reportDate ), organisationUnitUid ) ); try { JasperReport jasperReport = JasperCompileManager.compileReport( IOUtils.toInputStream( report.getDesignContent(), StandardCharsets.UTF_8 ) ); if ( report.hasVisualization() ) // Use JR data source { Visualization visualization = report.getVisualization(); Grid grid = visualizationService.getVisualizationGrid( visualization.getUid(), reportDate, organisationUnitUid ); print = JasperFillManager.fillReport( jasperReport, params, grid ); } else // Use JDBC data source { if ( report.hasRelativePeriods() ) { AnalyticsFinancialYearStartKey financialYearStart = (AnalyticsFinancialYearStartKey) systemSettingManager.getSystemSetting( SettingKey.ANALYTICS_FINANCIAL_YEAR_START ); List<Period> relativePeriods = report.getRelatives().getRelativePeriods( reportDate, null, false, financialYearStart ); String periodString = getCommaDelimitedString( getIdentifiers( periodService.reloadPeriods( relativePeriods ) ) ); String isoPeriodString = getCommaDelimitedString( IdentifiableObjectUtils.getUids( relativePeriods ) ); params.put( PARAM_RELATIVE_PERIODS, periodString ); params.put( PARAM_RELATIVE_ISO_PERIODS, isoPeriodString ); } if ( report.hasReportParams() && report.getReportParams().isOrganisationUnit() && orgUnit != null ) { params.put( PARAM_ORG_UNITS, String.valueOf( orgUnit.getId() ) ); params.put( PARAM_ORG_UNITS_UID, String.valueOf( orgUnit.getUid() ) ); } Connection connection = DataSourceUtils.getConnection( dataSource ); try { print = JasperFillManager.fillReport( jasperReport, params, connection ); } finally { DataSourceUtils.releaseConnection( connection, dataSource ); } } if ( print != null ) { JRExportUtils.export( type, out, print ); } } catch ( Exception ex ) { throw new RuntimeException( "Failed to render report", ex ); } return print; }
Example #22
Source File: AbstractTest.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
protected JasperReport compileReport(File jrxmlFile) throws JRException, IOException { JasperDesign design = JRXmlLoader.load(jrxmlFile); return JasperCompileManager.compileReport(design); }
Example #23
Source File: DefaultReportCompiler.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
@Override public JasperReport compile(JasperDesign design) throws JRException { return JasperCompileManager.getInstance(jasperReportsContext).compile(design); }
Example #24
Source File: JRFillSubreport.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
protected DatasetExpressionEvaluator createEvaluator() throws JRException { return JasperCompileManager.getInstance(filler.getJasperReportsContext()).getEvaluator( getReport()); }
Example #25
Source File: JRFillDataset.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
protected static JRCalculator createCalculator(JasperReportsContext jasperReportsContext, JasperReport jasperReport, JRDataset dataset) throws JRException { JREvaluator evaluator = JasperCompileManager.getInstance(jasperReportsContext).getEvaluator(jasperReport, dataset); return new JRCalculator(evaluator); }
Example #26
Source File: JRAntCompileTask.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
/** * Performs the compilation of the selected report design files. */ protected void compile() throws BuildException { Collection<String> files = reportFilesMap.keySet(); if (files != null && files.size() > 0) { boolean isError = false; System.out.println("Compiling " + files.size() + " report design files."); for (Iterator<String> it = files.iterator(); it.hasNext();) { String srcFileName = it.next(); String destFileName = reportFilesMap.get(srcFileName); File destFileParent = new File(destFileName).getParentFile(); if(!destFileParent.exists()) { destFileParent.mkdirs(); } try { System.out.print("File : " + srcFileName + " ... "); JasperCompileManager.getInstance(jasperReportsContext).compileToFile(srcFileName, destFileName); System.out.println("OK."); } catch(JRException e) { System.out.println("FAILED."); System.out.println("Error compiling report design : " + srcFileName); e.printStackTrace(System.out); isError = true; } } if(isError) { throw new BuildException("Errors were encountered when compiling report designs."); } } }
Example #27
Source File: CompileServlet.java From jasperreports with GNU Lesser General Public License v3.0 | 4 votes |
@Override public void service( HttpServletRequest request, HttpServletResponse response ) throws IOException, ServletException { ServletContext context = this.getServletConfig().getServletContext(); response.setContentType("text/html"); PrintWriter out = response.getWriter(); try { JasperCompileManager.compileReportToFile(context.getRealPath("/reports/WebappReport.jrxml")); } catch (JRException e) { out.println("<html>"); out.println("<head>"); out.println("<title>JasperReports - Web Application Sample</title>"); out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("<span class=\"bnew\">JasperReports encountered this error :</span>"); out.println("<pre>"); e.printStackTrace(out); out.println("</pre>"); out.println("</body>"); out.println("</html>"); return; } out.println("<html>"); out.println("<head>"); out.println("<title>JasperReports - Web Application Sample</title>"); out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"../stylesheet.css\" title=\"Style\">"); out.println("</head>"); out.println("<body bgcolor=\"white\">"); out.println("<span class=\"bold\">The JRXML report design was successfully compiled.</span>"); out.println("</body>"); out.println("</html>"); }