2 * Copyright (C) 2007 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
.excel
.common
;
12 import java
.util
.HashMap
;
14 import org
.apache
.commons
.lang
.StringUtils
;
15 import org
.apache
.log4j
.Logger
;
17 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
23 public abstract class ExcelTaxonOrSpecimenImportBase
<STATE
extends ExcelImportState
<?
extends ExcelImportConfiguratorBase
>> extends ExcelImporterBase
<STATE
> {
24 private static final Logger logger
= Logger
.getLogger(ExcelTaxonOrSpecimenImportBase
.class);
27 protected static final String UUID_COLUMN
= "(?i)(UUID)";
30 protected static final String RANK_COLUMN
= "(?i)(Rank)";
31 protected static final String FULL_NAME_COLUMN
= "(?i)(FullName)";
32 protected static final String FAMILY_COLUMN
= "(?i)(Family)";
33 protected static final String GENUS_COLUMN
= "(?i)(Genus)";
34 protected static final String SPECIFIC_EPITHET_COLUMN
= "(?i)(SpecificEpi(thet)?)";
35 protected static final String INFRASPECIFIC_EPITHET_COLUMN
= "(?i)(InfraSpecificEpi(thet)?)";
38 protected class KeyValue
{
43 public String postfix
;
46 public String refAuthor
;
47 public String refIndex
;
57 protected KeyValue
makeKeyValue(HashMap
<String
, String
> record
, String originalKey
) {
58 KeyValue keyValue
= new KeyValue();
59 String indexedKey
= CdmUtils
.removeDuplicateWhitespace(originalKey
.trim()).toString();
60 String
[] split
= indexedKey
.split("_");
61 keyValue
.key
= split
[0];
62 if (split
.length
> 1){
63 for (int i
= 1 ; i
< split
.length
; i
++ ){
64 String indexString
= split
[i
];
65 if (isInteger(indexString
)){
66 keyValue
.index
= Integer
.valueOf(indexString
);
68 keyValue
.postfix
= split
[i
];
73 //TODO shouldn't we use originalKey here??
74 String value
= (String
) record
.get(indexedKey
);
75 if (! StringUtils
.isBlank(value
)) {
76 if (logger
.isDebugEnabled()) { logger
.debug(keyValue
.key
+ ": " + value
); }
77 value
= CdmUtils
.removeDuplicateWhitespace(value
.trim()).toString();
78 keyValue
.value
= value
;
80 keyValue
.value
= null;
86 protected boolean isInteger(String value
){
88 Integer
.valueOf(value
);
90 } catch (NumberFormatException e
) {