if (zoomRatio != null)
{
zoom = zoomRatio.floatValue();
if (zoom <= 0)
{
throw new JRException("Invalid zoom ratio : " + zoom);
}
}
else
{
zoom = DEFAULT_ZOOM;
}
isIgnorePageMargins =
getBooleanParameter(
JRExporterParameter.IGNORE_PAGE_MARGINS,
JRExporterParameter.PROPERTY_IGNORE_PAGE_MARGINS,
false
);
fontMap = (Map) parameters.get(JRExporterParameter.FONT_MAP);
setHyperlinkProducerFactory();
StringBuffer sb = (StringBuffer)parameters.get(JRExporterParameter.OUTPUT_STRING_BUFFER);
if (sb != null)
{
try
{
writer = new StringWriter();
exportReportToWriter();
sb.append(writer.toString());
}
catch (IOException e)
{
throw new JRException("Error writing to StringBuffer writer : " + jasperPrint.getName(), e);
}
finally
{
if (writer != null)
{
try
{
writer.close();
}
catch(IOException e)
{
}
}
}
}
else
{
writer = (Writer)parameters.get(JRExporterParameter.OUTPUT_WRITER);
if (writer != null)
{
try
{
exportReportToWriter();
}
catch (IOException e)
{
throw new JRException("Error writing to writer : " + jasperPrint.getName(), e);
}
}
else
{
OutputStream os = (OutputStream)parameters.get(JRExporterParameter.OUTPUT_STREAM);
if (os != null)
{
try
{
writer = new OutputStreamWriter(os, encoding);
exportReportToWriter();
}
catch (IOException e)
{
throw new JRException("Error writing to OutputStream writer : " + jasperPrint.getName(), e);
}
}
else
{
File destFile = (File)parameters.get(JRExporterParameter.OUTPUT_FILE);
if (destFile == null)
{
String fileName = (String)parameters.get(JRExporterParameter.OUTPUT_FILE_NAME);
if (fileName != null)
{
destFile = new File(fileName);
}
else
{
throw new JRException("No output specified for the exporter.");
}
}
try
{
os = new FileOutputStream(destFile);
writer = new OutputStreamWriter(os, encoding);
}
catch (IOException e)
{
throw new JRException("Error creating to file writer : " + jasperPrint.getName(), e);
}
if (imagesDir == null)
{
imagesDir = new File(destFile.getParent(), destFile.getName() + "_files");
}
if (isOutputImagesToDirParameter == null)
{
isOutputImagesToDir = true;
}
if (imagesURI == null)
{
imagesURI = imagesDir.getName() + "/";
}
try
{
exportReportToWriter();
}
catch (IOException e)
{
throw new JRException("Error writing to file writer : " + jasperPrint.getName(), e);
}
finally
{
if (writer != null)
{
try
{
writer.close();
}
catch(IOException e)
{
}
}
}
}
}
}
if (isOutputImagesToDir)
{
if (imagesDir == null)
{
throw new JRException("The images directory was not specified for the exporter.");
}
if (imagesToProcess != null && imagesToProcess.size() > 0)
{
if (!imagesDir.exists())
{
imagesDir.mkdir();
}
for(Iterator it = imagesToProcess.iterator(); it.hasNext();)
{
JRPrintElementIndex imageIndex = (JRPrintElementIndex)it.next();
JRPrintImage image = getImage(jasperPrintList, imageIndex);
JRRenderable renderer = image.getRenderer();
if (renderer.getType() == JRRenderable.TYPE_SVG)
{
renderer =
new JRWrappingSvgRenderer(
renderer,
new Dimension(image.getWidth(), image.getHeight()),
ModeEnum.OPAQUE == image.getModeValue() ? image.getBackcolor() : null
);
}
byte[] imageData = renderer.getImageData();
File imageFile = new File(imagesDir, getImageName(imageIndex));
FileOutputStream fos = null;
try
{
fos = new FileOutputStream(imageFile);
fos.write(imageData, 0, imageData.length);
}
catch (IOException e)
{
throw new JRException("Error writing to image file : " + imageFile, e);
}
finally
{
if (fos != null)
{