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

The following examples show how to use net.sf.jasperreports.engine.util.JRLoader#loadBytes() . 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: RenderableUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public Renderable getRenderable(InputStream is, OnErrorTypeEnum onErrorType) throws JRException
{
	Renderable result;
	try
	{
		result = new JRImageRenderer(JRLoader.loadBytes(is));
	}
	catch (Exception e)
	{
		result = handleImageError(e, onErrorType); 
		
		if (log.isDebugEnabled())
		{
			log.debug("handled image error with type " + onErrorType, e);
		}
	}
	return result;
}
 
Example 2
Source File: RenderableUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public Renderable getRenderable(URL url, OnErrorTypeEnum onErrorType) throws JRException
{
	Renderable result;
	try
	{
		result = new JRImageRenderer(JRLoader.loadBytes(url));
	}
	catch (Exception e)
	{
		result = handleImageError(e, onErrorType); 
		
		if (log.isDebugEnabled())
		{
			log.debug("handled image error with type " + onErrorType + " for URL " + url, e);
		}
	}
	return result;
}
 
Example 3
Source File: RenderableUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public Renderable getRenderable(File file, OnErrorTypeEnum onErrorType) throws JRException
{
	Renderable result;
	try
	{
		result = new JRImageRenderer(JRLoader.loadBytes(file));
	}
	catch (Exception e)
	{
		result = handleImageError(e, onErrorType); 
		
		if (log.isDebugEnabled())
		{
			log.debug("handled image error with type " + onErrorType + " for file " + file, e);
		}
	}
	return result;
}
 
Example 4
Source File: RendererUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public Renderable getRenderable(InputStream is, OnErrorTypeEnum onErrorType) throws JRException
{
	byte[] data = null;
	try
	{
		data = JRLoader.loadBytes(is);
	}
	catch (Exception e)
	{
		if (log.isDebugEnabled())
		{
			log.debug("handled image error with type " + onErrorType, e);
		}

		return handleImageError(e, onErrorType); 
	}
	return SimpleDataRenderer.getInstance(data);
}
 
Example 5
Source File: RendererUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public Renderable getRenderable(URL url, OnErrorTypeEnum onErrorType) throws JRException
{
	byte[] data = null;
	try
	{
		data = JRLoader.loadBytes(url);
	}
	catch (Exception e)
	{
		if (log.isDebugEnabled())
		{
			log.debug("handled image error with type " + onErrorType + " for URL " + url, e);
		}

		return handleImageError(e, onErrorType); 
	}
	return SimpleDataRenderer.getInstance(data);
}
 
Example 6
Source File: RendererUtil.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 *
 */
public Renderable getRenderable(File file, OnErrorTypeEnum onErrorType) throws JRException
{
	byte[] data = null;
	try
	{
		data = JRLoader.loadBytes(file);
	}
	catch (Exception e)
	{
		if (log.isDebugEnabled())
		{
			log.debug("handled image error with type " + onErrorType + " for file " + file, e);
		}

		return handleImageError(e, onErrorType); 
	}
	return SimpleDataRenderer.getInstance(data);
}
 
Example 7
Source File: AbstractTest.java    From jasperreports with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected String getDigestFromFile(String fileName) throws JRException
{
	URL resourceURL = JRResourcesUtil.findClassLoaderResource(fileName, null);
	if (resourceURL == null)
	{
		log.debug("did not find resource " + fileName);
		return null;
	}
	
	byte[] bytes = JRLoader.loadBytes(resourceURL);
	String digest = null;
	try
	{
		digest = new String(bytes, "UTF-8");
	}
	catch (UnsupportedEncodingException e)
	{
		throw new JRException(e);
	}
	log.debug("Reference report digest is " + digest + " for " + fileName);
	return digest;
}
 
Example 8
Source File: FillPlaceItem.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Float[] getCoords(String address) throws JRException {
	String reqParams = ((MapFillComponent)fillContextProvider).getReqParams();
	Float[] coords = null;
	if(address != null) {
		try {
			
			String urlStr = MapFillComponent.PLACE_URL_PREFIX 
					+ URLEncoder.encode(address, MapFillComponent.DEFAULT_ENCODING) 
					+ MapFillComponent.PLACE_URL_SUFFIX
					+ (reqParams != null && reqParams.trim().length() > 0 ? "&" + reqParams : "");

			URL url = new URL(urlStr);
			byte[] response = JRLoader.loadBytes(url);
			Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(response));
			Node statusNode = (Node) new DOMXPath(MapFillComponent.STATUS_NODE).selectSingleNode(document);
			String status = statusNode.getTextContent();
			if(MapFillComponent.STATUS_OK.equals(status)) {
				coords = new Float[2];
				Node latNode = (Node) new DOMXPath(MapFillComponent.LATITUDE_NODE).selectSingleNode(document);
				coords[0] = Float.valueOf(latNode.getTextContent());
				Node lngNode = (Node) new DOMXPath(MapFillComponent.LONGITUDE_NODE).selectSingleNode(document);
				coords[1] = Float.valueOf(lngNode.getTextContent());
			} else {
				throw 
					new JRException(
						MapFillComponent.EXCEPTION_MESSAGE_KEY_ADDRESS_REQUEST_FAILED,  
						new Object[]{status}
						);
			}
		} catch (Exception e) {
			throw new JRException(e);
		}
	}
	return coords;
}
 
