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