Java Code Examples for org.apache.commons.io.FilenameUtils#getPrefixLength()

The following examples show how to use org.apache.commons.io.FilenameUtils#getPrefixLength() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Local.java    From cyberduck with GNU General Public License v3.0 6 votes vote down vote up
private String parent(final String absolute) {
    final String prefix = FilenameUtils.getPrefix(absolute);
    if(absolute.equals(prefix)) {
        return null;
    }
    int index = absolute.length() - 1;
    if(absolute.charAt(index) == this.getDelimiter()) {
        if(index > 0) {
            index--;
        }
    }
    final int cut = absolute.lastIndexOf(this.getDelimiter(), index);
    if(cut > FilenameUtils.getPrefixLength(absolute)) {
        return absolute.substring(0, cut);
    }
    return String.valueOf(prefix);
}
 
Example 2
Source File: ApplicationArchiveReaderTest.java    From multiapps-controller with Apache License 2.0 5 votes vote down vote up
private ApplicationArchiveReader getApplicationArchiveReaderForAbsolutePath() {
    return new ApplicationArchiveReader() {
        @Override
        protected void validateEntry(ZipEntry entry) {
            String path = entry.getName();
            if (!path.equals(FilenameUtils.normalize(path, true))) {
                throw new IllegalArgumentException(MessageFormat.format(FileUtils.PATH_SHOULD_BE_NORMALIZED, path));
            }
            if (FilenameUtils.getPrefixLength(path) != 0 || Paths.get(path)
                                                                 .isAbsolute()) {
                throw new IllegalArgumentException(MessageFormat.format(FileUtils.PATH_SHOULD_NOT_BE_ABSOLUTE, path));
            }
        }
    };
}
 
Example 3
Source File: RelativePath.java    From sldeditor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Checks if is file is a relative path.
 *
 * @param path the path
 * @return true if the path is relative
 */
public static Boolean isRelativePath(String path) {
    if (path == null) {
        return false;
    }

    int prefixLen = FilenameUtils.getPrefixLength(path);
    return !(testPathWin(path, prefixLen) || testPathLinux(prefixLen));
}
 
Example 4
Source File: PdfFileSourceListAdapter.java    From sejda with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Parse fileset definitions <filelist><fileset>[...]</fileset></filelist> ignoring the rest of the document
 * 
 * @param doc
 * @return a list of string matching the contents of the <filelist><fileset> tags in the document
 * @throws XPathExpressionException
 */
private List<String> parseFileSets(Document doc, File configFile) throws XPathExpressionException {
    List<String> result = new ArrayList<>();

    NodeList nodeList = getNodeListMatchingXpath("//filelist/fileset/file", doc);
    for (int i = 0; i < nodeList.getLength(); i++) {
        Node node = nodeList.item(i);
        Node fileSet = node.getParentNode();

        String parentDirPath = nullSafeGetStringAttribute(fileSet, "dir");
        if (parentDirPath == null) {
            parentDirPath = configFile.getAbsoluteFile().getParent();
        }

        String filePath = extractFilePath(node);

        // warn if file in fileset is using absolute path mode
        if (FilenameUtils.getPrefixLength(filePath) > 0) {
            LOG.warn("File " + filePath + " in fileset "
                    + StringUtils.defaultIfBlank(nullSafeGetStringAttribute(fileSet, "dir"), "")
                    + " seems to be an absolute path. Will _not_ be resolved relative to the <fileset>, but as an absolute path. Normally you would want to use relative paths in a //filelist/fileset/file, and absolute paths in a //filelist/file.");
        }

        result.add(FilenameUtils.concat(parentDirPath, filePath));
    }

    return result;
}
 
Example 5
Source File: MtaPathValidator.java    From multiapps-controller with Apache License 2.0 4 votes vote down vote up
private static boolean isAbsolute(String path) {
    return FilenameUtils.getPrefixLength(path) != 0;
}
 
Example 6
Source File: WorkdirPrefixer.java    From cyberduck with GNU General Public License v3.0 4 votes vote down vote up
private boolean isAbsolute(final String path) {
    return FilenameUtils.getPrefixLength(path) != 0;
}
 
Example 7
Source File: MsBuildParser.java    From analysis-model with MIT License 4 votes vote down vote up
private boolean canResolveRelativeFileName(final String fileName, final String projectDir) {
    return StringUtils.isNotBlank(projectDir) && FilenameUtils.getPrefixLength(fileName) == 0
            && !"MSBUILD".equals(fileName.trim());
}