19 package org.turro.elephant.context;
22 import java.io.FileInputStream;
23 import java.io.FilenameFilter;
24 import java.io.IOException;
25 import java.util.List;
26 import java.util.Properties;
27 import java.util.logging.Level;
28 import java.util.logging.Logger;
29 import java.util.stream.Collectors;
30 import org.amic.util.file.FileUtil;
38 private static Properties _elephantContext;
39 private static final String ELEPHANT_CONTEXT_FOLDER =
"/WEB-INF/elephant/conf";
42 _elephantContext =
null;
47 return _elephantContext !=
null ? _elephantContext.containsKey(context +
"_" + property) :
false;
56 return _elephantContext !=
null ? _elephantContext.getProperty(context +
"_" + property, defaultValue) :
null;
59 public static Boolean
getContextProperty(String context, String property, Boolean defaultValue) {
60 return Boolean.valueOf(
getContextProperty(context, property, defaultValue.toString()));
65 return _elephantContext.keySet().stream()
66 .filter(k -> ((String) k).startsWith(context +
"_" + prefix))
67 .map(k -> (String) _elephantContext.get(k))
68 .collect(Collectors.toList());
74 private static void checkProperties() {
75 if(_elephantContext ==
null) {
76 _elephantContext =
new Properties();
79 public boolean accept(File dir, String name) {
80 return name.endsWith(
".properties") && !name.startsWith(
"formula-context");
83 for(File propFile : propFiles) {
84 String prefix = FileUtil.getBaseName(propFile);
85 try(FileInputStream fis =
new FileInputStream(propFile)) {
86 Properties properties =
new Properties();
88 for(String key : properties.stringPropertyNames()) {
89 _elephantContext.put(prefix +
"_" + key, properties.get(key));
91 }
catch (IOException ex) {
92 Logger.getLogger(ElephantContext.class.getName()).log(Level.SEVERE, ElephantContext.logMsg(
null), ex);
static String getRealPath(String path)
static String getContextProperty(String context, String property, String defaultValue)
static List< String > getContextPrefixedProperties(String context, String prefix)
static void resetProperties()
static boolean containsContextProperty(String context, String property)
static Boolean getContextProperty(String context, String property, Boolean defaultValue)
static String getContextProperty(String context, String property)