Here are the examples of the java api com.blade.Environment taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
3 Examples
19
Source : WebContext.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* Tale初始化进程
*
* @author biezhi
*/
@Bean
public clreplaced WebContext implements BeanProcessor {
@Inject
private OptionsService optionsService;
@Inject
private Environment environment;
@Override
public void preHandle(Blade blade) {
Ioc ioc = blade.ioc();
boolean devMode = true;
if (blade.environment().hasKey("app.dev")) {
devMode = blade.environment().getBoolean("app.dev", true);
}
if (blade.environment().hasKey("app.devMode")) {
devMode = blade.environment().getBoolean("app.devMode", true);
}
SqliteJdbc.importSql(devMode);
Sql2o sql2o = new Sql2o(SqliteJdbc.DB_SRC, null, null);
Base.open(sql2o);
Commons.setSiteService(ioc.getBean(SiteService.clreplaced));
}
@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;
}
}
19
Source : TaleConst.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* Tale 常量存储
*
* @author biezhi
*/
public clreplaced TaleConst {
public static final String USER_IN_COOKIE = "S_L_ID";
public static String AES_SALT = "0123456789abcdef";
public static String LOGIN_SESSION_KEY = "login_user";
public static Environment OPTIONS = Environment.of(new HashMap<>());
public static Boolean INSTALLED = false;
public static Boolean ENABLED_CDN = true;
public static Environment BCONF = null;
/**
* 最大页码
*/
public static final int MAX_PAGE = 100;
/**
* 最大获取文章条数
*/
public static final int MAX_POSTS = 9999;
/**
* 文章最多可以输入的文字数
*/
public static final int MAX_TEXT_COUNT = 200000;
/**
* 文章标题最多可以输入的文字个数
*/
public static final int MAX_replacedLE_COUNT = 200;
/**
* 插件菜单
*/
public static final List<PluginMenu> PLUGIN_MENUS = new ArrayList<>();
/**
* 上传文件最大20M
*/
public static Integer MAX_FILE_SIZE = 204800;
/**
* 要过滤的ip列表
*/
public static final Set<String> BLOCK_IPS = new HashSet<>(16);
/**
* 静态资源URI
*/
public static final String STATIC_URI = "/static";
/**
* 安装页面URI
*/
public static final String INSTALL_URI = "/install";
/**
* 后台URI前缀
*/
public static final String ADMIN_URI = "/admin";
/**
* 后台登录地址
*/
public static final String LOGIN_URI = "/admin/login";
/**
* 插件菜单 Attribute Name
*/
public static final String PLUGINS_MENU_NAME = "plugin_menus";
}
14
Source : IndexController.java
with MIT License
from tfssweb
with MIT License
from tfssweb
/**
* 保存系统设置
*/
@Route(value = "setting", method = HttpMethod.POST)
@JSON
public RestResponse saveSetting(@Param String site_theme, Request request) {
try {
Map<String, List<String>> querys = request.parameters();
optionsService.saveOptions(querys);
Environment config = Environment.of(optionsService.getOptions());
TaleConst.OPTIONS = config;
new Logs(LogActions.SYS_SETTING, JsonKit.toString(querys), request.address(), this.getUid()).save();
return RestResponse.ok();
} catch (Exception e) {
String msg = "保存设置失败";
if (e instanceof TipException) {
msg = e.getMessage();
} else {
log.error(msg, e);
}
return RestResponse.fail(msg);
}
}