Java Code Examples for org.apache.commons.vfs2.provider.UriParser#checkUriEncoding()

The following examples show how to use org.apache.commons.vfs2.provider.UriParser#checkUriEncoding() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefaultFileSystemManager.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Resolve the uri to a file name.
 *
 * @param uri The URI to resolve.
 * @return The FileName of the file.
 * @throws FileSystemException if an error occurs.
 */
@Override
public FileName resolveURI(final String uri) throws FileSystemException {
    UriParser.checkUriEncoding(uri);

    if (uri == null) {
        throw new IllegalArgumentException();
    }

    // Extract the scheme
    final String scheme = UriParser.extractScheme(getSchemes(), uri);
    if (scheme != null) {
        // An absolute URI - locate the provider
        final FileProvider provider = providers.get(scheme);
        if (provider != null) {
            return provider.parseUri(null, uri);
        }

        // Otherwise, assume a local file
    }

    // Handle absolute file names
    if (localFileProvider != null && localFileProvider.isAbsoluteLocalName(uri)) {
        return localFileProvider.parseUri(null, uri);
    }

    if (scheme != null) {
        // An unknown scheme - hand it to the default provider
        FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri);
        return defaultProvider.parseUri(null, uri);
    }

    // Assume a relative name - use the supplied base file
    FileSystemException.requireNonNull(baseFile, "vfs.impl/find-rel-file.error", uri);

    return resolveName(baseFile.getName(), uri, NameScope.FILE_SYSTEM);
}
 
Example 2
Source File: DefaultFileSystemManager.java    From commons-vfs with Apache License 2.0 4 votes vote down vote up
/**
 * Resolves a URI, relative to a base file with specified FileSystem configuration.
 *
 * @param baseFile The base file.
 * @param uri The file name. May be a fully qualified or relative path or a url.
 * @param fileSystemOptions Options to pass to the file system.
 * @return A FileObject representing the target file.
 * @throws FileSystemException if an error occurs accessing the file.
 */
public FileObject resolveFile(final FileObject baseFile, final String uri,
        final FileSystemOptions fileSystemOptions) throws FileSystemException {
    final FileObject realBaseFile;
    if (baseFile != null && VFS.isUriStyle() && baseFile.getName().isFile()) {
        realBaseFile = baseFile.getParent();
    } else {
        realBaseFile = baseFile;
    }
    // TODO: use resolveName and use this name to resolve the fileObject

    UriParser.checkUriEncoding(uri);

    if (uri == null) {
        throw new IllegalArgumentException();
    }

    // Extract the scheme
    final String scheme = UriParser.extractScheme(getSchemes(), uri);
    if (scheme != null) {
        // An absolute URI - locate the provider
        final FileProvider provider = providers.get(scheme);
        if (provider != null) {
            return provider.findFile(realBaseFile, uri, fileSystemOptions);
        }
        // Otherwise, assume a local file
    }

    // Handle absolute file names
    if (localFileProvider != null && localFileProvider.isAbsoluteLocalName(uri)) {
        return localFileProvider.findLocalFile(uri);
    }

    if (scheme != null) {
        // An unknown scheme - hand it to the default provider
        FileSystemException.requireNonNull(defaultProvider, "vfs.impl/unknown-scheme.error", scheme, uri);
        return defaultProvider.findFile(realBaseFile, uri, fileSystemOptions);
    }

    // Assume a relative name - use the supplied base file
    FileSystemException.requireNonNull(realBaseFile, "vfs.impl/find-rel-file.error", uri);

    return realBaseFile.resolveFile(uri);
}