Esempio n. 1
0
  @Override
  public Resource getResource(String host, String sPath)
      throws NotAuthorizedException, BadRequestException {
    LogUtils.trace(log, "getResource", host, sPath);
    Path path = Path.path(sPath);
    Path parent = path.getParent();
    Request request = HttpManager.request();
    String encodedPath = request.getAbsolutePath();

    // This is to support a use case where a developer wants their resources to
    // be accessible through milton-json, but don't want to use DAV urls. Instead
    // they use a parameter and DO NOT implement PostableResource.
    if (request.getMethod().equals(Method.POST)) {
      Resource wrappedResource = wrapped.getResource(host, sPath);
      if (wrappedResource != null && !(wrappedResource instanceof PostableResource)) {
        LogUtils.trace(log, "getResource: is post, and got a: ", wrappedResource.getClass());
        return new PostJsonResource(host, encodedPath, wrappedResource, methodParamName, this);
      }
    }
    if (request.getMethod().equals(Method.GET)
        && isMatchingContentType(request.getAcceptHeader())) {
      Resource wrappedResource = wrapped.getResource(host, sPath);
      if (wrappedResource != null) {
        log.trace("getResource: matches content type, and found wrapped resource");
        return wrapResource(host, wrappedResource, Method.PROPFIND.code, encodedPath);
      } else {
        LogUtils.trace(
            log, "getResource: is GET and matched type, but found no actual resource on", sPath);
      }
    }
    if (isMatchingPath(parent)) {
      log.trace("getResource: is matching path");
      Path resourcePath = parent.getParent();
      if (resourcePath != null) {
        String method = path.getName();
        Resource wrappedResource = wrapped.getResource(host, resourcePath.toString());
        if (wrappedResource != null) {
          Resource r = wrapResource(host, wrappedResource, method, encodedPath);
          LogUtils.trace(log, "returning a", r.getClass());
          return r;
        }
      }
    } else {
      log.trace("getResource: not matching path");
      return wrapped.getResource(host, sPath);
    }
    return null;
  }
  @Override
  public String process(String host, String path, Resource calendar, Document doc)
      throws NotAuthorizedException, BadRequestException {
    log.debug("process");
    // The requested properties
    Set<QName> props = getProps(doc);
    // The requested resources
    List<String> hrefs = getHrefs(doc);

    PropertiesRequest parseResult = PropertiesRequest.toProperties(props);

    // Generate the response
    List<PropFindResponse> respProps = new ArrayList<PropFindResponse>();

    for (String href : hrefs) {
      Resource r = resourceFactory.getResource(host, href);
      if (r != null) {
        if (r instanceof PropFindableResource) {
          PropFindableResource pfr = (PropFindableResource) r;
          try {
            respProps.addAll(propertyBuilder.buildProperties(pfr, 0, parseResult, href));
          } catch (URISyntaxException ex) {
            throw new RuntimeException("There was an unencoded url requested: " + href, ex);
          }
        } else {
          // todo
        }
      } else {
        // todo
      }
    }

    String xml = xmlGenerator.generate(respProps);
    return xml;
  }