Example usage for org.apache.poi.ss.usermodel Row getRowNum

List of usage examples for org.apache.poi.ss.usermodel Row getRowNum

Introduction

In this page you can find the example usage for org.apache.poi.ss.usermodel Row getRowNum.

Prototype

int getRowNum();

Source Link

Document

Get row number this row represents

Usage

From source file:org.spdx.spdxspreadsheet.PackageInfoSheetV09d3.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/*w w w. j ava 2  s.  co m*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            if (i == DECLARED_LICENSE_COL || i == CONCLUDED_LICENSE_COL) {
                try {
                    SPDXLicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue());
                } catch (SpreadsheetException ex) {
                    if (i == DECLARED_LICENSE_COL) {
                        return "Invalid declared license in row " + String.valueOf(row.getRowNum())
                                + " detail: " + ex.getMessage();
                    } else {
                        return "Invalid seen license in row " + String.valueOf(row.getRowNum()) + " detail: "
                                + ex.getMessage();
                    }
                }
            } else if (i == LICENSE_INFO_IN_FILES_COL) {
                String[] licenses = row.getCell(LICENSE_INFO_IN_FILES_COL).getStringCellValue().split(",");
                if (licenses.length < 1) {
                    return "Missing licenss infos in files";
                }
                for (int j = 0; j < licenses.length; j++) {
                    try {
                        SPDXLicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue().trim());
                    } catch (SpreadsheetException ex) {
                        return "Invalid license infos in row " + String.valueOf(row.getRowNum()) + " detail: "
                                + ex.getMessage();
                    }
                }
            } else if (i == ORIGINATOR_COL) {
                Cell origCell = row.getCell(ORIGINATOR_COL);
                if (origCell != null) {
                    String originator = origCell.getStringCellValue();
                    if (originator != null && !originator.isEmpty()) {
                        String error = SpdxVerificationHelper.verifyOriginator(originator);
                        if (error != null && !error.isEmpty()) {
                            return "Invalid originator in row " + String.valueOf(row.getRowNum()) + ": "
                                    + error;
                        }
                    }
                }
            } else if (i == SUPPLIER_COL) {
                Cell supplierCell = row.getCell(SUPPLIER_COL);
                if (supplierCell != null) {
                    String supplier = supplierCell.getStringCellValue();
                    if (supplier != null && !supplier.isEmpty()) {
                        String error = SpdxVerificationHelper.verifySupplier(supplier);
                        if (error != null && !error.isEmpty()) {
                            return "Invalid supplier in row " + String.valueOf(row.getRowNum()) + ": " + error;
                        }
                    }
                }
            }
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.PackageInfoSheetV1d2.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/*from   w  w w.  j  av a2  s .  com*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            if (i == DECLARED_LICENSE_COL || i == CONCLUDED_LICENSE_COL) {
                try {
                    LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue(), null);
                } catch (SpreadsheetException ex) {
                    if (i == DECLARED_LICENSE_COL) {
                        return "Invalid declared license in row " + String.valueOf(row.getRowNum())
                                + " detail: " + ex.getMessage();
                    } else {
                        return "Invalid seen license in row " + String.valueOf(row.getRowNum()) + " detail: "
                                + ex.getMessage();
                    }
                }
            } else if (i == LICENSE_INFO_IN_FILES_COL) {
                String[] licenses = row.getCell(LICENSE_INFO_IN_FILES_COL).getStringCellValue().split(",");
                if (licenses.length < 1) {
                    return "Missing licenss information in files";
                }
                for (int j = 0; j < licenses.length; j++) {
                    try {
                        LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue().trim(), null);
                    } catch (SpreadsheetException ex) {
                        return "Invalid license information in row " + String.valueOf(row.getRowNum())
                                + " detail: " + ex.getMessage();
                    }
                }
            } else if (i == ORIGINATOR_COL) {
                Cell origCell = row.getCell(ORIGINATOR_COL);
                if (origCell != null) {
                    String originator = origCell.getStringCellValue();
                    if (originator != null && !originator.isEmpty()) {
                        String error = SpdxVerificationHelper.verifyOriginator(originator);
                        if (error != null && !error.isEmpty()) {
                            return "Invalid originator in row " + String.valueOf(row.getRowNum()) + ": "
                                    + error;
                        }
                    }
                }
            } else if (i == SUPPLIER_COL) {
                Cell supplierCell = row.getCell(SUPPLIER_COL);
                if (supplierCell != null) {
                    String supplier = supplierCell.getStringCellValue();
                    if (supplier != null && !supplier.isEmpty()) {
                        String error = SpdxVerificationHelper.verifySupplier(supplier);
                        if (error != null && !error.isEmpty()) {
                            return "Invalid supplier in row " + String.valueOf(row.getRowNum()) + ": " + error;
                        }
                    }
                }
            }
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.PackageInfoSheetV2d1.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/*from   www .  ja  v  a2  s .  co m*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum() + " in PackageInfo sheet.");
            }
        } else {
            if (i == DECLARED_LICENSE_COL || i == CONCLUDED_LICENSE_COL) {
                try {
                    LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue(), null);
                } catch (SpreadsheetException ex) {
                    if (i == DECLARED_LICENSE_COL) {
                        return "Invalid declared license in row " + String.valueOf(row.getRowNum())
                                + " detail: " + ex.getMessage() + " in PackageInfo sheet.";
                    } else {
                        return "Invalid seen license in row " + String.valueOf(row.getRowNum()) + " detail: "
                                + ex.getMessage() + " in PackageInfo sheet.";
                    }
                }
            } else if (i == LICENSE_INFO_IN_FILES_COL) {
                String[] licenses = row.getCell(LICENSE_INFO_IN_FILES_COL).getStringCellValue().split(",");
                if (licenses.length < 1) {
                    return "Missing licenss information in files in PackageInfo sheet.";
                }
                for (int j = 0; j < licenses.length; j++) {
                    try {
                        LicenseInfoFactory.parseSPDXLicenseString(licenses[j], null);
                    } catch (SpreadsheetException ex) {
                        return "Invalid license information in in files for license " + licenses[j] + " row "
                                + String.valueOf(row.getRowNum()) + " detail: " + ex.getMessage()
                                + " in PackageInfo sheet.";
                    }
                }
            } else if (i == ORIGINATOR_COL) {
                Cell origCell = row.getCell(ORIGINATOR_COL);
                if (origCell != null) {
                    String originator = origCell.getStringCellValue();
                    if (originator != null && !originator.isEmpty()) {
                        String error = SpdxVerificationHelper.verifyOriginator(originator);
                        if (error != null && !error.isEmpty()) {
                            return "Invalid originator in row " + String.valueOf(row.getRowNum()) + ": " + error
                                    + " in PackageInfo sheet.";
                        }
                    }
                }
            } else if (i == SUPPLIER_COL) {
                Cell supplierCell = row.getCell(SUPPLIER_COL);
                if (supplierCell != null) {
                    String supplier = supplierCell.getStringCellValue();
                    if (supplier != null && !supplier.isEmpty()) {
                        String error = SpdxVerificationHelper.verifySupplier(supplier);
                        if (error != null && !error.isEmpty()) {
                            return "Invalid supplier in row " + String.valueOf(row.getRowNum()) + ": " + error
                                    + " in PackageInfo sheet.";
                        }
                    }
                }
            } else if (i == FILES_ANALYZED_COL) {
                Cell filesAnalyzedCell = row.getCell(FILES_ANALYZED_COL);
                if (filesAnalyzedCell != null && filesAnalyzedCell.getStringCellValue() != null) {
                    String filesAnalyzedStr = filesAnalyzedCell.getStringCellValue().trim().toLowerCase();
                    if (!filesAnalyzedStr.equals("true") && !filesAnalyzedStr.equals("false")) {
                        return "Invalid value for files analyzed (expecting 'true' or 'false') in row "
                                + String.valueOf(row.getRowNum()) + ":" + filesAnalyzedStr;
                    }
                }
            }
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.PerFileSheet.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);//www  .  ja v a  2  s .c  om
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
            if (i == CONCLUDED_LIC_COL || i == LIC_INFO_IN_FILE_COL) {
                try {
                    SPDXLicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue());
                } catch (SpreadsheetException ex) {
                    if (i == CONCLUDED_LIC_COL) {
                        return "Invalid asserted license string in row " + String.valueOf(row.getRowNum())
                                + " details: " + ex.getMessage();
                    } else {
                        return "Invalid seen license string in row " + String.valueOf(row.getRowNum())
                                + " details: " + ex.getMessage();
                    }
                }
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.PerFileSheetV09d3.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/*w  w  w .j  ava2s  .com*/
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
            if (i == CONCLUDED_LIC_COL || i == LIC_INFO_IN_FILE_COL) {
                try {
                    LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue(), null);
                } catch (SpreadsheetException ex) {
                    if (i == CONCLUDED_LIC_COL) {
                        return "Invalid asserted license string in row " + String.valueOf(row.getRowNum())
                                + " details: " + ex.getMessage();
                    } else {
                        return "Invalid seen license string in row " + String.valueOf(row.getRowNum())
                                + " details: " + ex.getMessage();
                    }
                }
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.PerFileSheetV2d0.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);//from w ww  .j a va  2 s .  c o m
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            if (i == CONCLUDED_LIC_COL) {
                try {
                    LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue(), null);
                } catch (SpreadsheetException ex) {
                    return "Invalid asserted license string in row " + String.valueOf(row.getRowNum())
                            + " details: " + ex.getMessage();
                }
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.RelationshipsSheet.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);/*from   www .j  a va 2  s  . c om*/
        if (REQUIRED[i] && cell == null) {
            return "Required cell " + HEADER_TITLES[i] + " missing for row " + String.valueOf(row.getRowNum())
                    + " in relationships sheet";
        }
        if (i == RELATIONSHIP_COL && cell.getStringCellValue() != null) {
            RelationshipType rt = Relationship.TAG_TO_RELATIONSHIP_TYPE.get(cell.getStringCellValue());
            if (rt == null) {
                return "Invalid relationship type in row " + String.valueOf(row) + ": "
                        + cell.getStringCellValue();
            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.ReviewersSheet.java

License:Apache License

private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);//from   w  w w.  java 2s.  c  om
        if (REQUIRED[i] && cell == null) {
            return "Required cell " + HEADER_TITLES[i] + " missing for row " + String.valueOf(row.getRowNum())
                    + " in reviewer sheet";
        } else {
            if (i == TIMESTAMP_COL) {
                if (!(cell.getCellType() == Cell.CELL_TYPE_NUMERIC)) {
                    return "Timestamp cell is not a numeric type for row " + String.valueOf(row.getRowNum())
                            + " in Reviewer sheet";
                }
            }
            //            if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
            //               return "Invalid cell format for "+HEADER_TITLES[i]+" for forw "+String.valueOf(row.getRowNum());
            //            }
        }
    }
    return null;
}

