Example usage for org.apache.commons.io.filefilter WildcardFileFilter WildcardFileFilter

List of usage examples for org.apache.commons.io.filefilter WildcardFileFilter WildcardFileFilter

Introduction

In this page you can find the example usage for org.apache.commons.io.filefilter WildcardFileFilter WildcardFileFilter.

Prototype

public WildcardFileFilter(List wildcards, IOCase caseSensitivity) 

Source Link

Document

Construct a new wildcard filter for a list of wildcards specifying case-sensitivity.

Usage

From source file:org.kalypso.model.wspm.tuhh.schema.simulation.QIntervalReader.java

private void readResults() throws IOException {
    /* Read w-points first: PROFxxx.xxxx.txt files */
    final FilenameFilter filter = new WildcardFileFilter("PROF*.txt", IOCase.INSENSITIVE); //$NON-NLS-1$ 
    final File[] profFiles = m_inputDir.listFiles(filter);
    if (profFiles == null || profFiles.length == 0) {
        m_log.finish(IStatus.ERROR,/*from www  . j  av  a  2s  .  c o  m*/
                Messages.getString("org.kalypso.model.wspm.tuhh.schema.simulation.PolynomeProcessor.17")); //$NON-NLS-1$
        return;
    }

    read(profFiles);

    if (m_log.checkCanceled())
        return;

    final PolynomeReader polynomeReader = new PolynomeReader(m_intervalIndex, m_log);
    polynomeReader.read(new File(m_inputDir, "Polynome.TXT")); //$NON-NLS-1$

    final BuildingPolygonReader buildingReader = new BuildingPolygonReader(m_intervalIndex, m_log);
    buildingReader.read(new File(m_inputDir, PolynomeProcessor.WEIR_FILE_NAME));
    buildingReader.read(new File(m_inputDir, PolynomeProcessor.BRIDGE_FILE_NAME));

    if (m_log.checkCanceled())
        return;
}

From source file:org.kie.guvnor.m2repo.backend.server.GuvnorM2Repository.java

/**
 * Finds files within the repository with the given filters.
 *
 * @param filters filter to apply when finding files. The filter is used to create a wildcard matcher, ie., "*fileter*.*", in which "*" is
 * to represent a multiple wildcard characters.
 * @return an collection of java.io.File with the matching files
 *///from w w w. j  a  v a  2 s  . c om
public Collection<File> listFiles(String filters) {
    String wildcard = "*.jar";
    if (filters != null) {
        wildcard = "*" + filters + "*.jar";
    }
    Collection<File> files = FileUtils.listFiles(new File(M2_REPO_ROOT),
            new WildcardFileFilter(wildcard, IOCase.INSENSITIVE), DirectoryFileFilter.DIRECTORY);

    return files;
}

From source file:org.kuali.kfs.sys.businessobject.lookup.BatchFileLookupableHelperServiceImpl.java

protected IOFileFilter getFileNameBasedFilter(String fileNamePattern) {
    if (StringUtils.isNotBlank(fileNamePattern)) {
        return new WildcardFileFilter(fileNamePattern, IOCase.INSENSITIVE);
    }//  w w  w  .  j  a v a2 s .  c  o m
    return null;
}

From source file:org.mycontroller.standalone.api.BackupApi.java

/**
 * Call this method to get list of available backup files.
 * <p><b>Filter(s):</b>
 * <p>name - {@link List} of backup file names
 * <p><b>Page filter(s):</b>
 * <p>pageLimit - Set number of items per page
 * <p>page - Request page number/*from  ww w  .  j a  va  2 s.co  m*/
 * <p>order - Set order. <b>Option:</b> asc, desc
 * <p>orderBy - column name for order. <b>Option:</b> name
 * @param filters Supports various filter options.
 * @return QueryResponse Contains input filter and response
 * @throws IOException throws when problem with backup location
 */
