Exemplo n.º 1
0
  private boolean isDirectory(String url) throws IOException, DavException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(DavPropertyName.create(DavConstants.PROPERTY_RESOURCETYPE));

    PropFindMethod method = null;
    try {
      method = new PropFindMethod(url, nameSet, DavConstants.DEPTH_0);
      execute(method);
      if (method.succeeded()) {
        MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();
        MultiStatusResponse response = multiStatus.getResponses()[0];
        DavPropertySet propertySet = response.getProperties(HttpStatus.SC_OK);
        DavProperty<?> property = propertySet.get(DavConstants.PROPERTY_RESOURCETYPE);
        if (property != null) {
          Node node = (Node) property.getValue();
          return node.getLocalName().equals(DavConstants.XML_COLLECTION);
        }
      }
      return false;
    } finally {
      if (method != null) {
        method.releaseConnection();
      }
    }
  }
Exemplo n.º 2
0
  public WebdavEntry(MultiStatusResponse ms, String splitElement) {
    resetData();
    if (ms.getStatus().length != 0) {
      mUri = ms.getHref();

      mPath = mUri.split(splitElement, 2)[1];

      int status = ms.getStatus()[0].getStatusCode();
      DavPropertySet propSet = ms.getProperties(status);
      @SuppressWarnings("rawtypes")
      DavProperty prop = propSet.get(DavPropertyName.DISPLAYNAME);
      if (prop != null) mName = (String) prop.getName().toString();
      else {
        String[] tmp = mPath.split("/");
        if (tmp.length > 0) mName = tmp[tmp.length - 1];
      }

      // use unknown mimetype as default behavior
      mContentType = "application/octet-stream";
      prop = propSet.get(DavPropertyName.GETCONTENTTYPE);
      if (prop != null) {
        mContentType = (String) prop.getValue();
        // dvelasco: some builds of ownCloud server 4.0.x added a trailing ';' to the MIME type ; if
        // looks fixed, but let's be cautious
        if (mContentType.indexOf(";") >= 0) {
          mContentType = mContentType.substring(0, mContentType.indexOf(";"));
        }
      }

      // check if it's a folder in the standard way: see RFC2518 12.2 , or RFC4918 14.3
      prop = propSet.get(DavPropertyName.RESOURCETYPE);
      if (prop != null) {
        Object value = prop.getValue();
        if (value != null) {
          mContentType =
              "DIR"; // a specific attribute would be better, but this is enough; unless while we
          // have no reason to distinguish MIME types for folders
        }
      }

      prop = propSet.get(DavPropertyName.GETCONTENTLENGTH);
      if (prop != null) mContentLength = Long.parseLong((String) prop.getValue());

      prop = propSet.get(DavPropertyName.GETLASTMODIFIED);
      if (prop != null) {
        Date d = WebdavUtils.parseResponseDate((String) prop.getValue());
        mModifiedTimestamp = (d != null) ? d.getTime() : 0;
      }

      prop = propSet.get(DavPropertyName.CREATIONDATE);
      if (prop != null) {
        Date d = WebdavUtils.parseResponseDate((String) prop.getValue());
        mCreateTimestamp = (d != null) ? d.getTime() : 0;
      }

    } else {
      Log.e("WebdavEntry", "General fuckup, no status for webdav response");
    }
  }