Search in sources :

Example 41 with FileURL

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

the class SearchDialog method actionPerformed.

// /////////////////////////
// ActionListener method //
// /////////////////////////
@Override
public void actionPerformed(ActionEvent e) {
    Object source = e.getSource();
    if (source == cancelButton) {
        dispose();
        return;
    }
    // otherwise, searchButton was pressed
    if (!validateAndUpdateValues())
        return;
    String searchIn = searchInField.getText();
    AbstractFile file = FileFactory.getFile(searchIn);
    if (file == null || !file.exists()) {
        searchInField.setBorder(BorderFactory.createLineBorder(Color.RED, 1));
        searchInField.setToolTipText(Translator.get("folder_does_not_exist"));
        return;
    }
    FileURL fileURL = SearchUtils.toSearchURL(file);
    fileURL.setPath(searchFilesField.getText());
    String searchQuery = getSearchQuery();
    if (!searchQuery.isEmpty())
        fileURL.setQuery(searchQuery);
    dispose();
    mainFrame.getActivePanel().tryChangeCurrentFolder(fileURL);
}
Also used : FileURL(com.mucommander.commons.file.FileURL) AbstractFile(com.mucommander.commons.file.AbstractFile)

Example 42 with FileURL

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

the class DropboxConnectionHandler method startConnection.

@Override
public void startConnection() throws IOException, AuthException {
    FileURL credentialFileURL = getCredentialFileURL(fileURL.getHost());
    DbxCredential credential;
    try {
        credential = DbxCredential.Reader.readFromFile(credentialFileURL.getPath());
    } catch (JsonReader.FileLoadException e) {
        LOGGER.error("failed to load credentials to dropbox", e);
        throw new AuthException(fileURL, e.getMessage());
    }
    // Create a DbxClientV2, which is what you use to make API calls.
    DbxRequestConfig requestConfig = new DbxRequestConfig("examples-account-info");
    // Use DbxCredential to create dbx client.
    dbxClient = new DbxClientV2(requestConfig, credential);
}
Also used : FileURL(com.mucommander.commons.file.FileURL) DbxClientV2(com.dropbox.core.v2.DbxClientV2) DbxRequestConfig(com.dropbox.core.DbxRequestConfig) DbxCredential(com.dropbox.core.oauth.DbxCredential) JsonReader(com.dropbox.core.json.JsonReader) AuthException(com.mucommander.commons.file.AuthException)

Example 43 with FileURL

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

the class DropboxFile method getParent.

@Override
public AbstractFile getParent() {
    if (!parentValSet) {
        FileURL parentURL = fileURL.getParent();
        if (parentURL == null)
            this.parent = null;
        else {
            this.parent = FileFactory.getFile(parentURL);
        }
        this.parentValSet = true;
    }
    return this.parent;
}
Also used : FileURL(com.mucommander.commons.file.FileURL)

Example 44 with FileURL

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

the class CredentialsManager method getBestMatchIndex.

/**
 * Finds are returns the index of the CredentialsMapping instance that best matches the given location
 * amongst the provided matching CredentialsMapping Vector, or -1 if the matches Vector is empty.
 *
 * <p>
 * The path of each matching CredentialsMapping' location is compared to the provided location's path: the more
 * folder parts match, the better. If both paths are equal, then the CredentialsMapping index is returned (perfect match).
 * </p>
 *
 * @param location the location to be compared against CredentialsMapping matches
 * @param matches CredentialsMapping instances matching the given location
 * @return the CredentialsMapping instance that best matches the given location, -1 if the given matches Vector is empty.
 */
