Example usage for org.apache.commons.io FilenameUtils getFullPathNoEndSeparator

List of usage examples for org.apache.commons.io FilenameUtils getFullPathNoEndSeparator

Introduction

In this page you can find the example usage for org.apache.commons.io FilenameUtils getFullPathNoEndSeparator.

Prototype

public static String getFullPathNoEndSeparator(String filename) 

Source Link

Document

Gets the full path from a full filename, which is the prefix + path, and also excluding the final directory separator.

Usage

From source file:org.pgptool.gui.tools.PathUtilsTest.java

@Test
public void testExtractBasePath() {
    // NOTE: Nut sure how to write one test which will work on both
    // platforms =(
    if (System.getProperty("os.name").toLowerCase().contains("windows")) {
        String result = FilenameUtils.getFullPathNoEndSeparator("c:\\temp\\aaa.docx");
        assertEquals("c:\\temp", result);
    } else {//from  w  w w  . j a  v a 2s. co  m
        String result = FilenameUtils.getFullPathNoEndSeparator("/var/opt/file.txt");
        assertEquals("/var/opt", result);
    }
}

From source file:org.pgptool.gui.ui.decryptone.DecryptOnePm.java

public SaveFileChooserDialog getTargetFileChooser() {
    if (targetFileChooser == null) {
        targetFileChooser = new SaveFileChooserDialog(findRegisteredWindowIfAny(), "action.chooseTargetFile",
                "action.choose", appProps, "DecryptionTargetChooser") {
            @Override/*w w  w .java2 s  .  com*/
            protected String onDialogClosed(String filePathName, JFileChooser ofd) {
                String ret = super.onDialogClosed(filePathName, ofd);
                if (ret != null) {
                    targetFile.setValueByOwner(ret);
                }
                return ret;
            }

            @Override
            protected void suggestTarget(JFileChooser ofd) {
                String sourceFileStr = sourceFile.getValue();
                if (StringUtils.hasText(targetFile.getValue())) {
                    // Case 1: Based on current target
                    use(ofd, targetFile.getValue());
                } else if (decryptionDialogParameters != null
                        && decryptionDialogParameters.getTargetFile() != null) {
                    if (decryptionDialogParameters.getSourceFile().equals(sourceFileStr)) {
                        // exact match
                        use(ofd, decryptionDialogParameters.getTargetFile());
                    } else {
                        // case when suggested parameters are provided for
                        // neighbor
                        use(ofd, madeUpTargetFileName(FilenameUtils
                                .getFullPathNoEndSeparator(decryptionDialogParameters.getTargetFile())));
                    }
                } else if (StringUtils.hasText(sourceFileStr) && new File(sourceFileStr).exists()) {
                    use(ofd, madeUpTargetFileName(FilenameUtils.getFullPathNoEndSeparator(sourceFileStr)));
                }
            }

            private void use(JFileChooser ofd, String filePathName) {
                ofd.setCurrentDirectory(new File(FilenameUtils.getFullPathNoEndSeparator(filePathName)));
                ofd.setSelectedFile(new File(filePathName));
            }
        };
    }
    return targetFileChooser;
}

From source file:org.pgptool.gui.ui.encryptone.EncryptOnePm.java

public SaveFileChooserDialog getTargetFileChooser() {
    if (targetFileChooser == null) {
        targetFileChooser = new SaveFileChooserDialog(findRegisteredWindowIfAny(), "action.chooseTargetFile",
                "action.choose", appProps, "EncryptionTargetChooser") {
            @Override/*from   w  w  w . ja  v a  2  s  .  c om*/
            protected String onDialogClosed(String filePathName, JFileChooser ofd) {
                String ret = super.onDialogClosed(filePathName, ofd);
                if (ret != null) {
                    targetFile.setValueByOwner(ret);
                }
                return ret;
            }

            @Override
            protected void onFileChooserPostConstrct(JFileChooser ofd) {
                ofd.setAcceptAllFileFilterUsed(false);
                ofd.addChoosableFileFilter(new FileNameExtensionFilter("GPG Files (.pgp)", "pgp"));
                // NOTE: Should we support other extensions?....
                ofd.addChoosableFileFilter(ofd.getAcceptAllFileFilter());
                ofd.setFileFilter(ofd.getChoosableFileFilters()[0]);
            }

            @Override
            protected void suggestTarget(JFileChooser ofd) {
                String sourceFileStr = sourceFile.getValue();
                if (StringUtils.hasText(targetFile.getValue())) {
                    use(ofd, targetFile.getValue());
                } else if (encryptionDialogParameters != null
                        && encryptionDialogParameters.getTargetFile() != null) {
                    if (encryptionDialogParameters.getSourceFile().equals(sourceFile.getValue())) {
                        use(ofd, encryptionDialogParameters.getTargetFile());
                    } else {
                        use(ofd, madeUpTargetFileName(sourceFile.getValue(), FilenameUtils
                                .getFullPathNoEndSeparator(encryptionDialogParameters.getTargetFile())));
                    }
                } else if (StringUtils.hasText(sourceFileStr) && new File(sourceFileStr).exists()) {
                    String basePath = FilenameUtils.getFullPathNoEndSeparator(sourceFileStr);
                    ofd.setCurrentDirectory(new File(basePath));
                    ofd.setSelectedFile(new File(madeUpTargetFileName(sourceFileStr, basePath)));
                }
            }

            private void use(JFileChooser ofd, String filePathName) {
                ofd.setCurrentDirectory(new File(FilenameUtils.getFullPathNoEndSeparator(filePathName)));
                ofd.setSelectedFile(new File(filePathName));
            }
        };
    }
    return targetFileChooser;
}

