1
|
/**
|
2
|
* Copyright (C) 2020 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.api.service.media;
|
10
|
|
11
|
import java.util.regex.Pattern;
|
12
|
|
13
|
/**
|
14
|
* Defines a search and replace operation for the
|
15
|
* {@link MediaUriTransformation}. The search pattern is a regular expression.
|
16
|
* Internally the search regex is compiled into a cached regex pattern when it
|
17
|
* is requested by calling {@link #searchPattern}.
|
18
|
* <p>
|
19
|
* <b>CHANGING THIS CLASS MAY BREAK DESERIALIZATION OF EXISTING CDM PREFERENCES.</b>
|
20
|
*
|
21
|
* @author a.kohlbecker
|
22
|
* @since Aug 19, 2020
|
23
|
*/
|
24
|
public class SearchReplace {
|
25
|
|
26
|
private String replace;
|
27
|
private String search;
|
28
|
private Pattern searchPattern;
|
29
|
|
30
|
public SearchReplace() {
|
31
|
}
|
32
|
|
33
|
/**
|
34
|
* @param search
|
35
|
* the regular expressions to used as search pattern
|
36
|
* @param replace
|
37
|
* The replacement string
|
38
|
*/
|
39
|
public SearchReplace(String search, String replace) {
|
40
|
this.search = search;
|
41
|
this.replace = replace;
|
42
|
}
|
43
|
|
44
|
/**
|
45
|
* Get the regular expressions used as search pattern
|
46
|
*/
|
47
|
public String getSearch() {
|
48
|
return search;
|
49
|
}
|
50
|
|
51
|
/**
|
52
|
* @return The replacement string
|
53
|
*/
|
54
|
public String getReplace() {
|
55
|
return replace;
|
56
|
}
|
57
|
|
58
|
// not as property to avoid serialization
|
59
|
public Pattern searchPattern() {
|
60
|
if (searchPattern == null) {
|
61
|
searchPattern = Pattern.compile(search);
|
62
|
}
|
63
|
return searchPattern;
|
64
|
}
|
65
|
|
66
|
@Override
|
67
|
public String toString() {
|
68
|
return "SearchReplace [replace=" + replace + ", search=" + search + ", searchPattern=" + searchPattern + "]";
|
69
|
}
|
70
|
|
71
|
|
72
|
|
73
|
}
|