/** * Returns the name appended with the URL's scheme. * * @return the name appended with the URL's scheme. */ public String getNameWithProtocol() { return name+" ["+url.getScheme().toUpperCase()+"]"; }
/** * Check if a given URL represents a bookmark. * * @param fileURL the URL to examine * @return true if the given URL represents a bookmark, false otherwise */ public static boolean isBookmark(FileURL fileURL) { return BookmarkProtocolProvider.BOOKMARK.equals(fileURL.getScheme()); }
public boolean accept(AbstractFile file) { return file.getURL().getScheme().equals(FileProtocols.S3); } });
@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; }
/** * 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)); }
@Override public boolean isHidden() { if(!isHiddenSet && getFileAttributesAvailable && FileProtocols.FILE.equals(file.getURL().getScheme())) getFileAttributes(file); // Note: getFileAttributes() might fail to retrieve file attributes, so we need to test isDirectorySet again if(!isHiddenSet) { isHidden = file.isHidden(); isHiddenSet = true; } return isHidden; }
@Override public boolean exists() { if(!existsSet && getFileAttributesAvailable && FileProtocols.FILE.equals(file.getURL().getScheme())) getFileAttributes(file); // Note: getFileAttributes() might fail to retrieve file attributes, so we need to test isDirectorySet again if(!existsSet) { exists = file.exists(); existsSet = true; } return exists; }
@Override public boolean isDirectory() { if(!isDirectorySet && getFileAttributesAvailable && FileProtocols.FILE.equals(file.getURL().getScheme())) getFileAttributes(file); // Note: getFileAttributes() might fail to retrieve file attributes, so we need to test isDirectorySet again if(!isDirectorySet) { isDirectory = file.isDirectory(); isDirectorySet = true; } return isDirectory; }
/** * 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)); }
/** * Returns <code>true</code> if the given file should have its canonical path followed. In that case, the * AbstractFile instance must be resolved again. * * <p>HTTP files MUST have their canonical path followed. For all other file protocols, this is an option in * the preferences.</p> * * @param file the file to test * @return <code>true</code> if the given file should have its canonical path followed */ private boolean followCanonicalPath(AbstractFile file) { return (MuConfigurations.getPreferences().getVariable(MuPreference.CD_FOLLOWS_SYMLINKS, MuPreferences.DEFAULT_CD_FOLLOWS_SYMLINKS) || file.getURL().getScheme().equals(FileProtocols.HTTP)) && !file.getAbsolutePath(false).equals(file.getCanonicalPath(false)); }
/** * Return a workable location according the following logic: * - If the given folder exists, return it * - if the given folder is local file, find workable location * according to the logic used for inaccessible local files * - Otherwise, return the non-exist remote location */ private AbstractFile getWorkableLocation(FileURL folderURL) { AbstractFile folder = FileFactory.getFile(folderURL); if (folder != null && folder.exists()) return folder; if (folder == null) folder = new NullableFile(folderURL); return FileProtocols.FILE.equals(folderURL.getScheme()) ? getWorkableFolder(folder) : folder; }
/** * Adds the specified folder to history. The folder won't be added if the previous folder is the same. * * <p>This method is called by FolderPanel each time a folder is changed. */ public void tryToAddToHistory(FileURL folderURL) { // Do not add folder to history if new current folder is the same as previous folder if (historyIndex<0 || !folderURL.equals(history.get(historyIndex), false, false)) addToHistory(folderURL); // Save last recallable folder on startup, only if : // - it is a directory on a local filesytem // - it doesn't look like a removable media drive (cd/dvd/floppy), especially in order to prevent // Java from triggering that dreaded 'Drive not ready' popup. LOGGER.trace("folder="+folderURL); if(folderURL.getScheme().equals(FileProtocols.FILE)) { AbstractFile folder = FileFactory.getFile(folderURL); if (folder.isDirectory() && (folder instanceof LocalFile) && !((LocalFile)folder.getRoot()).guessRemovableDrive()) { this.lastRecallableFolder = folder.getAbsolutePath(); LOGGER.trace("lastRecallableFolder= "+lastRecallableFolder); } } }
public Icon lookupCache(AbstractFile file, Dimension preferredResolution) { // Under Mac OS X, return the icon of /Network for the root of remote (non-local) locations. if(OsFamily.MAC_OS_X.isCurrent() && !FileProtocols.FILE.equals(file.getURL().getScheme()) && file.isRoot()) return getSwingIcon(new java.io.File("/Network")); // Look for an existing icon instance for the file's extension return (file.isDirectory()? directoryIconCache : fileIconCache).get(getCheckedExtension(file)); }
@Override protected void toggleEnabledState() { AbstractFile currentFolder = mainFrame.getActivePanel().getCurrentFolder(); setEnabled(currentFolder.getURL().getScheme().equals(FileProtocols.FILE) && !currentFolder.isArchive() && !currentFolder.hasAncestor(AbstractArchiveEntryFile.class) ); }
@Override public FileURL getRealm(FileURL location) { FileURL realm = new FileURL(this); String newPath = location.getPath(); // Find first path token (share) int pos = newPath.indexOf('/', 1); newPath = newPath.substring(0, pos==-1?newPath.length():pos+1); realm.setPath(newPath); realm.setScheme(location.getScheme()); realm.setHost(location.getHost()); realm.setPort(location.getPort()); // Copy properties (if any) realm.importProperties(location); return realm; } });
/** * 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()); }
@Override protected void acceptListItem(AbstractFile item) { MainFrame mainFrame = WindowManager.getCurrentMainFrame(); if(item.getURL().getScheme().equals(FileProtocols.FILE) && (item.hasAncestor(LocalFile.class))) { try { DesktopManager.open(item); } catch(IOException e) {} } // Copies non-local file in a temporary local file and opens them using their native association. else { ProgressDialog progressDialog = new ProgressDialog(mainFrame, Translator.get("copy_dialog.copying")); TempExecJob job = new TempExecJob(progressDialog, mainFrame, item); progressDialog.start(job); } }
/** * Creates and returns an EditorFrame to start viewing the given file. The EditorFrame will be monitored * so that if it is the last window on screen when it is closed by the user, it will trigger the shutdown sequence. * * @param mainFrame the parent MainFrame instance * @param file the file that will be displayed by the returned EditorFrame * @param icon editor frame's icon. * @return the created EditorFrame */ public static FileFrame createEditorFrame(MainFrame mainFrame, AbstractFile file, Image icon) { EditorFrame frame = new EditorFrame(mainFrame, file, icon); // Use new Window decorations introduced in Mac OS X 10.5 (Leopard) if(OsFamily.MAC_OS_X.isCurrent() && OsVersion.MAC_OS_X_10_5.isCurrentOrHigher()) { // Displays the document icon in the window title bar, works only for local files if(file.getURL().getScheme().equals(FileProtocols.FILE)) frame.getRootPane().putClientProperty("Window.documentFile", file.getUnderlyingFileObject()); } // WindowManager will listen to window closed events to trigger shutdown sequence // if it is the last window visible frame.addWindowListener(WindowManager.getInstance()); return frame; }
/** * Creates and returns a ViewerFrame to start viewing the given file. The ViewerFrame will be monitored * so that if it is the last window on screen when it is closed by the user, it will trigger the shutdown sequence. * * @param mainFrame the parent MainFrame instance * @param file the file that will be displayed by the returned ViewerFrame * @param icon window's icon. * @return the created ViewerFrame */ public static FileFrame createViewerFrame(MainFrame mainFrame, AbstractFile file, Image icon) { ViewerFrame frame = new ViewerFrame(mainFrame, file, icon); // Use new Window decorations introduced in Mac OS X 10.5 (Leopard) if(OsFamily.MAC_OS_X.isCurrent() && OsVersion.MAC_OS_X_10_5.isCurrentOrHigher()) { // Displays the document icon in the window title bar, works only for local files if(file.getURL().getScheme().equals(FileProtocols.FILE)) frame.getRootPane().putClientProperty("Window.documentFile", file.getUnderlyingFileObject()); } // WindowManager will listen to window closed events to trigger shutdown sequence // if it is the last window visible frame.addWindowListener(WindowManager.getInstance()); return frame; }
/** * 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); }