Package v7db.files.mongodb

Examples of v7db.files.mongodb.V7File


  }

  public CollectionResource createCollection(String newName)
      throws NotAuthorizedException, ConflictException,
      BadRequestException {
    V7File child;
    try {
      child = file.createChild((byte[]) null, newName, null);
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
View Full Code Here


    }
    return new FolderResource(child, factory);
  }

  public Resource child(String childName) {
    V7File child = file.getChild(childName);
    if (child == null)
      return null;
    if (child.hasContent())
      return new FileResource(child, factory);
    return new FolderResource(child, factory);
  }
View Full Code Here

      String root = args[1];
      String path = args[2];
      String[] fullPath = ArrayUtils.add(StringUtils.split(path, '/'), 0,
          root);
      V7File file = fs.getFile(fullPath);
      if (file == null) {
        System.err.println("file not found");
        System.exit(1);
      }
      IOUtils.copy(file.getInputStream(), System.out);
    }

  }
View Full Code Here

    return storage.findContentPointerByPrefix(decodeSHAPrefix(shaPrefix));
  }

  static V7File getParent(V7GridFS fs, String[] childPath)
      throws FileNotFoundException {
    V7File parent = fs.getFile(ArrayUtils.subarray(childPath, 0,
        childPath.length - 1));
    if (parent == null)
      throw new FileNotFoundException("target path "
          + ArrayUtils.subarray(childPath, 0, childPath.length - 1));
    return parent;
View Full Code Here

    return parent;
  }

  private static void createFile(V7GridFS fs, ContentPointer content,
      String[] path, String contentType) throws IOException {
    V7File existing = fs.getFile(path);

    if (existing != null) {
      if (contentType == null)
        contentType = existing.getContentType();
      existing.setContent(content, contentType);
    } else {
      V7File parent = getParent(fs, path);
      parent.createChild(content, path[path.length - 1], contentType);
    }
  }
View Full Code Here

            + " is not a hex-encoded SHA-1 prefix");
      }
    } else {
      String[] srcPath = getPath(args[1], args[2]);
      String[] targetPath = getPath(args[3], args[4]);
      V7File src = fs.getFile(srcPath);
      if (src == null) {
        throw new FileNotFoundException(args[1] + " " + args[2]);
      }
      if (src.hasContent()) {
        createFile(fs, src.getContentPointer(), targetPath, src
            .getContentType());
      } else {
        V7File existing = fs.getFile(targetPath);
        if (existing != null) {
          throw new IOException("copy target " + targetPath
              + " already exists");
        }
        V7File parent = getParent(fs, targetPath);
        src.copyTo(parent.getId(), targetPath[targetPath.length - 1]);
      }

    }

  }
View Full Code Here

    }

    String[] p = path.split("/");
    p[0] = ROOT;

    V7File f = fs.getFile(p);
    if (f == null)
      return null;

    if (f.hasContent())
      return fakeLocking ? new LockableFileResource(f, this)
          : new FileResource(f, this);

    return fakeLocking ? new LockableFolderResource(f, this)
        : new FolderResource(f, this);
View Full Code Here

    V7GridFS fs = new V7GridFS(db);

    String[] path = CopyCommand.getPath(args[1], args[2]);

    V7File existing = fs.getFile(path);

    if (existing != null) {
      if (existing.hasContent()) {
        throw new IOException(args[2]
            + " already exists (and is a file)");
      }
      throw new IOException("directory " + args[2] + " already exists");
    }

    V7File parent = CopyCommand.getParent(fs, path);
    fs.addFolder(parent.getId(), path[path.length - 1]);

  }
View Full Code Here

  public boolean authoriseOpen(V7File resource, AuthenticationToken user) {
    Object[] acl = resource.getAcl("open");
    if (acl == null) {
      // no ACL set at all,
      // inherit from parent
      V7File parent = resource.getParent();
      if (parent != null)
        return authoriseOpen(parent, user);
      return global.authoriseOpen(resource, user);
    }
    if (acl.length == 0) {
View Full Code Here

      return global.authoriseRead(resource, user);
    return result;
  }

  public boolean authoriseRead(V7File resource, AuthenticationToken user) {
    V7File parent = resource.getParent();
    if (parent != null) {
      if (!authoriseOpen(parent, user))
        return false;
    }
    Boolean result = authorise(resource, user, "read");
View Full Code Here

TOP

Related Classes of v7db.files.mongodb.V7File

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.