2 * Copyright (C) 2009 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.cdm
.io
.wp6
;
12 import java
.util
.ArrayList
;
13 import java
.util
.HashMap
;
14 import java
.util
.List
;
16 import java
.util
.regex
.Matcher
;
17 import java
.util
.regex
.Pattern
;
19 import org
.apache
.commons
.lang
.StringUtils
;
20 import org
.apache
.log4j
.Logger
;
22 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
23 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
24 import eu
.etaxonomy
.cdm
.strategy
.parser
.INonViralNameParser
;
25 import eu
.etaxonomy
.cdm
.strategy
.parser
.NonViralNameParserImpl
;
28 * @author a.babadshanjan
32 public class CommonNameRow
{
33 private static final Logger logger
= Logger
.getLogger(CommonNameRow
.class);
36 private String species
;
37 private String reference
;
39 private String nameUsedInSource
;
41 private Map
<String
, List
<String
>> commonNames
= new HashMap
<String
, List
<String
>>();
44 public CommonNameRow() {
48 commonNames
= new HashMap
<String
, List
<String
>>();
51 // **************************** GETTER / SETTER *********************************/
53 public void setCommonNames(String commonNamesString
){
54 commonNamesString
= makeNameUsedInSource(commonNamesString
);
55 String
[] split
= commonNamesString
.split(";");
56 for (String oneLanguage
: split
){
57 oneLanguage
= oneLanguage
.trim();
58 String reLangPattern
= "\\((\\*|[a-z]{2,3}|.{2,},\\sno\\sISO-Code)\\)$";
59 String pattern
= ".+" + reLangPattern
;
60 if (! oneLanguage
.matches(pattern
)){
61 logger
.warn("Common name does not match: " + oneLanguage
);
63 Pattern langPattern
= Pattern
.compile(reLangPattern
);
64 Matcher matcher
= langPattern
.matcher(oneLanguage
);
66 String lang
= matcher
.group().substring(1);
67 lang
= lang
.substring(0, lang
.length()-1);
70 names
= oneLanguage
.substring(0,matcher
.start()-1);
71 } catch (Exception e
) {
74 String
[] splitNames
= names
.split(",");
75 List
<String
> nameList
= new ArrayList
<String
>();
76 for (String singleName
: splitNames
){
77 if (StringUtils
.isNotBlank(singleName
)){
78 nameList
.add(singleName
.trim());
81 if (!nameList
.isEmpty()){
82 this.commonNames
.put(lang
, nameList
);
85 logger
.warn("Common name does not match: " + oneLanguage
);
91 private String
makeNameUsedInSource(String commonNamesString
) {
92 String
[] split
= commonNamesString
.split(":");
93 if (split
.length
> 1){
94 logger
.debug("NameUsedInSource: " + split
[0]);
95 this.nameUsedInSource
= split
[0].trim();
96 if (split
.length
> 2){
97 logger
.warn("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:" + commonNamesString
);
99 return split
[1].trim();
101 return split
[0].trim();
105 public Map
<String
, List
<String
>> getCommonNames() {
109 public void parseSpecies(String species
){
110 INonViralNameParser parser
= NonViralNameParserImpl
.NewInstance();
111 BotanicalName name
= (BotanicalName
)parser
.parseFullName(species
, NomenclaturalCode
.ICNAFP
, null);
112 if (name
.isProtectedTitleCache()){
113 logger
.warn("Name could not be parsed: " + species
);
115 this.species
= species
;
118 public String
getSpecies() {
122 public void setSpecies(String species
) {
123 this.species
= species
;
126 public void setReference(String reference
) {
127 reference
= reference
.replace(".", "");
128 if (! reference
.matches("\\d{7}")){
129 logger
.warn("Unexpected reference");
131 this.reference
= reference
.substring(0,6);
134 public String
getReference() {
138 public void setArea(String area
) {
142 public String
getArea() {
146 public void setNameUsedInSource(String nameUsedInSource
) {
147 this.nameUsedInSource
= nameUsedInSource
;
150 public String
getNameUsedInSource() {
151 return nameUsedInSource
;