@COPY public Message copy( @PathTranslated Path path, @Destination URI destinationUri, @Overwrite boolean overwrite) throws IOException { final Resource source = resolveResource(path); final Resource destination = resolveResource(Path.fromString(destinationUri.getPath())); if (destination.isLocked()) { return clientErrorLocked(); } if (source.exists()) { if (source.isCollection()) { // source exists if (destination.exists()) { // source exists and is a collection if (destination.isCollection()) { return (overwrite ? copyCollectionToCollection(source, destination, overwrite) : clientErrorPreconditionFailed()); } else { return (overwrite ? copyCollectionToResource(source, destination, overwrite) : clientErrorPreconditionFailed()); } } else { return (destination.parent().exists() ? copyCollectionToCollection(source, destination, false) : clientErrorPreconditionFailed()); } } else { if (destination.exists()) { // source exists if (destination.isCollection()) { // source exists, return (overwrite ? copyResourceToCollection(source, destination, overwrite) : clientErrorPreconditionFailed()); } else { return (overwrite ? copyResourceToResource(source, destination, overwrite) : clientErrorPreconditionFailed()); } } else { if (destination.parent().exists()) { return (overwrite ? clientErrorPreconditionFailed() : copyResourceToCollection(source, destination, overwrite)); } else { return clientErrorConflict(); } } } } else { return clientErrorNotFound(); } }
private Message handleRequestWithIfMatch(Request request) throws IOException { final Path path = Path.fromString(request.uri().getPath()); final Resource resource = resolveResource(path); final String ifMatch = getOnlyElement(request.headers().get(Header.IF_MATCH)); if (ifMatch.equals("*") || !ifMatch.equals(resource.etag())) { return handleRequestWithoutIfMatch(request); } else { return Response.clientErrorPreconditionFailed(); } }
private Message handleRequestWithoutRange(Request request) { final Path path = Path.fromUri(request.uri()); final Resource resource = resolveResource(path); try { return Response.build(SUCCESS_OK) .header(CONTENT_TYPE) .set(APPLICATION_OCTET_STREAM.toString()) .setBody(resource.channel()); } catch (IOException e) { return serverErrorInternal(); } }
private Message handleRequestWithIfModifiedSince(final Request request) throws IOException { final Path path = Path.fromUri(request.uri()); final Resource resource = resolveResource(path); try { String date = getOnlyElement(request.headers().get(IF_MODIFIED_SINCE)); Date ifModifiedSince = new SimpleDateFormat().parse(date); if (!ifModifiedSince.after(new Date()) && !(resource.lastModified().after(new Date()))) { return redirectionNotModified(); } else { return handleRequestWithoutIfModifiedSince(request); } } catch (ParseException e) { return handleRequestWithoutIfModifiedSince(request); } }