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