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; }
/** @param args */ public static void main(String[] args) { if (args.length < MIN_ARGS) { usage(); return; } if (args.length > MAX_ARGS) { usage(); return; } File spdxSpreadsheetFile = new File(args[0]); if (!spdxSpreadsheetFile.exists()) { System.out.printf("Spreadsheet file %1$s does not exists.\n", args[0]); return; } File spdxRdfFile = new File(args[1]); if (spdxRdfFile.exists()) { System.out.printf("Error: File %1$s already exists - please specify a new file.\n", args[1]); return; } try { if (!spdxRdfFile.createNewFile()) { System.out.println("Could not create the new SPDX RDF file " + args[1]); usage(); return; } } catch (IOException e1) { System.out.println("Could not create the new SPDX RDF file " + args[1]); System.out.println("due to error " + e1.getMessage()); usage(); return; } FileOutputStream out; try { out = new FileOutputStream(spdxRdfFile); } catch (FileNotFoundException e1) { System.out.println("Could not write to the new SPDX RDF file " + args[1]); System.out.println("due to error " + e1.getMessage()); usage(); return; } Model model = ModelFactory.createDefaultModel(); SPDXDocument analysis = null; try { analysis = new SPDXDocument(model); } catch (InvalidSPDXAnalysisException ex) { System.out.print("Error creating SPDX Analysis: " + ex.getMessage()); return; } SPDXSpreadsheet ss = null; try { ss = new SPDXSpreadsheet(spdxSpreadsheetFile, false, true); copySpreadsheetToSPDXAnalysis(ss, analysis); ArrayList<String> verify = analysis.verify(); if (verify.size() > 0) { System.out.println( "Warning: The following verification errors were found in the resultant SPDX Document:"); for (int i = 0; i < verify.size(); i++) { System.out.println("\t" + verify.get(i)); } } model.write(out, "RDF/XML-ABBREV"); } catch (SpreadsheetException e) { System.out.println("Error creating or writing to spreadsheet: " + e.getMessage()); } catch (InvalidSPDXAnalysisException e) { System.out.println("Error translating the RDF file: " + e.getMessage()); } finally { if (ss != null) { try { ss.close(); } catch (SpreadsheetException e) { System.out.println("Error closing spreadsheet: " + e.getMessage()); } } if (out != null) { try { out.close(); } catch (IOException e) { System.out.println("Error closing RDF file: " + e.getMessage()); } } } }