Project

General

Profile

Download (3.7 KB) Statistics
| Branch: | Tag: | Revision:
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

    
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
import eu.etaxonomy.cdm.model.common.Language;
18

    
19
/**
20
 * @author a.mueller
21
 * @created 04.09.2009
22
 * @version 1.0
23
 */
24
public enum ParserProblem {
25
	CheckRank(WARNING()),
26
	CheckDetailOrYear(WARNING()),
27
	NameReferenceSeparation(ERROR()),
28
	UnparsableReferenceTitle(ERROR()),
29
	UnparsableNamePart(ERROR()),
30
	UnparsableAuthorPart(ERROR()),
31
	OldInfraSpeciesNotSupported(ERROR()),
32
	RankNotSupported(ERROR()),
33
	NewCombinationHasPublication(WARNING()),
34
	;
35

    
36
	@SuppressWarnings("unused")
37
	private static final Logger logger = Logger.getLogger(ParserProblem.class);
38

    
39
	private final static int WARNING(){return 0;};
40
	private final static int ERROR() {return 1;};
41

    
42
	int type;
43

    
44
	private ParserProblem(int type){
45
		this.type = type;
46
	}
47

    
48
	public String getMessage(){
49
		return getMessage(Language.DEFAULT());
50
	}
51

    
52
	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
			return "detail or year part ambiguous";
58
		}else if (this == NameReferenceSeparation){
59
			return "name or authorship not parsable or name-reference separation not possible";
60
		}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
		}else if (this == NewCombinationHasPublication){
71
			return "zool. new combination should not have a nomencl. reference";
72
		}else{
73
			return "unknown parser problem";
74
		}
75
	}
76

    
77

    
78
	public boolean isError(){
79
		return type == ERROR();
80
	}
81

    
82
	public boolean isWarning(){
83
		return type == WARNING();
84
	}
85

    
86

    
87
	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

    
98
	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
	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
	}
129

    
130
	public static int addProblems(int hasProblem, int newProblems) {
131
		return hasProblem | newProblems;
132
	}
133

    
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
	}
146

    
147

    
148

    
149
}
(5-5/7)