Example usage for org.apache.poi.hssf.usermodel HSSFSheet getPhysicalNumberOfRows

List of usage examples for org.apache.poi.hssf.usermodel HSSFSheet getPhysicalNumberOfRows

Introduction

In this page you can find the example usage for org.apache.poi.hssf.usermodel HSSFSheet getPhysicalNumberOfRows.

Prototype

@Override
public int getPhysicalNumberOfRows() 

Source Link

Document

Returns the number of physically defined rows (NOT the number of rows in the sheet)

Usage

From source file:org.sourcecodemetrics.report.generators.ClassGenerator.java

License:Open Source License

public static void generate(IClass c, HSSFSheet worksheet, HSSFWorkbook workbook) {
    int startRow = worksheet.getPhysicalNumberOfRows();

    HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

    // clearing the package level
    HSSFCell cell = row.createCell(0);//from w  w w .j  a va  2  s  .com
    cell.setCellStyle(ReportGeneratorImpl.getWhiteStyle());

    // writing dashes to the invalid metrics
    for (int i = 2; i < ReportGeneratorImpl.headings.size(); i++) {
        HSSFCell ce = row.createCell(i);
        ce.setCellStyle(ReportGeneratorImpl.getDottedYellowStyle());
    }

    // writing the name
    cell = row.createCell(1);
    cell.setCellStyle(ReportGeneratorImpl.getYellowStyle());
    cell.setCellValue(c.getName());

    // writing the metrics
    int colIdx = ReportGeneratorImpl.headings.indexOf("C");
    cell = row.createCell(colIdx);
    cell.setCellStyle(
            c.getC() ? ReportGeneratorImpl.getYellowStyle() : ReportGeneratorImpl.getRedYellowStyle());
    cell.setCellValue(c.getC() ? "yes" : "no");

    colIdx = ReportGeneratorImpl.headings.indexOf("LCC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LCC", "class", (double) c.getLCC());
    cell.setCellValue(c.getLCC());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM1");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LCOM1", "class", (double) c.getLCOM1());
    cell.setCellValue(c.getLCOM1());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM2");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LCOM2", "class", (double) c.getLCOM2());
    cell.setCellValue(c.getLCOM2());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM3");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LCOM3", "class", (double) c.getLCOM3());
    cell.setCellValue(c.getLCOM3());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM4");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LCOM4", "class", (double) c.getLCOM4());
    cell.setCellValue(c.getLCOM4());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM5");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LCOM5", "class", (double) c.getLCOM5());
    cell.setCellValue(c.getLCOM5());

    colIdx = ReportGeneratorImpl.headings.indexOf("NAK");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NAK", "class", (double) c.getNAK());
    cell.setCellValue(c.getNAK());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOF");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOF", "class", (double) c.getNOF());
    cell.setCellValue(c.getNOF());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOM");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOM", "class", (double) c.getNOM());
    cell.setCellValue(c.getNOM());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOSF");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOSF", "class", (double) c.getNOSF());
    cell.setCellValue(c.getNOSF());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOSM");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOSM", "class", (double) c.getNOSM());
    cell.setCellValue(c.getNOSM());

    colIdx = ReportGeneratorImpl.headings.indexOf("NTM");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NTM", "class", (double) c.getNTM());
    cell.setCellValue(c.getNTM());

    colIdx = ReportGeneratorImpl.headings.indexOf("TCC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "TCC", "class", (double) c.getTCC());
    cell.setCellValue(c.getTCC());

    colIdx = ReportGeneratorImpl.headings.indexOf("WMC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "WMC", "class", (double) c.getWMC());
    cell.setCellValue(c.getWMC());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOC", "class", (double) c.getNOC());
    cell.setCellValue(c.getNOC());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOC", "class", (double) c.getLOC());
    cell.setCellValue(c.getLOC());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCm");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCm", "class", (double) c.getLOCm());
    cell.setCellValue(c.getLOCm());

    // method metrics
    colIdx = ReportGeneratorImpl.headings.indexOf("VG");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "VG", "method", (double) c.getMethodVGAvg());
    cell.setCellValue(c.getMethodVGAvg());

    colIdx = ReportGeneratorImpl.headings.indexOf("NBD");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NBD", "method", (double) c.getMethodNBDAvg());
    cell.setCellValue(c.getMethodNBDAvg());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOP");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOP", "method", (double) c.getMethodNOPSum());
    cell.setCellValue(c.getMethodNOPSum());

    if (c.getMethods().size() > 0) {
        worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    }

    // generate all of the methods
    for (Iterator<IMethod> it = c.getMethods().iterator(); it.hasNext();) {
        IMethod im = it.next();
        MethodGenerator.generate(im, worksheet, workbook);

        if (it.hasNext()) {
            worksheet.createRow(worksheet.getPhysicalNumberOfRows());
        }
    }
    ReportGeneratorImpl.appendEmptyRow(worksheet);

    int endRow = startRow + c.getMethods().size();
    worksheet.groupRow(startRow, endRow);
}

