001/* 002 * Copyright 2020 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.skinfactory.filefilter; 017 018import java.nio.file.Files; 019import java.nio.file.Path; 020import java.util.function.Predicate; 021 022/** 023 * File filters 024 */ 025public final class FileFilter 026{ 027 private FileFilter() 028 { 029 // emtpy 030 } 031 032 /** 033 * This filter accepts all <code>File</code>s excepted CVS and SVN directories 034 * @return The filter 035 */ 036 public static Predicate<Path> getSkinDirectoryFilter() 037 { 038 return path -> Files.isDirectory(path) 039 && !path.getFileName().toString().equals("CVS") 040 && !path.getFileName().toString().equals(".svn"); 041 } 042 043 /** 044 * This filter accepts all <code>File</code>s excepted CVS and SVN directories 045 * @return The filter 046 */ 047 public static Predicate<Path> getSkinFileFilter() 048 { 049 return path -> !path.getFileName().toString().equals("CVS") 050 && !path.getFileName().toString().equals(".svn"); 051 } 052 053 /** 054 * This filter accepts all <code>File</code>s excepted CVS and SVN directories and root directory named "model" 055 * @param modelDir The model root directory 056 * @return the filter 057 */ 058 public static final Predicate<Path> getModelFilter(Path modelDir) 059 { 060 return f -> 061 !f.getFileName().toString().equals("CVS") 062 && !f.getFileName().toString().equals(".svn") 063 && (!f.getParent().equals(modelDir) || !f.getFileName().toString().equals("model")); 064 } 065 066 /** 067 * This filter accepts <code>File</code>s that are not the root variant's description files ([VARIANT_NAME].xml and [VARIANT_NAME].png) and that are not a CVS or SVN directory 068 * @param variantName The variant name 069 * @param variantDir The variant root dir 070 * @return the filter 071 */ 072 public static final Predicate<Path> getModelVariantFilter(String variantName, Path variantDir) 073 { 074 return f -> 075 !f.getFileName().toString().equals("CVS") 076 && !f.getFileName().toString().equals(".svn") 077 && (!f.getParent().equals(variantDir) 078 || (!f.getFileName().toString().equals(variantName + ".xml") 079 && !f.getFileName().toString().equals(variantName + ".png"))); 080 } 081 082}