Java Code Examples for net.sf.jasperreports.engine.JasperCompileManager#compileReport()

The following examples show how to use net.sf.jasperreports.engine.JasperCompileManager#compileReport() . 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: AbstractTest.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 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 2
Source File: Report.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 3
Source File: JasperReportExample.java    From dctb-utfpr-2018-1 with Apache License 2.0 5 votes vote down vote up
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 4
Source File: ShowReport.java    From Hotel-Properties-Management-System with GNU General Public License v2.0 5 votes vote down vote up
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 5
Source File: JRReportTemplate.java    From opencps-v2 with GNU Affero General Public License v3.0 5 votes vote down vote up
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 6
Source File: ShikoKonsumatoret.java    From Automekanik with GNU General Public License v3.0 5 votes vote down vote up
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 7
Source File: IconLabelApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
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 8
Source File: TravelReportFactoryServiceImpl.java    From kfs with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * 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 9
Source File: AbstractTest.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
protected JasperReport compileReport(File jrxmlFile) throws JRException, IOException
{
	JasperDesign design = JRXmlLoader.load(jrxmlFile);
	
	return JasperCompileManager.compileReport(design);
}
 
Example 10
Source File: DefaultReportService.java    From dhis2-core with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@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 11
Source File: JasperReportsUtil.java    From nextreports-server with Apache License 2.0 4 votes vote down vote up
public static JasperReport compileReport(byte[] xmlContent) throws JRException {
    ByteArrayInputStream bais = new ByteArrayInputStream(xmlContent);
    return JasperCompileManager.compileReport(bais);
}