#2358 add FessConfigImpl

This commit is contained in:
Shinsuke Sugaya 2020-01-15 22:03:59 +09:00
parent 3bc848bc6f
commit e4e9e5f188
3 changed files with 55 additions and 33 deletions

View file

@ -15,15 +15,8 @@
*/
package org.codelibs.fess.mylasta.direction;
import java.util.concurrent.ExecutionException;
import org.dbflute.helper.jprop.ObjectiveProperties;
import org.lastaflute.core.direction.PropertyFilter;
import org.lastaflute.core.direction.exception.ConfigPropertyNotFoundException;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
/**
* @author FreeGen
*/
@ -6473,31 +6466,6 @@ public interface FessConfig extends FessEnv, org.codelibs.fess.mylasta.direction
/** The serial version UID for object serialization. (Default) */
private static final long serialVersionUID = 1L;
private static final String FESS_CONFIG = "fess.config.";
@Override
protected ObjectiveProperties newObjectiveProperties(String resourcePath, PropertyFilter propertyFilter) {
return new ObjectiveProperties(resourcePath) { // for e.g. checking existence and filtering value
Cache<String, String> cache = CacheBuilder.newBuilder().build();
@Override
public String get(String propertyKey) {
final String plainValue = getFromCache(propertyKey);
final String filteredValue = propertyFilter.filter(propertyKey, plainValue);
verifyPropertyValue(propertyKey, filteredValue); // null checked
return filterPropertyAsDefault(filteredValue); // not null here
}
private String getFromCache(String propertyKey) {
try {
return cache.get(propertyKey, () -> System.getProperty(FESS_CONFIG + propertyKey, super.get(propertyKey)));
} catch (ExecutionException e) {
return super.get(propertyKey);
}
}
};
}
public String getDomainTitle() {
return get(FessConfig.DOMAIN_TITLE);
}

View file

@ -0,0 +1,54 @@
/*
* Copyright 2012-2019 CodeLibs Project and the Others.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
* either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
package org.codelibs.fess.mylasta.direction;
import java.util.concurrent.ExecutionException;
import org.dbflute.helper.jprop.ObjectiveProperties;
import org.lastaflute.core.direction.PropertyFilter;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
public class FessConfigImpl extends FessConfig.SimpleImpl {
private static final long serialVersionUID = 1L;
private static final String FESS_CONFIG = "fess.config.";
@Override
protected ObjectiveProperties newObjectiveProperties(String resourcePath, PropertyFilter propertyFilter) {
return new ObjectiveProperties(resourcePath) { // for e.g. checking existence and filtering value
Cache<String, String> cache = CacheBuilder.newBuilder().build();
@Override
public String get(String propertyKey) {
final String plainValue = getFromCache(propertyKey);
final String filteredValue = propertyFilter.filter(propertyKey, plainValue);
verifyPropertyValue(propertyKey, filteredValue); // null checked
return filterPropertyAsDefault(filteredValue); // not null here
}
private String getFromCache(String propertyKey) {
try {
return cache.get(propertyKey, () -> System.getProperty(FESS_CONFIG + propertyKey, super.get(propertyKey)));
} catch (ExecutionException e) {
return super.get(propertyKey);
}
}
};
}
}

View file

@ -3,5 +3,5 @@
"http://dbflute.org/meta/lastadi10.dtd">
<components>
<component name="assistantDirector" class="org.codelibs.fess.mylasta.direction.FessFwAssistantDirector"/>
<component name="fessConfig" class="org.codelibs.fess.mylasta.direction.FessConfig$SimpleImpl"/>
<component name="fessConfig" class="org.codelibs.fess.mylasta.direction.FessConfigImpl"/>
</components>