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 issue level.
34 * @param msg issue message.
35 * @param row issue row.
36 * @param col issue column.
37 */
38 void notifyIssue(IssueLevel level, String msg, int row, int col);
39
40 /**
41 * Prints out the content of the report.
42 *
43 * @param ps
44 */
45 void printReport(PrintStream ps);
46
47 /**
48 * Returns all the collected issues.
49 *
50 * @return a collection of {@link org.apache.any23.extractor.IssueReport.Issue}s.
51 */
52 Collection<Issue> getIssues();
53
54 /**
55 * Possible issue levels.
56 */
57 enum IssueLevel {
58 Warning,
59 Error,
60 Fatal
61 }
62
63 /**
64 * This class defines a generic issue traced by this extraction result.
65 */
66 public class Issue {
67
68 private IssueLevel level;
69 private String message;
70 private int row, col;
71
72 Issue(IssueLevel l, String msg, int r, int c) {
73 level = l;
74 message = msg;
75 row = r;
76 col = c;
77 }
78
79 public IssueLevel getLevel() {
80 return level;
81 }
82
83 public String getMessage() {
84 return message;
85 }
86
87 public int getRow() {
88 return row;
89 }
90
91 public int getCol() {
92 return col;
93 }
94
95 @Override
96 public String toString() {
97 return String.format("%s: \t'%s' \t(%d,%d)", level, message, row, col);
98 }
99 }
100
101 }