Project

General

Profile

Download (1.9 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
public final class UriConverter implements Converter<String, URI> {
24

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

    
27
    public UriConverter() {
28

    
29
    }
30
    @Override
31
    public Class<URI> getModelType() {
32
        return URI.class;
33
    }
34

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

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

    
57
    @Override
58
    public String convertToPresentation(URI value, Class<? extends String> targetType, Locale locale)
59
            throws com.vaadin.data.util.converter.Converter.ConversionException {
60
        if(value != null){
61
            try{
62
                return value.toString();
63
            } catch (Exception e){
64
                throw new com.vaadin.data.util.converter.Converter.ConversionException(e);
65
            }
66
        }
67
        return null;
68
    }
69
}
(12-12/14)