com.ajaxjs.config.SiteStruService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-web Show documentation
Show all versions of ajaxjs-web Show documentation
AJAXJS Web aims to full-stack, not only the server-side framework, but also integrates the front-end library. It's written in HTML5 + Java, a successor to the JVM platform, efficient, secure, stable, cross-platform and many other advantages, but it abandoned the traditional enterprise architecture brought about by the large and bloated, emphasizing the lightweight, and fast, very suitable for the Internet fast application.
/**
* Copyright Sp42 [email protected]
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.ajaxjs.config;
import java.io.File;
import java.util.List;
import java.util.Map;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.http.HttpServletRequest;
import com.ajaxjs.Version;
import com.ajaxjs.js.JsonHelper;
import com.ajaxjs.js.JsonStruTraveler;
import com.ajaxjs.mvc.Constant;
import com.ajaxjs.util.io.FileUtil;
import com.ajaxjs.util.logger.LogHelper;
/**
* 网站结构的配置
*
* @author Sp42 [email protected]
*/
@javax.servlet.annotation.WebListener
public class SiteStruService implements ServletContextListener {
private static final LogHelper LOGGER = LogHelper.getLog(SiteStruService.class);
public static SiteStru stru;
/**
* 配置 json 文件的路径
*/
public static String jsonPath = Version.srcFolder + "site_stru.json";
/**
* 加载网站结构的配置
*/
public static void load() {
stru = new SiteStru();
stru.setJsonPath(jsonPath);
stru.setJsonStr(FileUtil.openAsText(jsonPath));
stru.addAll(JsonHelper.parseList(stru.getJsonStr()));
stru.setLoaded(true);
}
@Override
public void contextInitialized(ServletContextEvent e) {
ServletContext cxt = e.getServletContext();
Version.tomcatVersionDetect(cxt.getServerInfo());
if (new File(ConfigService.jsonPath).exists()) {
ConfigService.load();
if (ConfigService.config.isLoaded()) {
cxt.setAttribute("aj_allConfig", ConfigService.config); // 所有配置保存在这里
// String configJson = JsonHelper.format(JsonHelper.stringifyMap(ConfigService.config));
LOGGER.infoGreen("加载 " + ConfigService.getValueAsString("clientFullName") + " " + cxt.getContextPath()
+ " 项目配置成功!All config loaded.");
} else
LOGGER.warning("加载配置失败!");
} else
LOGGER.info("没有项目配置文件");
if (new File(jsonPath).exists()) {
load();
t.travelList(stru);
cxt.setAttribute("SITE_STRU", this); // 所有网站结构保存在这里
LOGGER.infoGreen("加载网站的结构文件成功 Site Structure Config Loaded.");
} else
LOGGER.info("没有网站的结构文件");
cxt.setAttribute("ctx", cxt.getContextPath());
cxt.setAttribute("ajaxjsui", cxt.getContextPath() + "/" + Constant.ajajx_ui);
cxt.setAttribute("commonAsset", cxt.getContextPath() + "/" + Constant.commonAsset); // 静态资源目录
cxt.setAttribute("commonJsp", cxt.getContextPath() + "/" + Constant.jsp_perfix);
}
/**
* 获取导航
*
* @return 导航数据
*/
public List