From source file:org.sourcecodemetrics.report.generators.MethodGenerator.java

License:Open Source License

public static void generate(IMethod m, HSSFSheet worksheet, HSSFWorkbook workbook) {
    HSSFRow row = worksheet.getRow(worksheet.getPhysicalNumberOfRows() - 1);

    // clearing the package level
    HSSFCell cell = row.createCell(0);/*from   ww w  .j  a  va2 s .  co m*/
    cell.setCellStyle(ReportGeneratorImpl.getWhiteStyle());

    // clearing the class level
    cell = row.createCell(1);
    cell.setCellStyle(ReportGeneratorImpl.getWhiteStyle());

    // writing dashes to the invalid metrics
    for (int i = 3; i < ReportGeneratorImpl.headings.size(); i++) {
        HSSFCell ce = row.createCell(i);
        ce.setCellStyle(ReportGeneratorImpl.getDottedStyle());
    }

    // name of the method
    cell = row.createCell(2);
    cell.setCellStyle(ReportGeneratorImpl.getWhiteStyle());
    cell.setCellValue(m.getName());

    // writing the metrics
    int colIdx = ReportGeneratorImpl.headings.indexOf("VG");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "VG", "method", (double) m.getVG());
    cell.setCellValue(m.getVG());

    colIdx = ReportGeneratorImpl.headings.indexOf("NBD");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NBD", "method", (double) m.getNBD());
    cell.setCellValue(m.getNBD());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOP");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOP", "method", (double) m.getNOP());
    cell.setCellValue(m.getNOP());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOC", "method", (double) m.getLOC());
    cell.setCellValue(m.getLOC());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCm");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCm", "method", (double) m.getLOCm());
    cell.setCellValue(m.getLOCm());
}

From source file:org.sourcecodemetrics.report.generators.PackageGenerator.java

License:Open Source License