From source file:org.spdx.spdxspreadsheet.SnippetSheet.java

License:Apache License

/**
 * @param row/* w ww .  jav  a 2s .  c o  m*/
 * @return
 */
private String validateRow(Row row) {
    for (int i = 0; i < NUM_COLS; i++) {
        Cell cell = row.getCell(i);
        if (cell == null) {
            if (REQUIRED[i]) {
                return "Required cell " + HEADER_TITLES[i] + " missing for row "
                        + String.valueOf(row.getRowNum());
            }
        } else {
            if (i == CONCLUDED_LICENSE_COL) {
                try {
                    LicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue(), null);
                } catch (SpreadsheetException ex) {
                    return "Invalid asserted license string in row " + String.valueOf(row.getRowNum())
                            + " details: " + ex.getMessage();
                }
            } else if (i == BYTE_RANGE_COL || i == LINE_RANGE_COL) {
                String range = cell.getStringCellValue();
                if (range != null && !range.isEmpty()) {
                    Matcher rangeMatcher = NUMBER_RANGE_PATTERN.matcher(cell.getStringCellValue());
                    if (!rangeMatcher.matches()) {
                        return "Invalid range for " + HEADER_TITLES[i] + ": " + cell.getStringCellValue();
                    }
                    int start = 0;
                    int end = 0;
                    try {
                        start = Integer.parseInt(rangeMatcher.group(1));
                        end = Integer.parseInt(rangeMatcher.group(2));
                        if (start >= end) {
                            return "Invalid range for " + HEADER_TITLES[i] + ": " + cell.getStringCellValue()
                                    + ".  End is not greater than or equal to the end.";
                        }
                    } catch (Exception ex) {
                        return "Invalid range for " + HEADER_TITLES[i] + ": " + cell.getStringCellValue();
                    }
                }
            }
        }
    }
    return null;
}

From source file:org.squashtest.tm.service.internal.batchimport.testcase.excel.InstructionBuilder.java

License:Open Source License

/**
 * Template method : instruction building can be customized in subclasses by
 * overriding {@link #postProcessInstruction(Row, Instruction)}
 *
 * @param row/*from   ww w .  j  a v  a2  s  .c o  m*/
 * @return
 */
public final INST build(Row row) {
    INST instruction = createInstruction(row);
    instruction.setLine(row.getRowNum());

    processStandardColumns(row, instruction);

    if (instruction instanceof CustomFieldHolder) {
        processCustomFieldColumns(row, instruction);
    }

    postProcessInstruction(row, instruction);

    return instruction;
}