Example #1
0
  /**
   * Get the binary content of a datastream
   *
   * @param pid persistent identifier of the digital object
   * @param dsid datastream identifier
   * @return Binary blob
   * @throws RepositoryException
   */
  @GET
  @Path("/{dsid}/content")
  public Response getDatastreamContent(
      @PathParam("pid") final String pid, @PathParam("dsid") final String dsid)
      throws RepositoryException {

    final Datastream ds = DatastreamService.getDatastream(pid, dsid);
    return ok(ds.getContent(), ds.getMimeType()).build();
  }
Example #2
0
  /**
   * Get the binary content of a datastream
   *
   * @param pathList
   * @return Binary blob
   * @throws RepositoryException
   */
  @GET
  public Response getContent(
      @PathParam("path") List<PathSegment> pathList, @Context final Request request)
      throws RepositoryException {

    String path = toPath(pathList);
    final Datastream ds = datastreamService.getDatastream(path);

    final EntityTag etag = new EntityTag(ds.getContentDigest().toString());
    final Date date = ds.getLastModifiedDate();
    final Date roundedDate = new Date();
    roundedDate.setTime(date.getTime() - date.getTime() % 1000);
    ResponseBuilder builder = request.evaluatePreconditions(roundedDate, etag);

    final CacheControl cc = new CacheControl();
    cc.setMaxAge(0);
    cc.setMustRevalidate(true);

    if (builder == null) {
      builder = Response.ok(ds.getContent(), ds.getMimeType());
    }

    return builder.cacheControl(cc).lastModified(date).tag(etag).build();
  }