// Path: apache-rat-core/src/main/java/org/apache/rat/api/MetaData.java
// public static final class Datum {
//     private final String name;
//     private final String value;
//         
//     /**
//      * Constructs a datum.
//      * @param name not null
//      * @param value not null
//      */
//     public Datum(final String name, final String value) {
//         super();
//         this.name = name;
//         this.value = value;
//     }
//         
//     /**
//      * Gets the name of the data type.
//      * To avoid collisions, it is recommended that URLs are used.
//      * @return not null
//      */
//     public String getName() {
//         return name;
//     }
//      
//     /**
//      * Data type value.
//      * @return not null
//      */
//     public String getValue() {
//         return value;
//     }
// 
//     /**
//      * Constructs a <code>String</code> with all attributes
//      * in name = value format.
//      *
//      * @return a <code>String</code> representation 
//      * of this object.
//      */
//     @Override
//     public String toString()
//     {
//         return "Datum [ "
//             + "name ='" + this.name + "',"
//             + "value ='" + this.value + " "
//             + "']";
//     }
// }


import org.apache.rat.analysis.IHeaderMatcher;
import org.apache.rat.analysis.RatHeaderAnalysisException;
import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData.Datum;
import java.util.regex.Pattern;
/*
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 */
package org.apache.rat.analysis.license;



/**
 * Matches a typical Copyright header line only based on a regex pattern
 * which allows for one (starting) year or year range, and a
 * configurable copyright owner.
 * <br>
 * <br>The matching is done case insensitive<br>
 * <br>
 * Example supported Copyright header lines, using copyright owner &quot;FooBar&quot;
 * <ul>
 * <li>* Copyright 2010 FooBar. *</li>
 * <li>* Copyright 2010-2012 FooBar. *</li>
 * <li>*copyright 2012 foobar*</li>
 * </ul>
 * <p>Note also that the copyright owner is appended to the regex pattern, so
 * can support additional regex but also requires escaping where needed,<br>
 * e.g. use &quot;FooBar \(www\.foobar\.com\)&quot; for matching &quot;FooBar (www.foobar.com)&quot;</p>
 *
 * @since Rat 0.9
 */
public class CopyrightHeader extends BaseLicense implements IHeaderMatcher {

    public static final String COPYRIGHT_PREFIX_PATTERN_DEFN = ".*Copyright [0-9]{4}(\\-[0-9]{4})? ";

    private Pattern copyrightPattern;
    private String copyrightOwner;
    private boolean copyrightMatch = false;

    public CopyrightHeader() {
    }

    protected CopyrightHeader(Datum licenseFamilyCategory, Datum licenseFamilyName, String notes) {
        super(licenseFamilyCategory, licenseFamilyName, notes);
    }

    protected CopyrightHeader(Datum licenseFamilyCategory, Datum licenseFamilyName, String notes, String copyrightOwner) {
        this(licenseFamilyCategory, licenseFamilyName, notes);
        setCopyrightOwner(copyrightOwner);
    }

    // Called by ctor, so must not be overridden
    public final void setCopyrightOwner(String copyrightOwner) {
        this.copyrightOwner = copyrightOwner;
        this.copyrightPattern = Pattern.compile(COPYRIGHT_PREFIX_PATTERN_DEFN + copyrightOwner + ".*", Pattern.CASE_INSENSITIVE);
    }

    public String getCopyRightOwner() {
        return copyrightOwner;
    }

    public boolean hasCopyrightPattern() {
        return copyrightPattern != null;
    }

    protected boolean isCopyrightMatch() {
        return copyrightMatch;
    }

