1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.codelibs.fess.mylasta.direction;
17
18 import java.util.concurrent.ExecutionException;
19
20 import org.codelibs.fess.Constants;
21 import org.dbflute.helper.jprop.ObjectiveProperties;
22 import org.lastaflute.core.direction.PropertyFilter;
23
24 import com.google.common.cache.Cache;
25 import com.google.common.cache.CacheBuilder;
26
27 public class FessConfigImpl extends FessConfig.SimpleImpl {
28
29 private static final long serialVersionUID = 1L;
30
31 private static class KeyNotFoundException extends Exception {
32 private static final long serialVersionUID = 1L;
33
34 private KeyNotFoundException(final String key) {
35 super(key);
36 }
37 }
38
39 @Override
40 protected ObjectiveProperties newObjectiveProperties(final String resourcePath, final PropertyFilter propertyFilter) {
41 return new ObjectiveProperties(resourcePath) {
42 Cache<String, String> cache = CacheBuilder.newBuilder().build();
43
44 @Override
45 public String get(final String propertyKey) {
46 final String plainValue = getFromCache(propertyKey);
47 final String filteredValue = propertyFilter.filter(propertyKey, plainValue);
48 verifyPropertyValue(propertyKey, filteredValue);
49 return filterPropertyAsDefault(filteredValue);
50 }
51
52 private String getFromCache(final String propertyKey) {
53 try {
54 return cache.get(propertyKey, () -> {
55 final String value = System.getProperty(Constants.FESS_CONFIG_PREFIX + propertyKey, super.get(propertyKey));
56 if (value == null) {
57 throw new KeyNotFoundException(propertyKey);
58 }
59 return value;
60 });
61 } catch (final ExecutionException e) {
62 if (e.getCause() instanceof KeyNotFoundException) {
63 return null;
64 }
65 return super.get(propertyKey);
66 }
67 }
68 };
69 }
70 }