2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.cdm
.vaadin
.util
.converter
;
11 import java
.util
.Locale
;
13 import com
.vaadin
.data
.util
.converter
.Converter
;
16 * Creates a link from the values in the column.
18 * @author a.kohlbecker
22 public final class UrlStringConverter
implements Converter
<String
, String
> {
24 private String regex
= null;
25 private String replacement
= "";
27 public UrlStringConverter() {
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>.
35 public UrlStringConverter(String regex
) {
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.
45 public UrlStringConverter(String regex
, String replacement
) {
47 if(replacement
!= null){
48 this.replacement
= replacement
;
53 public String
convertToModel(String value
, Class
<?
extends String
> targetType
, Locale locale
)
54 throws com
.vaadin
.data
.util
.converter
.Converter
.ConversionException
{
59 public String
convertToPresentation(String value
, Class
<?
extends String
> targetType
, Locale locale
)
60 throws com
.vaadin
.data
.util
.converter
.Converter
.ConversionException
{
63 label
= label
.replace(regex
, replacement
);
65 return "<a href=\"" + value
+ "\" target=\"external\">" + label
+ "</a>";
69 public Class
<String
> getModelType() {
74 public Class
<String
> getPresentationType() {