Search in sources :

Example 21 with FileURL

use of com.mucommander.commons.file.FileURL in project mucommander by mucommander.

the class ConnectionHandler method throwAuthException.

/**
 * Throws an {@link AuthException} using this connection handler's realm, credentials and the message passed as
 * an argument (can be <code>null</code>). The FileURL instance representing the realm that is used to create
 * the <code>AuthException</code> is a clone of this realm, making it safe for modification.
 *
 * @param message the message to pass to AuthException's constructor, can be <code>null</code>
 * @throws AuthException always throws the created AuthException
 */
public void throwAuthException(String message) throws AuthException {
    FileURL clonedRealm = (FileURL) realm.clone();
    clonedRealm.setCredentials(credentials);
    throw new AuthException(clonedRealm, message);
}
Also used : FileURL(com.mucommander.commons.file.FileURL) AuthException(com.mucommander.commons.file.AuthException)

Example 22 with FileURL

use of com.mucommander.commons.file.FileURL in project mucommander by mucommander.

the class AbstractArchiveFile method getArchiveEntryFile.

/**
 * Creates and returns an AbstractFile using the provided entry and parent file. This method takes care of
 * creating the proper AbstractArchiveFile instance if the entry is itself an archive.
 * The entry file's path will use the separator of the underlying file, as returned by {@link #getSeparator()}.
 * That means entries paths of archives located on Windows local filesystems will use '\' as a separator, and
 * '/' for Unix local archives.
 */
protected AbstractFile getArchiveEntryFile(ArchiveEntry entry, AbstractFile parentFile) throws IOException {
    String entryPath = entry.getPath();
    // If the parent file's separator is not '/' (the default entry separator), replace '/' occurrences by
    // the parent file's separator. For local files Under Windows, this allows entries' path to have '\' separators.
    String fileSeparator = getSeparator();
    if (!fileSeparator.equals("/"))
        entryPath = entryPath.replace("/", fileSeparator);
    // Cache AbstractArchiveEntryFile instances so that there is only one AbstractArchiveEntryFile corresponding to
    // the same entry at any given time, to avoid attribute inconsistencies.
    AbstractArchiveEntryFile entryFile = archiveEntryFiles.get(entry);
    if (entryFile == null) {
        FileURL archiveURL = getURL();
        FileURL entryURL = (FileURL) archiveURL.clone();
        entryURL.setPath(addTrailingSeparator(archiveURL.getPath()) + entryPath);
        // Create an RO and RW entry file, depending on whether this archive file is RO or RW
        entryFile = this instanceof AbstractRWArchiveFile ? new RWArchiveEntryFile(entryURL, this, entry) : new ROArchiveEntryFile(entryURL, this, entry);
        entryFile.setParent(parentFile);
        archiveEntryFiles.put(entry, entryFile);
    }
    return FileFactory.wrapArchive(entryFile);
}
Also used : FileURL(com.mucommander.commons.file.FileURL)

Example 23 with FileURL

use of com.mucommander.commons.file.FileURL in project mucommander by mucommander.

the class ServerConnectDialog method updateURLLabel.

@Override
public void updateURLLabel() {
    try {
        FileURL url = currentServerPanel.getServerURL();
        urlLabel.setText(url == null ? " " : url.toString(false));
    } catch (MalformedURLException ex) {
        urlLabel.setText(" ");
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) MalformedURLException(java.net.MalformedURLException)

Example 24 with FileURL

use of com.mucommander.commons.file.FileURL in project mucommander by mucommander.

the class ServerConnectDialog method actionPerformed.

// //////////////////////////
// ActionListener methods //
// //////////////////////////
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source == cancelButton) {
        dispose();
        return;
    }
    try {
        currentServerPanel.dialogValidated();
        // Can throw a MalformedURLException
        FileURL serverURL = currentServerPanel.getServerURL();
        // Create a CredentialsMapping instance and pass to Folder so that it uses it to connect to the folder and
        // adds to CredentialsManager once the folder has been successfully changed
        Credentials credentials = serverURL.getCredentials();
        CredentialsMapping credentialsMapping;
        if (credentials != null) {
            credentialsMapping = new CredentialsMapping(credentials, serverURL, saveCredentialsCheckBox.isSelected());
        } else {
            credentialsMapping = null;
        }
        dispose();
        // Change the current folder
        folderPanel.tryChangeCurrentFolder(serverURL, credentialsMapping);
    } catch (IOException ex) {
        InformationDialog.showErrorDialog(this, Translator.get("table.folder_access_error_title"), Translator.get("folder_does_not_exist"));
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) IOException(java.io.IOException) Credentials(com.mucommander.commons.file.Credentials) CredentialsMapping(com.mucommander.auth.CredentialsMapping)

Example 25 with FileURL

