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