/** * 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; }
/** * update list model depending on the data in text component * * @param list - auto-completion popup's list that should be updated. * @param comp - text component * @return true if an auto-completion popup with the updated list should be shown, false otherwise. */ public boolean updateListData(final JList list, AutocompleterTextComponent comp) { list.setListData(getUpdatedSuggestions(comp)); if (list.getModel().getSize() == 1) { try { String typedFilename = FileURL.getFileURL(comp.getText()).getFilename(); // in case the suggestions-list contains only one suggestion and it // match the typed path - do not show an auto-completion popup. if (typedFilename==null || typedFilename.equalsIgnoreCase((String) list.getModel().getElementAt(0))) return false; } catch (MalformedURLException e) { } } return list.getModel().getSize() > 0; }
@Override public AbstractFile getParent() { if(!parentValSet) { FileURL parentFileURL = this.fileURL.getParent(); if(parentFileURL!=null) { try { parent = FileFactory.getFile(parentFileURL, null, createFTPFile(parentFileURL.getFilename(), true)); } catch(IOException e) { // No parent, that's all } } parentValSet = true; } return parent; }
/** * Tests {@link FileURL#getFilename()} method. * * @throws MalformedURLException should not happen */ @Test public void testFilename() throws MalformedURLException { assert "file".equals(getURL("/path/to/file").getFilename()); assert "file".equals(getURL("/path/to/file/").getFilename()); assert "path".equals(getURL("/path").getFilename()); assert "path".equals(getURL("/path/").getFilename()); assert getRootURL().getFilename() == null : "/"; assert (isQueryParsed()?"file":"file?param=value").equals(getURL(null, null, null, -1, "/path/to/file", "param=value").getFilename()); }
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; } }
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); }
protected FTPFile(FileURL fileURL, org.apache.commons.net.ftp.FTPFile file) throws IOException { super(fileURL); this.absPath = fileURL.getPath(); if(file==null) { this.file = getFTPFile(fileURL); // If file doesn't exist (could not be resolved), create it if(this.file==null) { String name = fileURL.getFilename(); // Filename could potentially be null this.file = createFTPFile(name==null?"":name, false); this.fileExists = false; } else { this.fileExists = true; } } else { this.file = file; this.fileExists = true; } this.permissions = new FTPFilePermissions(this.file); }
String wantedName = fileURL.getFilename(); for(int i=0; i<nbFiles; i++) { if(files[i].getName().equalsIgnoreCase(wantedName))
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:\\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()); assert "localhost".equals(url.getHost()); assert "/path".equals(url.getPath()); assert "path".equals(url.getFilename()); assert "localhost".equals(url.getHost());
assert "path".equals(parentURL.getFilename()); assert parentURL.getFilename() == null;
assert path.equals(url.getPath()); assert query.equals(url.getQuery()); assert "to".equals(url.getFilename()); assert "value".equals(url.getProperty("name")); assert "/".equals(url.getPath()); assert url.getQuery() == null; assert url.getFilename() == null; assert url.getProperty("name") == null; assert (scheme+"://").equals(url.toString(true, false));