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

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

Introduction

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

Prototype

public OrFileFilter(IOFileFilter filter1, IOFileFilter filter2) 

Source Link

Document

Constructs a new file filter that ORs the result of two other filters.

Usage

From source file:com.discursive.jccook.io.FilterExample.java

public void start() {
    File rootDir = new File(".");
    FilenameFilter fileFilter = new SuffixFileFilter(".xml");
    String[] xmlFiles = rootDir.list(fileFilter);
    System.out.println("*** XML Files");
    System.out.println(ArrayUtils.toString(xmlFiles));

    rootDir = new File("./test");

    IOFileFilter htmlFilter = new OrFileFilter(new SuffixFileFilter("htm"), new SuffixFileFilter("html"));
    IOFileFilter notDirectory = new NotFileFilter(DirectoryFileFilter.INSTANCE);
    fileFilter = new AndFileFilter(htmlFilter, notDirectory);

    String[] htmlFiles = rootDir.list(fileFilter);
    System.out.println("*** HTML Files");
    System.out.println(ArrayUtils.toString(htmlFiles));
}

From source file:com.norconex.jefmon.settings.panels.JobLocationsPanel.java

public JobLocationsPanel(String id, JEFMonConfig dirtyConfig) {
    super(id, dirtyConfig);
    setOutputMarkupId(true);//from w ww  .  jav a2s  .c om

    if (dirtyConfig.getMonitoredPaths() != null) {
        locations.addAll(Arrays.asList(dirtyConfig.getMonitoredPaths()));
    }
    formWrapper.setOutputMarkupId(true);
    add(formWrapper);

    // --- Locations Select ---
    locationsSelect = buildLocationsSelect("locations");
    formWrapper.add(locationsSelect);

    // --- Remove ---
    removeButton = new WebMarkupContainer("removeButton");
    removeButton.setOutputMarkupId(true);
    removeButton.add(new OnClickBehavior() {
        private static final long serialVersionUID = 2072304873075922291L;

        @Override
        protected void onClick(AjaxRequestTarget target) {
            Collection<File> files = locationsSelect.getModelObject();
            locations.removeAll(files);
            locationsSelect.setChoices(locations);
            removeButton.setVisible(false);
            target.add(formWrapper);
        }
    });
    removeButton.setVisible(false);
    formWrapper.add(removeButton);

    // --- Add File ---
    IOFileFilter validationFilter = new SuffixFileFilter(".index");
    FilenameFilter browseFilter = new OrFileFilter(DirectoryFileFilter.DIRECTORY, validationFilter);
    BootstrapFileSystemDialog fileDialog = new BootstrapFileSystemDialog("addFileModal",
            new ResourceModel("location.dlg.file"), browseFilter, true) {
        private static final long serialVersionUID = 831482258795791951L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, File[] files) {
            addFileToSelect(target, files);
        }
    };
    fileDialog.setSelectionValidator(validationFilter);
    add(fileDialog);
    WebMarkupContainer addFileButton = new WebMarkupContainer("addFileButton");
    addFileButton.add(new BootstrapModalLauncher(fileDialog));
    formWrapper.add(addFileButton);

    // --- Add Folder ---
    BootstrapFileSystemDialog folderDialog = new BootstrapFileSystemDialog("addFolderModal",
            new ResourceModel("location.dlg.dir"), DirectoryFileFilter.DIRECTORY, true) {
        private static final long serialVersionUID = -6453512318897096749L;

        @Override
        protected void onSubmit(AjaxRequestTarget target, File[] files) {
            addFileToSelect(target, files);
        }
    };
    folderDialog.setSelectionValidator(DirectoryFileFilter.DIRECTORY);
    add(folderDialog);
    WebMarkupContainer addFolderButton = new WebMarkupContainer("addFolderButton");
    addFolderButton.add(new BootstrapModalLauncher(folderDialog));
    formWrapper.add(addFolderButton);

}

From source file:org.cds06.speleograph.actions.OpenAction.java

/**
 * Construct the import action./*from ww  w.  ja  v  a 2s  . co m*/
 *
 * @param component The parent component used to display dialogs.
 */
public OpenAction(JComponent component, Class<? extends DataFileReader> reader) {
    super(I18nSupport.translate("actions.openFile"));
    try {
        this.reader = reader.newInstance();
    } catch (InstantiationException | IllegalAccessException e) {
        log.info("Can not create action for reader " + reader.getName());
        throw new IllegalArgumentException(e);
    }
    putValue(NAME, this.reader.getButtonText());
    parent = component;
    fileFilter = new OrFileFilter(DirectoryFileFilter.DIRECTORY, this.reader.getFileFilter());
    chooser = new JFileChooser();
    chooser.setFileFilter(new FileFilter() {
        @Override
        public boolean accept(File f) {
            return fileFilter.accept(f);
        }

        @Override
        public String getDescription() {
            return OpenAction.this.getDescription();
        }
    });
}

From source file:org.fuin.srcgen4j.core.velocity.ParameterizedTemplateParser.java