    protected boolean matchCopyright(String s) {
        if (!copyrightMatch) {
// Path: apache-rat-core/src/main/java/org/apache/rat/api/MetaData.java
// public static final class Datum {
//     private final String name;
//     private final String value;
//         
//     /**
//      * Constructs a datum.
//      * @param name not null
//      * @param value not null
//      */
//     public Datum(final String name, final String value) {
//         super();
//         this.name = name;
//         this.value = value;
//     }
//         
//     /**
//      * Gets the name of the data type.
//      * To avoid collisions, it is recommended that URLs are used.
//      * @return not null
//      */
//     public String getName() {
//         return name;
//     }
//      
//     /**
//      * Data type value.
//      * @return not null
//      */
//     public String getValue() {
//         return value;
//     }
// 
//     /**
//      * Constructs a <code>String</code> with all attributes
//      * in name = value format.
//      *
//      * @return a <code>String</code> representation 
//      * of this object.
//      */
//     @Override
//     public String toString()
//     {
//         return "Datum [ "
//             + "name ='" + this.name + "',"
//             + "value ='" + this.value + " "
//             + "']";
//     }
// }


// Path: apache-rat-core/src/main/java/org/apache/rat/analysis/license/CopyrightHeader.java
import org.apache.rat.analysis.IHeaderMatcher;
import org.apache.rat.analysis.RatHeaderAnalysisException;
import org.apache.rat.api.Document;
import org.apache.rat.api.MetaData.Datum;
import java.util.regex.Pattern;

/*
 * Licensed to the Apache Software Foundation (ASF) under one   *
 * or more contributor license agreements.  See the NOTICE file *
 * distributed with this work for additional information        *
 * regarding copyright ownership.  The ASF licenses this file   *
 * to you under the Apache License, Version 2.0 (the            *
 * "License"); you may not use this file except in compliance   *
 * with the License.  You may obtain a copy of the License at   *
 *                                                              *
 *   http://www.apache.org/licenses/LICENSE-2.0                 *
 *                                                              *
 * Unless required by applicable law or agreed to in writing,   *
 * software distributed under the License is distributed on an  *
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
 * KIND, either express or implied.  See the License for the    *
 * specific language governing permissions and limitations      *
 * under the License.                                           *
 */
package org.apache.rat.analysis.license;



/**
 * Matches a typical Copyright header line only based on a regex pattern
 * which allows for one (starting) year or year range, and a
 * configurable copyright owner.
 * <br>
 * <br>The matching is done case insensitive<br>
 * <br>
 * Example supported Copyright header lines, using copyright owner &quot;FooBar&quot;
 * <ul>
 * <li>* Copyright 2010 FooBar. *</li>
 * <li>* Copyright 2010-2012 FooBar. *</li>
 * <li>*copyright 2012 foobar*</li>
 * </ul>
 * <p>Note also that the copyright owner is appended to the regex pattern, so
 * can support additional regex but also requires escaping where needed,<br>
 * e.g. use &quot;FooBar \(www\.foobar\.com\)&quot; for matching &quot;FooBar (www.foobar.com)&quot;</p>
 *
 * @since Rat 0.9
 */
public class CopyrightHeader extends BaseLicense implements IHeaderMatcher {

    public static final String COPYRIGHT_PREFIX_PATTERN_DEFN = ".*Copyright [0-9]{4}(\\-[0-9]{4})? ";

    private Pattern copyrightPattern;
    private String copyrightOwner;
    private boolean copyrightMatch = false;

    public CopyrightHeader() {
    }

    protected CopyrightHeader(Datum licenseFamilyCategory, Datum licenseFamilyName, String notes) {
        super(licenseFamilyCategory, licenseFamilyName, notes);
    }

    protected CopyrightHeader(Datum licenseFamilyCategory, Datum licenseFamilyName, String notes, String copyrightOwner) {
        this(licenseFamilyCategory, licenseFamilyName, notes);
        setCopyrightOwner(copyrightOwner);
    }

    // Called by ctor, so must not be overridden
    public final void setCopyrightOwner(String copyrightOwner) {
        this.copyrightOwner = copyrightOwner;
        this.copyrightPattern = Pattern.compile(COPYRIGHT_PREFIX_PATTERN_DEFN + copyrightOwner + ".*", Pattern.CASE_INSENSITIVE);
    }

    public String getCopyRightOwner() {
        return copyrightOwner;
    }

    public boolean hasCopyrightPattern() {
        return copyrightPattern != null;
    }

    protected boolean isCopyrightMatch() {
        return copyrightMatch;
    }

    protected boolean matchCopyright(String s) {
        if (!copyrightMatch) {
            copyrightMatch = copyrightPattern.matcher(s).matches();