JRHtmlExporter.java

Index Score
net.sf.jasperreports.engine.export
JasperReports

View: Reasons, Metrics, Source Code

These are the metrics that contribute to the Enerjy Score for this file, ranked by impact. So the metrics listed at the top influence the score to a greater extent that the metrics listed at the bottom.

MetricDescription
RETURNSNumber of return points from functions
LOCLines of code
INTERFACE_COMPLEXITYInterface complexity
CYCLOMATICCyclomatic complexity
LOGICAL_LINESNumber of statements
BLOCKSNumber of blocks
ELOCEffective lines of code
COMPARISONSNumber of comparison operators
LINESNumber of lines in the source file
EXITSProcedure exits
PROGRAM_LENGTHHalstead program length
OPERATORSNumber of operators
OPERANDSNumber of operands
JAVA0145JAVA0145 Tab character used in source file
JAVA0049JAVA0049 Nested block at depth N (maximum: M)
SIZESize of the file in bytes
UNIQUE_OPERANDSNumber of unique operands
PROGRAM_VOCABHalstead program vocabulary
JAVA0108JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0115JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
WHITESPACENumber of whitespace lines
JAVA0031JAVA0031 Case statement not properly closed
PARAMSNumber of formal parameter declarations
JAVA0117JAVA0117 Missing javadoc: method 'method'
DECL_COMMENTSComments in declarations
JAVA0144JAVA0144 Line exceeds maximum M characters
LOOPSNumber of loops
FUNCTIONSNumber of function declarations
JAVA0110JAVA0110 Incorrect javadoc: no @return tag
EXEC_COMMENTSComments in executable code
JAVA0034JAVA0034 Missing braces in if statement
NEST_DEPTHMaximum nesting depth
UNIQUE_OPERATORSNumber of unique operators
JAVA0075JAVA0075 Method parameter hides field
JAVA0177JAVA0177 Variable declaration missing initializer
JAVA0119JAVA0119 Control variable changed within body of for loop
PROGRAM_VOLUMEHalstead program volume
JAVA0136JAVA0136 N methods defined in class (maximum: M)
COMMENTSComment lines
JAVA0126JAVA0126 Method declares unchecked exception in throws
JAVA0123JAVA0123 Use all three components of for loop
JAVA0173JAVA0173 Unused method parameter
JAVA0100JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0254JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0130JAVA0130 Non-static method does not use instance fields
/* * ============================================================================ * GNU Lesser General Public License * ============================================================================ * * JasperReports - Free Java report-generating library. * Copyright (C) 2001-2006 JasperSoft Corporation http://www.jaspersoft.com * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. * * JasperSoft Corporation * 303 Second Street, Suite 450 North * San Francisco, CA 94107 * http://www.jaspersoft.com */ /* * Contributors: * Alex Parfenov - aparfeno@users.sourceforge.net * Adrian Jackson - iapetus@users.sourceforge.net * David Taylor - exodussystems@users.sourceforge.net * Lars Kristensen - llk@users.sourceforge.net */ package net.sf.jasperreports.engine.export; import java.awt.Color; import java.awt.Dimension; import java.awt.Rectangle; import java.awt.font.TextAttribute; import java.awt.geom.Dimension2D; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.StringWriter; import java.io.Writer; import java.text.AttributedCharacterIterator; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedList; import java.util.List; import java.util.ListIterator; import java.util.Map; import net.sf.jasperreports.engine.JRAbstractExporter; import net.sf.jasperreports.engine.JRAlignment; import net.sf.jasperreports.engine.JRElement; import net.sf.jasperreports.engine.JRException; import net.sf.jasperreports.engine.JRExporterParameter; import net.sf.jasperreports.engine.JRHyperlink; import net.sf.jasperreports.engine.JRImage; import net.sf.jasperreports.engine.JRImageMapRenderer; import net.sf.jasperreports.engine.JRImageRenderer; import net.sf.jasperreports.engine.JRLine; import net.sf.jasperreports.engine.JRLineBox; import net.sf.jasperreports.engine.JRPen; import net.sf.jasperreports.engine.JRPrintElement; import net.sf.jasperreports.engine.JRPrintElementIndex; import net.sf.jasperreports.engine.JRPrintEllipse; import net.sf.jasperreports.engine.JRPrintFrame; import net.sf.jasperreports.engine.JRPrintGraphicElement; import net.sf.jasperreports.engine.JRPrintHyperlink; import net.sf.jasperreports.engine.JRPrintImage; import net.sf.jasperreports.engine.JRPrintImageArea; import net.sf.jasperreports.engine.JRPrintImageAreaHyperlink; import net.sf.jasperreports.engine.JRPrintLine; import net.sf.jasperreports.engine.JRPrintPage; import net.sf.jasperreports.engine.JRPrintRectangle; import net.sf.jasperreports.engine.JRPrintText; import net.sf.jasperreports.engine.JRRenderable; import net.sf.jasperreports.engine.JRRuntimeException; import net.sf.jasperreports.engine.JRTextElement; import net.sf.jasperreports.engine.JRWrappingSvgRenderer; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.util.JRColorUtil; import net.sf.jasperreports.engine.util.JRProperties; import net.sf.jasperreports.engine.util.JRStringUtil; import net.sf.jasperreports.engine.util.JRStyledText; import net.sf.jasperreports.engine.util.Pair; /** * Exports a JasperReports document to HTML format. It has character output type and exports the document to a * grid-based layout. * <p> * Since classic AWT fonts can be sometimes very different from HTML fonts, a font mapping feature was added. * By using the {@link JRExporterParameter#FONT_MAP} parameter, a logical font like "sansserif" can be mapped to a * list of HTML specific fonts, like "Arial, Verdana, Tahoma". Both map keys and values are strings. * @author Teodor Danciu (teodord@users.sourceforge.net) * @version $Id: JRHtmlExporter.java 2216 2008-06-10 13:15:44Z lucianc $ */ public class JRHtmlExporter extends JRAbstractExporter { private static final String HTML_EXPORTER_PROPERTIES_PREFIX = JRProperties.PROPERTY_PREFIX + "export.html."; /** * @deprecated Replaced by {@link JRHtmlExporterParameter#PROPERTY_FRAMES_AS_NESTED_TABLES}. */ public static final String PROPERTY_FRAMES_AS_NESTED_TABLES = JRHtmlExporterParameter.PROPERTY_FRAMES_AS_NESTED_TABLES; /** * */ protected static final String JR_PAGE_ANCHOR_PREFIX = "JR_PAGE_ANCHOR_"; /** * */ protected static final String CSS_TEXT_ALIGN_LEFT = "left"; protected static final String CSS_TEXT_ALIGN_RIGHT = "right"; protected static final String CSS_TEXT_ALIGN_CENTER = "center"; protected static final String CSS_TEXT_ALIGN_JUSTIFY = "justify"; /** * */ protected static final String HTML_VERTICAL_ALIGN_TOP = "top"; protected static final String HTML_VERTICAL_ALIGN_MIDDLE = "middle"; protected static final String HTML_VERTICAL_ALIGN_BOTTOM = "bottom"; public static final String IMAGE_NAME_PREFIX = "img_"; protected static final int IMAGE_NAME_PREFIX_LEGTH = IMAGE_NAME_PREFIX.length(); /** * */ protected Writer writer = null; protected JRExportProgressMonitor progressMonitor = null; protected Map rendererToImagePathMap = null; protected Map imageMaps; protected Map imageNameToImageDataMap = null; protected List imagesToProcess = null; protected boolean isPxImageLoaded = false; protected int reportIndex = 0; protected int pageIndex = 0; /** * */ protected File imagesDir = null; protected String imagesURI = null; protected boolean isOutputImagesToDir = false; protected boolean isRemoveEmptySpace; protected boolean isWhitePageBackground; protected String encoding; protected String sizeUnit = null; protected boolean isUsingImagesToAlign; protected boolean isWrapBreakWord; protected boolean isIgnorePageMargins; /** * */ protected String htmlHeader = null; protected String betweenPagesHtml = null; protected String htmlFooter = null; protected StringProvider emptyCellStringProvider = null; /** * */ protected Map fontMap = null; private LinkedList backcolorStack; private Color backcolor; protected JRHyperlinkProducerFactory hyperlinkProducerFactory; protected boolean deepGrid; protected ExporterNature nature = null; public JRHtmlExporter() { backcolorStack = new LinkedList(); backcolor = null; } /** * */ public void exportReport() throws JRException { progressMonitor = (JRExportProgressMonitor)parameters.get(JRExporterParameter.PROGRESS_MONITOR); /* */ setOffset(); try { /* */ setExportContext(); /* */ setInput(); if (!parameters.containsKey(JRExporterParameter.FILTER)) { filter = createFilter(HTML_EXPORTER_PROPERTIES_PREFIX); } /* */ if (!isModeBatch) { setPageRange(); } htmlHeader = (String)parameters.get(JRHtmlExporterParameter.HTML_HEADER); betweenPagesHtml = (String)parameters.get(JRHtmlExporterParameter.BETWEEN_PAGES_HTML); htmlFooter = (String)parameters.get(JRHtmlExporterParameter.HTML_FOOTER); imagesDir = (File)parameters.get(JRHtmlExporterParameter.IMAGES_DIR); if (imagesDir == null) { String dir = (String)parameters.get(JRHtmlExporterParameter.IMAGES_DIR_NAME); if (dir != null) { imagesDir = new File(dir); } } isRemoveEmptySpace = getBooleanParameter( JRHtmlExporterParameter.IS_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, JRHtmlExporterParameter.PROPERTY_REMOVE_EMPTY_SPACE_BETWEEN_ROWS, false ); isWhitePageBackground = getBooleanParameter( JRHtmlExporterParameter.IS_WHITE_PAGE_BACKGROUND, JRHtmlExporterParameter.PROPERTY_WHITE_PAGE_BACKGROUND, true ); Boolean isOutputImagesToDirParameter = (Boolean)parameters.get(JRHtmlExporterParameter.IS_OUTPUT_IMAGES_TO_DIR); if (isOutputImagesToDirParameter != null) { isOutputImagesToDir = isOutputImagesToDirParameter.booleanValue(); } String uri = (String)parameters.get(JRHtmlExporterParameter.IMAGES_URI); if (uri != null) { imagesURI = uri; } encoding = getStringParameterOrDefault( JRExporterParameter.CHARACTER_ENCODING, JRExporterParameter.PROPERTY_CHARACTER_ENCODING ); rendererToImagePathMap = new HashMap(); imageMaps = new HashMap(); imagesToProcess = new ArrayList(); isPxImageLoaded = false; //backward compatibility with the IMAGE_MAP parameter imageNameToImageDataMap = (Map)parameters.get(JRHtmlExporterParameter.IMAGES_MAP); // if (imageNameToImageDataMap == null) // { // imageNameToImageDataMap = new HashMap(); // } //END - backward compatibility with the IMAGE_MAP parameter isWrapBreakWord = getBooleanParameter( JRHtmlExporterParameter.IS_WRAP_BREAK_WORD, JRHtmlExporterParameter.PROPERTY_WRAP_BREAK_WORD, false ); sizeUnit = getStringParameterOrDefault( JRHtmlExporterParameter.SIZE_UNIT, JRHtmlExporterParameter.PROPERTY_SIZE_UNIT ); 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, String sizeUnit) { return "><img alt=\"\" src=\"" + value + "px\" style=\"width: " + width + sizeUnit + "; height: " + height + sizeUnit + ";\"/>"; } public String getStringForEmptyTD(Object value) { return "<img alt=\"\" src=\"" + value + "px\" border=\"0\"/>"; } }; loadPxImage(); } else { emptyCellStringProvider = new StringProvider() { public String getStringForCollapsedTD(Object value, int width, int height, String sizeUnit) { return " style=\"width: " + width + sizeUnit + "; height: " + height + sizeUnit + ";\">"; } public String getStringForEmptyTD(Object value) { return ""; } }; } isIgnorePageMargins = getBooleanParameter( JRExporterParameter.IGNORE_PAGE_MARGINS, JRExporterParameter.PROPERTY_IGNORE_PAGE_MARGINS, false ); fontMap = (Map) parameters.get(JRExporterParameter.FONT_MAP); setHyperlinkProducerFactory(); setDeepGrid(); nature = new JRHtmlExporterNature(filter, deepGrid, isIgnorePageMargins); 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()), JRElement.MODE_OPAQUE == image.getMode() ? 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) { try { fos.close(); } catch(IOException e) { } } } } } } } finally { resetExportContext(); } } protected void setHyperlinkProducerFactory() { hyperlinkProducerFactory = (JRHyperlinkProducerFactory) parameters.get(JRExporterParameter.HYPERLINK_PRODUCER_FACTORY); } protected void setDeepGrid() { boolean nestedTables; Boolean nestedTablesParam = (Boolean) parameters.get(JRHtmlExporterParameter.FRAMES_AS_NESTED_TABLES); if (nestedTablesParam == null) { nestedTables = JRProperties.getBooleanProperty(PROPERTY_FRAMES_AS_NESTED_TABLES); } else { nestedTables = nestedTablesParam.booleanValue(); } deepGrid = !nestedTables; } public static JRPrintImage getImage(List jasperPrintList, String imageName) { return getImage(jasperPrintList, getPrintElementIndex(imageName)); } public static JRPrintImage getImage(List jasperPrintList, JRPrintElementIndex imageIndex) { JasperPrint report = (JasperPrint)jasperPrintList.get(imageIndex.getReportIndex()); JRPrintPage page = (JRPrintPage)report.getPages().get(imageIndex.getPageIndex()); Integer[] elementIndexes = imageIndex.getAddressArray(); Object element = page.getElements().get(elementIndexes[0].intValue()); for (int i = 1; i < elementIndexes.length; ++i) { JRPrintFrame frame = (JRPrintFrame) element; element = frame.getElements().get(elementIndexes[i].intValue()); } return (JRPrintImage) element; } /** * */ protected void exportReportToWriter() throws JRException, IOException { if (htmlHeader == null) { // no doctype because of bug 1430880 // writer.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n"); // writer.write("<html xmlns=\"http://www.w3.org/1999/xhtml\">\n"); writer.write("<html>\n"); writer.write("<head>\n"); writer.write(" <title></title>\n"); writer.write(" <meta http-equiv=\"Content-Type\" content=\"text/html; charset=" + encoding + "\"/>\n"); writer.write(" <style type=\"text/css\">\n"); writer.write(" a {text-decoration: none}\n"); writer.write(" </style>\n"); writer.write("</head>\n"); writer.write("<body text=\"#000000\" link=\"#000000\" alink=\"#000000\" vlink=\"#000000\">\n"); writer.write("<table width=\"100%\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n"); writer.write("<tr><td width=\"50%\">&nbsp;</td><td align=\"center\">\n"); writer.write("\n"); } else { writer.write(htmlHeader); } for(reportIndex = 0; reportIndex < jasperPrintList.size(); reportIndex++) { jasperPrint = (JasperPrint)jasperPrintList.get(reportIndex); List pages = jasperPrint.getPages(); if (pages != null && pages.size() > 0) { if (isModeBatch) { startPageIndex = 0; endPageIndex = pages.size() - 1; } JRPrintPage page = null; for(pageIndex = startPageIndex; pageIndex <= endPageIndex; pageIndex++) { if (Thread.currentThread().isInterrupted()) { throw new JRException("Current thread interrupted."); } page = (JRPrintPage)pages.get(pageIndex); writer.write("<a name=\"" + JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + (pageIndex + 1) + "\"/>\n"); /* */ exportPage(page); if (reportIndex < jasperPrintList.size() - 1 || pageIndex < endPageIndex) { if (betweenPagesHtml == null) { writer.write("<br/>\n<br/>\n"); } else { writer.write(betweenPagesHtml); } } writer.write("\n"); } } } if (htmlFooter == null) { writer.write("</td><td width=\"50%\">&nbsp;</td></tr>\n"); writer.write("</table>\n"); writer.write("</body>\n"); writer.write("</html>\n"); } else { writer.write(htmlFooter); } writer.flush(); } /** * */ protected void exportPage(JRPrintPage page) throws JRException, IOException { JRGridLayout layout = new JRGridLayout( nature, page.getElements(), jasperPrint.getPageWidth(), jasperPrint.getPageHeight(), globalOffsetX, globalOffsetY, null //address ); exportGrid(layout, isWhitePageBackground); if (progressMonitor != null) { progressMonitor.afterPageExport(); } } /** * */ protected void exportGrid(JRGridLayout gridLayout, boolean whitePageBackground) throws IOException, JRException { CutsInfo xCuts = gridLayout.getXCuts(); JRExporterGridCell[][] grid = gridLayout.getGrid(); writer.write("<table style=\"width: " + gridLayout.getWidth() + sizeUnit + "\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\""); if (whitePageBackground) { writer.write(" bgcolor=\"white\""); } writer.write(">\n"); if (whitePageBackground) { setBackcolor(Color.white); } writer.write("<tr>\n"); int width = 0; for(int i = 1; i < xCuts.size(); i++) { width = xCuts.getCut(i) - xCuts.getCut(i - 1); writer.write(" <td" + emptyCellStringProvider.getStringForCollapsedTD(imagesURI, width, 1, sizeUnit) + "</td>\n"); } writer.write("</tr>\n"); for(int y = 0; y < grid.length; y++) { if (gridLayout.getYCuts().isCutSpanned(y) || !isRemoveEmptySpace) { JRExporterGridCell[] gridRow = grid[y]; int rowHeight = JRGridLayout.getRowHeight(gridRow); boolean hasEmptyCell = hasEmptyCell(gridRow); writer.write("<tr valign=\"top\""); if (!hasEmptyCell) { writer.write(" style=\"height:" + rowHeight + sizeUnit + "\""); } writer.write(">\n"); for(int x = 0; x < gridRow.length; x++) { JRExporterGridCell gridCell = gridRow[x]; if(gridCell.getWrapper() == null) { writeEmptyCell(gridCell, rowHeight); } else { JRPrintElement element = gridCell.getWrapper().getElement(); if (element instanceof JRPrintLine) { exportLine((JRPrintLine)element, gridCell); } else if (element instanceof JRPrintRectangle) { exportRectangle((JRPrintRectangle)element, gridCell); } else if (element instanceof JRPrintEllipse) { exportRectangle((JRPrintEllipse)element, gridCell); } else if (element instanceof JRPrintImage) { exportImage((JRPrintImage)element, gridCell); } else if (element instanceof JRPrintText) { exportText((JRPrintText)element, gridCell); } else if (element instanceof JRPrintFrame) { exportFrame((JRPrintFrame) element, gridCell); } } x += gridCell.getColSpan() - 1; } writer.write("</tr>\n"); } } if (whitePageBackground) { restoreBackcolor(); } writer.write("</table>\n"); } private boolean hasEmptyCell(JRExporterGridCell[] gridRow) { if (gridRow[0].getWrapper() == null) // quick exit { return true; } boolean hasEmptyCell = false; for(int x = 1; x < gridRow.length; x++) { if (gridRow[x].getWrapper() == null) { hasEmptyCell = true; break; } } return hasEmptyCell; } protected void writeEmptyCell(JRExporterGridCell cell, int rowHeight) throws IOException { writer.write(" <td"); if (cell.getColSpan() > 1) { writer.write(" colspan=\"" + cell.getColSpan() + "\""); } StringBuffer styleBuffer = new StringBuffer(); appendBackcolorStyle(cell, styleBuffer); appendBorderStyle(cell.getBox(), styleBuffer); if (styleBuffer.length() > 0) { writer.write(" style=\""); writer.write(styleBuffer.toString()); writer.write("\""); } writer.write(emptyCellStringProvider.getStringForCollapsedTD(imagesURI, cell.getWidth(), rowHeight, sizeUnit)); writer.write("</td>\n"); } /** * */ protected void exportLine(JRPrintLine line, JRExporterGridCell gridCell) throws IOException { writeCellTDStart(gridCell); StringBuffer styleBuffer = new StringBuffer(); appendBackcolorStyle(gridCell, styleBuffer); String side = null; float ratio = line.getWidth() / line.getHeight(); if (ratio > 1) { if (line.getDirection() == JRLine.DIRECTION_TOP_DOWN) { side = "top"; } else { side = "bottom"; } } else { if (line.getDirection() == JRLine.DIRECTION_TOP_DOWN) { side = "left"; } else { side = "right"; } } appendPen( styleBuffer, line.getLinePen(), side ); if (styleBuffer.length() > 0) { writer.write(" style=\""); writer.write(styleBuffer.toString()); writer.write("\""); } writer.write(">"); writer.write(emptyCellStringProvider.getStringForEmptyTD(imagesURI)); writer.write("</td>\n"); } /** * */ protected void writeCellTDStart(JRExporterGridCell gridCell) throws IOException { writer.write(" <td"); if (gridCell.getColSpan() > 1) { writer.write(" colspan=\"" + gridCell.getColSpan() +"\""); } if (gridCell.getRowSpan() > 1) { writer.write(" rowspan=\"" + gridCell.getRowSpan() + "\""); } } /** * */ protected void exportRectangle(JRPrintGraphicElement element, JRExporterGridCell gridCell) throws IOException { writeCellTDStart(gridCell); StringBuffer styleBuffer = new StringBuffer(); appendBackcolorStyle(gridCell, styleBuffer); appendPen( styleBuffer, element.getLinePen(), null ); if (styleBuffer.length() > 0) { writer.write(" style=\""); writer.write(styleBuffer.toString()); writer.write("\""); } writer.write(">"); writer.write(emptyCellStringProvider.getStringForEmptyTD(imagesURI)); writer.write("</td>\n"); } /** * */ protected void exportStyledText(JRStyledText styledText) throws IOException { String text = styledText.getText(); int runLimit = 0; AttributedCharacterIterator iterator = styledText.getAttributedString().getIterator(); while(runLimit < styledText.length() && (runLimit = iterator.getRunLimit()) <= styledText.length()) { exportStyledTextRun(iterator.getAttributes(), text.substring(iterator.getIndex(), runLimit)); iterator.setIndex(runLimit); } } /** * */ protected void exportStyledTextRun(Map attributes, String text) throws IOException { String fontFamily; String fontFamilyAttr = (String)attributes.get(TextAttribute.FAMILY); if (fontMap != null && fontMap.containsKey(fontFamilyAttr)) { fontFamily = (String) fontMap.get(fontFamilyAttr); } else { fontFamily = fontFamilyAttr; } writer.write("<span style=\"font-family: "); writer.write(fontFamily); writer.write("; "); Color forecolor = (Color)attributes.get(TextAttribute.FOREGROUND); if (!Color.black.equals(forecolor)) { writer.write("color: #"); writer.write(JRColorUtil.getColorHexa(forecolor)); writer.write("; "); } Color runBackcolor = (Color)attributes.get(TextAttribute.BACKGROUND); if (runBackcolor != null) { writer.write("background-color: #"); writer.write(JRColorUtil.getColorHexa(runBackcolor)); writer.write("; "); } writer.write("font-size: "); writer.write(String.valueOf(attributes.get(TextAttribute.SIZE))); writer.write(sizeUnit); writer.write(";"); /* if (!horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT)) { writer.write(" text-align: "); writer.write(horizontalAlignment); writer.write(";"); } */ if (TextAttribute.WEIGHT_BOLD.equals(attributes.get(TextAttribute.WEIGHT))) { writer.write(" font-weight: bold;"); } if (TextAttribute.POSTURE_OBLIQUE.equals(attributes.get(TextAttribute.POSTURE))) { writer.write(" font-style: italic;"); } if (TextAttribute.UNDERLINE_ON.equals(attributes.get(TextAttribute.UNDERLINE))) { writer.write(" text-decoration: underline;"); } if (TextAttribute.STRIKETHROUGH_ON.equals(attributes.get(TextAttribute.STRIKETHROUGH))) { writer.write(" text-decoration: line-through;"); } if (TextAttribute.SUPERSCRIPT_SUPER.equals(attributes.get(TextAttribute.SUPERSCRIPT))) { writer.write(" vertical-align: super;"); } else if (TextAttribute.SUPERSCRIPT_SUB.equals(attributes.get(TextAttribute.SUPERSCRIPT))) { writer.write(" vertical-align: sub;"); } writer.write("\">"); writer.write( JRStringUtil.htmlEncode(text) ); writer.write("</span>"); } /** * */ protected void exportText(JRPrintText text, JRExporterGridCell gridCell) throws IOException { JRStyledText styledText = getStyledText(text); int textLength = 0; if (styledText != null) { textLength = styledText.length(); } writeCellTDStart(gridCell);//FIXME why dealing with cell style if no text to print (textLength == 0)? String verticalAlignment = HTML_VERTICAL_ALIGN_TOP; switch (text.getVerticalAlignment()) { case JRAlignment.VERTICAL_ALIGN_BOTTOM : { verticalAlignment = HTML_VERTICAL_ALIGN_BOTTOM; break; } case JRAlignment.VERTICAL_ALIGN_MIDDLE : { verticalAlignment = HTML_VERTICAL_ALIGN_MIDDLE; break; } case JRAlignment.VERTICAL_ALIGN_TOP : default : { verticalAlignment = HTML_VERTICAL_ALIGN_TOP; } } if (!verticalAlignment.equals(HTML_VERTICAL_ALIGN_TOP)) { writer.write(" valign=\""); writer.write(verticalAlignment); writer.write("\""); } if (text.getRunDirection() == JRPrintText.RUN_DIRECTION_RTL) { writer.write(" dir=\"rtl\""); } StringBuffer styleBuffer = new StringBuffer(); appendBackcolorStyle(gridCell, styleBuffer); appendBorderStyle(gridCell.getBox(), styleBuffer); String horizontalAlignment = CSS_TEXT_ALIGN_LEFT; if (textLength > 0) { switch (text.getHorizontalAlignment()) { case JRAlignment.HORIZONTAL_ALIGN_RIGHT : { horizontalAlignment = CSS_TEXT_ALIGN_RIGHT; break; } case JRAlignment.HORIZONTAL_ALIGN_CENTER : { horizontalAlignment = CSS_TEXT_ALIGN_CENTER; break; } case JRAlignment.HORIZONTAL_ALIGN_JUSTIFIED : { horizontalAlignment = CSS_TEXT_ALIGN_JUSTIFY; break; } case JRAlignment.HORIZONTAL_ALIGN_LEFT : default : { horizontalAlignment = CSS_TEXT_ALIGN_LEFT; } } if ( (text.getRunDirection() == JRPrintText.RUN_DIRECTION_LTR && !horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT)) || (text.getRunDirection() == JRPrintText.RUN_DIRECTION_RTL && !horizontalAlignment.equals(CSS_TEXT_ALIGN_RIGHT)) ) { styleBuffer.append("text-align: "); styleBuffer.append(horizontalAlignment); styleBuffer.append(";"); } } if (isWrapBreakWord) { styleBuffer.append("width: " + gridCell.getWidth() + sizeUnit + "; "); styleBuffer.append("word-wrap: break-word; "); } if (text.getLineSpacing() != JRTextElement.LINE_SPACING_SINGLE) { styleBuffer.append("line-height: " + text.getLineSpacingFactor() + "; "); } if (styleBuffer.length() > 0) { writer.write(" style=\""); writer.write(styleBuffer.toString()); writer.write("\""); } writer.write(">"); if (text.getAnchorName() != null) { writer.write("<a name=\""); writer.write(text.getAnchorName()); writer.write("\"/>"); } boolean startedHyperlink = startHyperlink(text); if (textLength > 0) { exportStyledText(styledText); } else { writer.write(emptyCellStringProvider.getStringForEmptyTD(imagesURI)); } if (startedHyperlink) { endHyperlink(); } writer.write("</td>\n"); } protected boolean startHyperlink(JRPrintHyperlink link) throws IOException { String href = getHyperlinkURL(link); if (href != null) { writer.write("<a href=\""); writer.write(href); writer.write("\""); String target = getHyperlinkTarget(link); if (target != null) { writer.write(" target=\""); writer.write(target); writer.write("\""); } if (link.getHyperlinkTooltip() != null) { writer.write(" title=\""); writer.write(JRStringUtil.xmlEncode(link.getHyperlinkTooltip())); writer.write("\""); } writer.write(">"); } return href != null; } protected String getHyperlinkTarget(JRPrintHyperlink link) { String target = null; switch(link.getHyperlinkTarget()) { case JRHyperlink.HYPERLINK_TARGET_BLANK : { target = "_blank"; break; } case JRHyperlink.HYPERLINK_TARGET_PARENT : { target = "_parent"; break; } case JRHyperlink.HYPERLINK_TARGET_TOP : { target = "_top"; break; } case JRHyperlink.HYPERLINK_TARGET_SELF : default : { break; } } return target; } protected String getHyperlinkURL(JRPrintHyperlink link) { String href = null; JRHyperlinkProducer customHandler = getCustomHandler(link); if (customHandler == null) { switch(link.getHyperlinkType()) { case JRHyperlink.HYPERLINK_TYPE_REFERENCE : { if (link.getHyperlinkReference() != null) { href = link.getHyperlinkReference(); } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_ANCHOR : { if (link.getHyperlinkAnchor() != null) { href = "#" + link.getHyperlinkAnchor(); } break; } case JRHyperlink.HYPERLINK_TYPE_LOCAL_PAGE : { if (link.getHyperlinkPage() != null) { href = "#" + JR_PAGE_ANCHOR_PREFIX + reportIndex + "_" + link.getHyperlinkPage().toString(); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_ANCHOR : { if ( link.getHyperlinkReference() != null && link.getHyperlinkAnchor() != null ) { href = link.getHyperlinkReference() + "#" + link.getHyperlinkAnchor(); } break; } case JRHyperlink.HYPERLINK_TYPE_REMOTE_PAGE : { if ( link.getHyperlinkReference() != null && link.getHyperlinkPage() != null ) { href = link.getHyperlinkReference() + "#" + JR_PAGE_ANCHOR_PREFIX + "0_" + link.getHyperlinkPage().toString(); } break; } case JRHyperlink.HYPERLINK_TYPE_NONE : default : { break; } } } else { href = customHandler.getHyperlink(link); } return href; } protected JRHyperlinkProducer getCustomHandler(JRPrintHyperlink link) { return hyperlinkProducerFactory == null ? null : hyperlinkProducerFactory.getHandler(link.getLinkType()); } protected void endHyperlink() throws IOException { writer.write("</a>"); } protected boolean appendBorderStyle(JRLineBox box, StringBuffer styleBuffer) { boolean addedToStyle = false; if (box != null) { addedToStyle |= appendPen( styleBuffer, box.getTopPen(), "top" ); addedToStyle |= appendPadding( styleBuffer, box.getTopPadding(), "top" ); addedToStyle |= appendPen( styleBuffer, box.getLeftPen(), "left" ); addedToStyle |= appendPadding( styleBuffer, box.getLeftPadding(), "left" ); addedToStyle |= appendPen( styleBuffer, box.getBottomPen(), "bottom" ); addedToStyle |= appendPadding( styleBuffer, box.getBottomPadding(), "bottom" ); addedToStyle |= appendPen( styleBuffer, box.getRightPen(), "right" ); addedToStyle |= appendPadding( styleBuffer, box.getRightPadding(), "right" ); } return addedToStyle; } protected Color appendBackcolorStyle(JRExporterGridCell gridCell, StringBuffer styleBuffer) { Color cellBackcolor = gridCell.getCellBackcolor(); if (cellBackcolor != null && (backcolor == null || cellBackcolor.getRGB() != backcolor.getRGB())) { styleBuffer.append("background-color: #"); styleBuffer.append(JRColorUtil.getColorHexa(cellBackcolor)); styleBuffer.append("; "); return cellBackcolor; } return null; } /** * */ protected void exportImage(JRPrintImage image, JRExporterGridCell gridCell) throws JRException, IOException { writeCellTDStart(gridCell); String horizontalAlignment = CSS_TEXT_ALIGN_LEFT; switch (image.getHorizontalAlignment()) { case JRAlignment.HORIZONTAL_ALIGN_RIGHT : { horizontalAlignment = CSS_TEXT_ALIGN_RIGHT; break; } case JRAlignment.HORIZONTAL_ALIGN_CENTER : { horizontalAlignment = CSS_TEXT_ALIGN_CENTER; break; } case JRAlignment.HORIZONTAL_ALIGN_LEFT : default : { horizontalAlignment = CSS_TEXT_ALIGN_LEFT; } } if (!horizontalAlignment.equals(CSS_TEXT_ALIGN_LEFT)) { writer.write(" align=\""); writer.write(horizontalAlignment); writer.write("\""); } String verticalAlignment = HTML_VERTICAL_ALIGN_TOP; switch (image.getVerticalAlignment()) { case JRAlignment.VERTICAL_ALIGN_BOTTOM : { verticalAlignment = HTML_VERTICAL_ALIGN_BOTTOM; break; } case JRAlignment.VERTICAL_ALIGN_MIDDLE : { verticalAlignment = HTML_VERTICAL_ALIGN_MIDDLE; break; } case JRAlignment.VERTICAL_ALIGN_TOP : default : { verticalAlignment = HTML_VERTICAL_ALIGN_TOP; } } if (!verticalAlignment.equals(HTML_VERTICAL_ALIGN_TOP)) { writer.write(" valign=\""); writer.write(verticalAlignment); writer.write("\""); } StringBuffer styleBuffer = new StringBuffer(); appendBackcolorStyle(gridCell, styleBuffer); boolean addedToStyle = appendBorderStyle(gridCell.getBox(), styleBuffer); if (!addedToStyle) { appendPen( styleBuffer, image.getLinePen(), null ); } if (styleBuffer.length() > 0) { writer.write(" style=\""); writer.write(styleBuffer.toString()); writer.write("\""); } writer.write(">"); if (image.getAnchorName() != null) { writer.write("<a name=\""); writer.write(image.getAnchorName()); writer.write("\"/>"); } JRRenderable renderer = image.getRenderer(); JRRenderable originalRenderer = renderer; boolean imageMapRenderer = renderer != null && renderer instanceof JRImageMapRenderer && ((JRImageMapRenderer) renderer).hasImageAreaHyperlinks(); boolean startedHyperlink = false; boolean hasHyperlinks = false; if(renderer != null || isUsingImagesToAlign) { if (imageMapRenderer) { hasHyperlinks = true; } else { hasHyperlinks = startedHyperlink = startHyperlink(image); } writer.write("<img"); String imagePath = null; String imageMapName = null; List imageMapAreas = null; byte scaleImage = image.getScaleImage(); if (renderer != null) { if (renderer.getType() == JRRenderable.TYPE_IMAGE && rendererToImagePathMap.containsKey(renderer.getId())) { imagePath = (String)rendererToImagePathMap.get(renderer.getId()); } else { if (image.isLazy()) { imagePath = ((JRImageRenderer)renderer).getImageLocation(); } else { JRPrintElementIndex imageIndex = getElementIndex(gridCell); imagesToProcess.add(imageIndex); String imageName = getImageName(imageIndex); imagePath = imagesURI + imageName; //backward compatibility with the IMAGE_MAP parameter if (imageNameToImageDataMap != null) { if (renderer.getType() == JRRenderable.TYPE_SVG) { renderer = new JRWrappingSvgRenderer( renderer, new Dimension(image.getWidth(), image.getHeight()), JRElement.MODE_OPAQUE == image.getMode() ? image.getBackcolor() : null ); } imageNameToImageDataMap.put(imageName, renderer.getImageData()); } //END - backward compatibility with the IMAGE_MAP parameter } rendererToImagePathMap.put(renderer.getId(), imagePath); } if (imageMapRenderer) { Rectangle renderingArea = new Rectangle(image.getWidth(), image.getHeight()); if (renderer.getType() == JRRenderable.TYPE_IMAGE) { imageMapName = (String) imageMaps.get(new Pair(renderer.getId(), renderingArea)); } if (imageMapName == null) { imageMapName = "map_" + getElementIndex(gridCell).toString(); imageMapAreas = ((JRImageMapRenderer) originalRenderer).getImageAreaHyperlinks(renderingArea);//FIXMECHART if (renderer.getType() == JRRenderable.TYPE_IMAGE) { imageMaps.put(new Pair(renderer.getId(), renderingArea), imageMapName); } } } } else // ie: if(isUsingImagesToAlign) { loadPxImage(); imagePath = imagesURI + "px"; scaleImage = JRImage.SCALE_IMAGE_FILL_FRAME; } writer.write(" src=\""); if (imagePath != null) writer.write(imagePath); writer.write("\""); int imageWidth = image.getWidth() - image.getLineBox().getLeftPadding().intValue() - image.getLineBox().getRightPadding().intValue(); if (imageWidth < 0) { imageWidth = 0; } int imageHeight = image.getHeight() - image.getLineBox().getTopPadding().intValue() - image.getLineBox().getBottomPadding().intValue(); if (imageHeight < 0) { imageHeight = 0; } switch (scaleImage) { case JRImage.SCALE_IMAGE_FILL_FRAME : { writer.write(" style=\"width: "); writer.write(String.valueOf(imageWidth)); writer.write(sizeUnit); writer.write("; height: "); writer.write(String.valueOf(imageHeight)); writer.write(sizeUnit); writer.write("\""); break; } case JRImage.SCALE_IMAGE_CLIP : //FIXMEIMAGE image clip could be achieved by cutting the image and preserving the image type case JRImage.SCALE_IMAGE_RETAIN_SHAPE : default : { double normalWidth = imageWidth; double normalHeight = imageHeight; if (!image.isLazy()) { // Image load might fail. JRRenderable tmpRenderer = JRImageRenderer.getOnErrorRendererForDimension(renderer, image.getOnErrorType()); Dimension2D dimension = tmpRenderer == null ? null : tmpRenderer.getDimension(); // If renderer was replaced, ignore image dimension. if (tmpRenderer == renderer && dimension != null) { normalWidth = dimension.getWidth(); normalHeight = dimension.getHeight(); } } if (imageHeight > 0) { double ratio = normalWidth / normalHeight; if( ratio > (double)imageWidth / (double)imageHeight ) { writer.write(" style=\"width: "); writer.write(String.valueOf(imageWidth)); writer.write(sizeUnit); writer.write("\""); } else { writer.write(" style=\"height: "); writer.write(String.valueOf(imageHeight)); writer.write(sizeUnit); writer.write("\""); } } } } if (imageMapName != null) { writer.write(" usemap=\"#" + imageMapName + "\""); } writer.write(" alt=\"\""); if (hasHyperlinks) { writer.write(" border=\"0\""); } writer.write("/>"); if (startedHyperlink) { endHyperlink(); } if (imageMapAreas != null) { writer.write("\n"); writeImageMap(imageMapName, image, imageMapAreas); } } writer.write("</td>\n"); } protected JRPrintElementIndex getElementIndex(JRExporterGridCell gridCell) { JRPrintElementIndex imageIndex = new JRPrintElementIndex( reportIndex, pageIndex, gridCell.getWrapper().getAddress() ); return imageIndex; } protected void writeImageMap(String imageMapName, JRPrintImage image, List imageMapAreas) throws IOException { writer.write("<map name=\"" + imageMapName + "\">\n"); for (ListIterator it = imageMapAreas.listIterator(imageMapAreas.size()); it.hasPrevious();) { JRPrintImageAreaHyperlink areaHyperlink = (JRPrintImageAreaHyperlink) it.previous(); JRPrintImageArea area = areaHyperlink.getArea(); writer.write(" <area shape=\"" + JRPrintImageArea.getHtmlShape(area.getShape()) + "\""); writeImageAreaCoordinates(area.getCoordinates()); writeImageAreaHyperlink(areaHyperlink.getHyperlink()); writer.write("/>\n"); } if (image.getHyperlinkType() != JRHyperlink.HYPERLINK_TYPE_NONE) { writer.write(" <area shape=\"default\""); writeImageAreaCoordinates(new int[]{0, 0, image.getWidth(), image.getHeight()});//for IE writeImageAreaHyperlink(image); writer.write("/>\n"); } writer.write("</map>\n"); } protected void writeImageAreaCoordinates(int[] coords) throws IOException { if (coords != null && coords.length > 0) { StringBuffer coordsEnum = new StringBuffer(coords.length * 4); coordsEnum.append(coords[0]); for (int i = 1; i < coords.length; i++) { coordsEnum.append(','); coordsEnum.append(coords[i]); } writer.write(" coords=\"" + coordsEnum + "\""); } } protected void writeImageAreaHyperlink(JRPrintHyperlink hyperlink) throws IOException { String href = getHyperlinkURL(hyperlink); if (href == null) { writer.write(" nohref=\"nohref\""); } else { writer.write(" href=\"" + href + "\""); String target = getHyperlinkTarget(hyperlink); if (target != null) { writer.write(" target=\""); writer.write(target); writer.write("\""); } } if (hyperlink.getHyperlinkTooltip() != null) { writer.write(" title=\""); writer.write(JRStringUtil.xmlEncode(hyperlink.getHyperlinkTooltip())); writer.write("\""); } } /** * */ protected void loadPxImage() throws JRException { isPxImageLoaded = true; //backward compatibility with the IMAGE_MAP parameter if (imageNameToImageDataMap != null && !imageNameToImageDataMap.containsKey("px")) { JRRenderable pxRenderer = JRImageRenderer.getInstance("net/sf/jasperreports/engine/images/pixel.GIF"); rendererToImagePathMap.put(pxRenderer.getId(), imagesURI + "px"); imageNameToImageDataMap.put("px", pxRenderer.getImageData()); } //END - backward compatibility with the IMAGE_MAP parameter } /** * */ protected static interface StringProvider { /** * */ public String getStringForCollapsedTD(Object value, int width, int height, String sizeUnit); /** * */ public String getStringForEmptyTD(Object value); } /** * */ private boolean appendPadding(StringBuffer sb, Integer padding, String side) { boolean addedToStyle = false; if (padding.intValue() > 0) { sb.append("padding"); if (side != null) { sb.append("-"); sb.append(side); } sb.append(": "); sb.append(padding); sb.append(sizeUnit); sb.append("; "); addedToStyle = true; } return addedToStyle; } /** * */ private boolean appendPen(StringBuffer sb, JRPen pen, String side) { boolean addedToStyle = false; float borderWidth = pen.getLineWidth().floatValue(); if (0f < borderWidth && borderWidth < 1f) { borderWidth = 1f; } String borderStyle = null; switch (pen.getLineStyle().byteValue()) { case JRPen.LINE_STYLE_DOUBLE : { borderStyle = "double"; break; } case JRPen.LINE_STYLE_DOTTED : { borderStyle = "dotted"; break; } case JRPen.LINE_STYLE_DASHED : { borderStyle = "dashed"; break; } case JRPen.LINE_STYLE_SOLID : default : { borderStyle = "solid"; break; } } if (borderWidth > 0f) { sb.append("border"); if (side != null) { sb.append("-"); sb.append(side); } sb.append("-style: "); sb.append(borderStyle); sb.append("; "); sb.append("border"); if (side != null) { sb.append("-"); sb.append(side); } sb.append("-width: "); sb.append((int)borderWidth); sb.append(sizeUnit); sb.append("; "); sb.append("border"); if (side != null) { sb.append("-"); sb.append(side); } sb.append("-color: #"); sb.append(JRColorUtil.getColorHexa(pen.getLineColor())); sb.append("; "); addedToStyle = true; } return addedToStyle; } /** * */ public static String getImageName(JRPrintElementIndex printElementIndex) { return IMAGE_NAME_PREFIX + printElementIndex.toString(); } /** * */ public static JRPrintElementIndex getPrintElementIndex(String imageName) { if (!imageName.startsWith(IMAGE_NAME_PREFIX)) { throw new JRRuntimeException("Invalid image name: " + imageName); } return JRPrintElementIndex.parsePrintElementIndex(imageName.substring(IMAGE_NAME_PREFIX_LEGTH)); } protected void exportFrame(JRPrintFrame frame, JRExporterGridCell gridCell) throws IOException, JRException { writeCellTDStart(gridCell); StringBuffer styleBuffer = new StringBuffer(); Color frameBackcolor = appendBackcolorStyle(gridCell, styleBuffer); appendBorderStyle(gridCell.getBox(), styleBuffer); if (styleBuffer.length() > 0) { writer.write(" style=\""); writer.write(styleBuffer.toString()); writer.write("\""); } writer.write(">\n"); if (frameBackcolor != null) { setBackcolor(frameBackcolor); } try { exportGrid(gridCell.getLayout(), false); } finally { if (frameBackcolor != null) { restoreBackcolor(); } } writer.write("</td>\n"); } protected void setBackcolor(Color color) { backcolorStack.addLast(backcolor); backcolor = color; } protected void restoreBackcolor() { backcolor = (Color) backcolorStack.removeLast(); } }

The table below shows all metrics for JRHtmlExporter.java.

MetricValueDescription
BLOCKS264.00Number of blocks
BLOCK_COMMENT47.00Number of block comment lines
COMMENTS153.00Comment lines
COMMENT_DENSITY 0.15Comment density
COMPARISONS185.00Number of comparison operators
CYCLOMATIC261.00Cyclomatic complexity
DECL_COMMENTS30.00Comments in declarations
DOC_COMMENT91.00Number of javadoc comment lines
ELOC1036.00Effective lines of code
EXEC_COMMENTS17.00Comments in executable code
EXITS188.00Procedure exits
FUNCTIONS43.00Number of function declarations
HALSTEAD_DIFFICULTY121.54Halstead difficulty
HALSTEAD_EFFORT 0.00Halstead effort
INTERFACE_COMPLEXITY325.00Interface complexity
JAVA0001 0.00JAVA0001 Package name does not contain only lower case letters
JAVA0002 0.00JAVA0002 Package name does not begin with a top level domain name or country code
JAVA0003 0.00JAVA0003 Minimize use of on-demand (.*) imports
JAVA0004 0.00JAVA0004 Unnecessary import from java.lang
JAVA0005 0.00JAVA0005 Imports not in specified order
JAVA0006 0.00JAVA0006 Empty finally block
JAVA0007 0.00JAVA0007 Should not declare public field
JAVA0008 0.00JAVA0008 Empty catch block
JAVA0009 0.00JAVA0009 Protected member in final class
JAVA0010 0.00JAVA0010 Non-instantiable class does not contain a non-private static member
JAVA0011 0.00JAVA0011 Abstract class does not contain an abstract method
JAVA0012 0.00JAVA0012 Non-constructor method with same name as declaring class
JAVA0013 0.00JAVA0013 Non-blank final field is not static
JAVA0014 0.00JAVA0014 Class with only static members has non-private constructor
JAVA0015 0.00JAVA0015 Package class contains public nested type
JAVA0016 0.00JAVA0016 Abstract class contains public constructor
JAVA0017 0.00JAVA0017 Class name does not have required form
JAVA0018 0.00JAVA0018 Method name does not have required form
JAVA0019 0.00JAVA0019 Interface name does not have required form
JAVA0020 0.00JAVA0020 Field name does not have required form
JAVA0021 0.00JAVA0021 Interface method name does not have required form
JAVA0022 0.00JAVA0022 Static final field name does not have required form
JAVA0023 0.00JAVA0023 Empty finalize method
JAVA0024 0.00JAVA0024 Empty class
JAVA0025 0.00JAVA0025 Method override is empty
JAVA0026 0.00JAVA0026 Finalize method with parameters
JAVA0029 0.00JAVA0029 Private method not used
JAVA0030 0.00JAVA0030 Private field not used
JAVA0031 5.00JAVA0031 Case statement not properly closed
JAVA0032 0.00JAVA0032 Switch statement missing default
JAVA0033 0.00JAVA0033 default: not last case in switch statement
JAVA0034 1.00JAVA0034 Missing braces in if statement
JAVA0035 0.00JAVA0035 Missing braces in for statement
JAVA0036 0.00JAVA0036 Missing braces in while statement
JAVA0038 0.00JAVA0038 Non-case label in switch statement
JAVA0039 0.00JAVA0039 Break statement with label
JAVA0040 0.00JAVA0040 Switch statement contains N cases (maximum: M)
JAVA0041 0.00JAVA0041 Nested synchronized block
JAVA0042 0.00JAVA0042 Empty synchronized statement
JAVA0043 0.00JAVA0043 Inner class does not use outer class
JAVA0044 0.00JAVA0044 Serializable class with no instance variables
JAVA0045 0.00JAVA0045 Serializable class with only transient fields
JAVA0046 0.00JAVA0046 Name of class not derived from Exception ends with 'Exception'
JAVA0047 0.00JAVA0047 Serializable class derives from invalid base class
JAVA0048 0.00JAVA0048 Name of class derived from Exception does not end with 'Exception'
JAVA004930.00JAVA0049 Nested block at depth N (maximum: M)
JAVA0050 0.00JAVA0050 Class derives from java.lang.Error
JAVA0051 0.00JAVA0051 Class derives from java.lang.RuntimeException
JAVA0052 0.00JAVA0052 Class derives from java.lang.Throwable
JAVA0053 0.00JAVA0053 Unused label
JAVA0054 0.00JAVA0054 Inheritance depth N exceeds maximum M
JAVA0055 0.00JAVA0055 Class should be interface
JAVA0056 0.00JAVA0056 Unnecessary abstract modifier for interface or annotation
JAVA0057 0.00JAVA0057 Unnecessary default constructor
JAVA0058 0.00JAVA0058 Constructor calls super()
JAVA0059 0.00JAVA0059 Method override only calls super()
JAVA0061 0.00JAVA0061 Inaccessible member in anonymous class
JAVA0062 0.00JAVA0062 Public class missing public member or protected constructor
JAVA0063 0.00JAVA0063 Identifier name should not contain '$'
JAVA0064 0.00JAVA0064 N variations of identifier name (maximum: M)
JAVA0065 0.00JAVA0065 Unnecessary final modifier for method in final class
JAVA0066 0.00JAVA0066 Unnecessary modifier for interface nested type
JAVA0067 0.00JAVA0067 Array descriptor on identifier name
JAVA0068 0.00JAVA0068 Modifiers not declared in recommended order
JAVA0071 0.00JAVA0071 Strings compared with ==
JAVA0073 1.00JAVA0073 Integer division in floating-point context
JAVA0074 0.00JAVA0074 Use of Object.notify()
JAVA0075 2.00JAVA0075 Method parameter hides field
JAVA0076 0.00JAVA0076 Use of magic number
JAVA0077 0.00JAVA0077 Private field not used in declaring class
JAVA0078 0.00JAVA0078 Floating point values compared with ==
JAVA0079 0.00JAVA0079 Use of instance to reference static member
JAVA0080 0.00JAVA0080 Import declaration not used
JAVA0081 0.00JAVA0081 Boolean literal in comparison
JAVA0082 0.00JAVA0082 Unnecessary widening cast
JAVA0083 0.00JAVA0083 Unnecessary instanceof test
JAVA0084 0.00JAVA0084 Should use compound assignment operator
JAVA0085 0.00JAVA0085 Use of sun.* class
JAVA0087 0.00JAVA0087 Use of Thread.sleep()
JAVA0089 0.00JAVA0089 Use of restricted package
JAVA0092 0.00JAVA0092 Use of restricted type
JAVA0093 0.00JAVA0093 Redundant assignment
JAVA0094 0.00JAVA0094 Field hides a superclass field
JAVA0095 0.00JAVA0095 Uninitialized private field
JAVA0096 0.00JAVA0096 Field in nested class hides outer field
JAVA0098 0.00JAVA0098 Minimize use of implicit field initializers
JAVA0100 1.00JAVA0100 Class contains N non-final fields (maximum: M)
JAVA0101 0.00JAVA0101 Unnecessary modifier for field in interface
JAVA0102 0.00JAVA0102 Last statement in finalize() not super.finalize()
JAVA0103 0.00JAVA0103 Explicit call to finalize()
JAVA0104 0.00JAVA0104 finalize() only calls super.finalize()
JAVA0105 0.00JAVA0105 Duplicate import declaration
JAVA0106 0.00JAVA0106 Unnecessary import from current package
JAVA010828.00JAVA0108 Incorrect javadoc: no @param tag for 'parameter'
JAVA0109 0.00JAVA0109 Incorrect javadoc: no parameter 'parameter'
JAVA0110 6.00JAVA0110 Incorrect javadoc: no @return tag
JAVA0111 0.00JAVA0111 Incorrect javadoc: @return tag for void method
JAVA0112 0.00JAVA0112 Incorrect javadoc: no exception 'exception' in throws
JAVA0113 0.00JAVA0113 Incorrect javadoc: no @author tag
JAVA0114 0.00JAVA0114 Incorrect javadoc: no @version tag
JAVA011516.00JAVA0115 Incorrect javadoc: no @throws or @exception tag for 'exception'
JAVA0116 1.00JAVA0116 Missing javadoc: field 'field'
JAVA011720.00JAVA0117 Missing javadoc: method 'method'
JAVA0118 0.00JAVA0118 Missing javadoc: type 'type'
JAVA0119 1.00JAVA0119 Control variable changed within body of for loop
JAVA0123 1.00JAVA0123 Use all three components of for loop
JAVA0125 0.00JAVA0125 Continue statement with label
JAVA0126 0.00JAVA0126 Method declares unchecked exception in throws
JAVA0128 0.00JAVA0128 Public constructor in non-public class
JAVA0130 1.00JAVA0130 Non-static method does not use instance fields
JAVA0131 0.00JAVA0131 Compatible method does not override base
JAVA0132 0.00JAVA0132 Method overload with compatible signature
JAVA0133 0.00JAVA0133 Non-synchronized method overrides synchronized method
JAVA0135 0.00JAVA0135 Only one of Object.equals and Object.hashCode defined: missing 'method'
JAVA0136 1.00JAVA0136 N methods defined in class (maximum: M)
JAVA0137 0.00JAVA0137 Non-abstract class missing constructor
JAVA0138 0.00JAVA0138 N parameters defined for method (maximum: M)
JAVA0139 0.00JAVA0139 Definition of main other than public static void main(java.lang.String[])
JAVA0141 2.00JAVA0141 Unnecessary modifier for method in interface
JAVA0143 0.00JAVA0143 Synchronized method
JAVA0144 7.00JAVA0144 Line exceeds maximum M characters
JAVA01455693.00JAVA0145 Tab character used in source file
JAVA0150 0.00JAVA0150 java.lang.Error (or subclass) thrown
JAVA0153 0.00JAVA0153 Inefficient conversion of integer to string
JAVA0159 0.00JAVA0159 Inefficient conversion of string to integer
JAVA0160 0.00JAVA0160 Method does not throw specified exception
JAVA0161 0.00JAVA0161 Conditional wait() not in loop
JAVA0163 0.00JAVA0163 Empty statement
JAVA0165 0.00JAVA0165 Conflicting return statement in finally block
JAVA0166 0.00JAVA0166 Generic exception caught
JAVA0167 0.00JAVA0167 ThreadDeath not rethrown
JAVA0169 0.00JAVA0169 Unnecessary catch block: exception 'exception'
JAVA0170 0.00JAVA0170 Caught exception not derived from java.lang.Exception
JAVA0171 0.00JAVA0171 Unused local variable
JAVA0173 1.00JAVA0173 Unused method parameter
JAVA0174 0.00JAVA0174 Assigned local variable never used
JAVA0175 0.00JAVA0175 Successive assignment to variable
JAVA0176 0.00JAVA0176 Local variable name does not have required form
JAVA0177 2.00JAVA0177 Variable declaration missing initializer
JAVA0179 0.00JAVA0179 Local variable hides visible field
JAVA0233 0.00JAVA0233 Definition of serialVersionUID other than 'private static final long serialVersionUID'
JAVA0234 0.00JAVA0234 Class is Serializable but does not define serialVersionUID
JAVA0235 0.00JAVA0235 Class defines serialVersionUID but does not implement Serializable
JAVA0236 0.00JAVA0236 Attempt to clone an object which does not implement Cloneable
JAVA0237 0.00JAVA0237 Class implements Cloneable but does not have public clone method
JAVA0238 0.00JAVA0238 Clone method does not call super.clone()
JAVA0239 0.00JAVA0239 Class declares 'readObject' or 'writeObject' but does not implement Serializable
JAVA0240 0.00JAVA0240 Serializable class which declares readObject or writeObject but not both
JAVA0241 0.00JAVA0241 'readObject' or 'writeObject' should be declared private in Serializable class
JAVA0242 0.00JAVA0242 Transient field in non-Serializable class
JAVA0243 0.00JAVA0243 'readResolve' or 'writeReplace' should be declared private or protected
JAVA0244 0.00JAVA0244 Field or method name in subclass differs only by case from inherited field or method
JAVA0245 0.00JAVA0245 JUnit TestCase with non-trivial constructor
JAVA0246 0.00JAVA0246 JUnit assertXXX statement missing message parameter
JAVA0247 0.00JAVA0247 JUnit 'setUp()' and 'tearDown()' should call super method
JAVA0248 0.00JAVA0248 JUnit method 'setUp' or 'tearDown' with incorrect signature
JAVA0249 0.00JAVA0249 JUnit TestCase 'suite()' should be declared static
JAVA0250 0.00JAVA0250 JUnit TestCase declares testXXX method with incorrect signature
JAVA0251 0.00JAVA0251 Use '%n' for line breaks in printf/format for platform independence
JAVA0252 0.00JAVA0252 'enum' is a Java 1.5 reserved word
JAVA0253 0.00JAVA0253 Not all enum constants consumed in switch statement
JAVA0254 1.00JAVA0254 Use enhanced for loop construct instead of Iterator
JAVA0255 0.00JAVA0255 Result of method invocation not used
JAVA0256 0.00JAVA0256 Assignment of external collection/array to field
JAVA0257 0.00JAVA0257 Use of 'Constant Interface' anti-pattern
JAVA0258 0.00JAVA0258 Implement Iterable for foreach compatibility
JAVA0259 0.00JAVA0259 Return of collection/array field
JAVA0260 0.00JAVA0260 Use 'enum' instead of Enumerated Type pattern
JAVA0261 0.00JAVA0261 Use specialized Enum collection types
JAVA0262 0.00JAVA0262 Use of char in integer context
JAVA0263 0.00JAVA0263 Long literal ends with 'l' instead of 'L'
JAVA0264 0.00JAVA0264 Integer math in long context - check for overflow
JAVA0265 0.00JAVA0265 Use of Throwable.printStackTrace()
JAVA0266 0.00JAVA0266 Use of System.out
JAVA0267 0.00JAVA0267 Use of System.err
JAVA0269 0.00JAVA0269 Contents of StringBuffer never used
JAVA0270 0.00JAVA0270 Use Java 5.0 enhanced for loop construct to iterate over all elements in an array
JAVA0271 0.00JAVA0271 Minimize use of on-demand (.*) static imports
JAVA0272 0.00JAVA0272 Thread.run() called
JAVA0273 0.00JAVA0273 Non-final derivative of Thread calls start() in constructor
JAVA0274 0.00JAVA0274 Serializable class has a synchronized readObject()
JAVA0275 0.00JAVA0275 Serializable class has a synchronized writeObject() and no other synchronized methods
JAVA0276 0.00JAVA0276 Unnecessary use of String constructor