From source file:org.pgptool.gui.ui.tools.browsefs.ExistingFileChooserDialog.java

public String askUserForFile() {
    JFileChooser ofd = buildFileChooserDialog();

    int result = ofd.showOpenDialog(optionalParent);
    if (result != JFileChooser.APPROVE_OPTION) {
        return handleFileWasChosen(null);
    }/*from  w w  w.ja  v a  2s  .  co  m*/
    File retFile = ofd.getSelectedFile();
    if (retFile == null) {
        return handleFileWasChosen(null);
    }

    String ret = retFile.getAbsolutePath();
    ret = handleFileWasChosen(ret);
    configPairs.put(configPairNameToRemember, FilenameUtils.getFullPathNoEndSeparator(ret));
    return ret;
}

From source file:org.pgptool.gui.ui.tools.browsefs.MultipleFilesChooserDialog.java

/**
 * Blocking call to browse for files/*from ww  w . j  a  v a2  s.  co  m*/
 * 
 * @return null if nothing was chosen, or array of files chosen otherwise
 */
public File[] askUserForMultipleFiles() {
    JFileChooser ofd = buildFileChooserDialog();

    int result = ofd.showOpenDialog(optionalParent);
    if (result != JFileChooser.APPROVE_OPTION) {
        handleFilesWereChosen(null);
        return null;
    }
    File[] retFile = ofd.getSelectedFiles();
    if (retFile == null || retFile.length == 0) {
        handleFilesWereChosen(null);
        return null;
    }

    handleFilesWereChosen(retFile);
    configPairs.put(configPairNameToRemember,
            FilenameUtils.getFullPathNoEndSeparator(retFile[0].getAbsolutePath()));
    return retFile;
}

From source file:org.pgptool.gui.ui.tools.browsefs.SaveFileChooserDialog.java

/**
 * Subclass can do post-processing if needed
 * /*w  w w.j av  a2 s .  c  o  m*/
 * @param filePathName
 *            user choice, might be null
 * @param ofd
 *            dialog
 * @return value that will be returned to initial invoker
 */
protected String onDialogClosed(String filePathName, JFileChooser ofd) {
    if (filePathName == null) {
        return null;
    }

    if (configPairs != null && configId != null) {
        configPairs.put(configId, FilenameUtils.getFullPathNoEndSeparator(filePathName));
    }

    return enforceExtension(filePathName, ofd);
}

From source file:org.polyfill.services.FinancialTimesPolyfillLoaderService.java

private String getBaseDirectoryName(Resource resource) throws IOException {
    // using string manipulation to handle path here because if resource is from jar,
    // we cannot create a file/path instance from it
    String dirPathString = FilenameUtils.getFullPathNoEndSeparator(resource.getURI().toString());
    return FilenameUtils.getName(dirPathString);
}

From source file:org.ros.internal.message.definition.MessageDefinitionFileProvider.java

private static String getParent(String filename) {
    return FilenameUtils.getFullPathNoEndSeparator(filename);
}

From source file:org.settings4j.connector.PropertyFileConnector.java

private static URL getParentFolderUrlFromClasspath(final String propertyPath) {
    final URL resource = ClasspathContentResolver.getResource(propertyPath);
    Validate.notNull(resource, "The URL for '%s' was null", propertyPath);
    final String fullPathNoEndSeparator = FilenameUtils.getFullPathNoEndSeparator(resource.toExternalForm());
    return createURL(fullPathNoEndSeparator + "/");
}

From source file:org.sipfoundry.sipxconfig.device.Resource.java

public String getDirName() {
    return FilenameUtils.getFullPathNoEndSeparator(m_path);
}