Example usage for org.apache.commons.io IOCase INSENSITIVE

List of usage examples for org.apache.commons.io IOCase INSENSITIVE

Introduction

In this page you can find the example usage for org.apache.commons.io IOCase INSENSITIVE.

Prototype

IOCase INSENSITIVE

To view the source code for org.apache.commons.io IOCase INSENSITIVE.

Click Source Link

Document

The constant for case insensitive regardless of operating system.

Usage

From source file:org.mycontroller.standalone.utils.McTemplateUtils.java

@SuppressWarnings("unchecked")
public static QueryResponse get(Query query) throws IOException {
    //Check less info available and true, if true set less info return
    Boolean lessInfo = (Boolean) query.getFilters().get(TemplatesHandler.KEY_LESS_INFO);
    if (lessInfo) {
        query.setPageLimit(-1);/*from   ww  w  .  j a v  a  2s. c  om*/
    }

    String locationCanonicalPath = McUtils.getDirectoryLocation(
            FileUtils.getFile(AppProperties.getInstance().getTemplatesLocation()).getCanonicalPath());

    if (FileUtils.getFile(locationCanonicalPath).exists()) {
        List<McTemplate> files = new ArrayList<McTemplate>();
        List<String> filesString = new ArrayList<String>();

        //Filters
        //Extension filter
        String[] extensionSuffixFilter = null;
        if (query.getFilters().get(TemplatesHandler.KEY_EXTENSION) != null) {
            if (Arrays.asList(MC_SCRIPT_SUFFIX_FILTER)
                    .contains(query.getFilters().get(TemplatesHandler.KEY_EXTENSION))) {
                extensionSuffixFilter = new String[] {
                        (String) query.getFilters().get(TemplatesHandler.KEY_EXTENSION) };
            }
        }

        if (extensionSuffixFilter == null) {
            extensionSuffixFilter = MC_SCRIPT_SUFFIX_FILTER;
        }

        SuffixFileFilter extensionFilter = new SuffixFileFilter(extensionSuffixFilter, IOCase.INSENSITIVE);

        //name filter
        IOFileFilter nameFileFilter = null;
        List<String> fileNames = (List<String>) query.getFilters().get(TemplatesHandler.KEY_NAME);
        if (fileNames != null && !fileNames.isEmpty()) {
            for (String fileName : fileNames) {
                if (nameFileFilter == null) {
                    nameFileFilter = FileFilterUtils
                            .and(new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                } else {
                    nameFileFilter = FileFilterUtils.and(nameFileFilter,
                            new WildcardFileFilter("*" + fileName + "*", IOCase.INSENSITIVE));
                }
            }
        }

        //Combine all filters
        IOFileFilter templatesFileFilter = null;
        if (nameFileFilter != null) {
            templatesFileFilter = FileFilterUtils.and(extensionFilter, nameFileFilter);
        } else {
            templatesFileFilter = extensionFilter;
        }
        List<File> templateFiles = new ArrayList<File>(FileUtils.listFiles(
                FileUtils.getFile(locationCanonicalPath), templatesFileFilter, TrueFileFilter.INSTANCE));
        query.setFilteredCount((long) templateFiles.size());
        //Get total items without filter
        query.setTotalItems((long) FileUtils.listFiles(FileUtils.getFile(locationCanonicalPath),
                new SuffixFileFilter(MC_SCRIPT_SUFFIX_FILTER, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE)
                .size());

        int fileFrom;
        int fileTo;
        if (query.getPageLimit() == -1) {
            fileTo = templateFiles.size();
            fileFrom = 0;
        } else {
            fileFrom = query.getStartingRow().intValue();
            fileTo = (int) (query.getPage() * query.getPageLimit());
        }
        for (; fileFrom < fileTo; fileFrom++) {
            if (templateFiles.size() > fileFrom) {
                File templateFile = templateFiles.get(fileFrom);
                String name = templateFile.getCanonicalPath().replace(locationCanonicalPath, "");
                if (lessInfo) {
                    filesString.add(name);
                } else {
                    files.add(McTemplate.builder().name(name)
                            .extension(FilenameUtils.getExtension(templateFile.getCanonicalPath()))
                            .size(templateFile.length()).lastModified(templateFile.lastModified()).build());
                }
            } else {
                break;
            }
        }
        if (lessInfo) {
            return QueryResponse.builder().data(filesString).query(query).build();
        } else {
            return QueryResponse.builder().data(files).query(query).build();
        }

    } else {
        throw new FileNotFoundException("File location not found: " + locationCanonicalPath);
    }
}

From source file:org.noroomattheinn.visibletesla.AppContext.java

public final File ensureAppFilesFolder() {
    boolean storeFilesWithApp = prefs.storeFilesWithApp.get();
    if (storeFilesWithApp)
        return null;

    File aff = getAppFileFolder();
    if (aff.exists())
        return aff;
    if (aff.mkdir()) {
        // Since we're creating this folder for the first time, we might
        // need to copy over existing files from the app folder.
        // HACK ALERT!! This code should not know the file names of the
        // the files to be copied! This is pure expediency!
        File srcDir = new File(System.getProperty("user.dir"));
        IOFileFilter logFilter = FileFilterUtils.suffixFileFilter(".stats.log");
        IOFileFilter txtFilter = FileFilterUtils.nameFileFilter("cookies.txt", IOCase.INSENSITIVE);
        IOFileFilter filter = FileFilterUtils.and(FileFilterUtils.or(logFilter, txtFilter),
                FileFileFilter.FILE);/*from www  .  j  a va  2 s .  c om*/
        try {
            FileUtils.copyDirectory(srcDir, aff, filter);
        } catch (IOException ex) {
            Dialogs.showWarningDialog(stage, "Unable to copy files to Application File Folder: " + aff,
                    "Warning", "VisibleTesla");
        }

        return aff;
    }

    Tesla.logger.log(Level.WARNING, "Could not create Application Files Folder: {0}", aff);
    return null;
}

From source file:org.nuxeo.connect.packages.dependencies.TargetPlatformFilterHelper.java

/**
 * @param targetPlatforms The target platforms on which to check compliance.
 * @param targetPlatform The target platform to match with.
 * @since 1.4.24/* w ww . ja  v a2 s  . c  o m*/
 */
public static boolean isCompatibleWithTargetPlatform(String[] targetPlatforms, String targetPlatform) {
    if (targetPlatform == null || targetPlatforms == null || targetPlatforms.length == 0) {
        return true;
    }
    for (String target : targetPlatforms) {
        if (FilenameUtils.wildcardMatch(targetPlatform, target, IOCase.INSENSITIVE)) {
            return true;
        }
    }
    return false;
}

From source file:org.opensextant.xtext.XText.java

/**
 * Navigate a folder trying to convert each file and return something to the
 * listener. Do not sacrifice the entire job if one file fails, so exception
 * is trapped in loop//  w w w  .  ja  v a2  s . c om
 *
 * @param input
 *            the input
 * @throws IOException
 *             on err
 */
public void convertFolder(File input) throws IOException {
    java.util.Collection<File> files = FileUtils.listFiles(input,
            new SuffixFileFilter(fileFilters, IOCase.INSENSITIVE), FileFilterUtils.trueFileFilter());
    for (File f : files) {
        try {
            convertFile(f);
        } catch (Exception convErr) {
            log.error("Conversion error, FILE=" + f.getPath(), convErr);
        }
    }
}

From source file:org.owasp.dependencycheck.utils.FileFilterBuilder.java

/**
 * Builds the filter and returns it./*from ww  w .  j  av  a 2 s  .  c  o  m*/
 *
 * @return a filter that is the logical OR of all the conditions provided by the add... methods
 * @throws IllegalStateException if no add... method has been called with one or more arguments
 */
public FileFilter build() {
    if (filenames.isEmpty() && extensions.isEmpty() && fileFilters.isEmpty()) {
        throw new IllegalStateException(
                "May only be invoked after at least one add... method has been invoked.");
    }
    final OrFileFilter filter = new OrFileFilter();
    if (!filenames.isEmpty()) {
        filter.addFileFilter(new NameFileFilter(new ArrayList<String>(filenames)));
    }
    if (!extensions.isEmpty()) {
        filter.addFileFilter(new SuffixFileFilter(new ArrayList<String>(extensions), IOCase.INSENSITIVE));
    }
    for (IOFileFilter iof : fileFilters) {
        filter.addFileFilter(iof);
    }
    return filter;
}

From source file:org.pdfsam.support.io.FileType.java

/**
 * @param filename//  www .ja v  a2  s  .c om
 * @return true if the input filename is of this {@link FileType}
 */
public boolean matches(String filename) {
    for (String current : getFilter().getExtensions()) {
        if (wildcardMatch(filename, current, IOCase.INSENSITIVE)) {
            return true;
        }
    }
    return false;
}

From source file:org.silverpeas.core.util.file.FileFolderManager.java

/**
 * Returns all the files (and only the files, not the directories) that are directly inside the
 * given directory. Throws an {@link UtilException} if the
 * specified path doesn't denote a directory or if the listing of all of its files fails.
 * @param path the path of the directory
 * @return a collection of files//from   w  w w. ja  va 2  s.c  o m
 */
public static Collection<File> getAllFile(final String path) {
    final List<File> result;
    final Path directory = Paths.get(path);
    if (directory.toFile().isDirectory()) {
        try (final Stream<Path> folders = Files.list(directory)) {
            result = folders.filter(p -> p.toFile().isFile()).map(Path::toFile)
                    .sorted(new NameFileComparator(IOCase.INSENSITIVE)).collect(Collectors.toList());
        } catch (IOException e) {
            throw new UtilException(e);
        }
    } else {
        throw new UtilException(path + NOT_A_DIRECTORY_MSG);
    }
    return result;
}

From source file:org.sonar.java.JavaClasspath.java

private List<File> getMatchingFiles(String pattern, File dir, boolean libraryProperty) {
    WilcardPatternFileFilter wilcardPatternFileFilter = new WilcardPatternFileFilter(dir, pattern);
    FileFilter fileFilter = wilcardPatternFileFilter;
    List<File> files = Lists.newArrayList();
    if (libraryProperty) {
        if (pattern.endsWith("*")) {
            fileFilter = new AndFileFilter((IOFileFilter) fileFilter,
                    new OrFileFilter(Lists.newArrayList(suffixFileFilter(".jar", IOCase.INSENSITIVE),
                            suffixFileFilter(".zip", IOCase.INSENSITIVE))));
        }//from   ww  w. j a  v a  2s  .c  o m
        //find jar and zip files
        files.addAll(
                Lists.newArrayList(FileUtils.listFiles(dir, (IOFileFilter) fileFilter, TrueFileFilter.TRUE)));
    }
    //find directories matching pattern.
    IOFileFilter subdirectories = pattern.isEmpty() ? FalseFileFilter.FALSE : TrueFileFilter.TRUE;
    Collection<File> dirs = FileUtils.listFilesAndDirs(dir,
            new AndFileFilter(wilcardPatternFileFilter, DirectoryFileFilter.DIRECTORY), subdirectories);
    //remove searching dir from matching as listFilesAndDirs always includes it in the list see https://issues.apache.org/jira/browse/IO-328
    if (!pattern.isEmpty()) {
        dirs.remove(dir);
        //remove subdirectories that were included during search
        Iterator<File> iterator = dirs.iterator();
        while (iterator.hasNext()) {
            File matchingDir = iterator.next();
            if (!wilcardPatternFileFilter.accept(matchingDir)) {
                iterator.remove();
            }
        }
    }

    if (libraryProperty) {
        for (File directory : dirs) {
            files.addAll(getMatchingFiles("**/*.jar", directory, true));
            files.addAll(getMatchingFiles("**/*.zip", directory, true));
        }
    }
    files.addAll(dirs);
    return files;
}

From source file:org.springframework.integration.aws.s3.WildcardFileNameFilter.java

/**
 * Default construtor accepting the wildcard string
 *
 * @param wildcardString// ww w  . j a v a  2  s.  c  om
 */
public WildcardFileNameFilter(String wildcardString) {
    Assert.hasText(wildcardString, "Wildcard string should be non null, non empty String");
    filter = new WildcardFileFilter(wildcardString, IOCase.INSENSITIVE);
    //Our checks will be case insensitive
}

From source file:sernet.gs.service.AbstractReportTemplateService.java

@SuppressWarnings("unchecked")
public Iterator<File> listPropertiesFiles(String fileName) {
    String baseName = removeSuffix(fileName);
    IOFileFilter filter = new RegexFileFilter(baseName + "\\_?.*\\.properties", IOCase.INSENSITIVE);
    Iterator<File> iter = FileUtils.iterateFiles(new File(getTemplateDirectory()), filter, null);
    return iter;//from   ww  w . jav  a  2  s .  com
}