Project

General

Profile

Download (4.01 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
	//logger.warn("ICNCP parsing not yet implemented");
37
	//logger.warn("ICNB not yet implemented");
38
	//logger.error("Viral name is not a NonViralName !!");
39
	//logger.error("Unknown Nomenclatural Code !!");
40
	//logger.warn("nameToBeFilled class not supported ("+nameToBeFilled.getClass()+")");
41
	
42
	@SuppressWarnings("unused")
43
	private static final Logger logger = Logger.getLogger(ParserProblem.class);
44
	
45
	private final static int WARNING(){return 0;};
46
	private final static int ERROR() {return 1;};
47
	
48
	int type;  
49
	
50
	private ParserProblem(int type){
51
		this.type = type;
52
	}
53
	
54
	public String getMessage(){
55
		return getMessage(Language.DEFAULT());
56
	}
57
	
58
	public String getMessage(Language language){
59
		//TODO language not yet supported
60
		if (this == CheckRank){
61
			return "check rank";
62
		}else if (this == CheckDetailOrYear){
63
			return "detail or year part ambiguous";
64
		}else if (this == NameReferenceSeparation){
65
			return "name or authorship not parsable or name-reference separation not possible";
66
		}else if (this == UnparsableReferenceTitle){
67
			return "reference title not parsable";
68
		}else if (this == UnparsableAuthorPart){
69
			return "author part not parsable";
70
		}else if (this == UnparsableNamePart){
71
			return "name part not parsable";
72
		}else if (this == OldInfraSpeciesNotSupported){
73
			return "name not parsable - old infraspecific marker not supported by parser";
74
		}else if (this == RankNotSupported){
75
			return "rank not supported by parser";
76
		}else if (this == NewCombinationHasPublication){
77
			return "zool. new combination should not have a nomencl. reference";
78
		}else{
79
			return "unknown parser problem";
80
		}
81
	}
82
	
83
	
84
	public boolean isError(){
85
		return type == ERROR();
86
	}
87

    
88
	public boolean isWarning(){
89
		return type == WARNING();
90
	}
91

    
92
	
93
	public static List<ParserProblem> warningList(int problem){
94
		List<ParserProblem> result = new ArrayList<ParserProblem>();
95
		ParserProblem[] values = ParserProblem.values();
96
		for (ParserProblem warning: values){
97
			if (testBit(problem, warning.ordinal())){
98
				result.add(warning);
99
			}
100
		}
101
		return result;
102
	}
103
	
104
	public static boolean hasError(int problem){
105
		List<ParserProblem> list = warningList(problem);
106
		for (ParserProblem warning : list){
107
			if (warning.isError()){
108
				return true;
109
			}
110
		}
111
		return false;
112
	}
113

    
114

    
115
	/**
116
	 * @param number
117
	 * @param pos
118
	 * @return
119
	 */
120
	private static boolean testBit(int number, int pos) {
121
		return  (number & 1<<pos)!=0;
122
	}
123
	/**
124
	 * @param hasProblem
125
	 * @param warning
126
	 * @return
127
	 */
128
	public static int addProblem(int originalProblems, ParserProblem newProblem) {
129
		if (newProblem == null){
130
			return originalProblems;
131
		}else{
132
			return originalProblems | 1 << newProblem.ordinal();
133
		}
134
	}
135
	
136
	public static int addProblems(int hasProblem, int newProblems) {
137
		return hasProblem | newProblems;
138
	}
139

    
140
	/**
141
	 * @param parsingProblem
142
	 * @param problemToRemove
143
	 * @return
144
	 */
145
	public static int removeProblem(int originalProblems, ParserProblem problemToRemove) {
146
		if (problemToRemove == null){
147
			return originalProblems;
148
		}else{
149
			return originalProblems & ~(1 << problemToRemove.ordinal());
150
		}
151
	}	
152

    
153
	
154
	
155
}
(5-5/8)