Ejemplo n.º 1
0
  /** Parses URI and constructs S3 file name. */
  public FileName parseUri(
      final VfsComponentContext context, final FileName base, final String filename)
      throws FileSystemException {
    StringBuffer name = new StringBuffer();

    String scheme = UriParser.extractScheme(filename, name);
    UriParser.canonicalizePath(name, 0, name.length(), this);

    // Normalize separators in the path
    UriParser.fixSeparators(name);

    // Normalise the path
    FileType fileType = UriParser.normalisePath(name);

    // Extract bucket name
    final String bucketName = UriParser.extractFirstElement(name);

    return new S3FileName(scheme, bucketName, name.toString(), fileType);
  }
Ejemplo n.º 2
0
  public FileName parseUri(final VfsComponentContext context, FileName base, final String filename)
      throws FileSystemException {
    final StringBuffer name = new StringBuffer();

    // Extract the scheme and authority parts
    final Authority auth = extractToPath(filename, name);

    // extract domain
    String username = auth.getUserName();
    String domain = extractDomain(username);
    if (domain != null) {
      username = username.substring(domain.length() + 1);
    }

    // Decode and adjust separators
    UriParser.canonicalizePath(name, 0, name.length(), this);
    UriParser.fixSeparators(name);

    // Extract the share
    final String share = UriParser.extractFirstElement(name);
    if (share == null || share.length() == 0) {
      throw new FileSystemException("vfs.provider.smb/missing-share-name.error", filename);
    }

    // Normalise the path.  Do this after extracting the share name,
    // to deal with things like smb://hostname/share/..
    FileType fileType = UriParser.normalisePath(name);
    final String path = name.toString();

    return new SmbFileName(
        auth.getScheme(),
        auth.getHostName(),
        auth.getPort(),
        username,
        auth.getPassword(),
        domain,
        share,
        path,
        fileType);
  }
Ejemplo n.º 3
0
  public void init() throws FileSystemException {
    super.init();

    // Build the index
    List strongRef = new ArrayList(100);
    Enumeration entries = getZipFile().entries();
    while (entries.hasMoreElements()) {
      ZipEntry entry = (ZipEntry) entries.nextElement();
      FileName name =
          getFileSystemManager().resolveName(getRootName(), UriParser.encode(entry.getName()));

      // Create the file
      ZipFileObject fileObj;
      if (entry.isDirectory() && getFileFromCache(name) != null) {
        fileObj = (ZipFileObject) getFileFromCache(name);
        fileObj.setZipEntry(entry);
        continue;
      }

      fileObj = createZipFileObject(name, entry);
      putFileToCache(fileObj);
      strongRef.add(fileObj);
      fileObj.holdObject(strongRef);

      // Make sure all ancestors exist
      // TODO - create these on demand
      ZipFileObject parent = null;
      for (FileName parentName = name.getParent();
          parentName != null;
          fileObj = parent, parentName = parentName.getParent()) {
        // Locate the parent
        parent = (ZipFileObject) getFileFromCache(parentName);
        if (parent == null) {
          parent = createZipFileObject(parentName, null);
          putFileToCache(parent);
          strongRef.add(parent);
          parent.holdObject(strongRef);
        }

        // Attach child to parent
        parent.attachChild(fileObj.getName());
      }
    }
  }
Ejemplo n.º 4
0
  /**
   * Locates a file object, by absolute URI.
   *
   * @param baseFile The base file.
   * @param uri The URI of the file to locate.
   * @param fileSystemOptions The FileSystem options.
   * @return the FileObject.
   * @throws FileSystemException if an error occurs.
   */
  public FileObject findFile(
      final FileObject baseFile, final String uri, final FileSystemOptions fileSystemOptions)
      throws FileSystemException {
    StringBuffer buf = new StringBuffer(80);
    UriParser.extractScheme(uri, buf);
    String resourceName = buf.toString();

    ClassLoader cl =
        ResourceFileSystemConfigBuilder.getInstance().getClassLoader(fileSystemOptions);
    if (cl == null) {
      cl = getClass().getClassLoader();
    }
    final URL url = cl.getResource(resourceName);

    if (url == null) {
      throw new FileSystemException("vfs.provider.url/badly-formed-uri.error", uri);
    }

    FileObject fo = getContext().getFileSystemManager().resolveFile(url.toExternalForm());
    return fo;
  }