Java Code Examples for net.sf.jasperreports.engine.util.JRLoader#loadObjectFromFile()

The following examples show how to use net.sf.jasperreports.engine.util.JRLoader#loadObjectFromFile() . 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: SubreportApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
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 2
Source File: JasperPrintManager.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public boolean print(
	String sourceFileName,
	int firstPageIndex,
	int lastPageIndex,
	boolean withPrintDialog
	) throws JRException
{
	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(sourceFileName);

	return 
		print(
			jasperPrint,
			firstPageIndex,
			lastPageIndex,
			withPrintDialog
			);
}
 
Example 3
Source File: SubreportApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
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 4
Source File: JasperExportManager.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Exports the generated report file specified by the first parameter into PDF format,
 * the result being placed in the second file parameter.
 *  
 * @param sourceFileName source file containing the generated report
 * @param destFileName   file name to place the PDF content into
 * @see net.sf.jasperreports.engine.export.JRPdfExporter
 */
public void exportToPdfFile(
	String sourceFileName, 
	String destFileName
	) throws JRException
{
	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(sourceFileName);

	exportToPdfFile(jasperPrint, destFileName);
}
 
Example 5
Source File: JasperExportManager.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Exports the generated report file specified by the first parameter into XML format,
 * placing the result into the second file parameter.
 * <p>
 * If not embedded into the XML content itself using the Base64 encoder, 
 * the images are placed as distinct files inside a directory having the same name 
 * as the XML destination file, plus the "_files" suffix. 
 * 
 * @param sourceFileName    source file containing the generated report
 * @param destFileName      file name to place the XML representation into
 * @param isEmbeddingImages flag that indicates whether the images should be embedded in the
 *                          XML content itself using the Base64 encoder or be referenced as external resources
 * @see net.sf.jasperreports.engine.export.JRPdfExporter
 */
public void exportToXmlFile(
	String sourceFileName, 
	String destFileName,
	boolean isEmbeddingImages
	) throws JRException
{
	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(sourceFileName);

	exportToXmlFile(
		jasperPrint, 
		destFileName,
		isEmbeddingImages
		);
}
 
Example 6
Source File: JasperExportManager.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Exports the generated report file specified by the first parameter into HTML format,
 * placing the result into the second file parameter.
 * <p>
 * The images are placed as distinct files inside a directory having the same name 
 * as the HTML destination file, plus the "_files" suffix. 
 * 
 * @param sourceFileName source file containing the generated report
 * @param destFileName   file name to place the HTML content into
 * @see net.sf.jasperreports.engine.export.JRPdfExporter
 */
public void exportToHtmlFile(
	String sourceFileName, 
	String destFileName
	) throws JRException
{
	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(sourceFileName);

	exportToHtmlFile(
		jasperPrint, 
		destFileName
		);
}
 
Example 7
Source File: JasperPrintManager.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public boolean print(
	String sourceFileName,
	boolean withPrintDialog
	) throws JRException
{
	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(sourceFileName);

	return print(jasperPrint, withPrintDialog);
}
 
Example 8
Source File: JasperPrintManager.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public boolean print(
	String sourceFileName,
	int pageIndex,
	boolean withPrintDialog
	) throws JRException
{
	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(sourceFileName);

	return print(jasperPrint, pageIndex, withPrintDialog);
}
 
Example 9
Source File: JasperPrintManager.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public Image printToImage(
	String sourceFileName,
	int pageIndex,
	float zoom
	) throws JRException
{
	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(sourceFileName);

	return printToImage(jasperPrint, pageIndex, zoom);
}
 
Example 10
Source File: JasperCompileManager.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Generates the XML representation of the report design loaded from the first file parameter
 * and place it in the file specified by the second parameter. The result is "UTF-8" encoded.
 * 
 * @param sourceFileName source file name containing the report design object
 * @param destFileName   output file name to write the XML report design representation to
 */
public void writeToXmlFile(
	String sourceFileName, 
	String destFileName
	) throws JRException
{
	JRReport report = (JRReport)JRLoader.loadObjectFromFile(sourceFileName);

	writeToXmlFile(report, destFileName);
}
 
