@RequestMapping("/container.do") public String container( @RequestParam(value = "key", defaultValue = "") String key, @RequestParam(value = "theme", defaultValue = THEME_DEFAULT) String theme, @RequestParam("pageId") int pageId, @RequestParam(value = "p", defaultValue = "") String param, Model model, HttpServletRequest req, HttpServletResponse resp) { LOG.info("[container] pageId:" + pageId); model.addAttribute("theme", getTheme(theme)); if (null == key || "".equals(key)) { model.addAttribute("error", "密钥不能为空!"); } else { key = getKey(key); User user = userService.getUserByKey(key); if (null != user) { if ("".equals(user.getKey())) { model.addAttribute("error", "密钥已失效!"); } else { Page page = userService.getUserPageByPageId(user.getUserId(), pageId); List<Page> subPages = userService.getUserSubPagesByPageId(user.getUserId(), pageId); if (null == subPages) { subPages = Collections.emptyList(); } else { // 替换子页面的参数 Map<String, Object> configs = new HashMap<String, Object>(); Map<String, String> params = generateParams(param); configs.put("request", params); for (Page subPage : subPages) { subPage.setParams(""); subPage.setContentURL(TemplateParser.parse(configs, subPage.getContentURL())); } } model.addAttribute("subPages", JSON.toJSONString(subPages)); model.addAttribute("p", param); model.addAttribute("page", page); model.addAttribute("user", user); return "container"; } } else { model.addAttribute("error", "没有找到密钥对应的用户。密钥:" + key); } } model.addAttribute("referer", req.getRequestURI() + "?" + req.getQueryString()); return "login"; }
@RequestMapping("/page.do") public String page( @RequestParam(value = "key", defaultValue = "") String key, @RequestParam(value = "theme", defaultValue = THEME_DEFAULT) String theme, @RequestParam(value = "id") String id, @RequestParam(value = "p", required = false) String param, Model model, HttpServletRequest req, HttpServletResponse resp) { LOG.info("[page] " + id); model.addAttribute("theme", getTheme(theme)); if (null == key || "".equals(key)) { model.addAttribute("error", "密钥不能为空!"); } else { key = getKey(key); User user = userService.getUserByKey(key); if (null != user) { model.addAttribute("user", user); // Map<String, String> params = new HashMap<String, String>(); Page page = userService.getUserPageByPageId(user.getUserId(), Integer.parseInt(id)); if (null != page) { // 判断是否包含子页面,如果包含子页面,则直接跳转到使用容器的页面 List<Page> subPages = userService.getUserSubPagesByPageId(user.getUserId(), page.getPageId()); if (null != subPages && !subPages.isEmpty()) { // 包含子页面 // 替换子页面的参数 Map<String, Object> configs = new HashMap<String, Object>(); Map<String, String> params = generateParams(param); configs.put("request", params); for (Page subPage : subPages) { subPage.setParams(""); subPage.setContentURL(TemplateParser.parse(configs, subPage.getContentURL())); } model.addAttribute("subPages", JSON.toJSONString(subPages)); model.addAttribute("p", param); model.addAttribute("page", page); model.addAttribute("user", user); return "container"; } Map<String, Object> configs = new HashMap<String, Object>(); configs.put("config", userService.getUserConfigs(user.getUserId())); Map<String, String> params = generateParams(param); configs.put("request", params); String url = page.getContentURL(); if (null != url && (url.startsWith("http://") || url.startsWith("https://"))) { // 外部链接 if (!params.isEmpty()) { StringBuilder msg = new StringBuilder(); boolean isFirst = true; for (Entry<String, String> entry : params.entrySet()) { if (isFirst) { isFirst = false; } else { msg.append("&"); } msg.append(entry.getKey()) .append("=") .append(TemplateParser.parse(configs, entry.getValue())); } if (!url.contains("?")) { url += "?" + msg.toString(); } else if (url.endsWith("&")) { url += msg.toString(); } else { url += "&" + msg.toString(); } } page.setContentURL(TemplateParser.parse(configs, url.replaceAll("'", "\\\\'"))); page.setParams(null); } else { // 内部链接 if (!StringUtils.isEmpty(param)) { page.setParams("p=" + TemplateParser.parse(configs, param)); } } } model.addAttribute("page", page); return "page"; } else { model.addAttribute("error", "没有找到密钥对应的用户。密钥:" + key); } } model.addAttribute("referer", req.getRequestURI() + "?" + req.getQueryString()); return "login"; }