コード例 #1
0
 public static URL getLocalURL(DSpaceObject dso) {
   URL url = null;
   ObjectIdentifier oid = dso.getIdentifier();
   if (oid == null) {
     return null;
   }
   url = IdentifierFactory.getURL(oid);
   return url;
 }
コード例 #2
0
  public static String getCanonicalForm(DSpaceObject dso) {
    String cf = "";
    String ns = ConfigurationManager.getProperty("identifier.url-scheme");
    if (!"".equals(ns) && ns != null) {
      ExternalIdentifierType type = ExternalIdentifierMint.getType(ns);
      List<ExternalIdentifier> eids = dso.getExternalIdentifiers();
      for (ExternalIdentifier eid : eids) {
        if (eid.getType().equals(type)) {
          cf = eid.getCanonicalForm();
        }
      }
    }

    if ("".equals(cf)) {
      ObjectIdentifier oid = dso.getIdentifier();
      if (oid == null) {
        return cf;
      }
      cf = oid.getCanonicalForm();
    }

    return cf;
  }
コード例 #3
0
  public static URL getURL(DSpaceObject dso) {
    URL url = null;

    String ns = ConfigurationManager.getProperty("identifier.url-scheme");
    if (!"".equals(ns) && ns != null) {
      ExternalIdentifierType type = ExternalIdentifierMint.getType(ns);
      List<ExternalIdentifier> eids = dso.getExternalIdentifiers();
      for (ExternalIdentifier eid : eids) {
        if (eid.getType().equals(type)) {
          url = IdentifierFactory.getURL(eid);
        }
      }
    }

    if (url == null) {
      ObjectIdentifier oid = dso.getIdentifier();
      if (oid == null) {
        return null;
      }
      url = IdentifierFactory.getURL(oid);
    }

    return url;
  }
コード例 #4
0
  public void processDSpaceObject(
      Context context,
      HttpServletRequest request,
      HttpServletResponse response,
      DSpaceObject dso,
      String extraPathInfo)
      throws ServletException, IOException, SQLException, AuthorizeException {
    // OK, we have a valid URI. What is it?
    if (dso.getType() == Constants.BITSTREAM) {
      // FIXME: Check for if-modified-since header
      Bitstream bitstream = (Bitstream) dso;

      log.info(
          LogManager.getHeader(context, "view_bitstream", "bitstream_id=" + bitstream.getID()));

      // Pipe the bits
      //            InputStream is = bitstream.retrieve();
      InputStream is = BitstreamStorageManager.retrieve(context, bitstream);

      // Set the response MIME type
      response.setContentType(bitstream.getFormat().getMIMEType());

      response.setHeader("Content-Length", String.valueOf(bitstream.getSize()));
      response.setHeader("Content-disposition", "attachment; filename=" + bitstream.getName());

      Utils.bufferedCopy(is, response.getOutputStream());
      is.close();
      response.getOutputStream().flush();
    } else if (dso.getType() == Constants.ITEM) {
      Item item = (Item) dso;

      response.setDateHeader("Last-Modified", item.getLastModified().getTime());

      // Check for if-modified-since header
      long modSince = request.getDateHeader("If-Modified-Since");

      if (modSince != -1 && item.getLastModified().getTime() < modSince) {
        // Item has not been modified since requested date,
        // hence bitstream has not; return 304
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
      } else {
        // Display the item page
        displayItem(context, request, response, item);
      }
    } else if (dso.getType() == Constants.COLLECTION) {
      Collection c = (Collection) dso;

      // Store collection location in request
      request.setAttribute("dspace.collection", c);

      /*
       * Find the "parent" community the collection, mainly for
       * "breadcrumbs" FIXME: At the moment, just grab the first community
       * the collection is in. This should probably be more context
       * sensitive when we have multiple inclusion.
       */
      Community[] parents = (Community[]) c.getCommunities().toArray();
      request.setAttribute("dspace.community", parents[0]);

      /*
       * Find all the "parent" communities for the collection for
       * "breadcrumbs"
       */
      request.setAttribute("dspace.communities", getParents(parents[0], true));

      // home page, or forward to another page?
      if ((extraPathInfo == null) || (extraPathInfo.equals("/"))) {
        collectionHome(context, request, response, parents[0], c);
      } else {
        // Forward to another servlet
        request.getRequestDispatcher(extraPathInfo).forward(request, response);
      }
    } else if (dso.getType() == Constants.COMMUNITY) {
      Community c = (Community) dso;

      // Store collection location in request
      request.setAttribute("dspace.community", c);

      /*
       * Find all the "parent" communities for the community
       */
      request.setAttribute("dspace.communities", getParents(c, false));

      // home page, or forward to another page?
      if ((extraPathInfo == null) || (extraPathInfo.equals("/"))) {
        communityHome(context, request, response, c);
      } else {
        // Forward to another servlet
        request.getRequestDispatcher(extraPathInfo).forward(request, response);
      }
    } else {
      // Shouldn't happen. Log and treat as invalid ID
      log.info(
          LogManager.getHeader(
              context,
              "URI not an item, collection or community",
              "identifier=" + dso.getIdentifier().toString()));
      JSPManager.showInvalidIDError(request, response, request.getPathInfo(), -1);

      return;
    }
  }