List of usage examples for org.apache.commons.io FilenameUtils separatorsToUnix
public static String separatorsToUnix(String path)
From source file:com.weaforce.system.component.fckeditor.tool.UtilsFile.java
/** * Checks if a path corresponds to the rules defined <a * href="http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Server_Side_Integration#File_Browser_Requests">here</a>. * /*from ww w .j a v a 2s . com*/ * @param path * @return <code>true</code> if path corresponds to rules or * <code>false</code>. */ public static boolean isValidPath(final String path) { if (Utils.isEmpty(path)) return false; if (!path.startsWith("/")) return false; if (!path.endsWith("/")) return false; if (!path.equals(FilenameUtils.separatorsToUnix(FilenameUtils.normalize(path)))) return false; return true; }
From source file:net.sf.zekr.engine.server.HttpServer.java
public String toUrl(String localPath) { String normPath = FilenameUtils.normalize(localPath); for (Entry<String, String> entry : pathLookup.entrySet()) { String value = entry.getValue(); if (normPath.startsWith(value)) return getUrl() + entry.getKey() + "/" + FilenameUtils.separatorsToUnix(normPath.substring(value.length() + 1)); }/*from www .jav a 2 s . c om*/ return ""; }
From source file:de.fhg.iais.cortex.services.ingest.worker.ArchiveContentWorker.java
@Override public boolean apply(IIngestContext context) { this.storage.storeAIP(context.getAipObject()); try {/*from w w w. ja va 2s . co m*/ IAipBinaries binaries = context.getAipObject().getBinaries(); try { binaries.setBeforeFirstBinary(); } catch (IllegalStateException e) { context.reportAndThrowTechnicalError(RevisionReport.INGEST_PART, ReportSections.BINARY, "ArchiveBinaryContentWorker: ZipStreamAipBinaries can be only read once!", e); } INamedBinaryStream namedStream; while ((namedStream = binaries.nextBinary()) != null) { String name = namedStream.getBinaryName(); if (name != null) { name = FilenameUtils.separatorsToUnix(name); if (StringUtils.startsWithIgnoreCase(name, "binaries/")) { InputStream stream = namedStream.getBinaryStream(); this.storage.writeBinary(context.getItemId(), name, stream); } } } } catch (Exception e) { LOGGER.error("Storing AIP (" + context.getItemId() + ") failed: ", e); context.reportAndThrowDataError(RevisionReport.INGEST_PART, ReportSections.STORE, "Storing AIP (" + context.getItemId() + ") failed", e); } context.reportSuccess(RevisionReport.INGEST_PART, ReportSections.STORE); return true; }
From source file:com.thoughtworks.go.config.FetchTask.java
public String getSrcfile() { return FilenameUtils.separatorsToUnix(srcfile); }
From source file:me.childintime.childintime.util.file.PathUtils.java
/** * Get the relative path from one file to another, specifying the directory separator. * If one of the provided resources does not exist, it is assumed to be a file unless it ends with '/' or '\'. * * @param targetPath targetPath is calculated to this file * @param basePath basePath is calculated from this file * @param pathSeparator directory separator. The platform default is not assumed so that we can test Unix behaviour when running on Windows (for example) * * @return The relative path./*from w w w. ja v a 2 s. c o m*/ */ public static String getRelativePath(String targetPath, String basePath, String pathSeparator) { // Normalize the paths String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath); String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath); // Undo the changes to the separators made by normalization switch (pathSeparator) { case "/": normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath); break; case "\\": normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToWindows(normalizedBasePath); break; default: throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'"); } String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator)); String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator)); // First get all the common elements. Store them as a string, // and also count how many of them there are. StringBuilder common = new StringBuilder(); int commonIndex = 0; while (commonIndex < target.length && commonIndex < base.length && target[commonIndex].equals(base[commonIndex])) { common.append(target[commonIndex]).append(pathSeparator); commonIndex++; } if (commonIndex == 0) // No single common path element. This most // likely indicates differing drive letters, like C: and D:. // These paths cannot be relativized. throw new PathResolutionException("No common path element found for '" + normalizedTargetPath + "' and '" + normalizedBasePath + "'"); // The number of directories we have to backtrack depends on whether the base is a file or a dir // For example, the relative path from // // /foo/bar/baz/gg/ff to /foo/bar/baz // // ".." if ff is a file // "../.." if ff is a directory // // The following is a heuristic to figure out if the base refers to a file or dir. It's not perfect, because // the resource referred to by this path may not actually exist, but it's the best I can do boolean baseIsFile = true; File baseResource = new File(normalizedBasePath); if (baseResource.exists()) baseIsFile = baseResource.isFile(); else if (basePath.endsWith(pathSeparator)) baseIsFile = false; StringBuilder relative = new StringBuilder(); if (base.length != commonIndex) { int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex; for (int i = 0; i < numDirsUp; i++) relative.append("..").append(pathSeparator); } relative.append(normalizedTargetPath.substring(common.length())); return relative.toString(); }
From source file:com.logsniffer.model.file.WildcardLogsSource.java
/** * @param pattern//from w w w . ja v a2 s . c o m * the pattern to set */ public void setPattern(final String pattern) { this.pattern = FilenameUtils.separatorsToUnix(pattern); }
From source file:AIR.ResourceBundler.Xml.FileSetInput.java
public String getRelative(String basePath, String targetPath) { targetPath = targetPath.replace('\\', '/'); basePath = basePath.replace('\\', '/'); String pathSeparator = "/"; // Normalize the paths String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath); String normalizedBasePath = FilenameUtils.normalizeNoEndSeparator(basePath); // Undo the changes to the separators made by normalization normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath); normalizedBasePath = FilenameUtils.separatorsToUnix(normalizedBasePath); String[] base = normalizedBasePath.split(Pattern.quote(pathSeparator)); String[] target = normalizedTargetPath.split(Pattern.quote(pathSeparator)); // First get all the common elements. Store them as a string, // and also count how many of them there are. StringBuffer common = new StringBuffer(); int commonIndex = 0; while (commonIndex < target.length && commonIndex < base.length && target[commonIndex].equals(base[commonIndex])) { common.append(target[commonIndex] + pathSeparator); commonIndex++;/*from www . jav a 2s. c o m*/ } if (commonIndex == 0) { // No single common path element. This most // likely indicates differing drive letters, like C: and D:. // These paths cannot be relativized. try { throw new Exception("No common path element found for '" + normalizedTargetPath + "' and '" + normalizedBasePath + "'"); } catch (Exception e) { } } // The number of directories we have to backtrack depends on whether the // base is a file or a dir // For example, the relative path from // // /foo/bar/baz/gg/ff to /foo/bar/baz // // ".." if ff is a file // "../.." if ff is a directory // // The following is a heuristic to figure out if the base refers to a // file or dir. It's not perfect, because // the resource referred to by this path may not actually exist, but // it's the best I can do boolean baseIsFile = true; File baseResource = new File(normalizedBasePath); if (baseResource.exists()) { baseIsFile = baseResource.isFile(); } else if (basePath.endsWith(pathSeparator)) { baseIsFile = false; } StringBuffer relative = new StringBuffer(); if (base.length != commonIndex) { int numDirsUp = baseIsFile ? base.length - commonIndex - 1 : base.length - commonIndex; for (int i = 0; i < numDirsUp; i++) { relative.append(".." + pathSeparator); } } relative.append(normalizedTargetPath.substring(common.length())); return relative.toString(); }
From source file:edu.cornell.med.icb.io.ResourceFinder.java
/** * Create a resource finder. If the resource isn't found directly at the specified * path, each of searchPathsVal will be prepended to the resource requested to look * in those locations as well./* w w w . java 2 s .com*/ * @param searchPathsVal the additional searchPaths to search for the resource. */ public ResourceFinder(final String... searchPathsVal) { searchPaths = new LinkedList<String>(); if (searchPathsVal != null && searchPathsVal.length > 0) { for (String searchPath : searchPathsVal) { searchPath = FilenameUtils.separatorsToUnix(searchPath); while (searchPath.endsWith("/")) { searchPath = searchPath.substring(0, searchPath.length() - 1); } this.searchPaths.add(searchPath); } } else { // Default to searching "." (current directory) searchPaths.add("."); } }
From source file:com.thoughtworks.go.domain.DirHandler.java
private String getSrcFilePath(ZipEntry entry) { String parent = new File(srcFile).getParent(); return FilenameUtils.separatorsToUnix(new File(parent, entry.getName()).getPath()); }
From source file:com.apporiented.hermesftp.usermanager.model.PermissionData.java
/** * Fills the placeholders in the path template and checks if the passed path matches the * template.// ww w . jav a2s . c o m * * @param checkPath The path to check. * @param ftproot The ftp root folder. * @param username The username. * @return True, if the path matches the configured pattern. * @throws FtpConfigException Error on reading or processing a configuration file. */ public boolean matches(String checkPath, String ftproot, String username) throws FtpConfigException { if (checkPath == null) { return false; } AntPathMatcher pathMatcher = new AntPathMatcher(); String antPath = replacePlaceholders(ftproot, username); antPath = FilenameUtils.normalizeNoEndSeparator(antPath); antPath = FilenameUtils.separatorsToUnix(antPath); checkPath = FilenameUtils.normalizeNoEndSeparator(checkPath); checkPath = FilenameUtils.separatorsToUnix(checkPath); return pathMatcher.match(antPath, checkPath); }