Package com.adito.vfs.webdav

Examples of com.adito.vfs.webdav.DAVException


     * <p>As this servlet does not handle the creation of custom properties,
     * this method will always fail with a <code>403</code> (Forbidden).</p>
     */
    public void process(DAVTransaction transaction, VFSResource resource)
    throws IOException {
        throw new DAVException(403, "All properties are immutable");
    }
View Full Code Here


    try {
         
          URI target = transaction.getDestination();

          if (target == null)
              throw new DAVException(412, "No destination");
          if(log.isDebugEnabled())
              log.debug("Target " + target.getPath());
         
      try {
              DAVProcessor processor = DAVServlet.getDAVProcessor(transaction.getRequest());
              dest = processor.getRepository().getResource(resource.getLaunchSession(), target.getPath(), transaction.getCredentials()/*, transaction*/);
              VFSLockManager.getInstance().lock(dest, transaction.getSessionInfo(), true, false, handle);

          } catch (Exception ex) {
              log.error("Failed to get resource. ", ex);
              transaction.setStatus(500);
              return;
          }
         
        int depth = transaction.getDepth();
        boolean recursive = false;
        if (depth == 0) {
            recursive = false;
        } else if (depth == DAVTransaction.INFINITY) {
            recursive = true;
        } else {
            throw new DAVException(412, "Invalid Depth specified");
        }
        try {
            resource.copy(dest, transaction.getOverwrite(), recursive);
            transaction.setStatus(204);
        } catch (DAVMultiStatus multistatus) {
View Full Code Here

            transaction.setHeader("content-type", "application/octet-stream");
            /*
             * Unsupported media type, we don't want content
             */
            if (transaction.getInputStream() != null)
                throw new DAVException(415, "No request body allowed in request");

            /* Create the collection */
            resource.makeCollection();
            transaction.setStatus(201);
            resource.getMount().resourceCollectionCreated(resource, transaction, null);
View Full Code Here

            return getRepositoryResource();
        } else {
            store = (VFSStore) this.getStore(storeName);
            if (store == null) {
                log.error("No store named \"" + storeName + "\".");
                throw new DAVException(404, "No store named \"" + storeName + "\".");
            }
        }

        // Extract the mount
        mountName = path;
        idx = path.indexOf('/', 1);
        if (idx != -1) {
            mountName = mountName.substring(0, idx);
            path = path.substring(idx + 1);
        } else {
            path = "";
        }
        if (mountName.length() == 0) {
            return store.getStoreResource(/*transaction*/);
        }       
       
        // Check the launch session is valid
        if(launchSession.isTracked())
          launchSession.checkAccessRights(null, getSession());

        //
        try {
            mount = store.getMountFromString(mountName, launchSession);
        }
        catch(DAVAuthenticationRequiredException dare) {
            throw dare;
        }
        catch(Exception e) {
            log.error("Failed to get mount.", e);
            mount = null;
        }
       
        if (mount == null || mount.equals("")) {
            log.error("No mount named \"" + mountName + "\" for store \"" + storeName + "\".");
            throw new DAVException(404, "No mount named \"" + mountName + "\" for store \"" + storeName + "\".");
        }

       
        path = DAVUtilities.stripTrailingSlash(path);

View Full Code Here

  /* (non-Javadoc)
   * @see com.adito.vfs.VFSResource#delete()
   */
  public void delete() throws DAVMultiStatus, IOException {
    if (this.isNull())
      throw new DAVException(404, "Not found", this);

    if (getMount().isReadOnly()) {
      throw new DAVException(DAVStatus.SC_FORBIDDEN, "You cannot delete this file because the the mount is readonly!");
    }

    if (this.isResource()) {
      try {
        if (!getFile().delete()) {
          throw new DAVException(403, "Can't delete resource '" + getRelativePath() + "'", this);
        } else {
          this.getMount().getStore().getRepository().notify(this, DAVListener.RESOURCE_REMOVED);
        }
      } catch (IOException e) {
        throw new DAVException(403, "Can't delete resource. " + VfsUtils.maskSensitiveArguments(e.getMessage()), this);
      }
    } else if (this.isMount()) {
      throw new DAVException(403, "Can't delete resource '" + getRelativePath()
        + "' as it is the root for the mount point "
        + this.getMount().getMountString(), this);
    } else if (this.isCollection()) {

      DAVMultiStatus multistatus = new DAVMultiStatus();

      Iterator children = this.getChildren();
      while (children.hasNext())
        try {
          ((VFSResource) children.next()).delete();
        } catch (DAVException exception) {
          multistatus.merge(exception);
        }

      if (multistatus.size() > 0)
        throw multistatus;
      try {
        if (!getFile().delete()) {
          throw new DAVException(403, "Can't delete collection", this);
        } else {
          this.getMount().getStore().getRepository().notify(this, DAVListener.COLLECTION_REMOVED);
        }
      } catch (IOException e) {
        log.error("Failed to delete resource.", e);
        throw new DAVException(403, "Can't delete collection " + getRelativePath() + ". " + e.getMessage(), this);
      }
    }
  }
View Full Code Here

     * this class (and in DAVOutputStream for resources) rather than on
     * files temselves, notifications are sent elsewhere, not here.
     */

    if (this.isNull())
      throw new DAVException(404, "Not found", this);

    /* Check if the destination exists and delete if possible */
    if (!dest.isNull()) {
      if (!overwrite) {
        String msg = "Not overwriting existing destination";
        throw new DAVException(412, msg, dest);
      }
      dest.delete();
    }

    /* Copy a single resource (destination is null as we deleted it) */
    if (this.isResource()) {
      VFSInputStream in = this.getInputStream();
      VFSOutputStream out = dest.getOutputStream();
      byte buffer[] = new byte[4096];
      int k = -1;
      while ((k = in.read(buffer)) != -1)
        out.write(buffer, 0, k);
      out.close();
    }

    /* Copy the collection and all nested members */
    if (this.isCollection()) {
      dest.makeCollection();
      if (!recursive)
        return;

      DAVMultiStatus multistatus = new DAVMultiStatus();
      Iterator children = this.getChildren();
      while (children.hasNext())
        try {
          FileObjectVFSResource childResource = (FileObjectVFSResource) children.next();
          try {
            FileObject child = ((FileObjectVFSResource) dest).getFile().resolveFile(childResource.getFile()
                    .getName()
                    .getBaseName());
            FileObjectVFSResource target = new FileObjectVFSResource(getLaunchSession(),
                    this.getMount(),
                    this, /* transaction, */
                    this.getMount().getMountString(),
                    repository,
                    requestCredentials);
            childResource.copy(target, overwrite, recursive);
          } catch (IOException e) {
            throw new DAVException(403, "Could not resolve child.", e);
          }
        } catch (DAVException exception) {
          multistatus.merge(exception);
        }
      if (multistatus.size() > 0)
View Full Code Here

     * this class (and in DAVOutputStream for resources) rather than on
     * files temselves, notifications are sent elsewhere, not here.
     */

    if (this.isNull())
      throw new DAVException(404, "Not found", this);

    /* Check read only */
    if (getMount().isReadOnly()) {
      throw new DAVException(DAVStatus.SC_FORBIDDEN, "You cannot move this file because the the mount is readonly!");
    }

    /* Check if the destination exists and delete if possible */
    if (!dest.isNull()) {
      if (!overwrite) {
        String msg = "Not overwriting existing destination";
        throw new DAVException(412, msg, dest);
      }
      dest.delete();
    }

    /* If the file system supports then move then just do it */
 
View Full Code Here

   * @see com.adito.vfs.VFSResource#makeCollection()
   */
  public void makeCollection() throws IOException {
    VFSResource parent = this.getParent();
    if (!this.isNull())
      throw new DAVException(405, "Resource exists", this);
    if (parent.isNull())
      throw new DAVException(409, "Parent does not not exist", this);
    if (!parent.isCollection())
      throw new DAVException(403, "Parent not a collection", this);

    /* Check read only */
    if (getMount().isReadOnly()) {
      throw new DAVException(DAVStatus.SC_FORBIDDEN, "You cannot create a folder here because the the mount is readonly!");
    }

    try {
      getFile().createFolder();
      this.getMount().getStore().getRepository().notify(this, DAVListener.COLLECTION_CREATED);
    } catch (IOException e) {
      throw new DAVException(507, "Can't create collection", this);
    }
  }
View Full Code Here

  /* (non-Javadoc)
   * @see com.adito.vfs.VFSResource#getInputStream()
   */
  public VFSInputStream getInputStream() throws IOException {
    if (this.isNull())
      throw new DAVException(404, "Not found", this);
    if (this.isCollection())
      throw new DAVException(403, "Resource is collection", this);
    return new VFSInputStream(this);
  }
View Full Code Here

  /* (non-Javadoc)
   * @see com.adito.vfs.VFSResource#getOutputStream()
   */
  public VFSOutputStream getOutputStream() throws IOException {
    if (this.isCollection())
      throw new DAVException(409, "Can't write a collection", this);

    if (getMount().isReadOnly()) {
      throw new DAVException(DAVStatus.SC_FORBIDDEN, "You cannot create a write here because the the mount is readonly!");
    }
    return new VFSOutputStream(this);
  }
View Full Code Here

TOP

Related Classes of com.adito.vfs.webdav.DAVException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.