public static void generate(IPackage p, HSSFSheet worksheet, HSSFWorkbook workbook) {
    int startRow = worksheet.getPhysicalNumberOfRows();

    HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

    // writing the name of the package
    HSSFCell cell = row.createCell(0);//w ww . j  a  v a  2 s  .  c  om
    cell.setCellValue(p.getName());
    cell.setCellStyle(ReportGeneratorImpl.getBlueStyle());

    for (int i = 1; i < ReportGeneratorImpl.headings.size(); i++) {
        HSSFCell c = row.createCell(i);
        c.setCellValue("");
        c.setCellStyle(ReportGeneratorImpl.getDottedBlueStyle());
    }

    int colIdx = ReportGeneratorImpl.headings.indexOf("NCP");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NCP", "package", (double) p.getNCP());
    cell.setCellValue(p.getNCP());

    colIdx = ReportGeneratorImpl.headings.indexOf("NIP");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NIP", "package", (double) p.getNIP());
    cell.setCellValue(p.getNIP());

    colIdx = ReportGeneratorImpl.headings.indexOf("A");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "A", "package", (double) p.getA());
    cell.setCellValue(p.getA());

    colIdx = ReportGeneratorImpl.headings.indexOf("EC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "EC", "package", (double) p.getEC());
    cell.setCellValue(p.getEC());

    colIdx = ReportGeneratorImpl.headings.indexOf("AC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "AC", "package", (double) p.getAC());
    cell.setCellValue(p.getAC());

    colIdx = ReportGeneratorImpl.headings.indexOf("I");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "I", "package", (double) p.getI());
    cell.setCellValue(p.getI());

    colIdx = ReportGeneratorImpl.headings.indexOf("D");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "D", "package", (double) p.getD());
    cell.setCellValue(p.getD());

    colIdx = ReportGeneratorImpl.headings.indexOf("C");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "C", "package", (double) p.getC());
    cell.setCellValue(p.getC());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOC", "package", (double) p.getLOC());
    cell.setCellValue(p.getLOC());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCm");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCm", "package", (double) p.getLOCm());
    cell.setCellValue(p.getLOCm());

    // class metrics 
    colIdx = ReportGeneratorImpl.headings.indexOf("LCC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LCC", "class", (double) p.getClassLCCAvg());
    cell.setCellValue(p.getClassLCCAvg());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM1");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCM1", "class", (double) p.getClassLCOM1Avg());
    cell.setCellValue(p.getClassLCOM1Avg());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM2");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCM2", "class", (double) p.getClassLCOM2Avg());
    cell.setCellValue(p.getClassLCOM2Avg());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM3");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCM3", "class", (double) p.getClassLCOM3Avg());
    cell.setCellValue(p.getClassLCOM3Avg());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM4");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCM4", "class", (double) p.getClassLCOM4Avg());
    cell.setCellValue(p.getClassLCOM4Avg());

    colIdx = ReportGeneratorImpl.headings.indexOf("LOCM5");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "LOCM5", "class", (double) p.getClassLCOM5Avg());
    cell.setCellValue(p.getClassLCOM5Avg());

    colIdx = ReportGeneratorImpl.headings.indexOf("NAK");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NAK", "class", (double) p.getClassNAKAvg());
    cell.setCellValue(p.getClassNAKAvg());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOF");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOF", "class", (double) p.getClassNOFSum());
    cell.setCellValue(p.getClassNOFSum());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOM");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOM", "class", (double) p.getClassNOMSum());
    cell.setCellValue(p.getClassNOMSum());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOSF");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOSF", "class", (double) p.getClassNOSFSum());
    cell.setCellValue(p.getClassNOSFSum());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOSM");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOSM", "class", (double) p.getClassNOSMSum());
    cell.setCellValue(p.getClassNOSMSum());

    colIdx = ReportGeneratorImpl.headings.indexOf("NTM");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NTM", "class", (double) p.getClassNTMSum());
    cell.setCellValue(p.getClassNTMSum());

    colIdx = ReportGeneratorImpl.headings.indexOf("TCC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "TCC", "class", (double) p.getClassTCCAvg());
    cell.setCellValue(p.getClassTCCAvg());

    colIdx = ReportGeneratorImpl.headings.indexOf("WMC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "WMC", "class", (double) p.getClassWMCSum());
    cell.setCellValue(p.getClassWMCSum());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOC");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOC", "class", (double) p.getClassNOCSum());
    cell.setCellValue(p.getClassNOCSum());

    // method metrics
    colIdx = ReportGeneratorImpl.headings.indexOf("VG");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "VG", "method", (double) p.getMethodVGAvg());
    cell.setCellValue(p.getMethodVGAvg());

    colIdx = ReportGeneratorImpl.headings.indexOf("NBD");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NBD", "method", (double) p.getMethodNBDAvg());
    cell.setCellValue(p.getMethodNBDAvg());

    colIdx = ReportGeneratorImpl.headings.indexOf("NOP");
    cell = row.createCell(colIdx);
    setCellStyle(cell, "NOP", "method", (double) p.getMethodNOPSum());
    cell.setCellValue(p.getMethodNOPSum());

    // generation of all of the classes
    for (ISourceFile isf : p.getSourceFiles()) {
        for (IClass ic : isf.getClasses()) {
            ClassGenerator.generate(ic, worksheet, workbook);
        }
    }
    ReportGeneratorImpl.appendEmptyRow(worksheet);

    int endRow = worksheet.getPhysicalNumberOfRows() - 2;
    worksheet.groupRow(startRow, endRow);
}

From source file:org.sourcecodemetrics.report.generators.RawDataGenerator.java

License:Open Source License

private static void generatePackages(IProject project, HSSFWorkbook workbook) throws IntrospectionException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException, NoSuchMethodException {
    HSSFSheet worksheet = workbook.createSheet("Raw package metrics");

    // generation of header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    for (int i = 0; i < packageMetrics.size(); i++) {
        String title = packageMetrics.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);/*from   w  w w. ja  va  2s  .  c  o  m*/
    }

    // generation of package metrics
    for (IPackage pkg : project.getPackages()) {
        if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {

            HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

            // writing out the name of the package
            HSSFCell nameCell = row.createCell(0);
            nameCell.setCellValue(pkg.getName());

            for (int i = 1; i < packageMetrics.size(); i++) {

                String propertyName = packageMetrics.get(i);
                Method getter = pkg.getClass().getMethod("get" + propertyName);
                Object metricValue = getter.invoke(pkg);

                HSSFCell cell = row.createCell(i);

                if (metricValue instanceof Integer) {
                    cell.setCellValue((Integer) metricValue);
                } else if (metricValue instanceof Double) {
                    cell.setCellValue((Double) metricValue);
                } else if (metricValue instanceof String) {
                    cell.setCellValue((String) metricValue);
                }
            }
        }
    }

    // autosizing the main column
    worksheet.autoSizeColumn(0);
}

