1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.strategy.parser;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.Language;
|
17
|
|
18
|
/**
|
19
|
* @author a.mueller
|
20
|
* @since 04.09.2009
|
21
|
*/
|
22
|
public enum ParserProblem {
|
23
|
CheckRank(WARNING()),
|
24
|
CheckDetailOrYear(WARNING()),
|
25
|
NameReferenceSeparation(ERROR()),
|
26
|
UnparsableReferenceTitle(ERROR()),
|
27
|
UnparsableNamePart(ERROR()),
|
28
|
UnparsableAuthorPart(ERROR()),
|
29
|
OldInfraSpeciesNotSupported(ERROR()),
|
30
|
RankNotSupported(ERROR()),
|
31
|
NewCombinationHasPublication(WARNING()),
|
32
|
;
|
33
|
|
34
|
@SuppressWarnings("unused")
|
35
|
private static final Logger logger = LogManager.getLogger(ParserProblem.class);
|
36
|
|
37
|
private final static int WARNING(){return 0;}
|
38
|
private final static int ERROR() {return 1;}
|
39
|
|
40
|
int type;
|
41
|
|
42
|
private ParserProblem(int type){
|
43
|
this.type = type;
|
44
|
}
|
45
|
|
46
|
public String getMessage(){
|
47
|
return getMessage(Language.DEFAULT());
|
48
|
}
|
49
|
|
50
|
public String getMessage(Language language){
|
51
|
//TODO language not yet supported
|
52
|
if (this == CheckRank){
|
53
|
return "check rank";
|
54
|
}else if (this == CheckDetailOrYear){
|
55
|
return "detail or year part ambiguous";
|
56
|
}else if (this == NameReferenceSeparation){
|
57
|
return "name or authorship not parsable or name-reference separation not possible";
|
58
|
}else if (this == UnparsableReferenceTitle){
|
59
|
return "reference title not parsable";
|
60
|
}else if (this == UnparsableAuthorPart){
|
61
|
return "author part not parsable";
|
62
|
}else if (this == UnparsableNamePart){
|
63
|
return "name part not parsable";
|
64
|
}else if (this == OldInfraSpeciesNotSupported){
|
65
|
return "name not parsable - old infraspecific marker not supported by parser";
|
66
|
}else if (this == RankNotSupported){
|
67
|
return "rank not supported by parser";
|
68
|
}else if (this == NewCombinationHasPublication){
|
69
|
return "zool. new combination should not have a nomencl. reference";
|
70
|
}else{
|
71
|
return "unknown parser problem";
|
72
|
}
|
73
|
}
|
74
|
|
75
|
public boolean isError(){
|
76
|
return type == ERROR();
|
77
|
}
|
78
|
|
79
|
public boolean isWarning(){
|
80
|
return type == WARNING();
|
81
|
}
|
82
|
|
83
|
public static List<ParserProblem> warningList(int problem){
|
84
|
List<ParserProblem> result = new ArrayList<>();
|
85
|
ParserProblem[] values = ParserProblem.values();
|
86
|
for (ParserProblem warning: values){
|
87
|
if (testBit(problem, warning.ordinal())){
|
88
|
result.add(warning);
|
89
|
}
|
90
|
}
|
91
|
return result;
|
92
|
}
|
93
|
|
94
|
public static boolean hasError(int problem){
|
95
|
List<ParserProblem> list = warningList(problem);
|
96
|
for (ParserProblem warning : list){
|
97
|
if (warning.isError()){
|
98
|
return true;
|
99
|
}
|
100
|
}
|
101
|
return false;
|
102
|
}
|
103
|
|
104
|
private static boolean testBit(int number, int pos) {
|
105
|
return (number & 1<<pos)!=0;
|
106
|
}
|
107
|
|
108
|
public static int addProblem(int originalProblems, ParserProblem newProblem) {
|
109
|
if (newProblem == null){
|
110
|
return originalProblems;
|
111
|
}else{
|
112
|
return originalProblems | 1 << newProblem.ordinal();
|
113
|
}
|
114
|
}
|
115
|
|
116
|
public static int addProblems(int hasProblem, int newProblems) {
|
117
|
return hasProblem | newProblems;
|
118
|
}
|
119
|
|
120
|
public static int removeProblem(int originalProblems, ParserProblem problemToRemove) {
|
121
|
if (problemToRemove == null){
|
122
|
return originalProblems;
|
123
|
}else{
|
124
|
return originalProblems & ~(1 << problemToRemove.ordinal());
|
125
|
}
|
126
|
}
|
127
|
}
|