当前位置: 首页>>代码示例>>Java>>正文


Java JasperReport类代码示例

本文整理汇总了Java中net.sf.jasperreports.engine.JasperReport的典型用法代码示例。如果您正苦于以下问题:Java JasperReport类的具体用法?Java JasperReport怎么用?Java JasperReport使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JasperReport类属于net.sf.jasperreports.engine包,在下文中一共展示了JasperReport类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: gerarRelatorioClientesSintetico

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
@Override
public JasperViewer gerarRelatorioClientesSintetico() {

    Connection connection = PostgreSQLDAOFactory.getConnection();

    try {
        Statement stm = connection.createStatement();
        String query = "SELECT\n"
                + "     cl.\"cod_cliente\" AS codigo,\n"
                + "     cl.\"nome_cliente\" AS nome,\n"
                + "     ci.\"nome_cidade\" AS nome_cidade,\n"
                + "     ci.\"sigla_uf\" AS sigla,\n"
                + "     cl.\"telefone\" AS telefone\n"
                + "FROM\n"
                + "     \"cliente\" cl INNER JOIN \"cidade\" ci "
                + "ON cl.\"cod_cidade\" = ci.\"cod_cidade\"\n"
                + "ORDER BY\n"
                + "     cl.nome_cliente ASC";

        ResultSet rs = stm.executeQuery(query);

        JRResultSetDataSource jrRS = new JRResultSetDataSource(rs);

        InputStream fonte
                = PgRelatorioDAO.class.getResourceAsStream(
                        "/br/com/pitanga/report/RelatorioClientesSintetico.jrxml");

        JasperReport report = JasperCompileManager.compileReport(fonte);

        JasperPrint print = JasperFillManager.fillReport(report, null, jrRS);
        JasperViewer jv = new JasperViewer(print, false);

        return jv;

    } catch (JRException | SQLException ex) {
        throw new DAOException(
                "Falha ao gerar relatório sintético "
                + "de clientes em JDBCRelatorioDAO", ex);
    }
}
 
开发者ID:douglasgusson,项目名称:pitanga-system,代码行数:41,代码来源:PgRelatorioDAO.java

示例2: createReportPDFFile

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
/**
 * @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;

	}
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:29,代码来源:JRReportUtil.java

示例3: initApplicationContext

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
/**
 * Checks to see that a valid report file URL is supplied in the
 * configuration. Compiles the report file is necessary.
 * <p>Subclasses can add custom initialization logic by overriding
 * the {@link #onInit} method.
 */
@Override
protected final void initApplicationContext() throws ApplicationContextException {
	this.report = loadReport();

	// Load sub reports if required, and check data source parameters.
	if (this.subReportUrls != null) {
		if (this.subReportDataKeys != null && this.subReportDataKeys.length > 0 && this.reportDataKey == null) {
			throw new ApplicationContextException(
					"'reportDataKey' for main report is required when specifying a value for 'subReportDataKeys'");
		}
		this.subReports = new HashMap<String, JasperReport>(this.subReportUrls.size());
		for (Enumeration<?> urls = this.subReportUrls.propertyNames(); urls.hasMoreElements();) {
			String key = (String) urls.nextElement();
			String path = this.subReportUrls.getProperty(key);
			Resource resource = getApplicationContext().getResource(path);
			this.subReports.put(key, loadReport(resource));
		}
	}

	// Convert user-supplied exporterParameters.
	convertExporterParameters();

	if (this.headers == null) {
		this.headers = new Properties();
	}
	if (!this.headers.containsKey(HEADER_CONTENT_DISPOSITION)) {
		this.headers.setProperty(HEADER_CONTENT_DISPOSITION, CONTENT_DISPOSITION_INLINE);
	}

	onInit();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:38,代码来源:AbstractJasperReportsView.java

示例4: compileReport

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
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;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:23,代码来源:AbstractTest.java

示例5: printPagePartePDF

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
private void printPagePartePDF(HttpServletResponse response, VariablesSecureApp vars,
    String strcOrderId) throws IOException, ServletException {
  if (log4j.isDebugEnabled())
    log4j.debug("Output: pdf");
  String strLanguage = vars.getLanguage();
  String strBaseDesign = getBaseDesignPath(strLanguage);

  HashMap<String, Object> parameters = new HashMap<String, Object>();
  JasperReport jasperReportLines;
  try {
    jasperReportLines = ReportingUtils.compileReport(strBaseDesign
        + "/org/openbravo/erpReports/RptC_OrderPO_Lines.jrxml");
  } catch (JRException e) {
    e.printStackTrace();
    throw new ServletException(e.getMessage());
  }
  parameters.put("SR_LINES", jasperReportLines);
  parameters.put("ORDER_ID", strcOrderId);
  renderJR(vars, response, null, "pdf", parameters, null, null);
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:21,代码来源:RptC_OrderPO.java

示例6: printPagePartePDF

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
private void printPagePartePDF(HttpServletResponse response, VariablesSecureApp vars,
    String strmRequisitionId) throws IOException, ServletException {
  if (log4j.isDebugEnabled())
    log4j.debug("Output: pdf");
  String strBaseDesign = getBaseDesignPath(vars.getLanguage());

  HashMap<String, Object> parameters = new HashMap<String, Object>();
  JasperReport jasperReportLines;
  try {
    jasperReportLines = ReportingUtils.compileReport(strBaseDesign
        + "/org/openbravo/erpReports/RptM_Requisition_Lines.jrxml");
  } catch (JRException e) {
    e.printStackTrace();
    throw new ServletException(e.getMessage());
  }

  parameters.put("SR_LINES", jasperReportLines);
  parameters.put("REQUISITION_ID", strmRequisitionId);
  renderJR(vars, response, null, "pdf", parameters, null, null);
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:21,代码来源:RptM_Requisition.java

示例7: loadReport

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
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!");
		}

	}
 
开发者ID:Coder-ACJHP,项目名称:Hotel-Properties-Management-System,代码行数:36,代码来源:ShowReport.java

示例8: createReportFile

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
/**
 * @param jrxmlTemplate
 * @param jsonData
 * @param parameters
 * @param destFileName
 * @return
 */
public static String createReportFile(String jrxmlTemplate, String jsonData, Map<String, Object> parameters,
		String destFileName) {

	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 exportReport(jasperPrint, destFileName, DocType.PDF);
	} catch (Exception e) {
		_log.error(e);

		return StringPool.BLANK;

	}
}
 
