예제 #1
0
  int loadType(String uri) throws RepositoryException, IOException {
    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);

    DavMethodBase method = null;
    try {
      method = new PropFindMethod(uri, nameSet, DavConstants.DEPTH_0);
      client.executeMethod(method);
      method.checkSuccess();

      MultiStatusResponse[] responses = method.getResponseBodyAsMultiStatus().getResponses();
      if (responses.length == 1) {
        DavPropertySet props = responses[0].getProperties(DavServletResponse.SC_OK);
        DavProperty<?> type =
            props.get(JcrRemotingConstants.JCR_TYPE_LN, ItemResourceConstants.NAMESPACE);
        if (type != null) {
          return PropertyType.valueFromName(type.getValue().toString());
        } else {
          throw new RepositoryException("Internal error. Cannot retrieve property type at " + uri);
        }
      } else {
        throw new ItemNotFoundException("Internal error. Cannot retrieve property type at " + uri);
      }
    } catch (DavException e) {
      throw ExceptionConverter.generate(e);
    } finally {
      if (method != null) {
        method.releaseConnection();
      }
    }
  }
예제 #2
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();
      }
    }
  }
예제 #3
0
  ItemInfoImpl(DavPropertySet propSet, NamePathResolver resolver)
      throws NameException, NamespaceException {

    DavProperty<?> pathProp =
        propSet.get(JcrRemotingConstants.JCR_PATH_LN, ItemResourceConstants.NAMESPACE);
    String jcrPath = pathProp.getValue().toString();
    path = resolver.getQPath(jcrPath);
  }
예제 #4
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");
    }
  }
  public FileContentInfo create(FileContent fileContent) throws FileSystemException {
    WebdavFileObject file =
        (WebdavFileObject) (FileObjectUtils.getAbstractFileObject(fileContent.getFile()));

    String contentType = null;
    String contentEncoding = null;

    DavPropertyNameSet nameSet = new DavPropertyNameSet();
    nameSet.add(DavPropertyName.GETCONTENTTYPE);
    DavPropertySet propertySet = file.getProperties((URLFileName) file.getName(), nameSet, true);

    DavProperty property = propertySet.get(DavPropertyName.GETCONTENTTYPE);
    if (property != null) {
      contentType = (String) property.getValue();
    }
    property = propertySet.get(WebdavFileObject.RESPONSE_CHARSET);
    if (property != null) {
      contentEncoding = (String) property.getValue();
    }

    return new DefaultFileContentInfo(contentType, contentEncoding);
  }