Project

General

Profile

Download (1.96 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.net.URI;
12
import java.util.Locale;
13

    
14
import com.vaadin.data.util.converter.Converter;
15

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

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

    
27
    public UriConverter() {
28

    
29
    }
30

    
31

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

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

    
42

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

    
63

    
64
    /**
65
     * {@inheritDoc}
66
     */
67
    @Override
68
    public String convertToPresentation(URI 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
}
(11-11/13)