1 |
2a4ebda1
|
Andreas Kohlbecker
|
/**
|
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 |
4c4eace6
|
Andreas Kohlbecker
|
/**
|
14 |
|
|
* Defines a search and replace operation for the
|
15 |
|
|
* {@link MediaUriTransformation}. The search pattern is a regular expression.
|
16 |
3f04dd4e
|
Andreas Kohlbecker
|
* Internally the search regex is compiled into a cached regex pattern when it
|
17 |
|
|
* is requested by calling {@link #searchPattern}.
|
18 |
4c4eace6
|
Andreas Kohlbecker
|
* <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 |
2a4ebda1
|
Andreas Kohlbecker
|
public class SearchReplace {
|
25 |
|
|
|
26 |
|
|
private String replace;
|
27 |
|
|
private String search;
|
28 |
|
|
private Pattern searchPattern;
|
29 |
|
|
|
30 |
|
|
public SearchReplace() {
|
31 |
|
|
}
|
32 |
|
|
|
33 |
4c4eace6
|
Andreas Kohlbecker
|
/**
|
34 |
|
|
* @param search
|
35 |
|
|
* the regular expressions to used as search pattern
|
36 |
|
|
* @param replace
|
37 |
|
|
* The replacement string
|
38 |
|
|
*/
|
39 |
2a4ebda1
|
Andreas Kohlbecker
|
public SearchReplace(String search, String replace) {
|
40 |
|
|
this.search = search;
|
41 |
|
|
this.replace = replace;
|
42 |
|
|
}
|
43 |
|
|
|
44 |
4c4eace6
|
Andreas Kohlbecker
|
/**
|
45 |
|
|
* Get the regular expressions used as search pattern
|
46 |
|
|
*/
|
47 |
2a4ebda1
|
Andreas Kohlbecker
|
public String getSearch() {
|
48 |
|
|
return search;
|
49 |
|
|
}
|
50 |
|
|
|
51 |
4c4eace6
|
Andreas Kohlbecker
|
/**
|
52 |
|
|
* @return The replacement string
|
53 |
|
|
*/
|
54 |
2a4ebda1
|
Andreas Kohlbecker
|
public String getReplace() {
|
55 |
|
|
return replace;
|
56 |
|
|
}
|
57 |
|
|
|
58 |
2f0cabf1
|
Andreas Kohlbecker
|
// not as property to avoid serialization
|
59 |
|
|
public Pattern searchPattern() {
|
60 |
2a4ebda1
|
Andreas Kohlbecker
|
if (searchPattern == null) {
|
61 |
|
|
searchPattern = Pattern.compile(search);
|
62 |
|
|
}
|
63 |
|
|
return searchPattern;
|
64 |
|
|
}
|
65 |
|
|
|
66 |
|
|
}
|