public QueryResponse getBackupFiles(HashMap<String, Object> filters) throws IOException {
    Query query = Query.get(filters);

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

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

        //Filters
        //Extension filter
        SuffixFileFilter extensionFilter = new SuffixFileFilter(BACKUP_FILE_SUFFIX_FILTER, IOCase.INSENSITIVE);

        //name filter
        IOFileFilter nameFileFilter = null;
        @SuppressWarnings("unchecked")
        List<String> fileNames = (List<String>) query.getFilters().get(KEY_NAME);
        if (fileNames == null) {
            fileNames = new ArrayList<String>();
        }
        fileNames.add(BRCommons.FILE_NAME_IDENTITY);

        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 finalFileFilter = null;
        if (nameFileFilter != null) {
            finalFileFilter = FileFilterUtils.and(extensionFilter, nameFileFilter);
        } else {
            finalFileFilter = extensionFilter;
        }
        List<File> backupFiles = new ArrayList<File>(FileUtils
                .listFiles(FileUtils.getFile(locationCanonicalPath), finalFileFilter, TrueFileFilter.INSTANCE));
        query.setFilteredCount((long) backupFiles.size());
        //Get total items without filter
        query.setTotalItems((long) FileUtils
                .listFiles(FileUtils.getFile(locationCanonicalPath), extensionFilter, TrueFileFilter.INSTANCE)
                .size());
        int fileFrom;
        int fileTo;
        if (query.getPageLimit() == -1) {
            fileTo = backupFiles.size();
            fileFrom = 0;
        } else {
            fileFrom = query.getStartingRow().intValue();
            fileTo = (int) (query.getPage() * query.getPageLimit());
        }
        for (File backupFile : backupFiles) {
            String name = backupFile.getCanonicalPath().replace(locationCanonicalPath, "");
            files.add(BackupFile.builder().name(name).size(backupFile.length())
                    .timestamp(backupFile.lastModified()).canonicalPath(backupFile.getCanonicalPath()).build());
        }

        if (!files.isEmpty()) {
            //Do order reverse
            Collections.sort(files, Collections.reverseOrder());
            if (fileFrom < files.size()) {
                files = files.subList(Math.max(0, fileFrom), Math.min(fileTo, files.size()));
            }
        }
        return QueryResponse.builder().data(files).query(query).build();

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

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

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

    String scriptsFileLocation = AppProperties.getInstance().getScriptsLocation();

    String filesLocation = null;
    if (query.getFilters().get(ScriptsHandler.KEY_TYPE) == null) {
        filesLocation = scriptsFileLocation;
    } else if (query.getFilters().get(ScriptsHandler.KEY_TYPE) == SCRIPT_TYPE.CONDITION) {
        filesLocation = AppProperties.getInstance().getScriptsConditionsLocation();
    } else if (query.getFilters().get(ScriptsHandler.KEY_TYPE) == SCRIPT_TYPE.OPERATION) {
        filesLocation = AppProperties.getInstance().getScriptsOperationsLocation();
    }

    String locationCanonicalPath = McUtils
            .getDirectoryLocation(FileUtils.getFile(scriptsFileLocation).getCanonicalPath());

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

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

        if (scriptSuffixFilter == null) {
            scriptSuffixFilter = MC_SCRIPT_SUFFIX_FILTER;
        }
        SuffixFileFilter languageFilter = new SuffixFileFilter(scriptSuffixFilter, IOCase.INSENSITIVE);

        //name filter
        IOFileFilter nameFileFilter = null;
        List<String> fileNames = (List<String>) query.getFilters().get(ScriptsHandler.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 scriptsFileFilter = null;
        if (nameFileFilter != null) {
            scriptsFileFilter = FileFilterUtils.and(languageFilter, nameFileFilter);
        } else {
            scriptsFileFilter = languageFilter;
        }
        List<File> scriptFiles = new ArrayList<File>(FileUtils.listFiles(FileUtils.getFile(filesLocation),
                scriptsFileFilter, TrueFileFilter.INSTANCE));
        query.setFilteredCount((long) scriptFiles.size());
        //Get total items without filter
        query.setTotalItems((long) FileUtils.listFiles(FileUtils.getFile(scriptsFileLocation),
                new SuffixFileFilter(MC_SCRIPT_SUFFIX_FILTER, IOCase.INSENSITIVE), TrueFileFilter.INSTANCE)
                .size());

        int fileFrom;
        int fileTo;
        if (query.getPageLimit() == -1) {
            fileTo = scriptFiles.size();
            fileFrom = 0;
        } else {
            fileFrom = query.getStartingRow().intValue();
            fileTo = (int) (query.getPage() * query.getPageLimit());
        }
        for (; fileFrom < fileTo; fileFrom++) {
            if (scriptFiles.size() > fileFrom) {
                File scriptFile = scriptFiles.get(fileFrom);
                String name = scriptFile.getCanonicalPath().replace(locationCanonicalPath, "");
                if (lessInfo) {
                    filesString.add(name);
                } else {
                    files.add(McScript.builder().name(name)
                            .extension(FilenameUtils.getExtension(scriptFile.getCanonicalPath()))
                            .size(scriptFile.length()).lastModified(scriptFile.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.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);/* w  ww . java2  s. c  o  m*/
    }

    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.springframework.integration.aws.s3.WildcardFileNameFilter.java

/**
 * Default construtor accepting the wildcard string
 *
 * @param wildcardString// www  . ja v a 2 s. c o m
 */
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:tds.ContentUploader.Web.backing.ContentPublishBacking.java

public Collection<File> getResourceFiles(String directory, String resourceNamePattern) throws Exception {
    File baseDir = new File(directory);
    IOFileFilter filter = new WildcardFileFilter(resourceNamePattern, IOCase.INSENSITIVE);
    Collection<File> fileLists = FileUtils.listFiles(baseDir, filter, TrueFileFilter.INSTANCE);
    return fileLists;
}