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

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

Introduction

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

Prototype

public static String separatorsToUnix(String path) 

Source Link

Document

Converts all separators to the Unix separator of forward slash.

Usage

From source file:org.sonar.plugins.python.DirectoryScanner.java

public List<File> getIncludedFiles() {
    final String baseDirAbsolutePath = baseDir.getAbsolutePath();
    IOFileFilter fileFilter = new IOFileFilter() {

        @Override/* www . j a  va 2 s . c o  m*/
        public boolean accept(File dir, String name) {
            return accept(new File(dir, name));
        }

        @Override
        public boolean accept(File file) {
            String path = file.getAbsolutePath();
            path = path.substring(Math.min(baseDirAbsolutePath.length(), path.length()));
            return pattern.match(FilenameUtils.separatorsToUnix(path));
        }
    };
    return Lists.newArrayList(FileUtils.listFiles(baseDir, fileFilter, TrueFileFilter.INSTANCE));
}

From source file:org.sonar.runner.api.DirsTest.java

@Test
public void should_use_parameterized_task_work_dir() throws Exception {
    runner.setProperty("sonar.task", "views");
    runner.setProperty("sonar.working.directory", "generated/reports");
    dirs.init(runner);/*from  ww  w  .  j a  v  a2 s . c  o  m*/

    File workDir = new File(runner.property("sonar.working.directory", null));
    assertThat(workDir).isNotNull();
    assertThat(FilenameUtils.separatorsToUnix(workDir.getCanonicalPath())).contains("generated/reports");
}

From source file:org.sourcepit.common.utils.path.PathMatcher.java

public static PathMatcher parseFilePatterns(final File baseDir, String filePatterns) {
    final PatternParser parser = new PatternParser() {
        protected String prepareRawPattern(String rawPattern, boolean isExclude) {
            String result = super.prepareRawPattern(rawPattern, isExclude);
            if (!result.startsWith("**") && !new File(result).isAbsolute()) {
                result = new File(baseDir, result).getAbsolutePath();
            }/*w  w w  . j  av a  2s .  c om*/
            result = FilenameUtils.separatorsToUnix(result);
            return result;
        };

        @Override
        protected PathMatcher createMacher(Set<String> includes, Set<String> excludes) {
            return new PathMatcher(includes, excludes) {
                @Override
                public boolean isMatch(String path) {
                    return super.isMatch(FilenameUtils.separatorsToUnix(new File(path).getAbsolutePath()));
                }
            };
        }
    };
    parser.setPatternString(FilenameUtils.separatorsToUnix(filePatterns));
    parser.setPatternSeparator(",");
    parser.setSegmentSeparator("/");
    return parser.parse();
}

From source file:org.sourcepit.common.utils.path.PathUtils.java

public static String normalize(String targetPath, String pathSeparator) {
    // Normalize the paths
    String normalizedTargetPath = FilenameUtils.normalizeNoEndSeparator(targetPath);

    // Undo the changes to the separators made by normalization
    if (pathSeparator.equals("/")) {
        normalizedTargetPath = FilenameUtils.separatorsToUnix(normalizedTargetPath);

    } else if (pathSeparator.equals("\\")) {
        normalizedTargetPath = FilenameUtils.separatorsToWindows(normalizedTargetPath);

    } else {//  w  w  w . j a  v a 2s .co m
        throw new IllegalArgumentException("Unrecognised dir separator '" + pathSeparator + "'");
    }
    return normalizedTargetPath;
}

From source file:org.vafer.jdependency.Clazzpath.java

public ClazzpathUnit addClazzpathUnit(final File pFile, final String pId) throws IOException {
    if (pFile.isFile()) {
        return addClazzpathUnit(new FileInputStream(pFile), pId);
    }// ww w .  j  a  v a  2  s  . c  o m
    if (pFile.isDirectory()) {
        final String prefix = FilenameUtils.separatorsToUnix(FilenameUtils
                .normalize(new StringBuilder(pFile.getAbsolutePath()).append(File.separatorChar).toString()));
        final boolean recursive = true;
        @SuppressWarnings("unchecked")
        final Iterator<File> files = FileUtils.iterateFiles(pFile, new String[] { "class" }, recursive);
        return addClazzpathUnit(new Iterable<Resource>() {

            public Iterator<Resource> iterator() {
                return new Iterator<Clazzpath.Resource>() {

                    public boolean hasNext() {
                        return files.hasNext();
                    }

                    public Resource next() {
                        final File file = files.next();
                        return new Resource(file.getAbsolutePath().substring(prefix.length())) {

                            @Override
                            InputStream getInputStream() throws IOException {
                                return new FileInputStream(file);
                            }
                        };
                    }

                    public void remove() {
                        throw new UnsupportedOperationException();
                    }
                };
            }

        }, pId, true);
    }
    throw new IllegalArgumentException();
}

From source file:org.yamj.core.service.file.FileTools.java

public static String getPathFragment(String folderName) {
    return FilenameUtils.separatorsToUnix("/" + folderName + "/");
}

From source file:pt.webdetails.cdf.dd.api.RenderApi.java

