Project

General

Profile

Download (2.17 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2009 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 org.apache.commons.lang.StringUtils;
12

    
13
import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
14
import eu.etaxonomy.cdm.strategy.exceptions.UnknownCdmTypeException;
15

    
16
/**
17
 * @author a.mueller
18
 \* @since 02.08.2011
19
 *
20
 */
21
public class NameTypeParser {
22

    
23
	private static final String desigPattern =  "\\sdesig(\\.|nation)?";
24

    
25
	/**
26
	 * see also CentralAfricaFernsTaxonParser#handleTypeLocationPart
27
	 */
28
	public static final String typeTypePattern = "("+
29
			"lecto(\\.|type)?+" +
30
			"(original|present|subsequent)"+ desigPattern +
31
			"(subsequent monotypy|tautonomy)" +
32
			")";
33

    
34

    
35

    
36
	public static NameTypeDesignationStatus parseNameTypeStatus(String type) throws UnknownCdmTypeException {
37
		if (StringUtils.isBlank(type)){
38
			return null;
39
		}
40
		if (type.matches("(?i).*" + desigPattern)){
41
			if (type.matches("(?i)original" + desigPattern)){
42
				return NameTypeDesignationStatus.ORIGINAL_DESIGNATION();
43
			}else if (type.matches("(?i)present" + desigPattern)){
44
				return NameTypeDesignationStatus.PRESENT_DESIGNATION();
45
			}else if (type.matches("(?i)subsequent" + desigPattern)){
46
				return NameTypeDesignationStatus.SUBSEQUENT_DESIGNATION();
47
			}
48

    
49
		}else if(type.matches("(?i)subsequent monotypy")){
50
			return NameTypeDesignationStatus.SUBSEQUENT_MONOTYPY();
51
		}else if(type.matches("(?i)monotypy")){
52
			return NameTypeDesignationStatus.MONOTYPY();
53
		}else if(type.matches("(?i)tautonomy")){
54
			return NameTypeDesignationStatus.TAUTONYMY();
55
		}else if(type.matches("(?i)lectotype")){
56
			return NameTypeDesignationStatus.LECTOTYPE();
57
		}else if(type.matches("(?i)automatic")){
58
			return NameTypeDesignationStatus.AUTOMATIC();
59
		}else if(type.matches("(?i)not applicable")){
60
			return NameTypeDesignationStatus.NOT_APPLICABLE();
61
		}
62
		String message = "Type Status not supported: " + type;
63
		throw new UnknownCdmTypeException(message);
64

    
65
	}
66
}
(3-3/8)