Search in sources :

Example 21 with FileType

use of org.geotoolkit.gml.xml.v321.FileType in project commons-vfs by apache.

the class LocalFileNameParser method parseUri.

@Override
public FileName parseUri(final VfsComponentContext context, final FileName base, final String uri) throws FileSystemException {
    final StringBuilder nameBuilder = new StringBuilder();
    // Extract the scheme
    String scheme = UriParser.extractScheme(getSchemes(context, base, uri), uri, nameBuilder);
    if (scheme == null && base != null) {
        scheme = base.getScheme();
    }
    if (scheme == null) {
        scheme = "file";
    }
    // Remove encoding, and adjust the separators
    UriParser.canonicalizePath(nameBuilder, 0, nameBuilder.length(), this);
    UriParser.fixSeparators(nameBuilder);
    // Extract the root prefix
    final String rootFile = extractRootPrefix(uri, nameBuilder);
    // Normalise the path
    final FileType fileType = UriParser.normalisePath(nameBuilder);
    final String path = nameBuilder.toString();
    return createFileName(scheme, rootFile, path, fileType);
}
Also used : FileType(org.apache.commons.vfs2.FileType)

Example 22 with FileType

use of org.geotoolkit.gml.xml.v321.FileType in project commons-vfs by apache.

the class DefaultFileSystemManager method resolveName.

/**
 * Resolves a name, relative to the root.
 *
 * @param base the base file name
 * @param name the name
 * @param scope the {@link NameScope}
 * @return The FileName of the file.
 * @throws FileSystemException if an error occurs.
 */
@Override
public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException {
    FileSystemException.requireNonNull(base, "Invalid base FileName.");
    FileSystemException.requireNonNull(name, "Invalid name FileName.");
    final FileName realBase;
    if (VFS.isUriStyle() && base.isFile()) {
        realBase = base.getParent();
    } else {
        realBase = base;
    }
    final StringBuilder buffer = new StringBuilder(name);
    // Adjust separators
    UriParser.fixSeparators(buffer);
    String scheme = UriParser.extractScheme(getSchemes(), buffer.toString());
    // Determine whether to prepend the base path
    if (name.isEmpty() || scheme == null && buffer.charAt(0) != FileName.SEPARATOR_CHAR) {
        // Supplied path is not absolute
        if (!VFS.isUriStyle()) {
            // when using URIs the parent already do have the trailing "/"
            buffer.insert(0, FileName.SEPARATOR_CHAR);
        }
        buffer.insert(0, realBase.getPath());
    }
    // Normalise the path
    final FileType fileType = UriParser.normalisePath(buffer);
    // Check the name is ok
    final String resolvedPath = buffer.toString();
    if (!AbstractFileName.checkName(realBase.getPath(), resolvedPath, scope)) {
        throw new FileSystemException("vfs.provider/invalid-descendent-name.error", name);
    }
    final String fullPath;
    if (scheme != null) {
        fullPath = resolvedPath;
    } else {
        scheme = realBase.getScheme();
        fullPath = realBase.getRootURI() + resolvedPath;
    }
    final FileProvider provider = providers.get(scheme);
    if (provider != null) {
        return provider.parseUri(realBase, fullPath);
    }
    // An unknown scheme - hand it to the default provider - if possible
    if (scheme != null && defaultProvider != null) {
        return defaultProvider.parseUri(realBase, fullPath);
    }
    // this happens if we have a virtual filesystem (no provider for scheme)
    return ((AbstractFileName) realBase).createName(resolvedPath, fileType);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileType(org.apache.commons.vfs2.FileType) AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName) FileName(org.apache.commons.vfs2.FileName) LocalFileProvider(org.apache.commons.vfs2.provider.LocalFileProvider) AbstractFileProvider(org.apache.commons.vfs2.provider.AbstractFileProvider) FileProvider(org.apache.commons.vfs2.provider.FileProvider) AbstractFileName(org.apache.commons.vfs2.provider.AbstractFileName)

Example 23 with FileType

use of org.geotoolkit.gml.xml.v321.FileType in project agileway by fangjinuo.

the class SftpFileObject method doGetType.