Example 11
Source File: JasperReportsUtil.java    From nextreports-server with Apache License 2.0 5 votes vote down vote up
public static JasperReport getJasper(String file) throws JRException {
    	 // Jasper 5.1.0+
        JasperReport jr = (JasperReport) JRLoader.loadObjectFromFile(file);
        // default is WHEN_NO_DATA_TYPE_BLANK_PAGE
        // we want to show something even no data found
        jr.setWhenNoDataType(WhenNoDataTypeEnum.ALL_SECTIONS_NO_DETAIL);
        return jr;
    	
//    	JasperReport jr = (JasperReport) JRLoader.loadObject(file);
//        // default is WHEN_NO_DATA_TYPE_BLANK_PAGE
//        // we want to show something even no data found
//        jr.setWhenNoDataType(JasperReport.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL);
//        return jr;
    }
 
Example 12
Source File: HtmlServlet.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@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
	{
		File reportFile = new File(context.getRealPath("/reports/WebappReport.jasper"));
		if (!reportFile.exists())
			throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");

		JasperReport jasperReport = (JasperReport)JRLoader.loadObjectFromFile(reportFile.getPath());
	
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("ReportTitle", "Address Report");
		parameters.put("BaseDir", reportFile.getParentFile());
					
		JasperPrint jasperPrint = 
			JasperFillManager.fillReport(
				jasperReport, 
				parameters, 
				new WebappDataSource()
				);
					
		HtmlExporter exporter = new HtmlExporter();
	
		request.getSession().setAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
		
		exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
		SimpleHtmlExporterOutput output = new SimpleHtmlExporterOutput(out);
		output.setImageHandler(new WebHtmlResourceHandler("image?image={0}"));
		exporter.setExporterOutput(output);
		
		exporter.exportReport();
	}
	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>");
	}
}
 
Example 13
Source File: JRAntXmlExportTask.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Performs the export of the selected report files.
 */
protected void export() throws BuildException
{
	Collection<String> files = reportFilesMap.keySet();

	if (files != null && files.size() > 0)
	{
		boolean isError = false;
	
		System.out.println("Exporting " + files.size() + " report files.");

		String srcFileName = null;
		String destFileName = null;
		File destFileParent = null;

		for (Iterator<String> it = files.iterator(); it.hasNext();)
		{
			srcFileName = it.next();
			destFileName = reportFilesMap.get(srcFileName);
			destFileParent = new File(destFileName).getParentFile();
			if(!destFileParent.exists())
			{
				destFileParent.mkdirs();
			}

			try
			{
				System.out.print("File : " + srcFileName + " ... ");

				JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObjectFromFile(srcFileName);
				
				JasperExportManager.getInstance(jasperReportsContext).exportToXmlFile(jasperPrint, destFileName, false);
				
				System.out.println("OK.");
			}
			catch(JRException e)
			{
				System.out.println("FAILED.");
				System.out.println("Error updating report design : " + srcFileName);
				e.printStackTrace(System.out);
				isError = true;
			}
		}
	
		if(isError)
		{
			throw new BuildException("Errors were encountered when updating report designs.");
		}
	}
}
 
Example 14
Source File: JRAntDecompileTask.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Performs the decompilation of the selected report design files.
 */
protected void decompile() throws BuildException
{
	Collection<String> files = reportFilesMap.keySet();

	if (files != null && files.size() > 0)
	{
		boolean isError = false;
	
		System.out.println("Decompiling " + 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 + " ... ");

				JasperReport jasperReport = (JasperReport)JRLoader.loadObjectFromFile(srcFileName);
				
				new JRXmlWriter(jasperReportsContext).write(jasperReport, destFileName, "UTF-8");
				
				System.out.println("OK.");
			}
			catch(JRException e)
			{
				System.out.println("FAILED.");
				System.out.println("Error decompiling report design : " + srcFileName);
				e.printStackTrace(System.out);
				isError = true;
			}
		}
	
		if(isError)
		{
			throw new BuildException("Errors were encountered when decompiling report designs.");
		}
	}
}