View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *  http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  
18  package org.apache.any23.extractor;
19  
20  import java.io.PrintStream;
21  import java.util.Collection;
22  
23  /**
24   * This interface models an issue reporter.
25   *
26   * @author Michele Mostarda (michele.mostarda@gmail.com)
27   */
28  public interface IssueReport {
29  
30      /**
31       * Notifies an issue occurred while performing an extraction on an input stream.
32       *
33       * @param level
34       *            issue level.
35       * @param msg
36       *            issue message.
37       * @param row
38       *            issue row.
39       * @param col
40       *            issue column.
41       */
42      void notifyIssue(IssueLevel level, String msg, long row, long col);
43  
44      /**
45       * Prints out the content of the report.
46       *
47       * @param ps
48       *            a {@link java.io.PrintStream} to use for generating the report.
49       */
50      void printReport(PrintStream ps);
51  
52      /**
53       * Returns all the collected issues.
54       *
55       * @return a collection of {@link org.apache.any23.extractor.IssueReport.Issue}s.
56       */
57      Collection<Issue> getIssues();
58  
59      /**
60       * Possible issue levels.
61       */
62      enum IssueLevel {
63          WARNING, ERROR, FATAL
64      }
65  
66      /**
67       * This class defines a generic issue traced by this extraction result.
68       */
69      public class Issue {
70  
71          private IssueLevel level;
72          private String message;
73          private long row, col;
74  
75          Issue(IssueLevel l, String msg, long r, long c) {
76              level = l;
77              message = msg;
78              row = r;
79              col = c;
80          }
81  
82          public IssueLevel getLevel() {
83              return level;
84          }
85  
86          public String getMessage() {
87              return message;
88          }
89  
90          public long getRow() {
91              return row;
92          }
93  
94          public long getCol() {
95              return col;
96          }
97  
98          @Override
99          public String toString() {
100             return String.format(java.util.Locale.ROOT, "%s: \t'%s' \t(%d,%d)", level, message, row, col);
101         }
102     }
103 
104 }