com.ajaxjs.config.impl.ConfigController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ajaxjs-framework2 Show documentation
Show all versions of ajaxjs-framework2 Show documentation
AJAXJS 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.
The newest version!
/**
* 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.impl;
import com.ajaxjs.framework.BaseController;
import com.ajaxjs.util.io.FileHelper;
import com.ajaxjs.util.logger.LogHelper;
import com.ajaxjs.web.mvc.MvcRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.util.Map;
//import com.ajaxjs.website.stru.SiteStruService;
/**
* 编辑配置的控制器
*
* @author sp42 [email protected]
*
*/
@Controller
@RequestMapping("/admin/config/")
public class ConfigController extends BaseController {
private static final LogHelper LOGGER = LogHelper.getLog(ConfigController.class);
@GetMapping
public String config(ModelMap mv, MvcRequest r) {
LOGGER.info("参数配置");
loadJson(mv);
return "admin/config";
}
// TODO
private static void loadJson(ModelMap model) {
// model.put("configJson", FileHelper.openAsText(ConfigService.jsonPath));
// model.put("schemeJson", ConfigService.getSchemeJson());
}
@PostMapping(produces = JSON)
public String saveAllconfig(Map map, HttpServletRequest request) {
LOGGER.info("保存配置并且刷新配置");
// ConfigService.loadJSON_in_JS(map);
// ConfigService.load(ConfigService.jsonPath); // 刷新配置
//
// if (request.getServletContext().getAttribute("aj_allConfig") != null)
// request.getServletContext().setAttribute("aj_allConfig", ConfigService.CONFIG);
return BaseController.jsonOk("修改配置成功!");
}
@GetMapping("/admin/website/site")
public String siteUI() {
LOGGER.info("编辑网站信息");
return "website/config-site-form";
}
@ResponseBody
@PostMapping(value = "/admin/website/site", produces = JSON)
public String saveSite(Map map, HttpServletRequest request) {
LOGGER.info("保存网站信息");
return saveAllconfig(map, request);
}
// @GetMapping("/admin/website/siteStru")
// public String siteStruUI(ModelMap model) {
// LOGGER.info("编辑网站结构");
//
// if (SiteStruService.STRU != null && SiteStruService.STRU.isLoaded()) {
// model.put("siteStruJson", FileHelper.openAsText(SiteStruService.STRU.getJsonPath()));
//
// return "website/config-site-stru";
// } else
// return errMsg("该网站没有使用目录定义功能");
// }
// @POST
// @Path("/admin/website/siteStru")
// @Produces(MediaType.APPLICATION_JSON)
// public String saveSiteStru(@NotNull @FormParam("json") String json) {
// LOGGER.info("保存网站结构");
//
// FileHelper.saveText(SiteStruService.STRU.getJsonPath(), json);
// SiteStruService.loadSiteStru(MvcRequest.getHttpServletRequest().getServletContext());
//
// return jsonOk("修改网站结构成功!");
// }
@PostMapping(value = "/admin/website/siteStru/initJSP", produces = JSON)
public String siteStruUI_initJSP( String path, HttpServletRequest _req) {
LOGGER.info("初始化 JSP 页面");
MvcRequest req = (MvcRequest) _req;
String folder = req.mappath(path);
FileHelper.mkDir(folder);
String dest = folder + File.separator + "index.jsp";
FileHelper.copy(req.mappath(JSP_PERFIX_WEBINF + File.separator + "common-page.jsp"), dest, true);
return jsonOk("初始化 JSP 页面成功!");
}
}