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 == 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 information in files";
         }
         for (int j = 0; j < licenses.length; j++) {
           try {
             SPDXLicenseInfoFactory.parseSPDXLicenseString(cell.getStringCellValue().trim());
           } catch (SpreadsheetException ex) {
             return "Invalid license information in row "
                 + String.valueOf(row.getRowNum())
                 + " detail: "
                 + ex.getMessage();
           }
         }
       }
       //				if (cell.getCellType() != Cell.CELL_TYPE_STRING) {
       //					return "Invalid cell format for "+HEADER_TITLES[i]+" for forw
       // "+String.valueOf(row.getRowNum());
       //				}
     }
   }
   return null;
 }
예제 #2
0
 private static void copyOrigins(OriginsSheet originsSheet, SPDXDocument analysis)
     throws InvalidSPDXAnalysisException {
   Date createdDate = originsSheet.getCreated();
   String created = format.format(createdDate);
   String[] createdBys = originsSheet.getCreatedBy();
   String creatorComment = originsSheet.getAuthorComments();
   SPDXCreatorInformation creator =
       new SPDXCreatorInformation(createdBys, created, creatorComment);
   String specVersion = originsSheet.getSPDXVersion();
   analysis.setSpdxVersion(specVersion);
   String dataLicenseId = originsSheet.getDataLicense();
   if (dataLicenseId == null
       || dataLicenseId.isEmpty()
       || dataLicenseId.equals(RdfToSpreadsheet.NOT_SUPPORTED_STRING)) {
     if (specVersion.equals(SPDXDocument.ONE_DOT_ZERO_SPDX_VERSION)) {
       dataLicenseId = SpdxRdfConstants.SPDX_DATA_LICENSE_ID_VERSION_1_0;
     } else {
       dataLicenseId = SpdxRdfConstants.SPDX_DATA_LICENSE_ID;
     }
   }
   SPDXStandardLicense dataLicense = null;
   try {
     dataLicense =
         (SPDXStandardLicense) SPDXLicenseInfoFactory.parseSPDXLicenseString(dataLicenseId);
   } catch (Exception ex) {
     try {
       dataLicense =
           (SPDXStandardLicense)
               SPDXLicenseInfoFactory.parseSPDXLicenseString(
                   SpdxRdfConstants.SPDX_DATA_LICENSE_ID);
     } catch (InvalidLicenseStringException e) {
       throw (new InvalidSPDXAnalysisException("Unable to get document license"));
     }
   }
   analysis.setDataLicense(dataLicense);
   analysis.setCreationInfo(creator);
 }
 public SPDXPackageInfo getPackageInfo(int rowNum) throws SpreadsheetException {
   Row row = sheet.getRow(rowNum);
   if (row == null) {
     return null;
   }
   Cell nameCell = row.getCell(NAME_COL);
   if (nameCell == null || nameCell.getStringCellValue().isEmpty()) {
     return null;
   }
   String error = validateRow(row);
   if (error != null && !error.isEmpty()) {
     throw (new SpreadsheetException(error));
   }
   String declaredName = nameCell.getStringCellValue();
   String machineName = row.getCell(MACHINE_NAME_COL).getStringCellValue();
   String sha1 = row.getCell(PACKAGE_SHA_COL).getStringCellValue();
   String sourceInfo;
   Cell sourceInfocol = row.getCell(SOURCE_INFO_COL);
   if (sourceInfocol != null) {
     sourceInfo = sourceInfocol.getStringCellValue();
   } else {
     sourceInfo = "";
   }
   SPDXLicenseInfo declaredLicenses =
       SPDXLicenseInfoFactory.parseSPDXLicenseString(
           row.getCell(DECLARED_LICENSE_COL).getStringCellValue());
   SPDXLicenseInfo concludedLicense;
   Cell concludedLicensesCell = row.getCell(CONCLUDED_LICENSE_COL);
   if (concludedLicensesCell != null && !concludedLicensesCell.getStringCellValue().isEmpty()) {
     concludedLicense =
         SPDXLicenseInfoFactory.parseSPDXLicenseString(concludedLicensesCell.getStringCellValue());
   } else {
     concludedLicense = new SPDXNoneLicense();
   }
   String[] licenseStrings =
       row.getCell(LICENSE_INFO_IN_FILES_COL).getStringCellValue().split(",");
   SPDXLicenseInfo[] licenseInfosFromFiles = new SPDXLicenseInfo[licenseStrings.length];
   for (int i = 0; i < licenseStrings.length; i++) {
     licenseInfosFromFiles[i] =
         SPDXLicenseInfoFactory.parseSPDXLicenseString(licenseStrings[i].trim());
   }
   Cell licenseCommentCell = row.getCell(LICENSE_COMMENT_COL);
   String licenseComment;
   if (licenseCommentCell != null && !licenseCommentCell.getStringCellValue().isEmpty()) {
     licenseComment = licenseCommentCell.getStringCellValue();
   } else {
     licenseComment = "";
   }
   String declaredCopyright = row.getCell(DECLARED_COPYRIGHT_COL).getStringCellValue();
   Cell shortDescCell = row.getCell(SHORT_DESC_COL);
   String shortDesc;
   if (shortDescCell != null && !shortDescCell.getStringCellValue().isEmpty()) {
     shortDesc = shortDescCell.getStringCellValue();
   } else {
     shortDesc = "";
   }
   Cell descCell = row.getCell(FULL_DESC_COL);
   String description;
   if (descCell != null && !descCell.getStringCellValue().isEmpty()) {
     description = descCell.getStringCellValue();
   } else {
     description = "";
   }
   String url = row.getCell(URL_COL).getStringCellValue();
   String packageVerificationValue = row.getCell(FILE_VERIFICATION_VALUE_COL).getStringCellValue();
   String[] excludedFiles;
   String excludedFilesStr = row.getCell(VERIFICATION_EXCLUDED_FILES_COL).getStringCellValue();
   if (excludedFilesStr != null && !excludedFilesStr.isEmpty()) {
     excludedFiles = excludedFilesStr.split(",");
     for (int i = 0; i < excludedFiles.length; i++) {
       excludedFiles[i] = excludedFiles[i].trim();
     }
   } else {
     excludedFiles = new String[0];
   }
   SpdxPackageVerificationCode verificationCode =
       new SpdxPackageVerificationCode(packageVerificationValue, excludedFiles);
   String notAvailable = "Not available from spreadsheet";
   return new SPDXPackageInfo(
       declaredName,
       notAvailable,
       machineName,
       sha1,
       sourceInfo,
       declaredLicenses,
       concludedLicense,
       licenseInfosFromFiles,
       licenseComment,
       declaredCopyright,
       shortDesc,
       description,
       url,
       verificationCode,
       "",
       "");
 }