From source file:org.sourcecodemetrics.report.generators.RawDataGenerator.java

License:Open Source License

private static void generateClasses(IProject project, HSSFWorkbook workbook) throws NoSuchMethodException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    HSSFSheet worksheet = workbook.createSheet("Raw class metrics");

    // generation of header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    for (int i = 0; i < classMetrics.size(); i++) {
        String title = classMetrics.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);/*from   w  w w  .j a v a 2  s .  c  o m*/
    }

    // generation of class metrics
    for (IPackage pkg : project.getPackages()) {
        if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {
            for (ISourceFile sf : pkg.getSourceFiles()) {
                for (IClass c : sf.getClasses()) {
                    HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

                    // writing out the name of the package
                    HSSFCell packageCell = row.createCell(0);
                    packageCell.setCellValue(pkg.getName());

                    // writing out the name of the class
                    HSSFCell classCell = row.createCell(1);
                    classCell.setCellValue(c.getName());

                    // writing values of the metrics
                    for (int i = 2; i < classMetrics.size(); i++) {
                        String propertyName = classMetrics.get(i);
                        Method getter = c.getClass().getMethod("get" + propertyName);
                        Object metricValue = getter.invoke(c);

                        HSSFCell cell = row.createCell(i);

                        if (metricValue instanceof Integer) {
                            cell.setCellValue((Integer) metricValue);
                        } else if (metricValue instanceof Double) {
                            cell.setCellValue((Double) metricValue);
                        } else if (metricValue instanceof String) {
                            cell.setCellValue((String) metricValue);
                        } else if (metricValue instanceof Boolean) {
                            Boolean value = (Boolean) metricValue;
                            cell.setCellValue(value ? 1 : 0);
                        }
                    }
                }
            }
        }
    }

    // autosizing the main columns
    for (int i = 0; i < 2; i++) {
        worksheet.autoSizeColumn(i);
    }
}

From source file:org.sourcecodemetrics.report.generators.RawDataGenerator.java

License:Open Source License

private static void generateMethods(IProject project, HSSFWorkbook workbook) throws NoSuchMethodException,
        IllegalAccessException, IllegalArgumentException, InvocationTargetException {
    HSSFSheet worksheet = workbook.createSheet("Raw method metrics");

    // generation of header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    for (int i = 0; i < methodMetrics.size(); i++) {
        String title = methodMetrics.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);/*w w w.  j a v a  2  s .co m*/
    }

    // generation of method metrics
    for (IPackage pkg : project.getPackages()) {
        if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {
            if (!pkg.isTests() && !pkg.getSourceFiles().isEmpty()) {
                for (ISourceFile sf : pkg.getSourceFiles()) {
                    for (IClass c : sf.getClasses()) {
                        for (IMethod m : c.getMethods()) {
                            HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

                            // writing out the name of the package
                            HSSFCell packageCell = row.createCell(0);
                            packageCell.setCellValue(pkg.getName());

                            // writing out the name of the class
                            HSSFCell classCell = row.createCell(1);
                            classCell.setCellValue(c.getName());

                            // writing out the name of the method
                            HSSFCell methodCell = row.createCell(2);
                            methodCell.setCellValue(m.getName());

                            for (int i = 3; i < methodMetrics.size(); i++) {
                                String propertyName = methodMetrics.get(i);
                                Method getter = m.getClass().getMethod("get" + propertyName);
                                Object metricValue = getter.invoke(m);

                                HSSFCell cell = row.createCell(i);

                                if (metricValue instanceof Integer) {
                                    cell.setCellValue((Integer) metricValue);
                                } else if (metricValue instanceof Double) {
                                    cell.setCellValue((Double) metricValue);
                                } else if (metricValue instanceof String) {
                                    cell.setCellValue((String) metricValue);
                                }
                            }
                        }
                    }
                }
            }
        }
    }

    // autosizing the main columns
    for (int i = 0; i < 3; i++) {
        worksheet.autoSizeColumn(i);
    }
}

From source file:org.sourcecodemetrics.report.generators.ReportGeneratorImpl.java

License:Open Source License

