當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。