/** * Returns a String representation of this BonjourService in the form name / url. */ public String toString() { return name+" / "+url.toString(false); } }
/** * Returns a String representation of this FileURL, including the login and password parts (credentials) only if * requested. * * @param includeCredentials if <code>true</code>, the login and password parts (if any) will be included in the * returned URL. * @return a string representation of this <code>FileURL</code>. */ public String toString(boolean includeCredentials) { return toString(includeCredentials, false); }
/** * Returns a String representation of this FileURL, without including the login and password parts it may have. */ public String toString() { return toString(false); }
protected HTTPFile(FileURL fileURL) throws IOException { // TODO: optimize this this(fileURL, new URL(fileURL.toString(false))); }
protected void updateURLLabel() { try { FileURL url = currentServerPanel.getServerURL(); urlLabel.setText(url==null?" ":url.toString(false)); } catch(MalformedURLException ex) { urlLabel.setText(" "); } }
public String toString() { return credentials.toString()+" "+realm.toString(false); } }
@Override public String toString() { if (!FileProtocols.FILE.equals(url.getScheme())) return url.toString(); String path = url.getPath(); if (LocalFile.USES_ROOT_DRIVES && !path.isEmpty()) path = path.substring(1); return path; }
/** * Returns the absolute path to this file: * <ul> * <li>For local filesystems, the local file's path should be returned, and <b>not</b> a full URL with the scheme * and host parts (e.g. /path/to/file, not file://localhost/path/to/file)</li> * <li>For any other filesystems, the full URL including the protocol and host parts should be returned * (e.g. smb://192.168.1.1/root/blah)</li> * </ul> * <p> * This default implementation returns the string representation of this file's {@link #getURL() url}, without * the login and password parts. File implementations overridding this method should always return a path free of * any login and password, so that it can safely be displayed to the end user or stored, without risking to * compromise sensitive information. * </p> * * @return the absolute path to this file */ public String getAbsolutePath() { return getURL().toString(false); }
@Override protected FileSystem getHadoopFileSystem(FileURL url) throws IOException { // Note: getRealm returns a fresh instance every time FileURL realm = url.getRealm(); Configuration conf = new Configuration(); // Import the user from the URL's authority, if set // TODO: for some reason, setting the group has no effect: files are still created with the default supergroup conf.setStrings(UnixUserGroupInformation.UGI_PROPERTY_NAME, getUsername(url), getGroup(url)); return FileSystem.get(URI.create(realm.toString(false)), conf); }
/** * Creates a new OpenLocationAction instance using the provided url's string representation * (with credentials stripped out) as label. */ public OpenLocationAction(MainFrame mainFrame, Map<String,Object> properties, FileURL url) { this(mainFrame, properties, url, url.getScheme().equals(FileProtocols.FILE)?url.getPath():url.toString(false)); }
/** * Creates and returns a <code>java.net.URL</code> referring to the same location as this <code>FileURL</code>. * The <code>java.net.URL</code> is created from the string representation of this <code>FileURL</code>. * Thus, any credentials this <code>FileURL</code> contains are preserved, but properties are lost. * * <p>The returned <code>URL</code> uses an {@link AbstractFile} to access the associated resource. * An {@link AbstractFile} instance is created by the underlying <code>URLConnection</code> when the URL is * connected.</p> * * <p>It is important to note that this method is provided for interoperability purposes, for the sole purpose of * connecting to APIs that require a <code>java.net.URL</code>.</p> * * @return a <code>java.net.URL</code> referring to the same location as this <code>FileURL</code> * @throws MalformedURLException if the java.net.URL could not parse the location of this FileURL */ public URL getJavaNetURL() throws MalformedURLException { return new URL(null, toString(true), new CompatURLStreamHandler()); }
private void setGlobalHistory() { List<FileURL> locations = GlobalLocationHistory.Instance().getHistory(); configuration.setVariable(getRecentLocationsCountVariable(), locations.size()); Iterator<FileURL> iterator = locations.iterator(); for (int i=0; iterator.hasNext(); ++i) configuration.setVariable(getRecentLocationVariable(i), iterator.next().toString()); }
/** * Creates a new OpenLocationAction instance using the provided FileURL and label. */ public OpenLocationAction(MainFrame mainFrame, Map<String,Object> properties, FileURL url, String label) { super(mainFrame, properties); this.url = url; setLabel(label); setToolTipText(url.getScheme().equals(FileProtocols.FILE)?url.getPath():url.toString(false)); }
/** * Creates and returns a <code>java.net.URL</code> referring to the same location as the {@link FileURL} associated * with this <code>AbstractFile</code>. * The <code>java.net.URL</code> is created from the string representation of this file's <code>FileURL</code>. * Thus, any credentials this <code>FileURL</code> contains are preserved, but properties are lost. * * <p>The returned <code>URL</code> uses this {@link AbstractFile} to access the associated resource, via the * underlying <code>URLConnection</code> which delegates to this class.</p> * * <p>It is important to note that this method is provided for interoperability purposes, for the sole purpose of * connecting to APIs that require a <code>java.net.URL</code>.</p> * * @return a <code>java.net.URL</code> referring to the same location as this <code>FileURL</code> * @throws java.net.MalformedURLException if the java.net.URL could not parse the location of this FileURL */ public URL getJavaNetURL() throws MalformedURLException { return new URL(null, getURL().toString(true), new CompatURLStreamHandler(this)); }
/** * Tests FileURL's <code>toString</code> methods. * * @throws MalformedURLException should not happen */ @Test public void testStringRepresentation() throws MalformedURLException { FileURL url = getURL("login", "password", "host", 10000, "/path", "query"); String path = getSchemePath("/path"); String urlString = getScheme()+"://host:10000"+path+"?query"; assert urlString.equals(url.toString()); assert urlString.equals(url.toString(false)); assert urlString.equals(url.toString(false, false)); urlString = getScheme()+"://login:password@host:10000"+path+"?query"; assert urlString.equals(url.toString(true)); assert urlString.equals(url.toString(true, false)); urlString = getScheme()+"://login:********@host:10000"+path+"?query"; assert urlString.equals(url.toString(true, true)); }
@Override protected FileSystem getHadoopFileSystem(FileURL url) throws IOException { if(!url.containsCredentials()) throw new AuthException(url); // Note: getRealm returns a fresh instance every time FileURL realm = url.getRealm(); // Import credentials Credentials creds = url.getCredentials(); if(creds!=null) { // URL-encode secret as it may contain non URL-safe characters ('+' and '/') realm.setCredentials(new Credentials(creds.getLogin(), URLEncoder.encode(creds.getPassword(), "UTF-8"))); } // Change the scheme to the actual Hadoop fileystem (s3 -> s3n) realm.setScheme("s3n"); return FileSystem.get(URI.create(realm.toString(true, false)), DEFAULT_CONFIGURATION); }
public Object getElementAt(int i) { ConnectionHandler connHandler = connections.get(i); // Show login (but not password) in the URL // Note: realm returned by ConnectionHandler does not contain credentials FileURL clonedRealm = (FileURL)connHandler.getRealm().clone(); Credentials loginCredentials = new Credentials(connHandler.getCredentials().getLogin(), ""); clonedRealm.setCredentials(loginCredentials); return clonedRealm.toString(true) +" ("+Translator.get(connHandler.isLocked()?"server_connections_dialog.connection_busy":"server_connections_dialog.connection_idle")+")"; } });
/** * 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")); }
/** * 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); }
private void setTabsAttributes(int index, boolean isLeft, FileTableTabs tabs) { int tabsCounter = 0; Iterator<FileTableTab> tabsIterator = tabs.iterator(); // Save tabs locations while (tabsIterator.hasNext()) { FileTableTab tab = tabsIterator.next(); configuration.setVariable(getTabLocationVariable(index, isLeft, tabsCounter), tab.getLocation().toString()); configuration.setVariable(getTabLockedVariable(index, isLeft, tabsCounter), tab.isLocked()); configuration.setVariable(getTabTitleVariable(index, isLeft, tabsCounter), tab.getTitle()); ++tabsCounter; } if (tabsCounter > 0) { // Save tabs count configuration.setVariable(getTabsCountVariable(index, isLeft), tabsCounter); // Save the index of the selected tab configuration.setVariable(getTabsSelectionVariable(index, isLeft), tabs.getSelectedIndex()); } }