Example #1
0
  /**
   * Store a copy of the license a user granted in the item.
   *
   * @param context the dspace context
   * @param item the item object of the license
   * @param licenseText the license the user granted
   * @throws SQLException
   * @throws IOException
   * @throws AuthorizeException
   */
  public static void grantLicense(Context context, Item item, String licenseText)
      throws SQLException, IOException, AuthorizeException {
    // Put together text to store
    // String licenseText = "License granted by " + eperson.getFullName()
    // + " (" + eperson.getEmail() + ") on "
    // + DCDate.getCurrent().toString() + " (GMT):\n\n" + license;

    // Store text as a bitstream
    byte[] licenseBytes = licenseText.getBytes();
    ByteArrayInputStream bais = new ByteArrayInputStream(licenseBytes);
    Bitstream b = item.createSingleBitstream(bais, "LICENSE");

    // Now set the format and name of the bitstream
    b.setName("license.txt");
    b.setSource("Written by org.dspace.content.LicenseUtils");

    // Find the License format
    BitstreamFormat bf = BitstreamFormat.findByShortDescription(context, "License");
    b.setFormat(bf);

    b.update();
  }