@GET
@Path("/render")
@Produces(TEXT_HTML)/*  w  w w.  ja v  a 2s  .  c om*/
public String render(@QueryParam(MethodParams.SOLUTION) @DefaultValue("") String solution,
        @QueryParam(MethodParams.PATH) @DefaultValue("") String path,
        @QueryParam(MethodParams.FILE) @DefaultValue("") String file,
        @QueryParam(MethodParams.INFERSCHEME) @DefaultValue("false") boolean inferScheme,
        @QueryParam(MethodParams.ROOT) @DefaultValue("") String root,
        @QueryParam(MethodParams.ABSOLUTE) @DefaultValue("true") boolean absolute,
        @QueryParam(MethodParams.BYPASSCACHE) @DefaultValue("false") boolean bypassCache,
        @QueryParam(MethodParams.DEBUG) @DefaultValue("false") boolean debug,
        @QueryParam(MethodParams.SCHEME) @DefaultValue("") String scheme,
        @QueryParam(MethodParams.VIEW) @DefaultValue("") String view,
        @QueryParam(MethodParams.STYLE) @DefaultValue("") String style, @Context HttpServletRequest request)
        throws IOException {
    String schemeToUse = "";
    if (!inferScheme) {
        schemeToUse = StringUtils.isEmpty(scheme) ? request.getScheme() : scheme;
    }

    String filePath = getWcdfRelativePath(solution, path, file);
    if (StringUtils.isEmpty(filePath)) {
        return "No path provided.";
    }

    IReadAccess readAccess = Utils.getSystemOrUserReadAccess(filePath);
    if (readAccess == null) {
        return Messages.getString("XmlStructure.ERROR_011_READ_WRITE_ACCESS_EXCEPTION");
    }

    long start = System.currentTimeMillis();
    long end;
    ILogger iLogger = getAuditLogger();
    IParameterProvider requestParams = getParameterProvider(request.getParameterMap());

    UUID uuid = CpfAuditHelper.startAudit(getPluginName(), filePath, getObjectName(), this.getPentahoSession(),
            iLogger, requestParams);

    try {
        logger.info("[Timing] CDE Starting Dashboard Rendering");
        CdfRunJsDashboardWriteResult dashboard = loadDashboard(filePath, schemeToUse, root, absolute,
                bypassCache, debug, style);

        DashboardWcdfDescriptor dashboardWcdf = DashboardWcdfDescriptor.load(filePath);
        String context = dashboardWcdf.isRequire() ? getCdfRequireContext(filePath, requestParams)
                : getCdfContext(filePath, "", view, requestParams);
        String result = dashboard.render(context, getCdfRequireConfig(filePath, requestParams));

        //i18n token replacement
        if (!StringUtils.isEmpty(result) && !dashboardWcdf.isRequire()) {
            String msgDir = FilenameUtils.getPath(FilenameUtils.separatorsToUnix(filePath));
            msgDir = msgDir.startsWith(Util.SEPARATOR) ? msgDir : Util.SEPARATOR + msgDir;

            result = new MessageBundlesHelper(msgDir, Utils.getAppropriateReadAccess(msgDir),
                    CdeEnvironment.getPluginSystemWriter(), getEnv().getLocale(),
                    getEnv().getExtApi().getPluginStaticBaseUrl()).replaceParameters(result, null);
        }

        logger.info("[Timing] CDE Finished Dashboard Rendering: " + Utils.ellapsedSeconds(start) + "s");

        end = System.currentTimeMillis();
        CpfAuditHelper.endAudit(getPluginName(), filePath, getObjectName(), this.getPentahoSession(), iLogger,
                start, uuid, end);

        return result;
    } catch (Exception ex) { //TODO: better error handling?
        String msg = "Could not load dashboard: " + ex.getMessage();
        logger.error(msg, ex);

        end = System.currentTimeMillis();
        CpfAuditHelper.endAudit(getPluginName(), filePath, getObjectName(), this.getPentahoSession(), iLogger,
                start, uuid, end);

        return msg;
    }
}

From source file:pt.webdetails.cpf.localization.MessageBundlesHelper.java

public String getMessageFilesCacheUrl() {
    return FilenameUtils.separatorsToUnix(FilenameUtils.normalize(Util.joinPath(getPluginStaticBaseContentUrl(),
            BASE_CACHE_DIR, getDashboardFolderPath(), Util.SEPARATOR)));
}

From source file:pt.webdetails.cpf.persistence.PersistenceEngine.java

private String getOrientPath() {
    return (this.getClass().getClassLoader() instanceof PluginClassLoader)
            ? FilenameUtils.normalize(FilenameUtils
                    .separatorsToUnix(PentahoSystem.getApplicationContext().getSolutionPath("/system/.orient")))
            : ".";
}

From source file:pt.webdetails.cpf.repository.pentaho.PentahoLegacySolutionAccess.java

@Override
public boolean saveFile(String path, InputStream contents) {
    try {//from   w  ww.j  a  va 2s .co  m
        path = getPath(path);
        int status = getRepository().publish(
                FilenameUtils.separatorsToUnix(PentahoSystem.getApplicationContext().getSolutionPath("")),
                FilenameUtils.getFullPath(path), FilenameUtils.getName(path), IOUtils.toByteArray(contents),
                true);
        switch (status) {
        case ISolutionRepository.FILE_ADD_SUCCESSFUL:
            return true;
        case ISolutionRepository.FILE_ADD_FAILED:
        case ISolutionRepository.FILE_ADD_INVALID_PUBLISH_PASSWORD:
        case ISolutionRepository.FILE_ADD_INVALID_USER_CREDENTIALS:
        default:
            return false;
        }
    } catch (PentahoAccessControlException e) {
        logger.error(e);
        return false;
    } catch (IOException e) {
        logger.error(e);
        return false;
    }
}