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  
29      public static final String[] NOTE_FILE_NAMES = {
30          "NOTICE", "LICENSE",
31          "LICENSE.TXT", "NOTICE.TXT",
32          "INSTALL", "INSTALL.TXT",
33          "README", "README.TXT", 
34          "NEWS", "NEWS.TXT",
35          "AUTHOR", "AUTHOR.TXT",
36          "AUTHORS", "AUTHORS.txt",
37          "CHANGELOG", "CHANGELOG.TXT",
38          "DISCLAIMER", "DISCLAIMER.TXT",
39          "KEYS", "KEYS.TXT",
40          "RELEASE-NOTES", "RELEASE-NOTES.TXT",
41          "RELEASE_NOTES", "RELEASE_NOTES.TXT",
42          "UPGRADE", "UPGRADE.TXT",
43          "STATUS", "STATUS.TXT",
44          "THIRD_PARTY_NOTICES", "THIRD_PARTY_NOTICES.TXT",
45          "COPYRIGHT", "COPYRIGHT.TXT",
46          "BUILDING", "BUILDING.TXT",
47          "BUILD", "BUILT.TXT",
48      };
49      public static final String[] NOTE_FILE_EXTENSIONS = {
50          "LICENSE", "LICENSE.TXT",
51          "NOTICE", "NOTICE.TXT",
52      };
53      
54      /**
55       * Is a file by that name a note file?
56       */
57      public static final boolean isNote(final String name) {
58          if (name == null) {return false;}
59      
60          List l = Arrays.asList(NoteGuesser.NOTE_FILE_NAMES);
61          String normalisedName = GuessUtils.normalise(name);
62          
63          boolean result = l.contains(name) || l.contains(normalisedName);
64          for (int i = 0; !result && i < NoteGuesser.NOTE_FILE_EXTENSIONS.length; i++) {
65              result = normalisedName.endsWith("." + NoteGuesser.NOTE_FILE_EXTENSIONS[i]);
66          }
67          return result;
68      }
69  
70      public static final boolean isNote(final Document document) {
71          final String name = document.getName();
72          final boolean result = isNote(name);
73          return result;
74      }
75  
76  }