开发者ID:VietOpenCPS,项目名称:opencps-v2,代码行数:27,代码来源:JRReportUtil.java

示例9: printPagePDF

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
private void printPagePDF(HttpServletResponse response, VariablesSecureApp vars,
    String strcRemittanceId, String language) throws IOException, ServletException {
  if (log4j.isDebugEnabled())
    log4j.debug("Output: pdf");

  String strBaseDesign = getBaseDesignPath(language);

  String strOutput = new String("pdf");

  String strReportName = "@[email protected]/org/openbravo/erpReports/RptC_Remittance.jrxml";

  if (strOutput.equals("pdf"))
    response.setHeader("Content-disposition", "inline; filename=RptC_Remittance.pdf");

  RptCRemittanceData[] data = RptCRemittanceData
      .select(this, Utility.getContext(this, vars, "#User_Client", "RptC_RemittanceJR"),
          Utility.getContext(this, vars, "#AccessibleOrgTree", "RptC_RemittanceJR"),
          strcRemittanceId);

  JasperReport jasperReportLines;
  try {
    jasperReportLines = ReportingUtils.getTranslatedJasperReport(this, strBaseDesign
        + "/org/openbravo/erpReports/RptC_Remittance_Lines.jrxml", vars.getLanguage(),
        strBaseDesign);
  } catch (JRException e) {
    e.printStackTrace();
    throw new ServletException(e.getMessage());
  }

  HashMap<String, Object> parameters = new HashMap<String, Object>();
  parameters.put("LANGUAGE", language);
  parameters.put("SR_LINES", jasperReportLines);

  renderJR(vars, response, strReportName, strOutput, parameters, data, null);
}
 
开发者ID:mauyr,项目名称:openbravo-brazil,代码行数:36,代码来源:RptC_Remittance.java

示例10: saveAndGetUrl

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
private String saveAndGetUrl(JasperReport report, String templateName) throws IOException {
  File reportTempFile;
  try {
    reportTempFile = createTempFile(templateName, ".jasper");
  } catch (IOException ex) {
    throw new JasperReportViewException(ERROR_JASPER_FILE_CREATION, ex);
  }

  try (ByteArrayOutputStream bos = new ByteArrayOutputStream();
       ObjectOutputStream out = new ObjectOutputStream(bos)) {

    out.writeObject(report);
    writeByteArrayToFile(reportTempFile, bos.toByteArray());

    return reportTempFile.toURI().toURL().toString();
  }
}
 
开发者ID:OpenLMIS,项目名称:openlmis-stockmanagement,代码行数:18,代码来源:JasperReportService.java