@Override
public void generateReport(IProject project, String filePath) {
    try {//  w w w .  j  av  a 2s .co m
        FileOutputStream fileOut = new FileOutputStream(filePath);
        HSSFWorkbook workbook = new HSSFWorkbook();
        HSSFSheet worksheet = workbook.createSheet("Source Code Metrics");

        // creation of the header row
        whiteStyle = workbook.createCellStyle();
        whiteStyle.setFillForegroundColor(HSSFColor.WHITE.index);
        whiteStyle.setFillBackgroundColor(HSSFColor.WHITE.index);
        whiteStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        dottedBlueStyle = workbook.createCellStyle();
        dottedBlueStyle.setFillForegroundColor(HSSFColor.BLACK.index);
        dottedBlueStyle.setFillBackgroundColor(HSSFColor.AQUA.index);
        dottedBlueStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);

        blueStyle = workbook.createCellStyle();
        blueStyle.setFillForegroundColor(HSSFColor.AQUA.index);
        blueStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        HSSFFont font = workbook.createFont();
        font.setColor(HSSFColor.RED.index);
        redBlueStyle = workbook.createCellStyle();
        redBlueStyle.setFillForegroundColor(HSSFColor.AQUA.index);
        redBlueStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        redBlueStyle.setFont(font);

        dottedYellowStyle = workbook.createCellStyle();
        dottedYellowStyle.setFillForegroundColor(HSSFColor.BLACK.index);
        dottedYellowStyle.setFillBackgroundColor(HSSFColor.YELLOW.index);
        dottedYellowStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);

        yellowStyle = workbook.createCellStyle();
        yellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
        yellowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);

        redYellowStyle = workbook.createCellStyle();
        redYellowStyle.setFillForegroundColor(HSSFColor.YELLOW.index);
        redYellowStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        redYellowStyle.setFont(font);

        dottedStyle = workbook.createCellStyle();
        dottedStyle.setFillForegroundColor(HSSFColor.BLACK.index);
        dottedStyle.setFillBackgroundColor(HSSFColor.WHITE.index);
        dottedStyle.setFillPattern(HSSFCellStyle.SPARSE_DOTS);

        redWhiteStyle = workbook.createCellStyle();
        redWhiteStyle.setFillForegroundColor(HSSFColor.WHITE.index);
        redWhiteStyle.setFillBackgroundColor(HSSFColor.WHITE.index);
        redWhiteStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
        redWhiteStyle.setFont(font);

        HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
        for (int i = 0; i < headings.size(); i++) {
            String title = headings.get(i);
            HSSFCell cell = headerRow.createCell(i);
            cell.setCellValue(title);
            cell.setCellStyle(whiteStyle);
        }

        for (IPackage ip : project.getPackages()) {
            if (!ip.isTests() && !ip.getSourceFiles().isEmpty()) {
                PackageGenerator.generate(ip, worksheet, workbook);
            }
        }

        // adjusting first three columns
        try {
            for (int i = 0; i < 3; i++) {
                worksheet.autoSizeColumn(i);
            }
        } catch (ArrayIndexOutOfBoundsException e) {
            logger.log(Level.SEVERE, "Exception when trying to adjust columns", e);
        }

        // setting constant width to other columns
        for (int i = 3; i < headings.size(); i++) {
            worksheet.setColumnWidth(i, 2000);
        }

        // writing out the statistics to the report
        StatisticsGenerator.generateStatistics(project, workbook);

        // writing the raw data to the report
        RawDataGenerator.generateRawData(project, workbook);

        worksheet.createFreezePane(3, 1);

        workbook.write(fileOut);
        fileOut.flush();
        fileOut.close();
    } catch (FileNotFoundException ex) {
        Exceptions.printStackTrace(ex);
    } catch (IOException ex) {
        Exceptions.printStackTrace(ex);
    } catch (Exception ex) {
        Exceptions.printStackTrace(ex);
    }
}

From source file:org.sourcecodemetrics.report.generators.ReportGeneratorImpl.java

License:Open Source License

public static void appendEmptyRow(HSSFSheet worksheet) {
    HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());

    for (int i = 0; i < ReportGeneratorImpl.headings.size(); i++) {
        HSSFCell c = row.createCell(i);/*from   www . j  av  a2s. c om*/
        c.setCellStyle(whiteStyle);
    }
}

From source file:org.sourcecodemetrics.report.generators.StatisticsGenerator.java

License:Open Source License

