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;
20  
21  import org.apache.commons.io.IOUtils;
22  import org.apache.rat.api.Document;
23  import org.apache.rat.document.IDocumentAnalyser;
24  import org.apache.rat.document.RatDocumentAnalysisException;
25  
26  import java.io.IOException;
27  import java.io.Reader;
28  
29  public class DocumentHeaderAnalyser implements IDocumentAnalyser {
30  
31      private final IHeaderMatcher matcher;
32      
33      public DocumentHeaderAnalyser(final IHeaderMatcher matcher) {
34          super();
35          this.matcher = matcher;
36      }
37  
38      public void analyse(Document document) throws RatDocumentAnalysisException {
39          Reader reader = null;
40          try {
41              reader = document.reader();
42              // TODO: worker function should be moved into this class
43              HeaderCheckWorker worker = new HeaderCheckWorker(reader, matcher, document);
44              worker.read();
45          } catch (IOException e) {
46              throw new RatDocumentAnalysisException("Cannot read header", e);
47          } catch (RatHeaderAnalysisException e) {
48              throw new RatDocumentAnalysisException("Cannot analyse header", e);
49          } finally {
50              IOUtils.closeQuietly(reader);
51          }
52       }
53  
54  }