diff --git a/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java b/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java index 7986a27..673e2c1 100644 --- a/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -84,8 +84,8 @@ parentCategory = (CategoryEntity)categoryDao.getEntity(Integer.parseInt(categoryEntity.getCategoryId())); } //保存链接地址 - String path=ObjectUtil.isNotNull(parentCategory)?parentCategory.getCategoryPath():""; - categoryEntity.setCategoryPath( path+"/" + categoryEntity.getCategoryPinyin()); + String path=ObjectUtil.isNotNull(parentCategory)?parentCategory.getCategoryPath()+"/":""; + categoryEntity.setCategoryPath( path+ categoryEntity.getCategoryPinyin()); super.updateEntity(categoryEntity); } diff --git a/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java b/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java index 7986a27..673e2c1 100644 --- a/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java +++ b/ms-mcms/src/main/java/net/mingsoft/cms/biz/impl/CategoryBizImpl.java @@ -84,8 +84,8 @@ parentCategory = (CategoryEntity)categoryDao.getEntity(Integer.parseInt(categoryEntity.getCategoryId())); } //保存链接地址 - String path=ObjectUtil.isNotNull(parentCategory)?parentCategory.getCategoryPath():""; - categoryEntity.setCategoryPath( path+"/" + categoryEntity.getCategoryPinyin()); + String path=ObjectUtil.isNotNull(parentCategory)?parentCategory.getCategoryPath()+"/":""; + categoryEntity.setCategoryPath( path+ categoryEntity.getCategoryPinyin()); super.updateEntity(categoryEntity); } diff --git a/ms-mdiy/src/main/java/net/mingsoft/mdiy/util/ParserUtil.java b/ms-mdiy/src/main/java/net/mingsoft/mdiy/util/ParserUtil.java index 2b11da9..6fb3b84 100644 --- a/ms-mdiy/src/main/java/net/mingsoft/mdiy/util/ParserUtil.java +++ b/ms-mdiy/src/main/java/net/mingsoft/mdiy/util/ParserUtil.java @@ -1,16 +1,16 @@ /** * The MIT License (MIT) * Copyright (c) 2020 铭软科技(mingsoft.net) - + *

* Permission is hereby granted, free of charge, to any person obtaining a copy of * this software and associated documentation files (the "Software"), to deal in * the Software without restriction, including without limitation the rights to * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of * the Software, and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: - + *

* The above copyright notice and this permission notice shall be included in all * copies or substantial portions of the Software. - + *

* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR @@ -159,8 +159,7 @@ /** * 系统预设需要特殊条件的标签 */ - public static List systemTag=CollUtil.toList("field","pre","page","next"); - + public static List systemTag = CollUtil.toList("field", "pre", "page", "next"); /** @@ -189,10 +188,13 @@ * @return */ public static String buildHtmlPath(String path) { - return BasicUtil.getRealPath(HTML) + File.separator + BasicUtil.getAppId() + File.separator + path - + HTML_SUFFIX; - } + if (path.startsWith("/") || path.startsWith("\\")) { + return BasicUtil.getRealPath(HTML) + File.separator + BasicUtil.getAppId() + path + HTML_SUFFIX; + } else { + return BasicUtil.getRealPath(HTML) + File.separator + BasicUtil.getAppId() + File.separator + path + HTML_SUFFIX; + } + } /** @@ -219,6 +221,7 @@ String read = read(templatePath, params); return read; } + /** * 读取模板内容 * @@ -231,9 +234,10 @@ */ public static String read(String templatePath, Map map) throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException { - AttributeBean attributeBean = new AttributeBean(); - return read(templatePath,map,null,attributeBean); + AttributeBean attributeBean = new AttributeBean(); + return read(templatePath, map, null, attributeBean); } + /** * 读取模板内容 * @@ -271,9 +275,9 @@ /** * 渲染模板 * - * @param templatePath 模板路径 - * @param map 传入参数 - * @param pageBean 分页bean + * @param templatePath 模板路径 + * @param map 传入参数 + * @param pageBean 分页bean * @param attributeBean 属性bean * @return * @throws TemplateNotFoundException @@ -287,21 +291,21 @@ if (ftl == null || !buildTempletPath.equals(ftl.baseDir.getPath())) { stringLoader = new StringTemplateLoader(); ftl = new FileTemplateLoader(new File(buildTempletPath)); - MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader(new TemplateLoader[]{stringLoader,ftl}); + MultiTemplateLoader multiTemplateLoader = new MultiTemplateLoader(new TemplateLoader[]{stringLoader, ftl}); cfg.setNumberFormat("#"); cfg.setTemplateLoader(multiTemplateLoader); } // 读取模板文件 - String temp =FileUtil.readString(FileUtil.file(buildTempletPath,templatePath),"utf-8"); + String temp = FileUtil.readString(FileUtil.file(buildTempletPath, templatePath), "utf-8"); //替换标签 temp = regReplace(temp); //添加自定义模板 - stringLoader.putTemplate("ms:custom:"+templatePath,temp); + stringLoader.putTemplate("ms:custom:" + templatePath, temp); //获取自定义模板 - Template template = cfg.getTemplate("ms:custom:"+templatePath, Const.UTF8); + Template template = cfg.getTemplate("ms:custom:" + templatePath, Const.UTF8); //设置兼容模式 cfg.setClassicCompatible(true); - cfg.setSharedVariable(TAG_PREFIX+"includeEx", new IncludeExTag(buildTempletPath,stringLoader)); + cfg.setSharedVariable(TAG_PREFIX + "includeEx", new IncludeExTag(buildTempletPath, stringLoader)); ITagSqlBiz tagSqlBiz = SpringUtil.getBean(ITagSqlBiz.class); List list = tagSqlBiz.queryAll(); @@ -312,26 +316,26 @@ TagTypeEnum typeEnum = TagTypeEnum.get(x.getTagType()); //列表标签 if (typeEnum == TagTypeEnum.LIST) { - cfg.setSharedVariable(TAG_PREFIX+x.getTagName(), new CustomTag(map, x)); + cfg.setSharedVariable(TAG_PREFIX + x.getTagName(), new CustomTag(map, x)); } //分页标签 if (typeEnum == TagTypeEnum.PAGE) { - cfg.setSharedVariable(TAG_PREFIX+x.getTagName(), new PageListTag(map, x,pageBean,attributeBean)); + cfg.setSharedVariable(TAG_PREFIX + x.getTagName(), new PageListTag(map, x, pageBean, attributeBean)); }//其他内容标签 - else if(typeEnum==TagTypeEnum.SINGLE&&(!systemTag.contains(x.getTagName()) + else if (typeEnum == TagTypeEnum.SINGLE && (!systemTag.contains(x.getTagName()) //文字内容需要id参数 - ||(map.containsKey("id")&&x.getTagName().equals("field")) + || (map.containsKey("id") && x.getTagName().equals("field")) //分页需要pageTag参数 - ||(map.containsKey("pageTag")&&(x.getTagName().equals("pre")||x.getTagName().equals("next")||x.getTagName().equals("page"))) - )){ + || (map.containsKey("pageTag") && (x.getTagName().equals("pre") || x.getTagName().equals("next") || x.getTagName().equals("page"))) + )) { String sql = null; try { sql = rendering(map, x.getTagSql()); NamedParameterJdbcTemplate jdbc = SpringUtil.getBean(NamedParameterJdbcTemplate.class); - List list1 = jdbc.queryForList(sql, CollUtil.newHashMap()); - if(list1.size() > 0){ - map.put(x.getTagName(), list1.get(0)); - } + List list1 = jdbc.queryForList(sql, CollUtil.newHashMap()); + if (list1.size() > 0) { + map.put(x.getTagName(), list1.get(0)); + } } catch (IOException e) { } catch (TemplateException e) { @@ -376,21 +380,22 @@ /** * 旧标签正则替换处理 + * * @param content * @return */ - public static String regReplace(String content){ + public static String regReplace(String content) { // 创建 Pattern 对象 //替include标签 - content = content.replaceAll("<#include(.*)/>", StrUtil.format( "<@{}includeEx template=$1/>",TAG_PREFIX)); + content = content.replaceAll("<#include(.*)/>", StrUtil.format("<@{}includeEx template=$1/>", TAG_PREFIX)); //两种情况<#include "head.htm" >与<#include "head.htm" /> 不会写正则 简单处理 - content = content.replaceAll("<#include(.*)>", StrUtil.format( "<@{}includeEx template=$1/>",TAG_PREFIX)); + content = content.replaceAll("<#include(.*)>", StrUtil.format("<@{}includeEx template=$1/>", TAG_PREFIX)); //替换全局标签{ms:global.name/} content = content.replaceAll("\\{ms:([^\\}]+)/\\}", "\\${$1}"); //替换列表开头标签 - content = content.replaceAll("\\{ms:([^\\}]+)\\}", StrUtil.format( "<@{}$1>",TAG_PREFIX)); + content = content.replaceAll("\\{ms:([^\\}]+)\\}", StrUtil.format("<@{}$1>", TAG_PREFIX)); //替换列表结束标签 - content = content.replaceAll("\\{/ms:([^\\}]+)\\}", StrUtil.format( "",TAG_PREFIX)); + content = content.replaceAll("\\{/ms:([^\\}]+)\\}", StrUtil.format("", TAG_PREFIX)); //替换内容标签 [field.*/] content = content.replaceAll("\\[([^\\]]+)/\\]", "\\${$1}"); return content;