View Javadoc
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.Arrays;
22  import java.util.List;
23  
24  import org.apache.rat.api.Document;
25  
26  public class NoteGuesser {
27  
28      private static final String DOT = ".";
29  
30      private static final String[] NOTE_FILE_NAMES = {
31          "NOTICE", "LICENSE",
32          "LICENSE.TXT", "NOTICE.TXT",
33          "INSTALL", "INSTALL.TXT",
34          "README", "README.TXT",
35          "NEWS", "NEWS.TXT",
36          "AUTHOR", "AUTHOR.TXT",
37          "AUTHORS", "AUTHORS.txt",
38          "CHANGELOG", "CHANGELOG.TXT",
39          "DISCLAIMER", "DISCLAIMER.TXT",
40          "KEYS", "KEYS.TXT",
41          "RELEASE-NOTES", "RELEASE-NOTES.TXT",
42          "RELEASE_NOTES", "RELEASE_NOTES.TXT",
43          "UPGRADE", "UPGRADE.TXT",
44          "STATUS", "STATUS.TXT",
45          "THIRD_PARTY_NOTICES", "THIRD_PARTY_NOTICES.TXT",
46          "COPYRIGHT", "COPYRIGHT.TXT",
47          "BUILDING", "BUILDING.TXT",
48          "BUILD", "BUILT.TXT",//
49          "DEPENDENCIES"
50      };
51  
52      private static final String[] NOTE_FILE_EXTENSIONS = {
53          "LICENSE", "LICENSE.TXT",
54          "NOTICE", "NOTICE.TXT",
55      };
56  
57      /**
58       * @return Is a file by that name a note file?
59       * @param name file name.
60       */
61      public static boolean isNote(final String name) {
62          if (name == null) {return false;}
63  
64          List<String> l = Arrays.asList(NoteGuesser.NOTE_FILE_NAMES);
65          String normalisedName = GuessUtils.normalise(name);
66  
67          if (l.contains(name) || l.contains(normalisedName)) {
68              return true;
69          }
70  
71          for (int i = 0; i < NoteGuesser.NOTE_FILE_EXTENSIONS.length; i++) {
72              if (normalisedName.endsWith(DOT + NoteGuesser.NOTE_FILE_EXTENSIONS[i])) {
73                  return true;
74              }
75          }
76  
77          return false;
78      }
79  
80      public static boolean isNote(final Document document) {
81          return isNote(document.getName());
82      }
83  
84  }