/** * Sets the path part of this URL. The specified path cannot be <code>null</code> and must start with a leading * '/' character. If the specified path value is <code>null</code>, then the path will be set to "/". * If the path does not start with a leading separator, one will be added. * * @param path new path part of this URL * @see #getPath() */ public void setPath(String path) { if(path==null || path.equals("")) path = "/"; if(!path.startsWith("/")) path = "/"+path; this.path = path; // Extract new filename from path this.filename = getFilenameFromPath(path, getPathSeparator()); urlModified(); }
String separator = getPathSeparator();
return true; String separator = getPathSeparator(); if(separator.equals(url.getPathSeparator())) { int separatorLen = separator.length(); int len1 = path1.length();
/** * Ensures that the values returned by {@link FileURL#getPathSeparator()} and {@link SchemeHandler#getPathSeparator()} * match the expected one returned by {@link #getPathSeparator()}. * * @throws MalformedURLException should not happen */ @Test public void testPathSeparator() throws MalformedURLException { FileURL url = getRootURL(); String expectedPathSeparator = url.getPathSeparator(); // Assert that the path separator values returned by the FileURL and its handler match the expected one // and are consistent assert expectedPathSeparator.equals(url.getPathSeparator()); assert expectedPathSeparator.equals(url.getHandler().getPathSeparator()); }
/** * Returns a URL with the same scheme, host and port (if any) as the specified URL, and a path set to * <code>"/"</code> or <code>"\"</code> depending on the URL format. * The login, password, query and fragment parts of the returned URL are always <code>null</code>. * For example, when called with <code>http://www.mucommander.com:8080/path/to/file?query¶m=value</code>, * this method returns <code>http://www.mucommander.com:8080/</code>. * * @param location the location for which to return the authentication realm * @return the authentication realm of the specified location */ public FileURL getRealm(FileURL location) { // Start by cloning the given URL and then modify the parts that need it FileURL realm = (FileURL)location.clone(); realm.setPath(location.getPathSeparator()); realm.setCredentials(null); realm.setQuery(null); // Todo // realm.setFragment(null) return realm; } }
filePath = PathUtils.removeLeadingSeparator(filePath, "/"); String pathSeparator = fileURL.getPathSeparator();
url1.setPath(url1.getPath()+url1.getPathSeparator()); assertEquals(url1, url2); assertEquals(url1, url2, true, true);