コード例 #1
0
 private Message successMultiStatus(MULTISTATUS multiStatus) {
   final Document doc = new Document(XML_DECLARATION, multiStatus);
   return Response.build(SUCCESS_MULTI_STATUS)
       .header(CONTENT_TYPE)
       .set(APPLICATION_XML.toString())
       .setBody(CHARSET_UTF_8.encode(XMLWriter.write(doc)));
 }
コード例 #2
0
  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();
    }
  }
コード例 #3
0
  @MOVE
  public Message move(
      @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 Response.clientErrorLocked();
    }

    if (source.exists()) {
      if (source.isCollection()) { // source exists
        if (destination.exists()) { // source exists and is a collection
          if (destination.isCollection()) {
            return (overwrite
                ? moveCollectionToCollection(source, destination, overwrite)
                : Response.clientErrorPreconditionFailed());
          } else {
            return (overwrite
                ? moveCollectionToResource(source, destination, overwrite)
                : Response.clientErrorPreconditionFailed());
          }
        } else {
          return (destination.parent().exists()
              ? moveCollectionToCollection(source, destination, false)
              : Response.clientErrorPreconditionFailed());
        }
      } else {
        if (destination.exists()) { // source exists
          if (destination.isCollection()) { // source exists,
            return (overwrite
                ? moveResourceToCollection(source, destination, overwrite)
                : Response.clientErrorPreconditionFailed());
          } else {
            return (overwrite
                ? moveResourceToResource(source, destination, overwrite)
                : Response.clientErrorPreconditionFailed());
          }
        } else {
          if (destination.parent().exists()) {
            return (overwrite
                ? Response.clientErrorPreconditionFailed()
                : moveResourceToCollection(source, destination, overwrite));
          } else {
            return clientErrorConflict();
          }
        }
      }
    } else {
      return clientErrorNotFound();
    }
  }
コード例 #4
0
  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();
    }
  }
コード例 #5
0
  private Response doOptions(Environment env) {
    final Resource resource = resolveResource(env.pathInfo());

    Message response = Response.successNoContent();
    for (Method method : resource.supportedMethods()) {
      response.headers().put(ALLOW, method.name());
    }

    for (ComplianceClass value : resource.davOptions()) {
      response.headers().put(DAV, value.toString());
    }

    return response;
  }
コード例 #6
0
  @LOCK
  public Message lock(@PathTranslated Path path, Depth depth) throws IOException {
    final Resource resource = resolveResource(path);

    if (resource.exists()) {
      final Lock lock = resource.lock(WRITE, EXCLUSIVE);

      final ACTIVE_LOCK activelock = activeLock(lock, depth, relativizeResource(resource));
      final Element lockDiscovery = lockDiscovery(activelock);
      final Element prop = prop(lockDiscovery);
      final Document doc = new Document(XML_DECLARATION, prop);
      return Response.build(SUCCESS_OK)
          .header(LOCK_TOKEN)
          .set("<" + lock.token() + ">")
          .setBody(Charset.defaultCharset().encode(XMLWriter.write(doc)));
    } else {
      return clientErrorNotFound();
    }
  }
コード例 #7
0
 private Message handleRequestWithIfUnmodifiedSince() {
   return Response.serverErrorNotImplemented();
 }