@Override
public void initialize(final SrcGen4JContext context, final ParserConfig config) {

    // This type of parser always needs a configuration
    Contract.requireArgNotNull("config", config);

    name = config.getName();//from w ww . j  a va 2s  . c om
    varMap = config.getParent().getVarMap();

    LOG.debug("Initialize parser: " + name);

    parserConfig = getConcreteConfig(config);
    modelFilter = new RegexFileFilter(parserConfig.getModelFilter());
    templateFilter = new RegexFileFilter(parserConfig.getTemplateFilter());
    fileFilter = new OrFileFilter(modelFilter, templateFilter);

    this.context = context;

}

From source file:org.kuali.kfs.gl.batch.EnterpriseFeederFileSetType.java

/**
 * Return set of file user identifiers from a list of files
 * //from  w  ww  .j  av  a 2s . c  o  m
 * @param user user who uploaded or will upload file
 * @param files list of files objects
 * @return Set containing all user identifiers from list of files
 * @see org.kuali.kfs.sys.batch.BatchInputFileSetType#extractFileUserIdentifiers(org.kuali.rice.kim.api.identity.Person, java.util.List)
 */
public Set<String> extractFileUserIdentifiers(Person user, List<File> files) {
    Set<String> extractedFileUserIdentifiers = new TreeSet<String>();

    StringBuilder buf = new StringBuilder();
    buf.append(FILE_NAME_PREFIX).append(FILE_NAME_PART_DELIMITER).append(user.getPrincipalName())
            .append(FILE_NAME_PART_DELIMITER);
    String prefixString = buf.toString();
    IOFileFilter prefixFilter = new PrefixFileFilter(prefixString);

    IOFileFilter suffixFilter = new OrFileFilter(new SuffixFileFilter(EnterpriseFeederService.DATA_FILE_SUFFIX),
            new SuffixFileFilter(EnterpriseFeederService.RECON_FILE_SUFFIX));

    IOFileFilter combinedFilter = new AndFileFilter(prefixFilter, suffixFilter);

    for (File file : files) {
        if (combinedFilter.accept(file)) {
            String fileName = file.getName();
            if (fileName.endsWith(EnterpriseFeederService.DATA_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString,
                        EnterpriseFeederService.DATA_FILE_SUFFIX));
            } else if (fileName.endsWith(EnterpriseFeederService.RECON_FILE_SUFFIX)) {
                extractedFileUserIdentifiers.add(StringUtils.substringBetween(fileName, prefixString,
                        EnterpriseFeederService.RECON_FILE_SUFFIX));
            } else {
                LOG.error("Unable to determine file user identifier for file name: " + fileName);
                throw new RuntimeException(
                        "Unable to determine file user identifier for file name: " + fileName);
            }
        }
    }

    return extractedFileUserIdentifiers;
}

From source file:org.wso2.carbon.registry.extensions.handlers.scm.ExternalContentHandler.java

private void loadRegistryResources(Registry registry, File directory, String workingDir, String mountPoint)
        throws RegistryException {
    File[] files = directory.listFiles((FileFilter) new AndFileFilter(HiddenFileFilter.VISIBLE,
            new OrFileFilter(DirectoryFileFilter.INSTANCE, FileFileFilter.FILE)));
    if (files == null) {
        return;/*www  . j a v  a 2 s  . c  om*/
    }
    for (File file : files) {
        if (file.isDirectory()) {
            loadRegistryResources(registry, file, workingDir, mountPoint);
        } else {
            // convert windows paths so that it fits into the Unix-like registry path structure.
            String path = mountPoint + file.getAbsolutePath().substring(workingDir.length()).replace("\\", "/");
            if (!registry.resourceExists(path)) {
                registry.put(path, registry.newResource());
            }
        }
    }
}

From source file:org.wso2.carbon.registry.extensions.handlers.scm.FilesystemManager.java

public String[] getDirectoryContent(String path) throws RegistryException {
    File directory = new File(baseDir, path);
    if (!directory.exists() || !directory.isDirectory()) {
        throw new RegistryException("A directory does not exist at path: " + directory.getAbsolutePath());
    }/*www.ja v  a2s  .c  o m*/
    return directory.list(new AndFileFilter(HiddenFileFilter.VISIBLE,
            new OrFileFilter(DirectoryFileFilter.INSTANCE, FileFileFilter.FILE)));
}

From source file:uk.co.danielrendall.imagetiler.gui.FileChoosers.java

public FileChoosers(ResourceMap appResourceMap) {
    openFileChooser = createFileChooser("openFileChooser", new FileFilter() {

        private final java.io.FileFilter delegate = new OrFileFilter(new SuffixFileFilter("bmp"),
                DirectoryFileFilter.INSTANCE);

        @Override/*from  w w w  .java  2 s  .  c  o m*/
        public boolean accept(File f) {
            return delegate.accept(f);
        }

        @Override
        public String getDescription() {
            return "BMP Files";
        }
    }, appResourceMap);

    saveFileChooser = createFileChooser("saveFileChooser", new FileFilter() {

        private final java.io.FileFilter delegate = new SuffixFileFilter("svg");

        @Override
        public boolean accept(File f) {
            return delegate.accept(f);
        }

        @Override
        public String getDescription() {
            return "SVG Files";
        }
    }, appResourceMap);
}