if (zoomRatio != null)
{
zoom = zoomRatio.floatValue();
if (zoom <= 0)
{
throw new JRException("Invalid zoom ratio : " + zoom);
}
}
else
{
zoom = DEFAULT_ZOOM;
}
isUsingImagesToAlign =
getBooleanParameter(
JRHtmlExporterParameter.IS_USING_IMAGES_TO_ALIGN,
JRHtmlExporterParameter.PROPERTY_USING_IMAGES_TO_ALIGN,
true
);
if (isUsingImagesToAlign)
{
emptyCellStringProvider =
new StringProvider()
{
public String getStringForCollapsedTD(Object value, int width, int height)
{
return "><img alt=\"\" src=\"" + value + "px\" style=\"width: " + toSizeUnit(width) + "; height: " + toSizeUnit(height) + ";\"/>";
}
public String getStringForEmptyTD(Object value)
{
return "<img alt=\"\" src=\"" + value + "px\" border=\"0\"/>";
}
public String getReportTableStyle()
{
return null;
}
};
loadPxImage();
}
else
{
emptyCellStringProvider =
new StringProvider()
{
public String getStringForCollapsedTD(Object value, int width, int height)
{
return " style=\"width: " + toSizeUnit(width) + "; height: " + toSizeUnit(height) + ";\">";
}
public String getStringForEmptyTD(Object value)
{
return "";
}
public String getReportTableStyle()
{
// required for lines and rectangles, but doesn't work in IE
// border-collapse: collapse seems to take care of this though
return "empty-cells: show";
}
};
}
isIgnorePageMargins =
getBooleanParameter(
JRExporterParameter.IGNORE_PAGE_MARGINS,
JRExporterParameter.PROPERTY_IGNORE_PAGE_MARGINS,
false
);
accessibleHtml =
JRProperties.getBooleanProperty(
jasperPrint,
PROPERTY_ACCESSIBLE,
false
);
fontMap = (Map) parameters.get(JRExporterParameter.FONT_MAP);
setHyperlinkProducerFactory();
//FIXMENOW check all exporter properties that are supposed to work at report level
boolean deepGrid =
!getBooleanParameter(
JRHtmlExporterParameter.FRAMES_AS_NESTED_TABLES,
JRHtmlExporterParameter.PROPERTY_FRAMES_AS_NESTED_TABLES,
true
);
nature = new JRHtmlExporterNature(filter, deepGrid, isIgnorePageMargins);
flushOutput = getBooleanParameter(JRHtmlExporterParameter.FLUSH_OUTPUT,
JRHtmlExporterParameter.PROPERTY_FLUSH_OUTPUT,
true);
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 (isPxImageLoaded || (imagesToProcess != null && imagesToProcess.size() > 0))
{
if (!imagesDir.exists())
{
imagesDir.mkdir();
}
if (isPxImageLoaded)
{
JRRenderable pxRenderer =
JRImageRenderer.getInstance("net/sf/jasperreports/engine/images/pixel.GIF");
byte[] imageData = pxRenderer.getImageData();
File imageFile = new File(imagesDir, "px");
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)
{
try
{
fos.close();
}
catch(IOException e)
{
}
}
}
}
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)
{