/** * Returns <code>true</code> if the specified {@link FileURL} denotes a Windows UNC file. * * @param fileURL the {@link FileURL} to test * @return <code>true</code> if the specified {@link FileURL} denotes a Windows UNC file. */ private static boolean isUncFile(FileURL fileURL) { return IS_WINDOWS && !FileURL.LOCALHOST.equals(fileURL.getHost()); } }
private String createDisplayableTitleFromLocation(FileURL location) { if (BookmarkManager.isBookmark(location) && location.getHost() == null) return Translator.get("bookmarks_menu"); boolean local = FileURL.LOCALHOST.equals(location.getHost()); return getHostRepresentation(location.getHost(), local) + getFilenameRepresentation(location.getFilename(), local); }
/** * Returns this file's name. * * <p>The returned name is the filename extracted from this file's <code>FileURL</code> * as returned by {@link FileURL#getFilename()}. If the filename is <code>null</code> (e.g. http://google.com), the * <code>FileURL</code>'s host will be returned instead. If the host is <code>null</code> (e.g. smb://), an empty * String will be returned. Thus, the returned name will never be <code>null</code>.</p> * * <p>This method should be overridden if a special processing (e.g. URL-decoding) needs to be applied to the * returned filename.</p> * * @return this file's name */ public String getName() { String name = fileURL.getFilename(); // If filename is null, use host instead if(name==null) { name = fileURL.getHost(); // If host is null, return an empty string if(name==null) return ""; } return name; }
/** * Creates a new instance of UNCFile, using the given {@link File} if not <code>null</code>, creating a new * {@link File} instance otherwise. */ protected UNCFile(FileURL fileURL, File file) throws IOException { super(fileURL); if(file==null) { absPath = SEPARATOR+SEPARATOR+fileURL.getHost()+fileURL.getPath().replace('/', '\\'); // Replace leading / char by \ // Create the java.io.File instance and throw an exception if the path is not absolute. file = new File(absPath); if(!file.isAbsolute()) throw new IOException(); } // the java.io.File instance was created by ls(), no need to re-create it or call the costly File#getAbsolutePath() else { absPath = SEPARATOR+SEPARATOR+fileURL.getHost()+fileURL.getPath().replace('/', '\\'); } // Remove the trailing separator if present if(absPath.endsWith(SEPARATOR)) absPath = absPath.substring(0, absPath.length()-1); this.file = file; this.permissions = new UNCFilePermissions(file); }
protected HTTPFile(FileURL fileURL, URL url) throws IOException { super(fileURL); String scheme = fileURL.getScheme().toLowerCase(); if((!scheme.equals(FileProtocols.HTTP) && !scheme.equals(FileProtocols.HTTPS)) || fileURL.getHost()==null) throw new IOException(); this.url = url; attributes = getDefaultAttributes(); String mimeType; String filename = fileURL.getFilename(); // Simple/fuzzy heuristic to avoid file resolution (HEAD) in cases where we have good reasons to believe that // the URL denotes a HTML/XTHML document: // - URL's path has no filename (e.g. http://www.mucommander.com/) or path ends with '/' (e.g. http://www.mucommander.com/download/) // - URL has a query part (works most of the time, must not always) // - URL has an extension that registered with an HTML/XHTML mime type if((filename==null || fileURL.getPath().endsWith("/") || fileURL.getQuery()!=null || ((mimeType=MimeTypes.getMimeType(this))!=null && isParsableMimeType(mimeType)))) { attributes.setDirectory(true); resolve = false; } else { resolve = true; } }
if(folderURL.getScheme().equals(FileProtocols.FILE)) { if (FileURL.LOCALHOST.equals(folderURL.getHost())) { locationText = folderURL.getPath(); locationText = "\\\\" + folderURL.getHost() + folderURL.getPath().replace('/', '\\'); if(!locationText.endsWith(UNCFile.SEPARATOR)) locationText += UNCFile.SEPARATOR;
@Override public FileURL getRealm(FileURL location) { FileURL realm = new FileURL(this); String newPath = location.getPath(); // Find first path token (share) int pos = newPath.indexOf('/', 1); newPath = newPath.substring(0, pos==-1?newPath.length():pos+1); realm.setPath(newPath); realm.setScheme(location.getScheme()); realm.setHost(location.getHost()); realm.setPort(location.getPort()); // Copy properties (if any) realm.importProperties(location); return realm; } });
public AbstractFile getFile(FileURL url, Object... instantiationParams) throws IOException { if(url.getHost() == null) { if(url.getPath().equals("/")) return new BookmarkRoot(url); if((bookmark = BookmarkManager.getBookmark(url.getHost())) == null) { if(!url.getPath().equals("/")) throw new IOException(); return new BookmarkFile(new Bookmark(url.getHost(), url.getPath()));
this.file = new XFile("nfs://"+fileURL.getHost()+":"+portString+nfsVersion+nfsProtocol+"m"+"/"+fileURL.getPath());
/** * Tests the resolution of Windows UNC paths (e.g. \\host\\share). This test is system-dependant. * * @throws MalformedURLException should not happen */ @Test public void testUNCParsing() throws MalformedURLException { FileURL url = FileURL.getFileURL("\\\\host\\share"); // UNC path will be transformed into either a 'file' or a 'smb' URL, depending on the current OS assert (OsFamily.WINDOWS.isCurrent()?"file":"smb").equals(url.getScheme()); assert "host".equals(url.getHost()); assert "/share".equals(url.getPath()); }
session = jsch.getSession(credentials.getLogin(), realm.getHost(), port); session.setUserInfo(new PasswordAuthentication());
private void initClientIfNeeded() throws RuntimeFaultFaultMsg, InvalidLocaleFaultMsg, InvalidLoginFaultMsg { if (client == null) { client = new VSphereClient(location.getHost(), location .getCredentials().getLogin(), location.getCredentials() .getPassword()); client.connect(); } }
service = new RestS3Service(new AWSCredentials(credentials.getLogin(), credentials.getPassword())); Jets3tProperties props = new Jets3tProperties(); props.setProperty("s3service.s3-endpoint", url.getHost());
assert "localhost".equals(url.getHost()); assert "/C:\\".equals(url.getPath()); assert "localhost".equals(url.getHost()); assert "/C:\\dir\\file".equals(url.getPath()); assert "file".equals(url.getFilename()); assert "localhost".equals(url.getHost()); assert "/C:\\dir\\".equals(url.getPath()); assert "dir".equals(url.getFilename()); assert "localhost".equals(url.getHost()); assert "/C:\\direc/tory".equals(url.getPath()); assert "direc/tory".equals(url.getFilename()); assert "localhost".equals(url.getHost()); assert "/C:\\".equals(url.getPath()); assert "localhost".equals(url.getHost()); assert "/C:\\dir\\file".equals(url.getPath()); assert "file".equals(url.getFilename()); assert "localhost".equals(url.getHost()); assert "/C:\\dir\\".equals(url.getPath()); assert "dir".equals(url.getFilename()); assert "localhost".equals(url.getHost()); assert "/C:\\direc\\tory".equals(url.getPath()); assert "tory".equals(url.getFilename());
if(OsFamily.WINDOWS.isCurrent() && !FileURL.LOCALHOST.equals(currentURL.getHost())) { newLabel = "SMB";
assert host.equals(url.getHost()); assert port == url.getPort();
url1.setHost(url1.getHost().toUpperCase()); assertEquals(url1, url2); assertEquals(url1, url2, true, true);