Here are the examples of the java api com.blade.Environment.get() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
6 Examples
19
View Complete Implementation : ValueInjector.java
Copyright Apache License 2.0
Author : lets-blade
Copyright Apache License 2.0
Author : lets-blade
@Override
public void injection(Object bean) {
try {
if (!key.isEmpty()) {
Clreplaced<?> clazz = target.getType();
target.setAccessible(true);
Optional<String> fieldValue = environment.get(key);
if (!fieldValue.isPresent()) {
log.warn("config is absent,so can't be injected:target is {}", bean.getClreplaced().getName());
return;
}
if (fieldValue.get().isEmpty()) {
log.warn("config is empty,so can't be injected:target is {}", bean.getClreplaced().getName());
return;
}
Object value = null;
// target field type is Basic Type
if (ReflectKit.isBasicType(clazz)) {
if (fieldValue.isPresent() && StringKit.isNotBlank(fieldValue.get())) {
value = ReflectKit.convert(clazz, fieldValue.get());
}
if (null != value) {
ReflectKit.setFieldValue(target, bean, value);
}
}
// List and Map support,just support String element
String split = environment.get("value.split", ",");
String mapSplit = environment.get("value.map.split", ":");
if (clazz.isreplacedignableFrom(List.clreplaced)) {
target.set(bean, Arrays.asList(fieldValue.get().split(split)));
return;
}
Map<String, String> map = new HashMap<>(16);
if (clazz.isreplacedignableFrom(Map.clreplaced)) {
Arrays.stream(fieldValue.get().split(split)).filter(d -> d.contains(mapSplit)).map(d -> d.split(mapSplit)).forEach(keyValue -> map.put(keyValue[0], keyValue[1]));
target.set(bean, map);
return;
}
} else {
log.warn("key is empty,so can't be injected:target is {}", bean.getClreplaced().getName());
}
} catch (IllegalAccessException e) {
log.error("inject config error! key is {},bean is {}", key, bean.getClreplaced().getSimpleName(), e);
}
}
19
View Complete Implementation : FileChangeDetector.java
Copyright Apache License 2.0
Author : lets-blade
Copyright Apache License 2.0
Author : lets-blade
public static Path getDestPath(Path src, Environment env) {
String templateDir = env.get(Const.ENV_KEY_TEMPLATE_PATH, "/templates");
Optional<String> staticDir = env.get(Const.ENV_KEY_STATIC_DIRS);
List<String> templateOrStaticDirKeyword = new ArrayList<>();
templateOrStaticDirKeyword.add(templateDir);
if (staticDir.isPresent()) {
templateOrStaticDirKeyword.addAll(Arrays.asList(staticDir.get().split(",")));
} else {
templateOrStaticDirKeyword.addAll(Const.DEFAULT_STATICS);
}
List result = templateOrStaticDirKeyword.stream().filter(dir -> src.toString().indexOf(dir) != -1).collect(Collectors.toList());
if (result.size() != 1) {
log.info("Cannot get dest dir");
return null;
}
String key = (String) result.get(0);
log.info(Const.CLreplacedPATH + src.toString().substring(src.toString().indexOf(key)));
return Paths.get(Const.CLreplacedPATH + src.toString().substring(src.toString().indexOf(key)));
}
19
View Complete Implementation : NettyServer.java
Copyright Apache License 2.0
Author : lets-blade
Copyright Apache License 2.0
Author : lets-blade
private void initConfig() {
if (null != blade.bootClreplaced()) {
blade.scanPackages(blade.bootClreplaced().getPackage().getName());
}
// print banner text
this.printBanner();
String statics = environment.get(ENV_KEY_STATIC_DIRS, "");
if (StringKit.isNotBlank(statics)) {
blade.addStatics(statics.split(","));
}
String templatePath = environment.get(ENV_KEY_TEMPLATE_PATH, "templates");
if (templatePath.charAt(0) == HttpConst.CHAR_SLASH) {
templatePath = templatePath.substring(1);
}
if (templatePath.endsWith(HttpConst.SLASH)) {
templatePath = templatePath.substring(0, templatePath.length() - 1);
}
DefaultEngine.TEMPLATE_PATH = templatePath;
}
19
View Complete Implementation : NettyServer.java
Copyright Apache License 2.0
Author : lets-blade
Copyright Apache License 2.0
Author : lets-blade
@Override
public void start(Blade blade) throws Exception {
this.blade = blade;
this.environment = blade.environment();
this.processors = blade.processors();
this.loaders = blade.loaders();
long startMs = System.currentTimeMillis();
int padSize = 16;
log.info("{} {}{}", StringKit.padRight("app.env", padSize), getPrefixSymbol(), environment.get(ENV_KEY_APP_ENV, "default"));
log.info("{} {}{}", StringKit.padRight("app.pid", padSize), getPrefixSymbol(), BladeKit.getPID());
log.info("{} {}{}", StringKit.padRight("app.devMode", padSize), getPrefixSymbol(), blade.devMode());
log.info("{} {}{}", StringKit.padRight("jdk.version", padSize), getPrefixSymbol(), System.getProperty("java.version"));
log.info("{} {}{}", StringKit.padRight("user.dir", padSize), getPrefixSymbol(), System.getProperty("user.dir"));
log.info("{} {}{}", StringKit.padRight("java.io.tmpdir", padSize), getPrefixSymbol(), System.getProperty("java.io.tmpdir"));
log.info("{} {}{}", StringKit.padRight("user.timezone", padSize), getPrefixSymbol(), System.getProperty("user.timezone"));
log.info("{} {}{}", StringKit.padRight("file.encoding", padSize), getPrefixSymbol(), System.getProperty("file.encoding"));
log.info("{} {}{}", StringKit.padRight("app.clreplacedpath", padSize), getPrefixSymbol(), CLreplacedPATH);
this.initConfig();
String contextPath = environment.get(ENV_KEY_CONTEXT_PATH, "/");
WebContext.init(blade, contextPath);
this.initIoc();
this.watchEnv();
this.startServer(startMs);
this.sessionCleaner();
this.startTask();
this.shutdownHook();
}
18
View Complete Implementation : NettyServer.java
Copyright Apache License 2.0
Author : lets-blade
Copyright Apache License 2.0
Author : lets-blade
private void startServer(long startMs) throws Exception {
ResourceLeakDetector.setLevel(ResourceLeakDetector.Level.DISABLED);
boolean SSL = environment.getBoolean(ENV_KEY_SSL, false);
// Configure SSL.
SslContext sslCtx = null;
if (SSL) {
String certFilePath = environment.get(ENV_KEY_SSL_CERT, null);
String privateKeyPath = environment.get(ENE_KEY_SSL_PRIVATE_KEY, null);
String privateKeyPreplacedword = environment.get(ENE_KEY_SSL_PRIVATE_KEY_Preplaced, null);
log.info("{}SSL CertChainFile Path: {}", getStartedSymbol(), certFilePath);
log.info("{}SSL PrivateKeyFile Path: {}", getStartedSymbol(), privateKeyPath);
sslCtx = SslContextBuilder.forServer(new File(certFilePath), new File(privateKeyPath), privateKeyPreplacedword).build();
}
var bootstrap = new ServerBootstrap();
int acceptThreadCount = environment.getInt(ENC_KEY_NETTY_ACCEPT_THREAD_COUNT, DEFAULT_ACCEPT_THREAD_COUNT);
int ioThreadCount = environment.getInt(ENV_KEY_NETTY_IO_THREAD_COUNT, DEFAULT_IO_THREAD_COUNT);
// enable epoll
if (BladeKit.epollIsAvailable()) {
log.info("{}Use EpollEventLoopGroup", getStartedSymbol());
bootstrap.option(EpollChannelOption.SO_REUSEPORT, true);
NettyServerGroup nettyServerGroup = EpollKit.group(acceptThreadCount, ioThreadCount);
this.bossGroup = nettyServerGroup.getBoosGroup();
this.workerGroup = nettyServerGroup.getWorkerGroup();
bootstrap.group(bossGroup, workerGroup).channel(nettyServerGroup.getSocketChannel());
} else {
log.info("{}Use NioEventLoopGroup", getStartedSymbol());
this.bossGroup = new NioEventLoopGroup(acceptThreadCount, new NamedThreadFactory("boss@"));
this.workerGroup = new NioEventLoopGroup(ioThreadCount, new NamedThreadFactory("worker@"));
bootstrap.group(bossGroup, workerGroup).channel(NioServerSocketChannel.clreplaced);
}
scheduleEventLoop = new DefaultEventLoop();
bootstrap.childHandler(new HttpServerInitializer(sslCtx, blade, scheduleEventLoop));
String address = environment.get(ENV_KEY_SERVER_ADDRESS, DEFAULT_SERVER_ADDRESS);
Integer port = environment.getInt(ENV_KEY_SERVER_PORT, DEFAULT_SERVER_PORT);
channel = bootstrap.bind(address, port).sync().channel();
String appName = environment.get(ENV_KEY_APP_NAME, "Blade");
String url = Ansi.BgRed.and(Ansi.Black).format(" %s:%d ", address, port);
String protocol = SSL ? "https" : "http";
log.info("{}{} initialize successfully, Time elapsed: {} ms", getStartedSymbol(), appName, (System.currentTimeMillis() - startMs));
log.info("{}Blade start with {}", getStartedSymbol(), url);
log.info("{}Open browser access {}://{}:{} ⚡\r\n", getStartedSymbol(), protocol, address.replace(DEFAULT_SERVER_ADDRESS, LOCAL_IP_ADDRESS), port);
blade.eventManager().fireEvent(EventType.SERVER_STARTED, new Event().attribute("blade", blade));
}
18
View Complete Implementation : WebContext.java
Copyright MIT License
Author : tfssweb
Copyright MIT License
Author : tfssweb
@Override
public void processor(Blade blade) {
JetbrickTemplateEngine templateEngine = new JetbrickTemplateEngine();
List<String> macros = new ArrayList<>(8);
macros.add(File.separatorChar + "comm" + File.separatorChar + "macros.html");
// 扫描主题下面的所有自定义宏
String themeDir = AttachController.CLreplacedPATH + "templates" + File.separatorChar + "themes";
File[] dir = new File(themeDir).listFiles();
for (File f : dir) {
if (f.isDirectory() && Files.exists(Paths.get(f.getPath() + File.separatorChar + "macros.html"))) {
String macroName = File.separatorChar + "themes" + File.separatorChar + f.getName() + File.separatorChar + "macros.html";
macros.add(macroName);
}
}
StringBuffer sbuf = new StringBuffer();
macros.forEach(s -> sbuf.append(',').append(s));
templateEngine.addConfig("jetx.import.macros", sbuf.substring(1));
GlobalResolver resolver = templateEngine.getGlobalResolver();
resolver.registerFunctions(Commons.clreplaced);
resolver.registerFunctions(Theme.clreplaced);
resolver.registerFunctions(AdminCommons.clreplaced);
resolver.registerTags(JetTag.clreplaced);
JetGlobalContext context = templateEngine.getGlobalContext();
context.set("version", environment.get("app.version", "v1.0"));
context.set("enableCdn", environment.getBoolean("app.enableCdn", false));
blade.templateEngine(templateEngine);
TaleConst.ENABLED_CDN = environment.getBoolean("app.enableCdn", false);
TaleConst.MAX_FILE_SIZE = environment.getInt("app.max-file-size", 20480);
TaleConst.AES_SALT = environment.get("app.salt", "012c456789abcdef");
TaleConst.OPTIONS.addAll(optionsService.getOptions());
String ips = TaleConst.OPTIONS.get(Types.BLOCK_IPS, "");
if (StringKit.isNotBlank(ips)) {
TaleConst.BLOCK_IPS.addAll(Arrays.asList(ips.split(",")));
}
if (Files.exists(Paths.get(AttachController.CLreplacedPATH + "install.lock"))) {
TaleConst.INSTALLED = Boolean.TRUE;
}
BaseController.THEME = "themes/" + Commons.site_option("site_theme");
TaleConst.BCONF = environment;
}