1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.rat.analysis.license;
20
21 import java.util.regex.Pattern;
22
23 import org.apache.rat.analysis.IHeaderMatcher;
24 import org.apache.rat.analysis.RatHeaderAnalysisException;
25 import org.apache.rat.api.Document;
26 import org.apache.rat.api.MetaData.Datum;
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48 public class CopyrightHeader extends BaseLicense implements IHeaderMatcher {
49
50 public static final String COPYRIGHT_PREFIX_PATTERN_DEFN = ".*Copyright [0-9]{4}(\\-[0-9]{4})? ";
51
52 private Pattern copyrightPattern;
53 private String copyrightOwner;
54 private boolean copyrightMatch = false;
55
56 public CopyrightHeader(){
57 }
58
59 protected CopyrightHeader(Datum licenseFamilyCategory, Datum licenseFamilyName, String notes) {
60 super(licenseFamilyCategory, licenseFamilyName, notes);
61 }
62
63 protected CopyrightHeader(Datum licenseFamilyCategory, Datum licenseFamilyName, String notes, String copyrightOwner) {
64 this(licenseFamilyCategory, licenseFamilyName, notes);
65 setCopyrightOwner(copyrightOwner);
66 }
67
68
69 public final void setCopyrightOwner(String copyrightOwner) {
70 this.copyrightOwner = copyrightOwner;
71 this.copyrightPattern = Pattern.compile(COPYRIGHT_PREFIX_PATTERN_DEFN+copyrightOwner+".*", Pattern.CASE_INSENSITIVE);
72 }
73
74 public String getCopyRightOwner() {
75 return copyrightOwner;
76 }
77
78 public boolean hasCopyrightPattern() {
79 return copyrightPattern != null;
80 }
81
82 protected boolean isCopyrightMatch() {
83 return copyrightMatch;
84 }
85
86 protected boolean matchCopyright(String s) {
87 if (!copyrightMatch) {
88 copyrightMatch = copyrightPattern.matcher(s).matches();
89 }
90 return copyrightMatch;
91 }
92
93 public boolean match(Document subject, String s) throws RatHeaderAnalysisException {
94 if (!copyrightMatch) {
95 if (matchCopyright(s)) {
96 reportOnLicense(subject);
97 }
98 }
99 return copyrightMatch;
100 }
101
102 public void reset() {
103 copyrightMatch = false;
104 }
105 }