/** * Creates a new special Windows location using the given CLSID (Class identifier). * * @param clsid a Windows class identifier * @throws java.net.MalformedURLException should not happen */ public SpecialWindowsLocation(String clsid) throws MalformedURLException { super(FileURL.getFileURL("file:///")); // dummy URL, '/' corresponds to nothing under Windows this.clsid = clsid; }
public BookmarkRoot() throws IOException {this(FileURL.getFileURL(BookmarkProtocolProvider.BOOKMARK + "://"));} public BookmarkRoot(FileURL url) {
/** * Creates a new bookmark file wrapping the specified bookmark. * @param bookmark bookmark to wrap. * @throws IOException if the specified bookmark's URL cannot be resolved. */ protected BookmarkFile(Bookmark bookmark) throws IOException { super(FileURL.getFileURL(BookmarkProtocolProvider.BOOKMARK + "://" + java.net.URLEncoder.encode(bookmark.getName(), "UTF-8"))); this.bookmark = bookmark; }
public TestFile(String name, boolean isdir, long size, long date, AbstractFile parent) throws MalformedURLException { super(FileURL.getFileURL(name)); this.isDir = isdir; this.size = size; this.date = date; this.parent = parent; }
public TestFile(String name, AbstractFile parent) throws MalformedURLException { super(FileURL.getFileURL(name)); this.parent = parent; }
/** * Returns an instance of AbstractFile for the given absolute path and use the given parent for the new file if * not null. AbstractFile subclasses should as much as possible call this method rather than {@link #getFile(String)} * because it is more efficient. * * @param absPath the absolute path to the file * @param parent the returned file's parent * @return an instance of <code>AbstractFile</code> for the specified absolute path. * @throws java.io.IOException if something went wrong during file or file url creation. * @throws AuthException if additionnal authentication information is required to create the file */ public static AbstractFile getFile(String absPath, AbstractFile parent) throws AuthException, IOException { return getFile(FileURL.getFileURL(absPath), parent); }
/** * Attemps to parse the specified url using {@link FileURL#getFileURL(String)} and returns <code>true</code> if it * succeeded, <code>false</code> if it threw a <code>MalformedURLException</code>. * * @param url the URL to try and parse * @return <code>true</code> if the URL could be parsed, <code>false</code> if a <code>MalformedURLException</code> was thrown */ protected boolean canParse(String url) { try { FileURL.getFileURL(url); return true; } catch(MalformedURLException e) { return false; } }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!(lastURL.toLowerCase().startsWith(FileProtocols.HTTP+"://") || lastURL.toLowerCase().startsWith(FileProtocols.HTTPS+"://"))) lastURL = FileProtocols.HTTP+"://"+lastURL; FileURL fileURL = FileURL.getFileURL(lastURL); fileURL.setCredentials(new Credentials(lastUsername, lastPassword)); return fileURL; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); FileURL url = FileURL.getFileURL(FileProtocols.SMB+"://"+lastServer+(lastShare.startsWith("/")?"":"/")+lastShare); // Insert the domain (if any) before the username, separated by a semicolon String userInfo = lastUsername; if(!lastDomain.equals("")) userInfo = lastDomain+";"+userInfo; url.setCredentials(new Credentials(userInfo, lastPassword)); return url; }
private FileURL restoreFileURL(String url) { try { return FileURL.getFileURL(url); } catch (MalformedURLException e) { return getHomeFolder().getURL(); } } }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); FileURL url = FileURL.getFileURL(FileProtocols.VSPHERE + "://" + lastVsphere + "/" + lastGuest + "/" + PathUtils.removeLeadingSeparator(lastDir)); url.setCredentials(new Credentials(lastUsername, new String(passwordField.getPassword()))); url.setProperty(VSphereFile.GUEST_CREDENTIALS, lastGuestUsername + ":" + new String(guestPasswordField.getPassword())); return url; }
/** * Returns the simplest FileURL instance possible using the scheme returned by {@link #getScheme()}, containing * only the scheme and '/' as a path. For instance, if <code>http</code> is the current scheme, a FileURL with * <code>http:///</code> as a string representation will be returned. * * @return a 'root' FileURL instance with the scheme returned by {@link # getScheme ()} * @throws MalformedURLException should never happen */ protected FileURL getRootURL() throws MalformedURLException { return FileURL.getFileURL(getScheme()+":///"); }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.SFTP+"://"+lastServer+lastInitialDir); // Set credentials url.setCredentials(new Credentials(lastUsername, lastPassword)); if(!"".equals(lastKeyPath.trim())) url.setProperty(SFTPFile.PRIVATE_KEY_PATH_PROPERTY_NAME, lastKeyPath); // Set port url.setPort(lastPort); return url; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); FileURL url = FileURL.getFileURL(FileProtocols.NFS+"://"+lastServer+(lastShare.startsWith("/")?"":"/")+lastShare); // Set port url.setPort(lastPort); // Set NFS version url.setProperty(NFSFile.NFS_VERSION_PROPERTY_NAME, lastNfsVersion); // Set NFS protocol url.setProperty(NFSFile.NFS_PROTOCOL_PROPERTY_NAME, lastNfsProtocol); return url; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.S3+"://"+lastServer+lastInitialDir); // Set credentials url.setCredentials(new Credentials(lastUsername, lastPassword)); // Set port url.setPort(lastPort); return url; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.HDFS+"://"+lastServer+lastInitialDir); // Set user and group url.setCredentials(new Credentials(lastUsername, "")); // url.setProperty(HDFSFile.GROUP_PROPERTY_NAME, lastGroup); // Set port url.setPort(lastPort); return url; }
/** * Private Constructor */ private GlobalLocationHistory() { Configuration snapshot = MuConfigurations.getSnapshot(); // Restore the global history from last run int nbLocations = snapshot.getIntegerVariable(MuSnapshot.getRecentLocationsCountVariable()); for (int i=0; i<nbLocations; ++i) { String filePath = snapshot.getVariable(MuSnapshot.getRecentLocationVariable(i)); try { history.add(FileURL.getFileURL(filePath)); } catch (MalformedURLException e) { LOGGER.debug("Got invalid URL from the snapshot file: " + filePath, e); } } }
/** * 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()); }
/** * Ensure that non URL-safe characters in login and password parts are properly handled, both when parsing * and representing URLs as string. * * @throws MalformedURLException should not happen */ @Test public void testCredentialsURLEncoding() throws MalformedURLException { FileURL url = getRootURL(); String urlDecodedString = ":@&=+$,/?t%#[]"; String urlEncodedString = "%3A%40%26%3D%2B%24%2C%2F%3Ft%25%23%5B%5D"; url.setCredentials(new Credentials(urlDecodedString, urlDecodedString)); String urlRep = url.getScheme()+"://"+urlEncodedString+":"+urlEncodedString+"@"; assert urlRep.equals(url.toString(true, false)); url = FileURL.getFileURL(urlRep); Credentials credentials = url.getCredentials(); assert credentials.getLogin().equals(urlDecodedString); assert credentials.getPassword().equals(urlDecodedString); }
@Override public void performAction() { AbstractFile file = mainFrame.getActiveTable().getSelectedFile(true, true); // Retrieves the currently selected file, aborts if none (should not normally happen). if(file == null || !file.isBrowsable()) return; FileURL fileURL = file.getURL(); if (BookmarkManager.isBookmark(fileURL)) { String bookmarkLocation = BookmarkManager.getBookmark(file.getName()).getLocation(); try { fileURL = FileURL.getFileURL(bookmarkLocation); } catch (MalformedURLException e) { LOGGER.error("Failed to resolve bookmark's location: " + bookmarkLocation); return; } } // Opens the currently selected file in a new tab mainFrame.getActivePanel().getTabs().add(fileURL); }