private static int getBestMatchIndex(FileURL location, List<CredentialsMapping> matches) {
    if (matches.size() == 0)
        return -1;
    // Splits the provided location's path into an array of folder tokens (e.g. "/home/maxence" -> ["home","maxence"])
    String path = location.getPath();
    List<String> pathTokensV = new Vector<String>();
    StringTokenizer st = new StringTokenizer(path, "/\\");
    while (st.hasMoreTokens()) {
        pathTokensV.add(st.nextToken());
    }
    int nbTokens = pathTokensV.size();
    String[] pathTokens = new String[nbTokens];
    pathTokensV.toArray(pathTokens);
    CredentialsMapping tempCredentialsMapping;
    FileURL tempURL;
    String tempPath;
    int nbMatchingToken;
    int maxTokens = 0;
    int bestMatchIndex = 0;
    // Compares the location's path against all the one of all CredentialsMapping instances
    int nbMatches = matches.size();
    for (int i = 0; i < nbMatches; i++) {
        tempCredentialsMapping = matches.get(i);
        tempURL = tempCredentialsMapping.getRealm();
        tempPath = tempURL.getPath();
        // We found a perfect match (same path), it can't get any better than this, return the CredentialsMapping' index
        if (tempPath.equalsIgnoreCase(path))
            return i;
        // Split the current CredentialsMapping' location into folder tokens and count the ones that match
        // the target location's tokens.
        // A few examples to illustrate:
        // /home and /home/maxence -> nbMatchingToken = 1
        // /var/log and /usr -> nbMatchingToken = 0
        st = new StringTokenizer(tempPath, "/\\");
        nbMatchingToken = 0;
        for (int j = 0; j < nbTokens && st.hasMoreTokens(); j++) {
            if (st.nextToken().equalsIgnoreCase(pathTokens[nbMatchingToken]))
                nbMatchingToken++;
            else
                break;
        }
        if (nbMatchingToken > maxTokens) {
            // We just found a better match
            maxTokens = nbMatchingToken;
            bestMatchIndex = i;
        }
    }
    LOGGER.trace("returning bestMatchIndex=" + bestMatchIndex);
    return bestMatchIndex;
}
Also used : FileURL(com.mucommander.commons.file.FileURL) StringTokenizer(java.util.StringTokenizer) AlteredVector(com.mucommander.commons.collections.AlteredVector) Vector(java.util.Vector)

Example 45 with FileURL

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

the class LocationChanger method tryChangeCurrentFolder.

/**
 * Tries to change current folder to the new specified one, and selects the given file after the folder has been
 * changed. The user is notified by a dialog if the folder could not be changed.
 *
 * <p>If the current folder could not be changed to the requested folder and <code>findWorkableFolder</code> is
 * <code>true</code>, the current folder will be changed to the first existing parent of the request folder if there
 * is one, to the first existing local volume otherwise. In the unlikely event that no local volume is workable,
 * the user will be notified that the folder could not be changed.</p>
 *
 * <p>This method spawns a separate thread that takes care of the actual folder change and returns it.
 * It does nothing and returns <code>null</code> if another folder change is already underway.</p>
 *
 * <p>
 * This method is <b>not</b> I/O-bound and returns immediately, without any chance of locking the calling thread.
 * </p>
 *
 * @param folder the folder to be made current folder
 * @param selectThisFileAfter the file to be selected after the folder has been changed (if it exists in the folder), can be null in which case FileTable rules will be used to select current file
 * @param changeLockedTab - flag that indicates whether to change the presented folder in the currently selected tab although it's locked
 * @return the thread that performs the actual folder change, null if another folder change is already underway
 */
public ChangeFolderThread tryChangeCurrentFolder(AbstractFile folder, AbstractFile selectThisFileAfter, boolean findWorkableFolder, boolean changeLockedTab) {
    LOGGER.debug("folder=" + folder + " selectThisFileAfter=" + selectThisFileAfter);
    synchronized (FOLDER_CHANGE_LOCK) {
        // MainFrame#setNoEventsMode.
        if (changeFolderThread != null) {
            LOGGER.debug("A folder change is already taking place (" + changeFolderThread + "), returning null");
            return null;
        }
        // Important: the ChangeFolderThread instance must be kept in a local variable (as opposed to the
        // changeFolderThread field only) before being returned. The reason for this is that ChangeFolderThread
        // changes the changeFolderThread field to null when finished, and it may do so before this method has
        // returned (I've seen this happening). Relying solely on the changeFolderThread field could thus cause
        // a null value to be returned, which is particularly problematic during startup (would cause an NPE).
        FileURL folderURL = folder.getURL();
        ChangeFolderThread thread;
        switch(folderURL.getScheme()) {
            case SearchFile.SCHEMA:
                if (folder instanceof SearchFile)
                    ((SearchFile) folder).stop();
                folder = FileFactory.getFile(folderURL);
                thread = new SearchUpdaterThread(folderURL, changeLockedTab, mainFrame, folderPanel, locationManager, this);
                break;
            default:
                thread = new BrowseLocationThread(folder, findWorkableFolder, changeLockedTab, mainFrame, folderPanel, locationManager, this);
        }
        if (selectThisFileAfter != null)
            thread.selectThisFileAfter(selectThisFileAfter);
        thread.start();
        changeFolderThread = thread;
        return thread;
    }
}
Also used : FileURL(com.mucommander.commons.file.FileURL) SearchFile(com.mucommander.commons.file.protocol.search.SearchFile)

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