@Override
protected FileType doGetType() throws Exception {
    com.jn.agileway.ssh.client.sftp.attrs.FileType fileType = getFileAttrs().getFileType();
    FileType ft = FileType.IMAGINARY;
    if (fileType != null) {
        switch(fileType) {
            case REGULAR:
                ft = FileType.FILE;
                break;
            case DIRECTORY:
                ft = FileType.FOLDER;
                break;
            case SYMBOLIC_LINK:
                ft = FileType.FILE_OR_FOLDER;
                break;
            case CHAR_SPECIAL:
            case FIFO_SPECIAL:
            case SOCKET_SPECIAL:
            case BLOCK_SPECIAL:
            case UNKNOWN:
                break;
            default:
                break;
        }
    }
    return ft;
}
Also used : FileType(org.apache.commons.vfs2.FileType)

Example 24 with FileType

use of org.geotoolkit.gml.xml.v321.FileType in project hop by apache.

the class AzureFileNameParser method parseUri.

@Override
public FileName parseUri(final VfsComponentContext context, FileName base, String filename) throws FileSystemException {
    final StringBuilder name = new StringBuilder();
    Authority auth = null;
    String path = null;
    FileType fileType;
    int eidx = filename.indexOf("@/");
    if (eidx != -1)
        filename = filename.substring(0, eidx + 1) + "windowsazure.com" + filename.substring(eidx + 1);
    String scheme;
    try {
        auth = extractToPath(filename, name);
        if (auth.getUserName() == null) {
            scheme = UriParser.extractScheme(filename, name);
            UriParser.canonicalizePath(name, 0, name.length(), this);
            UriParser.fixSeparators(name);
        } else {
            scheme = auth.getScheme();
        }
        fileType = UriParser.normalisePath(name);
        path = name.toString();
        if (path.equals("")) {
            path = "/";
        }
    } catch (FileSystemException fse) {
        scheme = UriParser.extractScheme(filename, name);
        UriParser.canonicalizePath(name, 0, name.length(), this);
        UriParser.fixSeparators(name);
        fileType = UriParser.normalisePath(name);
        path = name.toString();
    }
    return new AzureFileName(scheme, path, fileType);
}
Also used : FileSystemException(org.apache.commons.vfs2.FileSystemException) FileType(org.apache.commons.vfs2.FileType)

Example 25 with FileType

use of org.geotoolkit.gml.xml.v321.FileType in project hop by apache.

the class S3FileNameParser method parseUri.

@Override
public FileName parseUri(VfsComponentContext context, FileName base, String uri) throws FileSystemException {
    StringBuilder name = new StringBuilder();
    String scheme = UriParser.extractScheme(uri, name);
    UriParser.canonicalizePath(name, 0, name.length(), this);
    // Normalize separators in the path
    UriParser.fixSeparators(name);
    // Normalise the path
    FileType fileType = UriParser.normalisePath(name);
    String fullPath = name.toString();
    // Extract bucket name
    final String bucketName = UriParser.extractFirstElement(name);
    return new S3FileName(scheme, bucketName, fullPath, fileType);
}
Also used : FileType(org.apache.commons.vfs2.FileType)

Aggregations

FileType (org.apache.commons.vfs2.FileType)29 FileSystemException (org.apache.commons.vfs2.FileSystemException)8 FileObject (org.apache.commons.vfs2.FileObject)4 File (com.google.api.services.drive.model.File)2 ArrayList (java.util.ArrayList)2 FileName (org.apache.commons.vfs2.FileName)2 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 Timestamp (java.sql.Timestamp)1 JAXBElement (javax.xml.bind.JAXBElement)1 FileNotFolderException (org.apache.commons.vfs2.FileNotFolderException)1 AbstractFileName (org.apache.commons.vfs2.provider.AbstractFileName)1 AbstractFileProvider (org.apache.commons.vfs2.provider.AbstractFileProvider)1 FileProvider (org.apache.commons.vfs2.provider.FileProvider)1 LocalFileProvider (org.apache.commons.vfs2.provider.LocalFileProvider)1 DataIdentifier (org.apache.jackrabbit.core.data.DataIdentifier)1