public static void generateStatistics(IProject project, HSSFWorkbook workbook) {

    if (blueStyle == null) {
        blueStyle = workbook.createCellStyle();
        blueStyle.setFillForegroundColor(HSSFColor.AQUA.index);
        blueStyle.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
    }/*from   ww  w.  ja v  a 2  s  .  c  o m*/

    HSSFSheet worksheet = workbook.createSheet("Statistics");

    // creation of the header row
    HSSFRow headerRow = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    HSSFFont font = workbook.createFont();
    font.setColor(HSSFColor.WHITE.index);
    for (int i = 0; i < headings.size(); i++) {
        String title = headings.get(i);
        HSSFCell cell = headerRow.createCell(i);
        cell.setCellValue(title);
        cell.setCellStyle(blueStyle);
    }

    // writing out all of the values of the metrics
    HSSFRow row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    HSSFCell cell = row.createCell(0);
    cell.setCellValue("A");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Abstractness");
    cell = row.createCell(3);
    if (project.getPackageAMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageAMin());
    }
    cell = row.createCell(4);
    if (project.getPackageAMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageAMax());
    }
    cell = row.createCell(5);
    if (project.getPackageAAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageAAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("AC");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Afferent Coupling");
    cell = row.createCell(3);
    if (project.getPackageACMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageACMin());
    }
    cell = row.createCell(4);
    if (project.getPackageACMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageACMax());
    }
    cell = row.createCell(5);
    if (project.getPackageACAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageACAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("C");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Coverage");
    cell = row.createCell(3);
    if (project.getPackageCoverageMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageCoverageMin());
    }
    cell = row.createCell(4);
    if (project.getPackageCoverageMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageCoverageMax());
    }
    cell = row.createCell(5);
    if (project.getPackageCoverageAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageCoverageAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("D");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Distance");
    cell = row.createCell(3);
    if (project.getPackageDMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageDMin());
    }
    cell = row.createCell(4);
    if (project.getPackageDMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageDMax());
    }
    cell = row.createCell(5);
    if (project.getPackageDAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageDAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("EC");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Efferent Coupling");
    cell = row.createCell(3);
    if (project.getPackageECMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageECMin());
    }
    cell = row.createCell(4);
    if (project.getPackageECMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageECMax());
    }
    cell = row.createCell(5);
    if (project.getPackageECAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageECAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("I");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Instability");
    cell = row.createCell(3);
    if (project.getPackageIMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageIMin());
    }
    cell = row.createCell(4);
    if (project.getPackageIMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageIMax());
    }
    cell = row.createCell(5);
    if (project.getPackageIAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageIAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOC");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Code");
    cell = row.createCell(3);
    if (project.getPackageLocMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocMin());
    }
    cell = row.createCell(4);
    if (project.getPackageLocMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocMax());
    }
    cell = row.createCell(6);
    if (project.getLOC() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getLOC());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOCm");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Comments");
    cell = row.createCell(3);
    if (project.getPackageLocmMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocmMin());
    }
    cell = row.createCell(4);
    if (project.getPackageLocmMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageLocmMax());
    }
    cell = row.createCell(6);
    if (project.getLOCm() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getLOCm());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NCP");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Classes in Package");
    cell = row.createCell(3);
    if (project.getPackageNCPMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNCPMin());
    }
    cell = row.createCell(4);
    if (project.getPackageNCPMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNCPMax());
    }
    cell = row.createCell(6);
    if (project.getPackageNCPSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNCPSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NIP");
    cell = row.createCell(1);
    cell.setCellValue("package");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Interfaces in Package");
    cell = row.createCell(3);
    if (project.getPackageNIPMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNIPMin());
    }
    cell = row.createCell(4);
    if (project.getPackageNIPMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNIPMax());
    }
    cell = row.createCell(6);
    if (project.getPackageNIPSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getPackageNIPSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Loose Class Coupling");
    cell = row.createCell(3);
    if (project.getClassLCCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCCMax());
    }
    cell = row.createCell(4);
    if (project.getClassLCCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCCMin());
    }
    cell = row.createCell(5);
    if (project.getClassLCCAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCCAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM1");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 1");
    cell = row.createCell(3);
    if (project.getClassLCOM1Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM1Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM1Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM1Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM1Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM1Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM2");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 2");
    cell = row.createCell(3);
    if (project.getClassLCOM2Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM2Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM2Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM2Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM2Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM2Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM3");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 3");
    cell = row.createCell(3);
    if (project.getClassLCOM3Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM3Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM3Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM3Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM3Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM3Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM4");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 4");
    cell = row.createCell(3);
    if (project.getClassLCOM4Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM4Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM4Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM4Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM4Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM4Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LCOM5");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lack Of Cohesion in Methods 5");
    cell = row.createCell(3);
    if (project.getClassLCOM5Min() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM5Min());
    }
    cell = row.createCell(4);
    if (project.getClassLCOM5Max() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM5Max());
    }
    cell = row.createCell(5);
    if (project.getClassLCOM5Avg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLCOM5Avg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Code");
    cell = row.createCell(3);
    if (project.getClassLOCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCMin());
    }
    cell = row.createCell(4);
    if (project.getClassLOCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOCm");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Comments");
    cell = row.createCell(3);
    if (project.getClassLOCmMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCmMin());
    }
    cell = row.createCell(4);
    if (project.getClassLOCmMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassLOCmMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NAK");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number of Assertions per KLOC");
    cell = row.createCell(3);
    if (project.getClassNAKMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNAKMin());
    }
    cell = row.createCell(4);
    if (project.getClassNAKMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNAKMax());
    }
    cell = row.createCell(5);
    if (project.getClassNAKAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNAKAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Children");
    cell = row.createCell(3);
    if (project.getClassNOCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOCMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOCMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOCSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOCSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOF");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Fields");
    cell = row.createCell(3);
    if (project.getClassNOFMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOFMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOFMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOFMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOFSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOFSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOM");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Methods");
    cell = row.createCell(3);
    if (project.getClassNOMMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOMMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOMMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOMMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOMSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOMSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOSF");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Static Fields");
    cell = row.createCell(3);
    if (project.getClassNOSFMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSFMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOSFMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSFMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOSFSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSFSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOSM");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Static Methods");
    cell = row.createCell(3);
    if (project.getClassNOSMMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSMMin());
    }
    cell = row.createCell(4);
    if (project.getClassNOSMMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSMMax());
    }
    cell = row.createCell(6);
    if (project.getClassNOSMSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNOSMSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NTM");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Number of Test Methods");
    cell = row.createCell(3);
    if (project.getClassNTMMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNTMMin());
    }
    cell = row.createCell(4);
    if (project.getClassNTMMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNTMMax());
    }
    cell = row.createCell(6);
    if (project.getClassNTMSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassNTMSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("TCC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Tight Class Coupling");
    cell = row.createCell(3);
    if (project.getClassTCCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassTCCMin());
    }
    cell = row.createCell(4);
    if (project.getClassTCCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassTCCMax());
    }
    cell = row.createCell(5);
    if (project.getClassTCCAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassTCCAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("WMC");
    cell = row.createCell(1);
    cell.setCellValue("class");
    cell = row.createCell(2);
    cell.setCellValue("Weighted Method Count");
    cell = row.createCell(3);
    if (project.getClassWMCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassWMCMin());
    }
    cell = row.createCell(4);
    if (project.getClassWMCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassWMCMax());
    }
    cell = row.createCell(6);
    if (project.getClassWMCSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getClassWMCSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOC");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Code");
    cell = row.createCell(3);
    if (project.getMethodLOCMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCMin());
    }
    cell = row.createCell(4);
    if (project.getMethodLOCMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("LOCm");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Lines Of Comments");
    cell = row.createCell(3);
    if (project.getMethodLOCmMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCmMin());
    }
    cell = row.createCell(4);
    if (project.getMethodLOCmMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodLOCmMax());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NBD");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Nested Block Depth");
    cell = row.createCell(3);
    if (project.getMethodNBDMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNBDMin());
    }
    cell = row.createCell(4);
    if (project.getMethodNBDMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNBDMax());
    }
    cell = row.createCell(5);
    if (project.getMethodNBDAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNBDAvg());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("NOP");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("Number Of Parameters");
    cell = row.createCell(3);
    if (project.getMethodNOPMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNOPMin());
    }
    cell = row.createCell(4);
    if (project.getMethodNOPMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNOPMax());
    }
    cell = row.createCell(6);
    if (project.getMethodNOPSum() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodNOPSum());
    }

    row = worksheet.createRow(worksheet.getPhysicalNumberOfRows());
    cell = row.createCell(0);
    cell.setCellValue("VG");
    cell = row.createCell(1);
    cell.setCellValue("method");
    cell = row.createCell(2);
    cell.setCellValue("McGabe's Cyclomatic Complexity");
    cell = row.createCell(3);
    if (project.getMethodVGMin() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodVGMin());
    }
    cell = row.createCell(4);
    if (project.getMethodVGMax() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodVGMax());
    }
    cell = row.createCell(5);
    if (project.getMethodVGAvg() == null) {
        cell.setCellValue("-");
    } else {
        cell.setCellValue(project.getMethodVGAvg());
    }

    // adjusting first three columns
    try {
        for (int i = 0; i < 7; i++) {
            worksheet.autoSizeColumn(i);
        }
    } catch (ArrayIndexOutOfBoundsException e) {
        logger.log(Level.SEVERE, "Exception when trying to adjust columns", e);
    }

    // setting constant width to other columns
    for (int i = 3; i < 7; i++) {
        worksheet.setColumnWidth(i, 2700);
    }
}

