/** @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());
        }
      }
    }
  }