List of usage examples for org.apache.commons.io FilenameUtils getPrefixLength
public static int getPrefixLength(String filename)
C:/
or ~/
. From source file:com.sldeditor.ui.detail.config.symboltype.externalgraphic.RelativePath.java
/** * Checks if is file is a relative path. * * @param path the path//from w w w. j a va2s. c o m * @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)); }
From source file:ch.cyberduck.core.local.WorkdirPrefixer.java
private boolean isAbsolute(final String path) { return FilenameUtils.getPrefixLength(path) != 0; }
From source file:ch.systemsx.cisd.openbis.generic.shared.dto.hibernate.LocationValidator.java
public final boolean isValid(final Object value) { final String location = (String) value; final int prefixLength = FilenameUtils.getPrefixLength(location); if (relative) { return prefixLength == 0; } else {//from w w w.java 2s. c o m return prefixLength > 0; } }
From source file:com.themodernway.server.core.file.FileUtils.java
public static final String trunk(String path) { path = patch(path);// ww w. ja v a2 s . com while (path.startsWith(SINGLE_SLASH)) { path = path.substring(1).trim(); } if (CommonOps.IS_NOT_FOUND != path.indexOf(SINGLE_PREFIX_CHAR)) { while (path.startsWith(TILDE_SLASHY)) { path = path.substring(2).trim(); } while (path.startsWith(SLASHY_TILDE)) { path = SINGLE_SLASH + path.substring(2).trim(); } while (path.startsWith(SINGLE_TILDE)) { path = path.substring(1).trim(); } } final int prfx = FilenameUtils.getPrefixLength(path); if (prfx > 0) { path = trunk(path.substring(prfx).trim()); } return path; }
From source file:ch.cyberduck.core.local.FinderLocal.java
@Override public Local getSymlinkTarget() throws NotfoundException, LocalAccessDeniedException { final ObjCObjectByReference error = new ObjCObjectByReference(); final String destination = manager.destinationOfSymbolicLinkAtPath_error(this.getAbsolute(), error); if (null == destination) { final NSError f = error.getValueAs(NSError.class); if (null == f) { throw new LocalNotfoundException(this.getAbsolute()); }/* w w w. j av a2 s . c o m*/ throw new LocalNotfoundException(String.format("%s", f.localizedDescription())); } if (FilenameUtils.getPrefixLength(destination) != 0) { // Absolute path return new FinderLocal(destination); } // Relative path return new FinderLocal(this.getParent(), destination); }
From source file:ch.cyberduck.core.Local.java
private String parent(final String absolute) { final String prefix = FilenameUtils.getPrefix(absolute); if (absolute.equals(prefix)) { return null; }/*from w w w.j av a 2 s. c om*/ 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); }
From source file:org.pentaho.platform.repository.RepositoryFilenameUtils.java
/** * Returns the length of the filename prefix, * <p/>//from w w w . j a va2s .co m * The prefix length includes the first slash in the full filename if applicable. Thus, it is possible that the * length returned is greater than the length of the input string. * * <pre> * a/b/c.txt --> "" --> relative * /a/b/c.txt --> "/" --> absolute * </pre> * <p/> * * @param filename * the filename to find the prefix in, null returns -1 * @return the length of the prefix, -1 if invalid or null */ public static int getPrefixLength(final String filename) { return FilenameUtils.getPrefixLength(filename); }
From source file:org.primefaces.util.FileUploadUtils.java
public static String getValidFilename(String filename) { if (LangUtils.isValueBlank(filename)) { return null; }/*from w w w . j ava 2 s .co m*/ if (isSystemWindows()) { if (!filename.contains("\\\\")) { String[] parts = filename.substring(FilenameUtils.getPrefixLength(filename)) .split(Pattern.quote(File.separator)); for (String part : parts) { if (INVALID_FILENAME_PATTERN.matcher(part).find()) { throw new FacesException("Invalid filename: " + filename); } } } else { throw new FacesException("Invalid filename: " + filename); } } String name = FilenameUtils.getName(filename); String extension = FilenameUtils.EXTENSION_SEPARATOR_STR + FilenameUtils.getExtension(filename); if (extension.equals(FilenameUtils.EXTENSION_SEPARATOR_STR)) { throw new FacesException("File must have an extension"); } else if (name.isEmpty() || extension.equals(name)) { throw new FacesException("Filename can not be the empty string"); } return name; }
From source file:org.sejda.cli.MergeTaskTest.java
private static List<Matcher<Iterable<? super File>>> filesList(String... filenames) { List<Matcher<Iterable<? super File>>> result = new ArrayList<Matcher<Iterable<? super File>>>(); for (String current : filenames) { String filename = current.toString(); if (FilenameUtils.getPrefixLength(filename) > 0) { result.add(CombinableMatcher.<Iterable<? super File>>either(hasItem(new File(filename))) .or(hasItem(new File(FilenameUtils.separatorsToWindows("C:" + filename))))); }/*from w w w .j a va 2 s. c o m*/ result.add(hasItem(new File(filename))); } return result; }
From source file:org.sejda.conversion.PdfFileSourceListAdapter.java
/** * Parse fileset definitions <filelist><fileset>[...]</fileset></filelist> ignoring the rest of the document * //from w w w .ja v a 2s.c o m * @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; }