Example 9
Source File: MapFillComponent.java    From jasperreports with GNU Lesser General Public License v3.0 5 votes vote down vote up
private Float[] getCoords(String address) throws JRException {
	Float[] coords = null;
	if(address != null) {
		try {
			String reqParams = getReqParams();
			reqParams = reqParams != null && reqParams.trim().length() > 0 ? "&" + reqParams : reqParams;
			String urlStr = PLACE_URL_PREFIX + URLEncoder.encode(address, DEFAULT_ENCODING) + reqParams + PLACE_URL_SUFFIX;
			URL url = new URL(urlStr);
			byte[] response = JRLoader.loadBytes(url);
			Document document = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(response));
			Node statusNode = (Node) new DOMXPath(STATUS_NODE).selectSingleNode(document);
			String status = statusNode.getTextContent();
			if(STATUS_OK.equals(status)) {
				coords = new Float[2];
				Node latNode = (Node) new DOMXPath(LATITUDE_NODE).selectSingleNode(document);
				coords[0] = Float.valueOf(latNode.getTextContent());
				Node lngNode = (Node) new DOMXPath(LONGITUDE_NODE).selectSingleNode(document);
				coords[1] = Float.valueOf(lngNode.getTextContent());
			} else {
				throw 
					new JRException(
						EXCEPTION_MESSAGE_KEY_ADDRESS_REQUEST_FAILED,  
						new Object[]{status} 
						);
			}
		} catch (Exception e) {
			throw new JRException(e);
		}
	}
	return coords;
}
 
Example 10
Source File: JRAbstractClassCompiler.java    From jasperreports with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
protected String compileUnits(JRCompilationUnit[] units, String classpath, File tempDirFile) throws JRException
{
	File[] sources = new File[units.length];
	for (int i = 0; i < sources.length; i++)
	{
		sources[i] = units[i].getSourceFile();
	}
	
	File[] classFiles = new File[units.length];
	for (int i = 0; i < classFiles.length; i++)
	{
		classFiles[i] = new File(tempDirFile, units[i].getName() + ".class");
	}
	
	try
	{
		String errors = compileClasses(sources, classpath);

		if (errors == null)
		{
			for (int i = 0; i < units.length; i++)
			{
				byte[] classBytes = JRLoader.loadBytes(classFiles[i]);
				units[i].setCompileData(classBytes);
			}
		}
		
		return errors;
	}
	finally
	{
		for (int i = 0; i < classFiles.length; i++)
		{
			if (classFiles[i].exists())
			{
				classFiles[i].delete();
			}
		}
	}
}
 
Example 11
Source File: BatikRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Creates a SVG renderer from a data stream.
 *
 * <p>
 * Note: the data stream is exhausted, but not closed.
 * </p>
 *
 * @param svgDataStream the SVG binary data stream
 * @return a SVG renderer
 * @throws JRException
 */
public static BatikRenderer getInstance(InputStream svgDataStream) throws JRException
{
	byte[] data = JRLoader.loadBytes(svgDataStream);
	return new BatikRenderer(data, null);
}
 
Example 12
Source File: BatikRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Creates a SVG renderer from a file.
 *
 * @param svgFile the SVG file to read
 * @return a SVG renderer
 * @throws JRException
 */
public static BatikRenderer getInstance(File svgFile) throws JRException
{
	byte[] data = JRLoader.loadBytes(svgFile);
	return new BatikRenderer(data, null);
}
 
Example 13
Source File: BatikRenderer.java    From jasperreports with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Creates a SVG renderer from a {@link URL}.
 *
 * @param svgURL the SVG URL
 * @return a SVG renderer
 * @throws JRException
 */
public static BatikRenderer getInstance(URL svgURL) throws JRException
{
	byte[] data = JRLoader.loadBytes(svgURL);
	return new BatikRenderer(data, null);
}