net.sf.jasperreports.engine.JRException Java Examples

The following examples show how to use net.sf.jasperreports.engine.JRException. 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: SpiderChartApp.java    From jasperreports with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 *
 */
public void ods() throws JRException
{
	long start = System.currentTimeMillis();
	File sourceFile = new File("build/reports/SpiderChart.jrprint");

	JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

	File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".ods");
	
	JROdsExporter exporter = new JROdsExporter();
	
	exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
	exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));
	SimpleOdsReportConfiguration configuration = new SimpleOdsReportConfiguration();
	configuration.setOnePagePerSheet(true);
	exporter.setConfiguration(configuration);
	
	exporter.exportReport();

	System.err.println("ODT creation time : " + (System.currentTimeMillis() - start));
}
 
Example #2
Source File: ChartCustomizersApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public void fill() throws JRException
{
	Map<String, Object> parameters = new HashMap<String, Object>();
	parameters.put("legendWidth", "10");
	parameters.put("legendHeight", "10");
	
	File[] files = getFiles(new File("build/reports"), "jasper");
	for(int i = 0; i < files.length; i++)
	{
		File reportFile = files[i];
		long start = System.currentTimeMillis();
		JasperFillManager.fillReportToFile(
			reportFile.getAbsolutePath(), 
			new HashMap<String, Object>(parameters) 
			);
		System.err.println("Report : " + reportFile + ". Filling time : " + (System.currentTimeMillis() - start));
	}
}
 
Example #3
Source File: JRXmlUtils.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a XML document builder.
 * 
 * @return a XML document builder
 * @throws JRException
 */
public static DocumentBuilder createDocumentBuilder(boolean isNamespaceAware) throws JRException
{
	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	dbf.setValidating(false);
	dbf.setIgnoringComments(true);
	dbf.setNamespaceAware(isNamespaceAware);
	try
	{
		if (!allowDoctype())
		{
			dbf.setFeature(FEATURE_DISALLOW_DOCTYPE, true);
		}
		
		return dbf.newDocumentBuilder();
	}
	catch (ParserConfigurationException e)
	{
		throw 
		new JRException(
			EXCEPTION_MESSAGE_KEY_DOCUMENT_BUILDER_FACTORY_CREATION_FAILURE,
			null,
			e);
	}
}
 
Example #4
Source File: JRCsvDataSource.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Reads a character from the stream.
 * @throws IOException if any I/O error occurs
 * @throws JRException if end of stream has been reached
 */
private char getChar() throws IOException, JRException
{
	// end of buffer, fill a new buffer
	if (position + 1 > bufSize) {
		bufSize = reader.read(buffer);
		position = 0;
		if (bufSize == -1)
		{
			throw 
				new JRException(
					EXCEPTION_MESSAGE_KEY_NO_MORE_CHARS,
					(Object[])null);
		}
	}

	return buffer[position++];
}
 
Example #5
Source File: JRFillDataset.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * 
 */
private void setFillParameterValuesFromMap(Map<String,Object> parameterValues, boolean reset) throws JRException
{
	if (parameters != null && parameters.length > 0)
	{
		for (int i = 0; i < parameters.length; i++)
		{
			JRFillParameter parameter = parameters[i];
			String paramName = parameter.getName();
			
			Object value = null;
			if (parameterValues.containsKey(paramName))
			{
				value = parameterValues.get(paramName);
				setParameter(parameter, value);
			}
			else if (reset)
			{
				setParameter(parameter, null);
			}
		}
	}
}
 
Example #6
Source File: AegeanChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected JFreeChart createStackedBar3DChart() throws JRException
{
	JFreeChart jfreeChart = super.createStackedBar3DChart();
	CategoryPlot categoryPlot = (CategoryPlot)jfreeChart.getPlot();
	BarRenderer3D barRenderer3D = (BarRenderer3D)categoryPlot.getRenderer();
	barRenderer3D.setWallPaint(ChartThemesConstants.TRANSPARENT_PAINT);
	barRenderer3D.setItemMargin(0);
	CategoryDataset categoryDataset = categoryPlot.getDataset();
	if(categoryDataset != null)
	{
		for(int i = 0; i < categoryDataset.getRowCount(); i++)
		{
			barRenderer3D.setSeriesOutlinePaint(i, ChartThemesConstants.TRANSPARENT_PAINT);
		}
	}
	return jfreeChart;
}
 
