001/**
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.camel.component.file;
018
019/**
020 * File filter using AntPathMatcher.
021 * <p/>
022 * Exclude take precedence over includes. If a file match both exclude and include it will be regarded as excluded.
023 * @param <T>
024 */
025public class AntPathMatcherGenericFileFilter<T> implements GenericFileFilter<T> {
026
027    private final AntPathMatcherFileFilter filter;
028
029    public AntPathMatcherGenericFileFilter() {
030        filter = new AntPathMatcherFileFilter();
031    }
032
033    public AntPathMatcherGenericFileFilter(String... includes) {
034        filter = new AntPathMatcherFileFilter();
035        filter.setIncludes(includes);
036    }
037
038    public boolean accept(GenericFile<T> file) {
039        // directories should always be accepted by ANT path matcher
040        if (file.isDirectory()) {
041            return true;
042        }
043
044        String path = file.getRelativeFilePath();
045        return filter.acceptPathName(path);
046    }
047
048    public String[] getExcludes() {
049        return filter.getExcludes();
050    }
051
052    public void setExcludes(String[] excludes) {
053        filter.setExcludes(excludes);
054    }
055
056    public String[] getIncludes() {
057        return filter.getIncludes();
058    }
059
060    public void setIncludes(String[] includes) {
061        filter.setIncludes(includes);
062    }
063
064    /**
065     * Sets excludes using a single string where each element can be separated with comma
066     */
067    public void setExcludes(String excludes) {
068        filter.setExcludes(excludes);
069    }
070
071    /**
072     * Sets includes using a single string where each element can be separated with comma
073     */
074    public void setIncludes(String includes) {
075        filter.setIncludes(includes);
076    }
077
078    /**
079     * Sets case sensitive flag on {@link org.apache.camel.component.file.AntPathMatcherFileFilter}
080     * <p/>
081     * Is by default turned on <tt>true</tt>.
082     */
083    public void setCaseSensitive(boolean caseSensitive) {
084        filter.setCaseSensitive(caseSensitive);
085    }
086
087    public boolean isCaseSensitive() {
088        return filter.isCaseSensitive();
089    }
090}