Example #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();
      }
    }
  }
Example #2
0
  public List<String> getFileList(String destinationDirectory)
      throws TransferFailedException, ResourceDoesNotExistException, AuthorizationException {
    String repositoryUrl = repository.getUrl();
    String url = repositoryUrl + (repositoryUrl.endsWith("/") ? "" : "/") + destinationDirectory;

    PropFindMethod method = null;
    try {
      if (isDirectory(url)) {
        DavPropertyNameSet nameSet = new DavPropertyNameSet();
        nameSet.add(DavPropertyName.create(DavConstants.PROPERTY_DISPLAYNAME));

        method = new PropFindMethod(url, nameSet, DavConstants.DEPTH_1);
        int status = execute(method);
        if (method.succeeded()) {
          ArrayList<String> dirs = new ArrayList<String>();
          MultiStatus multiStatus = method.getResponseBodyAsMultiStatus();

          for (int i = 0; i < multiStatus.getResponses().length; i++) {

            MultiStatusResponse response = multiStatus.getResponses()[i];

            String entryUrl = response.getHref();
            String fileName = PathUtils.filename(URLDecoder.decode(entryUrl));
            if (entryUrl.endsWith("/")) {
              if (i == 0) {
                // by design jackrabbit webdav sticks parent directory as the first entry
                // so we need to ignore this entry
                // http://www.nabble.com/Extra-entry-in-get-file-list-with-jackrabbit-webdav-td21262786.html
                // http://www.webdav.org/specs/rfc4918.html#rfc.section.9.1
                continue;
              }

              // extract "dir/" part of "path.to.dir/"
              fileName = PathUtils.filename(PathUtils.dirname(URLDecoder.decode(entryUrl))) + "/";
            }

            if (!StringUtils.isEmpty(fileName)) {
              dirs.add(fileName);
            }
          }
          return dirs;
        }

        if (status == HttpStatus.SC_NOT_FOUND) {
          throw new ResourceDoesNotExistException("Destination directory does not exist: " + url);
        }
      }
    } catch (DavException e) {
      throw new TransferFailedException(e.getMessage(), e);
    } catch (IOException e) {
      throw new TransferFailedException(e.getMessage(), e);
    } finally {
      if (method != null) {
        method.releaseConnection();
      }
    }
    throw new ResourceDoesNotExistException(
        "Destination path exists but is not a " + "WebDAV collection (directory): " + url);
  }
Example #3
0
/** Programmer: rhodey */
public class WebDavConstants {

  public static final int SC_OK = 200;
  public static final int SC_NO_CONTENT = 204;

  public static final int SC_MOVED_PERMANENTLY = 301;
  public static final int SC_MOVED_TEMPORARILY = 302;
  public static final int SC_SEE_OTHER = 303;
  public static final int SC_USE_PROXY = 305;
  public static final int SC_TEMPORARY_REDIRECT = 307;

  public static final int SC_UNAUTHORIZED = 401;
  public static final int SC_FORBIDDEN = 403;
  public static final int SC_NOT_FOUND = 404;
  public static final int SC_PRECONDITION_FAILED = 412;
  public static final int SC_REQUEST_ENTITY_TOO_LARGE = 413;

  public static final String PROPERTY_RESOURCE_ID = "resource-id";
  public static final String PROPERTY_CURRENT_USER_PRINCIPAL = "current-user-principal";
  public static final String PROPERTY_SUPPORTED_REPORT_SET = "supported-report-set";
  public static final String PROPERTY_SYNC_TOKEN = "sync-token";
  public static final String PROPERTY_QUOTA_AVAILABLE_BYTES = "quota-available-bytes";
  public static final String PROPERTY_QUOTA_USED_BYTES = "quota-used-bytes";

  public static final DavPropertyName PROPERTY_NAME_PROP =
      DavPropertyName.create(DavConstants.XML_PROP, DavConstants.NAMESPACE);

  public static final DavPropertyName PROPERTY_NAME_RESOURCE_ID =
      DavPropertyName.create(PROPERTY_RESOURCE_ID, DavConstants.NAMESPACE);

  public static final DavPropertyName PROPERTY_NAME_CURRENT_USER_PRINCIPAL =
      DavPropertyName.create(PROPERTY_CURRENT_USER_PRINCIPAL, DavConstants.NAMESPACE);

  public static final DavPropertyName PROPERTY_NAME_SUPPORTED_REPORT_SET =
      DavPropertyName.create(PROPERTY_SUPPORTED_REPORT_SET, DavConstants.NAMESPACE);

  public static final DavPropertyName PROPERTY_NAME_SYNC_TOKEN =
      DavPropertyName.create(PROPERTY_SYNC_TOKEN, DavConstants.NAMESPACE);

  public static final DavPropertyName PROPERTY_NAME_QUOTA_USED_BYTES =
      DavPropertyName.create(PROPERTY_QUOTA_USED_BYTES, DavConstants.NAMESPACE);

  public static final DavPropertyName PROPERTY_NAME_QUOTA_AVAILABLE_BYTES =
      DavPropertyName.create(PROPERTY_QUOTA_AVAILABLE_BYTES, DavConstants.NAMESPACE);
}
/**
 * Provides constants for request headers, URL parameters, and XML namespaces, elements and values,
 * DAV properties and resource types defined by the WebDAV ticket spec.
 */
public interface TicketConstants extends DavConstants {

  /** The HTTP header name <code>Ticket</code> */
  public static final String HEADER_TICKET = "Ticket";

  /** The URL query string parameter name <code>ticket</code> */
  public static final String PARAM_TICKET = "ticket";

  /** The ticket XML namespace */
  public static final Namespace NAMESPACE_TICKET =
      Namespace.getNamespace("ticket", "http://www.xythos.com/namespaces/StorageServer");

  /** The ticket XML element name <ticket:ticketinfo */
  public static final String ELEMENT_TICKET_TICKETINFO = "ticketinfo";

  public static final String QN_TICKET_TICKETINFO =
      DomUtil.getQualifiedName(ELEMENT_TICKET_TICKETINFO, NAMESPACE_TICKET);
  /** The ticket XML element name <ticket:id */
  public static final String ELEMENT_TICKET_ID = "id";

  public static final String QN_TICKET_ID =
      DomUtil.getQualifiedName(ELEMENT_TICKET_ID, NAMESPACE_TICKET);
  /** The ticket XML element name <ticket:timeout */
  public static final String ELEMENT_TICKET_TIMEOUT = "timeout";

  public static final String QN_TICKET_TIMEOUT =
      DomUtil.getQualifiedName(ELEMENT_TICKET_TIMEOUT, NAMESPACE_TICKET);
  /** The ticket XML element name <ticket:visits */
  public static final String ELEMENT_TICKET_VISITS = "visits";
  /** The ticket XML element name <ticket:freebusy */
  public static final String ELEMENT_TICKET_FREEBUSY = "freebusy";

  /** The XML value <code>infinity</code> */
  public static final String VALUE_INFINITY = "infinity";

  /** The DAV property name <code>ticketdiscovery</code> */
  public static final String PROPERTY_TICKET_TICKETDISCOVERY = "ticketdiscovery";

  /** The ticket property <code>ticket:ticketdiscovery</code> */
  public static final DavPropertyName TICKETDISCOVERY =
      DavPropertyName.create(PROPERTY_TICKET_TICKETDISCOVERY, NAMESPACE_TICKET);
}