示例11: performAction

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
@Override
	public void performAction() 
	{
//		JasperDesign jasperDesign = getJasperDesign();
		JasperDesignCache cache = JasperDesignCache.getInstance(getJasperReportsContext(), getReportContext());
		Map<String, JasperDesignReportResource> cachedResources = cache.getCachedResources();
		for (String uri : cachedResources.keySet())
		{
			JasperDesignReportResource resource = cachedResources.get(uri);
			JasperDesign jasperDesign = resource.getJasperDesign();
			if (jasperDesign != null)
			{
				JasperReport jasperReport = resource.getReport();
				String appRealPath = null;//FIXMECONTEXT WebFileRepositoryService.getApplicationRealPath();
				try
				{
					JRSaver.saveObject(jasperReport, new File(new File(new File(appRealPath), "WEB-INF/repository"), uri));//FIXMEJIVE harcoded
				}
				catch (JRException e)
				{
					throw new JRRuntimeException(e);
				}
			}
		}
	}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:26,代码来源:SaveAction.java

示例12: createObject

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
@Override
public Object createObject(Attributes atts)
{
	JRDesignExpression expression = new JRDesignExpression();

	String value = atts.getValue(JRXmlConstants.ATTRIBUTE_class);
	
	if (value != null)
	{
		// being backward compatible
		if(value.equals("dori.jasper.engine.JasperReport"))
		{
			value = JasperReport.class.getName();
		}
		expression.setValueClassName(value);
	}
	else
	{
		expression.setValueClass(java.lang.String.class);
	}

	return expression;
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:24,代码来源:JRSubreportExpressionFactory.java

示例13: gerarDanfeNfse

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
private static void gerarDanfeNfse(String url, List<String> emit, List<String> dest, List<String> ser, List<String> nota, String xml, String logo) {
    try {
        // Teste
        //String compilado = System.getProperty("user.dir") + "/danfe_nfce_80.jasper";;
        String output = "danfe.pdf"; 
        map.put("emit", emit);
        map.put("dest", dest);
        map.put("ser", ser);
        map.put("nota", nota);
        map.put("logo", logo);
        // brasao
        String brasao = Paths.get(System.getProperty("user.dir"), "danfe","brasao.png").toAbsolutePath().toString();
        map.put("brasao", brasao);
        // JrDataSource
        JRDataSource jr = new JRXmlDataSource(xml);
        // Relatório compilado
        JasperReport report = (JasperReport) JRLoader.loadObjectFromFile(url);
        JasperPrint print = JasperFillManager.fillReport(report, map, jr);
        JasperExportManager.exportReportToPdfFile(print, output);
    } catch (JRException e) {
        System.out.println("erro: "+e.getMessage());
    }
}
 
开发者ID:juniortada,项目名称:Java-Danfe,代码行数:24,代码来源:DanfeNfe.java

示例14: loadEvaluator

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
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);
	}
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:17,代码来源:JRFillCrosstab.java

示例15: fill

import net.sf.jasperreports.engine.JasperReport; //导入依赖的package包/类
/**
 * Fills a report.
 * <p/>
 * The data source used to fill the report is determined in the following way:
 * <ul>
 * 	<li>If a non-null value of the {@link net.sf.jasperreports.engine.JRParameter#REPORT_DATA_SOURCE REPORT_DATA_SOURCE}
 * has been specified, it will be used as data source.</li>
 * 	<li>Otherwise, if the report has a query then a data source will be created based on the query and connection
 * parameter values.</li>
 * 	<li>Otherwise, the report will be filled without a data source.</li>
 * </ul>
 * 
 * @param jasperReport the report
 * @param parameters the fill parameters
 * @return the filled report
 * @throws JRException
 */
public static JasperPrint fill(
	JasperReportsContext jasperReportsContext,
	JasperReport jasperReport, 
	Map<String,Object> parameters
	) throws JRException
{
	ReportFiller filler = createReportFiller(jasperReportsContext, jasperReport);

	try
	{
		JasperPrint jasperPrint = filler.fill(parameters);

		return jasperPrint;
	}
	catch (JRFillInterruptedException e)
	{
		throw 
			new JRException(
				EXCEPTION_MESSAGE_KEY_THREAD_INTERRUPTED,
				null,
				e);
	}
}
 
开发者ID:TIBCOSoftware,项目名称:jasperreports,代码行数:41,代码来源:JRFiller.java


注:本文中的net.sf.jasperreports.engine.JasperReport类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。