Example #7
Source File: JRXmlUtils.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates a document having a node as root.
 * 
 * @param sourceNode the node
 * @return a document having the specified node as root
 * @throws JRException
 */
public static Document createDocument(Node sourceNode, boolean isNamespaceAware) throws JRException
{
	Document doc = JRXmlUtils.createDocumentBuilder(isNamespaceAware).newDocument();
	Node source;
	if (sourceNode.getNodeType() == Node.DOCUMENT_NODE) {
		source = ((Document) sourceNode).getDocumentElement();
	} else {
		source = sourceNode;
	}

	Node node = doc.importNode(source, true);
	doc.appendChild(node);
	
	return doc;
}
 
Example #8
Source File: BatchExportApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public void html() throws JRException
{
	long start = System.currentTimeMillis();
	List<JasperPrint> jasperPrintList = new ArrayList<JasperPrint>();
	jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report1.jrprint"));
	jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report2.jrprint"));
	jasperPrintList.add((JasperPrint)JRLoader.loadObjectFromFile("build/reports/Report3.jrprint"));
	
	HtmlExporter exporter = new HtmlExporter();
	
	exporter.setExporterInput(SimpleExporterInput.getInstance(jasperPrintList));
	exporter.setExporterOutput(new SimpleHtmlExporterOutput("build/reports/BatchExportReport.html"));
	
	exporter.exportReport();
	
	System.err.println("HTML creation time : " + (System.currentTimeMillis() - start));
}
 
Example #9
Source File: JRDesignViewerPanel.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected JRGraphics2DExporter getGraphics2DExporter() throws JRException
{
	return 
		new JRGraphics2DExporter(viewerContext.getJasperReportsContext())
		{
			@Override
			protected void initReport()
			{
				super.initReport();
				drawVisitor.setClip(true);//FIXMENOW thick border of margin elements is clipped
			}
			@Override
			protected RenderersCache getRenderersCache()
			{
				return viewerContext.getRenderersCache();
			}
		};
}
 
Example #10
Source File: WrappingSvgDataToGraphics2DRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected SVGDocument getSvgDocument(
	JasperReportsContext jasperReportsContext,
	SVGDocumentFactory documentFactory
	) throws JRException
{
	try
	{
		return 
			documentFactory.createSVGDocument(
				null, 
				new ByteArrayInputStream(
					dataRenderer.getData(jasperReportsContext)
					)
				);
	}
	catch (IOException e)
	{
		throw new JRRuntimeException(e);
	}
}
 
Example #11
Source File: CustomVisualizationApp.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public void ods() throws JRException
{
	File[] files = getFiles(new File("build/reports"), "jrprint");
	for(int i = 0; i < files.length; i++)
	{
		long start = System.currentTimeMillis();
		File sourceFile = files[i];

		JasperPrint jasperPrint = (JasperPrint)JRLoader.loadObject(sourceFile);

		File destFile = new File(sourceFile.getParent(), jasperPrint.getName() + ".ods");
	
		JROdsExporter exporter = new JROdsExporter();
		exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
		exporter.setExporterOutput(new SimpleOutputStreamExporterOutput(destFile));

		SimpleOdsReportConfiguration configuration = new SimpleOdsReportConfiguration();
		configuration.setOnePagePerSheet(true);
		exporter.setConfiguration(configuration);
	
		exporter.exportReport();

		System.err.println("Report : " + sourceFile + ". ODS export time : " + (System.currentTimeMillis() - start));
	}
}
 