From source file:org.wso2.ws.dataservice.DBUtils.java

License:Apache License

private static OMElement getExcelResult(HSSFWorkbook wb, OMElement queryElement, AxisService axisService)
        throws AxisFault {
    OMElement resultElement = null;// w w w  .  j av a2  s .  co m

    //OMElement excelElement = queryElement.getFirstChildWithName(new QName("excel"));
    ExcelQuery excelQuery = new ExcelQuery(axisService, queryElement);

    OMElement result = queryElement.getFirstChildWithName(new QName("result"));
    String wrapperElementName = result.getAttributeValue(new QName("element"));
    String rowElementName = result.getAttributeValue(new QName("rowName"));
    String columnDefalut = result.getAttributeValue(new QName("columnDefault"));

    OMFactory fac = OMAbstractFactory.getOMFactory();
    OMNamespace omNs = fac.createOMNamespace(axisService.getTargetNamespace(), "data");
    resultElement = fac.createOMElement(wrapperElementName, omNs);

    if (!axisService.isElementFormDefault()) {
        omNs = fac.createOMNamespace("", "data");
    }

    //Retrieve the sheet name, if user has set it in configuration file
    String sheetName = excelQuery.getWorkBookName();

    //this is used to skip header columns, the spread sheet
    int startReadingFromRow = excelQuery.getStartingRow();
    if (startReadingFromRow >= 0) {
        //rows start from 0
        startReadingFromRow = startReadingFromRow - 1;
    }
    int maxRowCount = excelQuery.getMaxRowCount();

    HSSFSheet sheet = wb.getSheet(sheetName);
    int rowCount = sheet.getPhysicalNumberOfRows();

    //If hasHeaders is set to true, we need first row object in later stage.
    HSSFRow firstRow = null;
    if (excelQuery.hasHeaders()) {
        //assumption : first row is the header row
        firstRow = sheet.getRow(0);
    }

    int processedRowCount = 0;
    for (int r = 0; r < rowCount; r++) {
        if (r >= startReadingFromRow) {
            if (processedRowCount == maxRowCount) {
                break;
            }
            HSSFRow hssfRow = sheet.getRow(r);
            OMElement row = fac.createOMElement(rowElementName, omNs);
            if (rowElementName == null) {
                row = resultElement;
            }

            Iterator elements = result.getChildElements();
            while (elements.hasNext()) {
                OMElement element = (OMElement) elements.next();
                if (element.getLocalName().equals("element")) {
                    String displayTagName = element.getAttributeValue(new QName("name"));
                    String columnValue = element.getAttributeValue(new QName("column"));

                    short a = 1;
                    short columnNumber;
                    if (excelQuery.hasHeaders()) {
                        //if hasHeaders is set to true, column Names should be specified
                        //get the column number using specified name
                        columnNumber = getExcelColumnNumber(columnValue, firstRow);
                    } else {
                        try {
                            columnNumber = (short) (Short.valueOf(columnValue).shortValue() - a);
                        } catch (NumberFormatException e) {
                            log.error("Column value for element : " + displayTagName + " should be a number.",
                                    e);
                            throw new AxisFault(
                                    "Column value for element : " + displayTagName + " should be a number.");
                        }

                    }

                    HSSFCell hssfCell = hssfRow.getCell(columnNumber);
                    String elementValue = "";
                    if (hssfCell != null) {
                        if (HSSFCell.CELL_TYPE_STRING == hssfCell.getCellType()) {
                            elementValue = hssfCell.getRichStringCellValue().getString();
                        } else if (HSSFCell.CELL_TYPE_BLANK == hssfCell.getCellType()) {
                            //do nothing
                        } else if (HSSFCell.CELL_TYPE_BOOLEAN == hssfCell.getCellType()) {
                            elementValue = String.valueOf(hssfCell.getBooleanCellValue());
                        } else if (HSSFCell.CELL_TYPE_FORMULA == hssfCell.getCellType()) {
                            elementValue = "{formula}";
                        } else if (HSSFCell.CELL_TYPE_NUMERIC == hssfCell.getCellType()) {
                            elementValue = String.valueOf(hssfCell.getNumericCellValue());
                        }
                    }

                    if (columnDefalut == null || columnDefalut.equals("element")) {
                        OMElement rowElement = fac.createOMElement(displayTagName, omNs);
                        rowElement.addChild(fac.createOMText(rowElement, elementValue));
                        row.addChild(rowElement);
                    } else if (columnDefalut.equals("attribute")) {
                        row.addAttribute(displayTagName, elementValue, omNs);
                    }
                }
            }
            if (rowElementName != null) {
                resultElement.addChild(row);
                processedRowCount++;
            }
        } //end of if( k >= startReadingFromRow)
    } //for (int r = 0; r < rowCount; r++)
    return resultElement;
}