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;
27
28
29
30
31
32 public class OASISLicense extends BaseLicense implements IHeaderMatcher {
33
34 private static final String COPYRIGHT_PATTERN_DEFN = ".*Copyright.*OASIS Open.*";
35 private static final String CLAUSE_DEFN
36 = ".*thisdocumentandtranslationsofitmaybecopiedandfurnishedtoothersandderivativeworks" +
37 "thatcommentonorotherwiseexplainitorassistinitsimplementationmaybeprepared" +
38 "copiedpublishedanddistributed.*";
39
40 private static final Pattern COPYRIGHT_PATTERN = Pattern.compile(COPYRIGHT_PATTERN_DEFN);
41 private static final Pattern CLAUSE_PATTERN = Pattern.compile(CLAUSE_DEFN);
42
43 boolean copyrightMatch = false;
44 final StringBuffer buffer = new StringBuffer();
45
46 public OASISLicense() {
47 super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_OASIS, MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_OASIS_OPEN_LICENSE, "No modifications allowed");
48 }
49
50 public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
51 boolean result = false;
52 if (copyrightMatch) {
53 line = line.toLowerCase();
54 buffer.append(line);
55 prune(buffer);
56 final boolean clauseMatch = CLAUSE_PATTERN.matcher(buffer).matches();
57 if (clauseMatch) {
58 result = true;
59 reportOnLicense(subject);
60 }
61
62 } else {
63 copyrightMatch = COPYRIGHT_PATTERN.matcher(line).matches();
64 }
65 return result;
66 }
67
68 private void prune(final StringBuffer buffer) {
69 final int length = buffer.length();
70 for (int i=length;i>0;) {
71 char at = buffer.charAt(--i);
72 if (at < 'a' || at > 'z')
73 {
74 buffer.deleteCharAt(i);
75 }
76 }
77 }
78
79 public void reset() {
80 copyrightMatch = false;
81 buffer.delete(0, buffer.length());
82 }
83 }