View Javadoc
1   /*
2    * Copyright 2012-2021 CodeLibs Project and the Others.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13   * either express or implied. See the License for the specific language
14   * governing permissions and limitations under the License.
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      @Override
32      protected ObjectiveProperties newObjectiveProperties(final String resourcePath, final PropertyFilter propertyFilter) {
33          return new ObjectiveProperties(resourcePath) { // for e.g. checking existence and filtering value
34              Cache<String, String> cache = CacheBuilder.newBuilder().build();
35  
36              @Override
37              public String get(final String propertyKey) {
38                  final String plainValue = getFromCache(propertyKey);
39                  final String filteredValue = propertyFilter.filter(propertyKey, plainValue);
40                  verifyPropertyValue(propertyKey, filteredValue); // null checked
41                  return filterPropertyAsDefault(filteredValue); // not null here
42              }
43  
44              private String getFromCache(final String propertyKey) {
45                  try {
46                      return cache.get(propertyKey,
47                              () -> System.getProperty(Constants.FESS_CONFIG_PREFIX + propertyKey, super.get(propertyKey)));
48                  } catch (final ExecutionException e) {
49                      return super.get(propertyKey);
50                  }
51              }
52          };
53      }
54  }