Example #12
Source File: JRFillSubreport.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected void cancelSubreportFill() throws JRException
{
	if (log.isDebugEnabled())
	{
		log.debug("Fill " + filler.fillerId + ": cancelling " + subreportFiller.fillerId);
	}
	
	// marking the subreport filler for interruption
	subreportFiller.setInterrupted(true);
	
	synchronized (subreportFiller)
	{
		// forcing the creation of a new thread and a new subreport filler
		runner.cancel();
		runner.reset();
	}

	filler.unregisterSubfiller(subreportFiller);
}
 
Example #13
Source File: SaveAction.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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);
				}
			}
		}
	}
 
Example #14
Source File: JRViewer.java    From nordpos with GNU General Public License v3.0 6 votes vote down vote up
void btnReloadActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_btnReloadActionPerformed
{//GEN-HEADEREND:event_btnReloadActionPerformed
	// Add your handling code here:
	if (type == TYPE_FILE_NAME)
	{
		try
		{
			loadReport(reportFileName, isXML);
		}
		catch (JRException e)
		{
			if (log.isErrorEnabled())
			{
				log.error("Reload error.", e);
			}
			jasperPrint = null;
			setPageIndex(0);
			refreshPage();

			JOptionPane.showMessageDialog(this, getBundleString("error.loading"));
		}

		forceRefresh();
	}
}
 
Example #15
Source File: JRDesignDataset.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Inserts a scriptlet at the specified position into the dataset.
 * @param index the scriptlet position
 * @param scriptlet the scriptlet to insert
 * @throws JRException
 * @see net.sf.jasperreports.engine.JRDataset#getScriptlets()
 */
public void addScriptlet(int index, JRScriptlet scriptlet) throws JRException
{
	if (scriptletsMap.containsKey(scriptlet.getName()))
	{
		throw 
		new JRException(
			EXCEPTION_MESSAGE_KEY_DUPLICATE_SCRIPTLET,
			new Object[]{scriptlet.getName()});
	}

	JRDesignParameter scriptletParameter = new JRDesignParameter();
	scriptletParameter.setName(scriptlet.getName() 
			+ JRScriptlet.SCRIPTLET_PARAMETER_NAME_SUFFIX);
	scriptletParameter.setValueClassName(scriptlet.getValueClassName());
	scriptletParameter.setSystemDefined(true);
	scriptletParameter.setForPrompting(false);

	addParameter(scriptletParameter);

	scriptletsList.add(index, scriptlet);
	scriptletsMap.put(scriptlet.getName(), scriptlet);
	
	getEventSupport().fireCollectionElementAddedEvent(PROPERTY_SCRIPTLETS, scriptlet, index);
}
 
Example #16
Source File: AegeanChartTheme.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
protected JFreeChart createScatterChart() throws JRException
{
	JFreeChart jfreeChart = super.createScatterChart();
	XYPlot xyPlot = (XYPlot) jfreeChart.getPlot();
	xyPlot.setDomainGridlinesVisible(false);
	XYLineAndShapeRenderer plotRenderer = (XYLineAndShapeRenderer) ((XYPlot)jfreeChart.getPlot()).getRenderer();
	plotRenderer.setBaseShapesFilled(false);
	plotRenderer.setBaseStroke(new BasicStroke(1f));
	return jfreeChart;
}
 
Example #17
Source File: FillExpressionEvaluatorDatasetAdapter.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object evaluateOld(JRExpression expression)
		throws JRExpressionEvalException
{
	try
	{
		return evaluator.evaluate(expression, JRExpression.EVALUATION_OLD);
	}
	catch (JRException e)
	{
		throw new JRExpressionEvalException(expression, e);
	}
}
 
Example #18
Source File: UnicodeApp.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();
	JasperPrintManager.printReport("build/reports/UnicodeReport.jrprint", true);
	System.err.println("Printing time : " + (System.currentTimeMillis() - start));
}
 
Example #19
Source File: TableApp.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();
	JasperPrintManager.printReport("build/reports/TableReport.jrprint", true);
	System.err.println("Printing time : " + (System.currentTimeMillis() - start));
}
 
Example #20
Source File: SpiderChartApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void xml() throws JRException
{
	long start = System.currentTimeMillis();
	JasperExportManager.exportReportToXmlFile("build/reports/SpiderChart.jrprint", false);
	System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
}
 
