@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; }
/** * Copy the properties of the given FileURL into this FileURL. * * @param url FileURL instance whose properties should be imported into this one. */ public void importProperties(FileURL url) { // Slight optimization to avoid creating an enumeration if the FileURL doesn't have any property if(url.properties==null) return; Enumeration<String> propertyKeys = url.getPropertyNames(); String key; while(propertyKeys.hasMoreElements()) { key = propertyKeys.nextElement(); setProperty(key, url.getProperty(key)); } }
@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; }
@Override FileURL getServerURL() throws MalformedURLException { updateValues(); if(!lastInitialDir.startsWith("/")) lastInitialDir = "/"+lastInitialDir; FileURL url = FileURL.getFileURL(FileProtocols.FTP+"://"+lastServer+lastInitialDir); if(anonymousUser) url.setCredentials(new Credentials(ANONYMOUS_CREDENTIALS.getLogin(), new String(passwordField.getPassword()))); else url.setCredentials(new Credentials(lastUsername, lastPassword)); // Set port url.setPort(lastPort); // Set passiveMode property to true (default) or false url.setProperty(FTPFile.PASSIVE_MODE_PROPERTY_NAME, ""+passiveMode); // Set FTP encoding property url.setProperty(FTPFile.ENCODING_PROPERTY_NAME, encodingSelectBox.getSelectedEncoding()); // Set connection retry properties url.setProperty(FTPFile.NB_CONNECTION_RETRIES_PROPERTY_NAME, ""+nbRetriesSpinner.getValue()); url.setProperty(FTPFile.CONNECTION_RETRY_DELAY_PROPERTY_NAME, ""+retryDelaySpinner.getValue()); return url; }
@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; }
url.setProperty(key, urlProperties.get(key));
/** * Use the credentials and realm properties of the specified <code>CredentialsMapping</code> to authenticate the * given {@link FileURL}. * <p>Any credentials contained by the <code>FileURL</code> will be lost and replaced with the new ones. * If properties with the same key are defined both in the realm and the given FileURL, the ones from the FileURL * will be preserved.</p> * * @param location the FileURL to authenticate * @param credentialsMapping the credentials to use to authenticate the given FileURL */ public static void authenticate(FileURL location, CredentialsMapping credentialsMapping) { location.setCredentials(credentialsMapping.getCredentials()); FileURL realm = credentialsMapping.getRealm(); Enumeration<String> propertyKeys = realm.getPropertyNames(); String key; while(propertyKeys.hasMoreElements()) { key = propertyKeys.nextElement(); if(location.getProperty(key)==null) location.setProperty(key, realm.getProperty(key)); } }
/** * Tests {@link FileURL#clone()}. * * @throws MalformedURLException should not happen */ @Test public void testClone() throws MalformedURLException { FileURL url = getURL("login", "password", "host", 10000, "/path/to", "query"); url.setProperty("name", "value"); FileURL clonedURL = (FileURL)url.clone(); // Assert that both instances are equal according to FileURL#equals assertEquals(url, clonedURL); // Assert that both URL's string representations (with credentials) are equal assert url.toString(true).equals(clonedURL.toString(true)); // Assert that both instances are not one and the same assert url!=clonedURL; // Assert that the property has survived the cloning assert "value".equals(clonedURL.getProperty("name")); }
url.setPath(path); url.setQuery(query); url.setProperty("name", "value"); url.setPath("/"); url.setQuery(null); url.setProperty("name", null);
public void testParent() throws MalformedURLException { FileURL url = getURL("login", "password", "host", 10000, "/path/to", "query¶m=value"); url.setProperty("key", "value");
url1.setProperty("name", "value"); FileURL url2 = (FileURL)url1.clone(); url1.setProperty("name", null); url1.setProperty("NAME", "value"); assertEquals(url1, url2, false, false); assertNotEquals(url1, url2, true, true); url1.setProperty("name", "VALUE"); assertEquals(url1, url2, false, false); assertNotEquals(url1, url2, true, true); url1.setProperty("NAME", null); url1.setProperty("name", "value"); assertEquals(url1, url2, true, true); url1.setProperty("name2", "value2"); assertNotEquals(url1, url2, true, true); url1.setProperty("name2", null); assertEquals(url1, url2, true, true);