private void updateLocation() { String pathText = wPath.getText(); String scheme = pathText.isEmpty() ? HDFS_SCHEME : UriParser.extractScheme( pathText ); if ( scheme != null ) { List<VFSScheme> availableVFSSchemes = getAvailableVFSSchemes(); for ( int i = 0; i < availableVFSSchemes.size(); i++ ) { VFSScheme s = availableVFSSchemes.get( i ); if ( scheme.equals( s.scheme ) ) { wLocation.select( i ); selectedVFSScheme = s; } } } }
@Override public URL getURL(final String basePath, final String file) throws MalformedURLException { if ((basePath != null && UriParser.extractScheme(basePath) == null) || (basePath == null && UriParser.extractScheme(file) == null)) { return super.getURL(basePath, file); } try { final FileSystemManager fsManager = VFS.getManager(); FileName path; if (basePath != null && UriParser.extractScheme(file) == null) { final FileName base = fsManager.resolveURI(basePath); path = fsManager.resolveName(base, file); } else { path = fsManager.resolveURI(file); } final URLStreamHandler handler = new VFSURLStreamHandler(path); return new URL(null, path.getURI(), handler); } catch (final FileSystemException fse) { throw new ConfigurationRuntimeException("Could not parse basePath: " + basePath + " and fileName: " + file, fse); } }
@Override public String getFileName(final String path) { if (UriParser.extractScheme(path) == null) { return super.getFileName(path); } try { final FileSystemManager fsManager = VFS.getManager(); final FileName name = fsManager.resolveURI(path); return name.getBaseName(); } catch (final FileSystemException fse) { fse.printStackTrace(); return null; } }
@Override public String getBasePath(final String path) { if (UriParser.extractScheme(path) == null) { return super.getBasePath(path); } try { final FileSystemManager fsManager = VFS.getManager(); final FileName name = fsManager.resolveURI(path); return name.getParent().getURI(); } catch (final FileSystemException fse) { fse.printStackTrace(); return null; } }
@Override public URL locateFromURL(final String basePath, final String fileName) final String fileScheme = UriParser.extractScheme(fileName); if ((basePath == null || UriParser.extractScheme(basePath) == null) && fileScheme == null) final String scheme = UriParser.extractScheme(basePath); final FileSystemOptions opts = (scheme != null) ? getOptions(scheme) : null; FileObject base = (opts == null) ? fsManager.resolveFile(basePath)
/** * Extracts the scheme from a URI. * * @param uri The URI. * @return The scheme name. Returns null if there is no scheme. */ public static String extractScheme(final String uri) { return extractScheme(uri, null); }
/** * Extracts the scheme from a URI. * * @param uri The URI. * @return The scheme name. Returns null if there is no scheme. */ public static String extractScheme(final String uri) { return extractScheme(uri, null); }
/** * Extracts the scheme from a URI. * * @param uri The URI. * @return The scheme name. Returns null if there is no scheme. */ static public String extractScheme(String uri){ return UriParser.extractScheme(uri); }
if (UriParser.extractScheme(fileName) != null)
private Map<String, String> parseSchemeFileOptions(String fileURI) { String scheme = UriParser.extractScheme(fileURI); if (scheme == null) { return null; } HashMap<String, String> schemeFileOptions = new HashMap<>(); schemeFileOptions.put(Constants.SCHEME, scheme); addOptions(scheme, schemeFileOptions); return schemeFileOptions; }
public static Map<String, String> parseSchemeFileOptions(String fileURI, ParameterInclude params) { String scheme = UriParser.extractScheme(fileURI); if (scheme == null) { return null; } Map<String, String> schemeFileOptions = parseSchemeFileOptions(scheme, fileURI); addOptions(schemeFileOptions, params); return schemeFileOptions; }
public static Map<String, String> parseSchemeFileOptions(String fileURI, Properties vfsProperties) { String scheme = UriParser.extractScheme(fileURI); if (scheme == null) { return null; } Map<String, String> schemeFileOptions = parseSchemeFileOptions(scheme, fileURI); addOptions(schemeFileOptions, vfsProperties); return schemeFileOptions; }
@Override public URL run() throws MalformedURLException { final StringBuilder buf = new StringBuilder(); final String scheme = UriParser.extractScheme(fileName.getURI(), buf); return new URL(scheme, "", -1, buf.toString(), new DefaultURLStreamHandler(fs.getContext(), fs.getFileSystemOptions())); } });
@Override public URL run() throws MalformedURLException, FileSystemException { final StringBuilder buf = new StringBuilder(); final String scheme = UriParser.extractScheme(VFS.getManager().getSchemes(), fileName.getURI(), buf); return new URL(scheme, "", -1, buf.toString(), new DefaultURLStreamHandler(fileSystem.getContext(), fileSystem.getFileSystemOptions())); } });
@Test public void testOneSlashSchemeWithBuffer() { StringBuilder buffer = new StringBuilder(); UriParser.extractScheme(schemes, "file:/user:pass@host/some/path/some:file", buffer); Assert.assertEquals("/user:pass@host/some/path/some:file", buffer.toString()); }
@Test public void testNormalScheme() { Assert.assertEquals("ftp", UriParser.extractScheme("ftp://user:pass@host/some/path/some:file")); }
@Test public void testColonInFileName() { Assert.assertEquals(null, UriParser.extractScheme("some/path/some:file")); }
@Test public void testNormalScheme() { Assert.assertEquals("ftp", UriParser.extractScheme(schemes, "ftp://user:pass@host/some/path/some:file")); }
@Test public void testColonInFileName() { Assert.assertEquals(null, UriParser.extractScheme("some/path/some:file")); }
@Test public void testNormalScheme() { Assert.assertEquals("ftp", UriParser.extractScheme("ftp://user:pass@host/some/path/some:file")); }