1
|
/**
|
2
|
* Copyright (C) 2017 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.vaadin.util.converter;
|
10
|
|
11
|
import java.util.Locale;
|
12
|
|
13
|
import org.apache.commons.lang3.StringUtils;
|
14
|
|
15
|
import com.vaadin.data.util.converter.Converter;
|
16
|
|
17
|
import eu.etaxonomy.cdm.common.DOI;
|
18
|
|
19
|
/**
|
20
|
* Creates a link from the values in the column.
|
21
|
*
|
22
|
* @author a.kohlbecker
|
23
|
* @since Mar 7, 2017
|
24
|
*
|
25
|
*/
|
26
|
public final class DoiConverter implements Converter<String, DOI> {
|
27
|
|
28
|
private static final long serialVersionUID = -6695362724769275484L;
|
29
|
|
30
|
public DoiConverter() {
|
31
|
|
32
|
}
|
33
|
|
34
|
|
35
|
@Override
|
36
|
public Class<DOI> getModelType() {
|
37
|
return DOI.class;
|
38
|
}
|
39
|
|
40
|
@Override
|
41
|
public Class<String> getPresentationType() {
|
42
|
return String.class;
|
43
|
}
|
44
|
|
45
|
|
46
|
/**
|
47
|
* {@inheritDoc}
|
48
|
*/
|
49
|
@Override
|
50
|
public DOI convertToModel(String value, Class<? extends DOI> targetType, Locale locale)
|
51
|
throws com.vaadin.data.util.converter.Converter.ConversionException {
|
52
|
if(StringUtils.isNoneEmpty(value)){
|
53
|
try{
|
54
|
DOI doi = DOI.fromString(value);
|
55
|
return doi;
|
56
|
} catch (Exception e){
|
57
|
throw new com.vaadin.data.util.converter.Converter.ConversionException(e);
|
58
|
}
|
59
|
}
|
60
|
return null;
|
61
|
}
|
62
|
|
63
|
|
64
|
/**
|
65
|
* {@inheritDoc}
|
66
|
*/
|
67
|
@Override
|
68
|
public String convertToPresentation(DOI value, Class<? extends String> targetType, Locale locale)
|
69
|
throws com.vaadin.data.util.converter.Converter.ConversionException {
|
70
|
if(value != null){
|
71
|
try{
|
72
|
return value.toString();
|
73
|
} catch (Exception e){
|
74
|
throw new com.vaadin.data.util.converter.Converter.ConversionException(e);
|
75
|
}
|
76
|
}
|
77
|
return null;
|
78
|
}
|
79
|
}
|