Ejemplo n.º 1
0
  public void setup(org.dspace.content.Bitstream bitstream, String expand) throws SQLException {
    List<String> expandFields = new ArrayList<String>();
    if (expand != null) {
      expandFields = Arrays.asList(expand.split(","));
    }

    // A logo bitstream might not have a bundle...
    if (bitstream.getBundles() != null & bitstream.getBundles().length >= 0) {
      if (bitstream.getParentObject().getType() == Constants.ITEM) {
        bundleName = bitstream.getBundles()[0].getName();
      }
    }

    description = bitstream.getDescription();
    format = bitstream.getFormatDescription();
    sizeBytes = bitstream.getSize();
    retrieveLink = "/bitstreams/" + bitstream.getID() + "/retrieve";
    mimeType = bitstream.getFormat().getMIMEType();
    sequenceId = bitstream.getSequenceID();
    CheckSum checkSum = new CheckSum();
    checkSum.setCheckSumAlgorith(bitstream.getChecksumAlgorithm());
    checkSum.setValue(bitstream.getChecksum());
    this.setCheckSum(checkSum);

    if (expandFields.contains("parent") || expandFields.contains("all")) {
      parentObject = new DSpaceObject(bitstream.getParentObject());
    } else {
      this.addExpand("parent");
    }

    if (!expandFields.contains("all")) {
      this.addExpand("all");
    }
  }
Ejemplo n.º 2
0
  /**
   * Generate a METS file element for a given bitstream.
   *
   * @param context
   * @param item If the bitstream is associated with an item, provide the item, otherwise leave
   *     null.
   * @param bitstream The bitstream to build a file element for.
   * @param fileID The unique file id for this file.
   * @param groupID The group id for this file, if it is derived from another file then they should
   *     share the same groupID.
   * @param admID The IDs of the administrative metadata sections which pertain to this file
   * @throws org.xml.sax.SAXException passed through.
   * @throws java.sql.SQLException passed through.
   */
  protected final void renderFile(
      Context context, Item item, Bitstream bitstream, String fileID, String groupID, String admID)
      throws SAXException, SQLException {
    AttributeMap attributes;

    // //////////////////////////////
    // Determine the file attributes
    BitstreamFormat format = bitstream.getFormat(context);
    String mimeType = null;
    if (format != null) {
      mimeType = format.getMIMEType();
    }
    String checksumType = bitstream.getChecksumAlgorithm();
    String checksum = bitstream.getChecksum();
    long size = bitstream.getSize();

    // ////////////////////////////////
    // Start the actual file
    attributes = new AttributeMap();
    attributes.put("ID", fileID);
    attributes.put("GROUPID", groupID);
    if (admID != null && admID.length() > 0) {
      attributes.put("ADMID", admID);
    }
    if (mimeType != null && mimeType.length() > 0) {
      attributes.put("MIMETYPE", mimeType);
    }
    if (checksumType != null && checksum != null) {
      attributes.put("CHECKSUM", checksum);
      attributes.put("CHECKSUMTYPE", checksumType);
    }
    attributes.put("SIZE", String.valueOf(size));
    startElement(METS, "file", attributes);

    // ////////////////////////////////////
    // Determine the file location attributes
    String name = bitstream.getName();
    String description = bitstream.getDescription();

    // If possible, reference this bitstream via a handle, however this may
    // be null if a handle has not yet been assigned. In this case reference the
    // item its internal id. In the last case where the bitstream is not associated
    // with an item (such as a community logo) then reference the bitstreamID directly.
    String identifier = null;
    if (item != null && item.getHandle() != null) {
      identifier = "handle/" + item.getHandle();
    } else if (item != null) {
      identifier = "item/" + item.getID();
    } else {
      identifier = "id/" + bitstream.getID();
    }

    String url = contextPath + "/bitstream/" + identifier + "/";

    // If we can, append the pretty name of the bitstream to the URL
    try {
      if (bitstream.getName() != null) {
        url += Util.encodeBitstreamName(bitstream.getName(), "UTF-8");
      }
    } catch (UnsupportedEncodingException uee) {
      // just ignore it, we don't have to have a pretty
      // name at the end of the URL because the sequence id will
      // locate it. However it means that links in this file might
      // not work....
    }

    url += "?sequence=" + bitstream.getSequenceID();

    // //////////////////////
    // Start the file location
    attributes = new AttributeMap();
    AttributeMap attributesXLINK = new AttributeMap();
    attributesXLINK.setNamespace(XLINK);
    attributes.put("LOCTYPE", "URL");
    attributesXLINK.put("type", "locator");
    attributesXLINK.put("title", name);
    if (description != null) {
      attributesXLINK.put("label", description);
    }
    attributesXLINK.put("href", url);
    startElement(METS, "FLocat", attributes, attributesXLINK);

    // ///////////////////////
    // End file location
    endElement(METS, "FLocate");

    // ////////////////////////////////
    // End the file
    endElement(METS, "file");
  }
