Project

General

Profile

« Previous | Next » 

Revision 5465eca0

Added by Andreas Kohlbecker about 7 years ago

ref #6169 showing citation in list and eums items in UPPERCASE

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/util/UrlStringConverter.java
13 13
import com.vaadin.data.util.converter.Converter;
14 14

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

  
24
    private String regex = null;
25
    private String replacement = "";
26

  
27
    public UrlStringConverter() {
28

  
29
    }
30

  
31
    /**
32
     * @param regex Regular expression for creating an alternative label by string replacement on the value.
33
     *  This is optional. No string replacement will be done when this is <code>null</code>.
34
     */
35
    public UrlStringConverter(String regex) {
36
        this(regex, null);
37
    }
38

  
39
    /**
40
     * @param regex Regular expression for creating an alternative label by string replacement on the value.
41
     *  This is optional. No string replacement will be done when this is <code>null</code>.
42
     * @param replacement The replacement to be used with the <code>regex</code>.
43
     * Defaults to an empty string when null.
44
     */
45
    public UrlStringConverter(String regex, String replacement) {
46
        this.regex = regex;
47
        if(replacement != null){
48
            this.replacement = replacement;
49
        }
50
    }
51

  
21 52
    @Override
22 53
    public String convertToModel(String value, Class<? extends String> targetType, Locale locale)
23 54
            throws com.vaadin.data.util.converter.Converter.ConversionException {
......
27 58
    @Override
28 59
    public String convertToPresentation(String value, Class<? extends String> targetType, Locale locale)
29 60
            throws com.vaadin.data.util.converter.Converter.ConversionException {
30
        // TODO Auto-generated method stub
31
        return "<a href=\"" + value + "\" target=\"external\">" + value + "</a>";
61
        String label = value;
62
        if(regex != null){
63
            label = label.replace(regex, replacement);
64
        }
65
        return "<a href=\"" + value + "\" target=\"external\">" + label + "</a>";
32 66
    }
33 67

  
34 68
    @Override

Also available in: Unified diff