use of org.redkale.util.AnyValue in project redkale by redkale.
the class HttpResourceServlet method init.
@Override
public void init(HttpContext context, AnyValue config) {
if (config != null) {
String rootstr = config.getValue("webroot", "root");
this.indexHtml = config.getValue("index", "index.html");
if (rootstr.indexOf(':') < 0 && rootstr.indexOf('/') != 0 && System.getProperty("APP_HOME") != null) {
rootstr = new File(System.getProperty("APP_HOME"), rootstr).getPath();
}
try {
this.root = new File(rootstr).getCanonicalFile();
} catch (IOException ioe) {
this.root = new File(rootstr);
}
AnyValue cacheconf = config.getAnyValue("cache");
if (cacheconf != null) {
this.cachelimit = parseLenth(cacheconf.getValue("limit"), 0 * 1024 * 1024L);
this.cachelengthmax = parseLenth(cacheconf.getValue("lengthmax"), 1 * 1024 * 1024L);
this.watch = cacheconf.getBoolValue("watch", false);
}
List<SimpleEntry<Pattern, String>> locations = new ArrayList<>();
for (AnyValue av : config.getAnyValues("rewrite")) {
if ("location".equals(av.getValue("type"))) {
String m = av.getValue("match");
String f = av.getValue("forward");
if (m != null && f != null) {
locations.add(new SimpleEntry<>(Pattern.compile(m), f));
}
}
}
this.locationRewrites = locations.isEmpty() ? null : locations.toArray(new SimpleEntry[locations.size()]);
}
// 不缓存不需要开启WatchThread监听
if (this.cachelimit < 1)
return;
if (this.root != null && this.watch) {
try {
this.watchThread = new WatchThread(this.root);
this.watchThread.start();
} catch (IOException ex) {
logger.log(Level.WARNING, HttpResourceServlet.class.getSimpleName() + " start watch-thread error", ex);
}
}
}
use of org.redkale.util.AnyValue in project redkale by redkale.
the class DataSources method loadPersistenceXml.
public static Map<String, Properties> loadPersistenceXml(final InputStream in0) {
final Map<String, Properties> map = new LinkedHashMap();
boolean flag = false;
try (final InputStream in = in0) {
AnyValue config = AnyValue.loadFromXml(in).getAnyValue("persistence");
for (AnyValue conf : config.getAnyValues("persistence-unit")) {
Properties result = new Properties();
conf.forEach(null, (n, c) -> {
if ("properties".equals(n)) {
for (AnyValue sub : c.getAnyValues("property")) {
result.put(sub.getValue("name"), sub.getValue("value"));
}
} else {
String v = c.getValue(AnyValue.XML_TEXT_NODE_NAME);
if (v != null) {
if ("shared-cache-mode".equalsIgnoreCase(n)) {
result.put(JDBC_CACHE_MODE, v);
} else {
result.put(n, v);
}
}
}
});
map.put(conf.getValue("name"), result);
}
in.close();
} catch (Exception ex) {
throw new RuntimeException(ex);
}
return map;
}
use of org.redkale.util.AnyValue in project redkale by redkale.
the class DataSources method createDataSource.
public static DataSource createDataSource(final String unitName, final AnyValue conf) throws IOException {
Properties prop = new Properties();
AnyValue[] confs = conf.getAnyValues("property");
if (confs != null) {
for (AnyValue itemConf : confs) {
String name = itemConf.getValue("name");
String value = itemConf.getValue("value");
if (name != null && value != null)
prop.put(name, value);
}
}
return createDataSource(unitName, prop, prop);
}
Aggregations