Java Code Examples for net.sf.jasperreports.engine.JRException#printStackTrace()

The following examples show how to use net.sf.jasperreports.engine.JRException#printStackTrace() . 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 Project: nextreports-server   File: JasperEngine.java    License: Apache License 2.0 6 votes vote down vote up
public void stopExport(String key) {
    JasperAsynchronousFillHandle currentRunner = JasperRunnerFactory.getRunner(key);
    System.out.println(">>> stop key==" + key);
    System.out.println(">>> runner=" + currentRunner);
    if (currentRunner != null) {
        System.out.println(">>> JasperReporterEngine : stop");
        try {
            currentRunner.cancellFill();
        } catch (JRException e) {
            e.printStackTrace();  
        }
    } else {
        // stop before the runner is created, but after the "running query" process
        // was started
        JasperRunnerFactory.addRunner(key, null);
    }
}
 
Example 2
@Override
public void start(Stage primaryStage) throws Exception {
	JasperPrint jasperPrint=null;
	try {
		jasperPrint = JasperFillManager.fillReport("target/classes/TestReport.jasper", new HashMap(),  new JREmptyDataSource());
	} catch (JRException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	};	
	JRViewerFx viewer = new JRViewerFx(jasperPrint, JRViewerFxMode.REPORT_VIEW,primaryStage);
	viewer.start(primaryStage);
	
}
 
Example 3
@FXML
private void print(){
	try {
		JasperPrintManager.printReport(jasperPrint, true);
	} catch (JRException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
Example 4
public static String getMasterQuery(Report report) {
String sql = "NA";
JasperContent jrc = (JasperContent) report.getContent();
byte[] xml = jrc.getMaster().getDataProvider().getBytes();
try {
	JasperReport jr = JasperReportsUtil.compileReport(xml);
	sql = jr.getQuery().getText();
} catch (JRException e) {
	e.printStackTrace();
	LOG.error(e.getMessage(), e);
}
return sql;
  }
 
Example 5
@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
	{
		String reportFileName = context.getRealPath("/reports/WebappReport.jasper");
		File reportFile = new File(reportFileName);
		if (!reportFile.exists())
			throw new JRRuntimeException("File WebappReport.jasper not found. The report design must be compiled first.");

		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("ReportTitle", "Address Report");
		parameters.put("BaseDir", reportFile.getParentFile());
					
		JasperPrint jasperPrint = 
			JasperFillManager.fillReport(
				reportFileName, 
				parameters, 
				new WebappDataSource()
				);
					
		request.getSession().setAttribute(BaseHttpServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE, jasperPrint);
	}
	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>");
	}

	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 compiled report design was successfully filled with data.</span>");

	out.println("</body>");
	out.println("</html>");
}
 
Example 6
@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 7
@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>");
}
 
Example 8
/**
 * Performs the update of the selected report design files.
 */
protected void update() throws BuildException
{
	Collection<String> files = reportFilesMap.keySet();

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

				JasperDesign jasperDesign = JRXmlLoader.load(srcFileName);
				
				if (updaters != null)
				{
					for(int i = 0; i < updaters.size(); i++)
					{
						ReportUpdater updater = updaters.get(i).getUpdater();
						if (updater != null)
						{
							jasperDesign = updater.update(jasperDesign);
						}
					}
				}
				
				new JRXmlWriter(jasperReportsContext).write(jasperDesign, destFileName, "UTF-8");
				
				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 9
/**
 * 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 10
/**
 * 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 11
/**
 * 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.");
		}
	}
}