Project

General

Profile

Download (1.98 KB) Statistics
| Branch: | Tag: | Revision:
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 com.vaadin.data.util.converter.Converter;
14

    
15
import eu.etaxonomy.cdm.common.URI;
16

    
17
/**
18
 * Creates a link from the values in the column.
19
 *
20
 * @author a.kohlbecker
21
 * @since Mar 7, 2017
22
 *
23
 */
24
public final class UriConverter implements Converter<String, URI> {
25

    
26
    private static final long serialVersionUID = -6695362724769275484L;
27

    
28
    public UriConverter() {
29

    
30
    }
31

    
32

    
33
    @Override
34
    public Class<URI> getModelType() {
35
        return URI.class;
36
    }
37

    
38
    @Override
39
    public Class<String> getPresentationType() {
40
        return String.class;
41
    }
42

    
43

    
44
    /**
45
     * {@inheritDoc}
46
     */
47
    @Override
48
    public URI convertToModel(String value, Class<? extends URI> targetType, Locale locale)
49
            throws com.vaadin.data.util.converter.Converter.ConversionException {
50
        if(value != null){
51
            value = value.trim();
52
            if(!value.isEmpty()){
53
                try{
54
                    URI uri = new URI(value.trim());
55
                    return uri;
56
                } catch (Exception e){
57
                    throw new com.vaadin.data.util.converter.Converter.ConversionException(e);
58
                }
59
            }
60
        }
61
        return null;
62
    }
63

    
64

    
65
    /**
66
     * {@inheritDoc}
67
     */
68
    @Override
69
    public String convertToPresentation(URI value, Class<? extends String> targetType, Locale locale)
70
            throws com.vaadin.data.util.converter.Converter.ConversionException {
71
        if(value != null){
72
            try{
73
                return value.toString();
74
            } catch (Exception e){
75
                throw new com.vaadin.data.util.converter.Converter.ConversionException(e);
76
            }
77
        }
78
        return null;
79
    }
80
}
(12-12/14)