use of com.mucommander.commons.file.FileURL in project mucommander by mucommander.

the class DrivePopupButton method updateButton.

/**
 * Updates the button's label and icon to reflect the current folder and match one of the current volumes: <
 * <ul>
 * <li>If the specified folder corresponds to a bookmark, the bookmark's name will be displayed
 * <li>If the specified folder corresponds to a local file, the enclosing volume's name will be displayed
 * <li>If the specified folder corresponds to a remote file, the protocol's name will be displayed
 * </ul>
 * The button's icon will be the current folder's one.
 */
private void updateButton() {
    AbstractFile currentFolder = folderPanel.getCurrentFolder();
    String currentPath = currentFolder.getAbsolutePath();
    FileURL currentURL = currentFolder.getURL();
    // First try to find a bookmark matching the specified folder
    for (Bookmark bookmark : BookmarkManager.getBookmarks()) {
        if (currentPath.equals(bookmark.getLocation())) {
            // Note: if several bookmarks match current folder, the first one will be used
            setText(bookmark.getName());
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.BOOKMARK_ICON_NAME));
            return;
        }
    }
    // If no bookmark matched current folder
    String protocol = currentURL.getScheme();
    switch(protocol) {
        // Local file, use volume's name
        case LocalFile.SCHEMA:
            String newLabel = null;
            // display 'SMB' which is the underlying protocol
            if (OsFamily.WINDOWS.isCurrent() && !FileURL.LOCALHOST.equals(currentURL.getHost())) {
                newLabel = "SMB";
            } else {
                if (OsFamily.WINDOWS.isCurrent())
                    currentPath = currentFolder.getAbsolutePath(false).toLowerCase();
                else
                    currentPath = currentFolder.getCanonicalPath(false).toLowerCase();
                int bestLength = -1;
                int bestIndex = 0;
                String temp;
                int len;
                for (int i = 0; i < volumes.length; i++) {
                    if (OsFamily.WINDOWS.isCurrent())
                        temp = volumes[i].getAbsolutePath(false).toLowerCase();
                    else
                        temp = volumes[i].getCanonicalPath(false).toLowerCase();
                    len = temp.length();
                    if (currentPath.startsWith(temp) && len > bestLength) {
                        bestIndex = i;
                        bestLength = len;
                    }
                }
                newLabel = volumes[bestIndex].getName();
            // Not used because the call to FileSystemView is slow
            // if(fileSystemView!=null)
            // newToolTip = getWindowsExtendedDriveName(volumes[bestIndex]);
            }
            setText(newLabel);
            setIcon(FileIcons.getFileIcon(currentFolder));
            break;
        case BookmarkProtocolProvider.BOOKMARK:
            String currentFolderName = currentFolder.getName();
            setText(currentFolderName.isEmpty() ? Translator.get("bookmarks_menu") : currentFolderName);
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.BOOKMARKS_ICON_NAME));
            break;
        case SearchFile.SCHEMA:
            setText(Translator.get("find"));
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.FIND_RESULT_ICON_NAME));
            break;
        case "gdrive":
            setText(Translator.get("gdrive"));
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.GOOGLE_DRIVE_ICON_NAME));
            break;
        case "dropbox":
            setText(Translator.get("dropbox"));
            setIcon(IconManager.getIcon(IconManager.FILE_ICON_SET, CustomFileIconProvider.DROPBOX_ICON_NAME));
            break;
        default:
            // Remote file, use the protocol's name
            setText(protocol.toUpperCase());
            setIcon(FileIcons.getFileIcon(currentFolder));
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) AbstractFile(com.mucommander.commons.file.AbstractFile) Bookmark(com.mucommander.bookmark.Bookmark)

Aggregations

FileURL (com.mucommander.commons.file.FileURL)60 AbstractFile (com.mucommander.commons.file.AbstractFile)18 Credentials (com.mucommander.commons.file.Credentials)16 IOException (java.io.IOException)11 AuthException (com.mucommander.commons.file.AuthException)7 MalformedURLException (java.net.MalformedURLException)5 CredentialsMapping (com.mucommander.auth.CredentialsMapping)3 UnsupportedFileOperationException (com.mucommander.commons.file.UnsupportedFileOperationException)3 ProtocolFile (com.mucommander.commons.file.protocol.ProtocolFile)3 File (java.io.File)3 SftpException (com.jcraft.jsch.SftpException)2 AuthDialog (com.mucommander.ui.dialog.auth.AuthDialog)2 RandomAccessFile (java.io.RandomAccessFile)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 DbxException (com.dropbox.core.DbxException)1 DbxRequestConfig (com.dropbox.core.DbxRequestConfig)1 JsonReader (com.dropbox.core.json.JsonReader)1 DbxCredential (com.dropbox.core.oauth.DbxCredential)1