Ejemplo n.º 3
0
  public void addBody(Body body)
      throws SAXException, WingException, UIException, SQLException, IOException,
          AuthorizeException {
    // If we are actually editing information of an uploaded file,
    // then display that body instead!
    if (this.editFile != null) {
      editFile.addBody(body);
      return;
    }

    // Get a list of all files in the original bundle
    Item item = submission.getItem();
    Collection collection = submission.getCollection();
    String actionURL =
        contextPath + "/handle/" + collection.getHandle() + "/submit/" + knot.getId() + ".continue";
    boolean disableFileEditing =
        (submissionInfo.isInWorkflow())
            && !ConfigurationManager.getBooleanProperty("workflow", "reviewer.file-edit");
    Bundle[] bundles = item.getBundles("ORIGINAL");
    Bitstream[] bitstreams = new Bitstream[0];
    if (bundles.length > 0) {
      bitstreams = bundles[0].getBitstreams();
    }

    // Part A:
    //  First ask the user if they would like to upload a new file (may be the first one)
    Division div =
        body.addInteractiveDivision(
            "submit-upload", actionURL, Division.METHOD_MULTIPART, "primary submission");
    div.setHead(T_submission_head);
    addSubmissionProgressList(div);

    List upload = null;
    if (!disableFileEditing) {
      // Only add the upload capabilities for new item submissions
      upload = div.addList("submit-upload-new", List.TYPE_FORM);
      upload.setHead(T_head);
      addRioxxVersionSection(upload, item);

      File file = upload.addItem().addFile("file");
      file.setLabel(T_file);
      file.setHelp(T_file_help);
      file.setRequired();

      // if no files found error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_NO_FILES_ERROR) {
        file.addError(T_file_error);
      }

      // if an upload error was thrown by processing class, display it!
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_UPLOAD_ERROR) {
        file.addError(T_upload_error);
      }

      // if virus checking was attempted and failed in error then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_VIRUS_CHECKER_UNAVAILABLE) {
        file.addError(T_virus_checker_error);
      }

      // if virus checking was attempted and a virus found then let the user know
      if (this.errorFlag == org.dspace.submit.step.UploadStep.STATUS_CONTAINS_VIRUS) {
        file.addError(T_virus_error);
      }

      Text description = upload.addItem().addText("description");
      description.setLabel(T_description);
      description.setHelp(T_description_help);

      Button uploadSubmit = upload.addItem().addButton("submit_upload");
      uploadSubmit.setValue(T_submit_upload);
    }

    make_sherpaRomeo_submission(item, div);

    // Part B:
    //  If the user has already uploaded files provide a list for the user.
    if (bitstreams.length > 0 || disableFileEditing) {
      Table summary = div.addTable("submit-upload-summary", (bitstreams.length * 2) + 2, 7);
      summary.setHead(T_head2);

      Row header = summary.addRow(Row.ROLE_HEADER);
      header.addCellContent(T_column0); // primary bitstream
      header.addCellContent(T_column1); // select checkbox
      header.addCellContent(T_column2); // file name
      header.addCellContent(T_column3); // size
      header.addCellContent(T_column4); // description
      header.addCellContent(T_column5); // format
      header.addCellContent(T_column6); // edit button

      for (Bitstream bitstream : bitstreams) {
        int id = bitstream.getID();
        String name = bitstream.getName();
        String url = makeBitstreamLink(item, bitstream);
        long bytes = bitstream.getSize();
        String desc = bitstream.getDescription();
        String algorithm = bitstream.getChecksumAlgorithm();
        String checksum = bitstream.getChecksum();

        Row row = summary.addRow();

        // Add radio-button to select this as the primary bitstream
        Radio primary = row.addCell().addRadio("primary_bitstream_id");
        primary.addOption(String.valueOf(id));

        // If this bitstream is already marked as the primary bitstream
        // mark it as such.
        if (bundles[0].getPrimaryBitstreamID() == id) {
          primary.setOptionSelected(String.valueOf(id));
        }

        if (!disableFileEditing) {
          // Workflow users can not remove files.
          CheckBox remove = row.addCell().addCheckBox("remove");
          remove.setLabel("remove");
          remove.addOption(id);
        } else {
          row.addCell();
        }

        row.addCell().addXref(url, name);
        row.addCellContent(bytes + " bytes");
        if (desc == null || desc.length() == 0) {
          row.addCellContent(T_unknown_name);
        } else {
          row.addCellContent(desc);
        }

        BitstreamFormat format = bitstream.getFormat();
        if (format == null) {
          row.addCellContent(T_unknown_format);
        } else {
          int support = format.getSupportLevel();
          Cell cell = row.addCell();
          cell.addContent(format.getMIMEType());
          cell.addContent(" ");
          switch (support) {
            case 1:
              cell.addContent(T_supported);
              break;
            case 2:
              cell.addContent(T_known);
              break;
            case 3:
              cell.addContent(T_unsupported);
              break;
          }
        }

        Button edit = row.addCell().addButton("submit_edit_" + id);
        edit.setValue(T_submit_edit);

        Row checksumRow = summary.addRow();
        checksumRow.addCell();
        Cell checksumCell = checksumRow.addCell(null, null, 0, 6, null);
        checksumCell.addHighlight("bold").addContent(T_checksum);
        checksumCell.addContent(" ");
        checksumCell.addContent(algorithm + ":" + checksum);
      }

      if (!disableFileEditing) {
        // Workflow users can not remove files.
        Row actionRow = summary.addRow();
        actionRow.addCell();
        Button removeSeleceted =
            actionRow.addCell(null, null, 0, 6, null).addButton("submit_remove_selected");
        removeSeleceted.setValue(T_submit_remove);
      }

      upload = div.addList("submit-upload-new-part2", List.TYPE_FORM);
    }

    // Part C:
    // add standard control/paging buttons
    addControlButtons(upload);
  }