1 /* 2 * Licensed to the Apache Software Foundation (ASF) under one * 3 * or more contributor license agreements. See the NOTICE file * 4 * distributed with this work for additional information * 5 * regarding copyright ownership. The ASF licenses this file * 6 * to you under the Apache License, Version 2.0 (the * 7 * "License"); you may not use this file except in compliance * 8 * with the License. You may obtain a copy of the License at * 9 * * 10 * http://www.apache.org/licenses/LICENSE-2.0 * 11 * * 12 * Unless required by applicable law or agreed to in writing, * 13 * software distributed under the License is distributed on an * 14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * 15 * KIND, either express or implied. See the License for the * 16 * specific language governing permissions and limitations * 17 * under the License. * 18 */ 19 package org.apache.rat.document.impl.guesser; 20 21 import java.util.Locale; 22 23 import org.apache.rat.api.Document; 24 25 public class ArchiveGuesser { 26 27 private static final String DOT = "."; 28 29 public static final String[] ARCHIVE_EXTENSIONS = { 30 "jar", "gz", 31 "zip", "tar", 32 "bz", "bz2", 33 "rar", "war", 34 "ear", "mar", 35 "par", "xar", 36 "odb", "odf", 37 "odg", "odp", 38 "ods", "odt", 39 }; 40 41 /** 42 * @param document the current document. 43 * @return whether the given document is an archive. 44 */ 45 public static final boolean isArchive(final Document document) { 46 return isArchive(document.getName()); 47 } 48 49 /** 50 * @return Is a file by that name an archive? 51 * @param name file name to check against. 52 */ 53 public static final boolean isArchive(final String name) { 54 if (name == null) {return false;} 55 String nameToLower = name.toLowerCase(Locale.US); 56 for (int i = 0; i < ArchiveGuesser.ARCHIVE_EXTENSIONS.length; i++) { 57 if (nameToLower.endsWith(DOT + ArchiveGuesser.ARCHIVE_EXTENSIONS[i])) { 58 return true; 59 } 60 } 61 return false; 62 } 63 64 }