diff options
-rw-r--r-- | pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java | 16 | ||||
-rw-r--r-- | pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java | 16 |
2 files changed, 32 insertions, 0 deletions
diff --git a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java index 42cdb8ab..43139966 100644 --- a/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java +++ b/pdf-as-common/src/main/java/at/gv/egiz/pdfas/common/settings/ISettings.java @@ -29,6 +29,22 @@ import java.util.Vector; public interface ISettings { public String getValue(String key); public boolean hasValue(String key); + + /** + * Get boolean configuration value. + * @param key Configuration key + * @return <code>true</code> if configuration exists and has value <code>true</code>, otherwise <code>false</code> + */ + public boolean isValue(String key); + + /** + * Get boolean configuration value. + * @param key Configuration key + * @param defaultValue Value if configuration does not exist + * @return <code>true</code> if configuration exists and has value <code>true</code>, otherwise default value + */ + public boolean isValue(String key, boolean defaultValue); + public boolean hasPrefix(String prefix); public Map<String, String> getValuesPrefix(String prefix); public Vector<String> getFirstLevelKeys(String prefix); diff --git a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java index 0b376455..8138f061 100644 --- a/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java +++ b/pdf-as-lib/src/main/java/at/gv/egiz/pdfas/lib/settings/Settings.java @@ -40,6 +40,7 @@ import java.util.stream.Collectors; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOCase; import org.apache.commons.io.filefilter.WildcardFileFilter; +import org.apache.commons.lang3.StringUtils; import at.gv.egiz.pdfas.common.exceptions.PdfAsSettingsException; import at.gv.egiz.pdfas.common.settings.IProfileConstants; @@ -322,6 +323,21 @@ public class Settings implements ISettings, IProfileConstants { return properties.getProperty(key); } + public boolean isValue(String key) { + return isValue(key, false); + + } + public boolean isValue(String key, boolean defaultValue) { + String value = getValue(key); + if (StringUtils.isNotEmpty(value)) { + return Boolean.valueOf(value); + + } else { + return defaultValue; + + } + } + @Override public boolean hasValue(String key) { return properties.containsKey(key); |