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.analysis.license;
20  
21  import java.util.regex.Pattern;
22  
23  import org.apache.rat.analysis.RatHeaderAnalysisException;
24  import org.apache.rat.api.Document;
25  import org.apache.rat.api.MetaData;
26  
27  /**
28   * Looks for documents contain the OASIS copyright claim plus derivative work clause.
29   * Perhaps need to match more.
30   */
31  public class OASISLicense extends FullTextMatchingLicense {
32  
33      private static final String COPYRIGHT_PATTERN_DEFN = ".*Copyright\\s.*OASIS Open.*";
34      private static final String CLAUSE_DEFN
35      = "This document and translations of it may be copied and furnished to others and derivative works" +
36              "that comment on or otherwise explain it or assist in its implementation may be prepared" +
37              "copied published and distributed";
38      
39      private static final Pattern COPYRIGHT_PATTERN = Pattern.compile(COPYRIGHT_PATTERN_DEFN);
40  
41      boolean copyrightMatch = false;
42      
43      public OASISLicense() {
44          super(MetaData.RAT_LICENSE_FAMILY_CATEGORY_DATUM_OASIS,
45                MetaData.RAT_LICENSE_FAMILY_NAME_DATUM_OASIS_OPEN_LICENSE,
46                "No modifications allowed",
47                CLAUSE_DEFN);
48      }
49  
50      @Override
51      public boolean match(Document subject, String line) throws RatHeaderAnalysisException {
52          boolean result = false;
53          if (copyrightMatch) {
54              result = super.match(subject, line);
55          } else {
56              copyrightMatch = COPYRIGHT_PATTERN.matcher(line).matches();
57          }
58          return result;
59      }
60  
61      @Override
62      public void reset() {
63          copyrightMatch = false;
64          super.reset();
65      }
66  }