1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.codehaus.plexus.components.secdispatcher.internal.sources;
20
21 import java.util.function.Function;
22 import java.util.function.Predicate;
23
24 import org.codehaus.plexus.components.secdispatcher.MasterSource;
25 import org.codehaus.plexus.components.secdispatcher.SecDispatcher;
26 import org.codehaus.plexus.components.secdispatcher.SecDispatcherException;
27
28 import static java.util.Objects.requireNonNull;
29
30
31
32
33 public abstract class MasterSourceSupport implements MasterSource {
34 private final Predicate<String> matcher;
35 private final Function<String, String> transformer;
36
37 public MasterSourceSupport(Predicate<String> matcher, Function<String, String> transformer) {
38 this.matcher = requireNonNull(matcher);
39 this.transformer = requireNonNull(transformer);
40 }
41
42 @Override
43 public String handle(String masterSource) throws SecDispatcherException {
44 if (matcher.test(masterSource)) {
45 return doHandle(transformer.apply(masterSource));
46 }
47 return null;
48 }
49
50 protected abstract String doHandle(String transformed) throws SecDispatcherException;
51
52 public SecDispatcher.ValidationResponse validateConfiguration(String masterSource) {
53 if (matcher.test(masterSource)) {
54 return doValidateConfiguration(transformer.apply(masterSource));
55 }
56 return null;
57 }
58
59 protected abstract SecDispatcher.ValidationResponse doValidateConfiguration(String transformed);
60 }