Example #21
Source File: JRCsvQueryExecuterFactory.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public JRQueryExecuter createQueryExecuter(
	JasperReportsContext jasperReportsContext,
	JRDataset dataset, 
	Map<String, ? extends JRValueParameter> parameters
	) throws JRException 
{
	return createQueryExecuter(SimpleQueryExecutionContext.of(jasperReportsContext), 
			dataset, parameters);
}
 
Example #22
Source File: JRChartAxisFactory.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public Object createObject(Attributes atts)	throws JRException
{
	JRDesignChart parentChart =	(JRDesignChart)digester.peek(1);
	JRDesignChartAxis axis = new JRDesignChartAxis(parentChart);

	AxisPositionEnum position = AxisPositionEnum.getByName(atts.getValue(ATTRIBUTE_position));
	
	if (position !=	null)
	{
		axis.setPosition(position);
	}

	return axis;
}
 
Example #23
Source File: XmlDataSourceApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void xml() throws JRException
{
	long start = System.currentTimeMillis();
	JasperExportManager.exportReportToXmlFile("build/reports/CustomersReport.jrprint", false);
	System.err.println("XML creation time : " + (System.currentTimeMillis() - start));
}
 
Example #24
Source File: VirtualizerApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void print() throws JRException
{
	JasperPrint jasperPrint = fillReport();

	JasperPrintManager.printReport(jasperPrint, true);
}
 
Example #25
Source File: ListApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void print() throws JRException
{
	File[] files = getFiles(new File("build/reports"), "jrprint");
	for(int i = 0; i < files.length; i++)
	{
		File reportFile = files[i];
		long start = System.currentTimeMillis();
		JasperPrintManager.printReport(
			reportFile.getAbsolutePath(), 
			true
			);
		System.err.println("Report : " + reportFile + ". Printing time : " + (System.currentTimeMillis() - start));
	}
}
 
Example #26
Source File: XalanXmlDataSource.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void moveToRecord(int index) throws JRException
{
	if (index >= 0 && index < nodeListLength)
	{
		currentNodeIndex = index;
		currentNode = nodeList.item(index);
	}
	else
	{
		throw new NoRecordAtIndexException(index);
	}
}
 
Example #27
Source File: ShapesApp.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();
	JasperPrintManager.printReport("build/reports/ShapesReport.jrprint", true);
	System.err.println("Printing time : " + (System.currentTimeMillis() - start));
}
 
Example #28
Source File: HorizontalApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void fill() throws JRException
{
	long start = System.currentTimeMillis();
	//Preparing parameters
	Image image = 
		Toolkit.getDefaultToolkit().createImage(
			JRLoader.loadBytesFromResource("dukesign.jpg")
			);
	MediaTracker traker = new MediaTracker(new Panel());
	traker.addImage(image, 0);
	try
	{
		traker.waitForID(0);
	}
	catch (Exception e)
	{
		e.printStackTrace();
	}
	
	Map<String, Object> parameters = new HashMap<String, Object>();
	parameters.put("ReportTitle", "The Horizontal Report");
	parameters.put("MaxOrderID", 10500);
	parameters.put("SummaryImage", image);
	
	JasperFillManager.fillReportToFile("build/reports/HorizontalReport.jasper", parameters, getDemoHsqldbConnection());
	System.err.println("Filling time : " + (System.currentTimeMillis() - start));
}
 
Example #29
Source File: FillSpiderChart.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void evaluateDelayedElement(JRPrintElement element, byte evaluation) throws JRException
{
	evaluateRenderer(evaluation);
	copy((JRPrintImage) element);
	fillContext.getFiller().updateBookmark(element);
}
 
Example #30
Source File: HyperlinkApp.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 *
 */
public void html() throws JRException
{
	long start = System.currentTimeMillis();
	JasperExportManager.exportReportToHtmlFile("build/reports/HyperlinkReport.jrprint");
	System.err.println("HTML creation time : " + (System.currentTimeMillis() - start));
}