铭飞MCMS将4.6模板标签升级至4.7


个人博客 地址:https://www.wenhaofan.com/article/20190610145529

介绍

MCMS提供的模板大多数都使用的是4.6版本的标签,但是现在MCMS最新的已经是4.7了,然而4.7并不能向下兼容4.6,所以在4.7的MCMS中使用4.6的模板需要处理其中的旧版本标签,为了方便以及复用,想到了使用正则表达式解析、替换标签将4.6模板一键升级至4.7,代码如下

代码

package live.autu.tools.mcms;
import java.io.File;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.core.io.file.FileReader;
import cn.hutool.core.io.file.FileWriter;
import cn.hutool.core.util.ReUtil;
public class UpgradeTag {
private static Map<String,String> tagMatch=new LinkedHashMap<String, String>(){{

put("\\{ms:globalskin.url/\\}", "{ms:global.host/}/{ms:global.style/}");
put("$\\{global.host!''\\}", "{ms:global.host/}");
put("$\\{global.style!''\\}", "{ms:global.style/}");
put("\\[field.date fmt=yyyy\\-MM\\-dd/\\]","{ms:field.date?string(\"yyyy-MM-dd\")}");
put("\\{ms\\:field\\.date fmt\\=yyyy\\-MM\\-dd/\\}", "{ms:field.date?string(\"yyyy-MM-dd\")}");
put("\\[field.date fmt\\=yyyy\\-MM\\-dd hh:mm:ss/\\]}", "{ms:field.date?string(\"yyyy-MM-dd hh:mm:ss\")}");
put("\\{ms\\:field\\.date fmt\\=yyyy\\-MM\\-dd hh:mm:ss/\\}","{ms:field.date?string(\"yyyy-MM-dd\")/}");
put("\\{ms\\:field.date\\?string\\(\"yyyy\\-MM\\-dd\"\\)\\}", "{ms:field.date?string(\"yyyy-MM-dd\")/}");
put("\\[field.link/\\]", "{ms:global.url/}[field.link/]");
put("\\[field.typelink/\\]", "{ms:global.url/}[field.typelink/]");
put("\\{ms\\:global.url/\\}\\{ms\\:global.url/\\}", "{ms:global.url/}");

}};

public static void main(String[] args) {

String projectPath="D:\\work\\eclipse\\order\\mcms\\src\\main\\webapp\\templets\\1\\";

//需要处理的路径
List<String> templets=new ArrayList<String>() {{
add("company1811");
add("company1811\\m");
}};

for (String templet : templets) {
renderTheme(projectPath.concat(templet));
}
}
 
private static void renderTheme(String filePath) {
File file=new File(filePath);
File[] files=file.listFiles();

for (File file2 : files) {
if(!file2.isFile()) {
continue;
}
String absolutePath=file2.getAbsolutePath();
Upgrade(absolutePath);
}
}
private static void Upgrade(String filePath) {
FileReader fileReader = new FileReader(filePath);
String content = fileReader.readString();
 
content = UpgradeInclude(content); 
for (String key : tagMatch.keySet()) {
content=content.replaceAll(key,tagMatch.get(key));
}
 

FileWriter writer = new FileWriter(filePath);
writer.write(content);

System.out.println(filePath+":success");
}
private static String UpgradeInclude(String content) {
String includeTagRegex="\\{ms:include[\\s]*filename=+[\\S]*.htm/\\}";
String includeFileNameRegex="=[\\S]*/";
Map<String,String> result=new HashMap<>();

List<String> resultFindAll = ReUtil.findAll(includeTagRegex, content, 0, new ArrayList<String>());

resultFindAll.forEach( tag ->{
 
   String fileName=ReUtil.get(includeFileNameRegex, tag,0);
   fileName=fileName.replaceFirst("=", "").replace("/", "");
   
   result.put(tag, "<#include \""+fileName+"\">");
 
});

for (String key : result.keySet()) {
String finalKey =key.replaceAll("\\{","\\\\{");
finalKey=finalKey.replaceAll("\\}","\\\\}");
content=content.replaceAll(finalKey, result.get(key));
}
return content;
}
}

下载

http://qiniu.wenhaofan.com/UpgradeTag.java

转载于:https://www.cnblogs.com/fanwenhao/p/10997658.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MCMS铭飞cms建站系统完整开源!基于SpringBoot 2架构,前端基于vue、element ui。每月28定期更新版本,为开发者提供上百套免费模板,同时提供适用的插件(文章、商城、微信、论坛、会员、评论、支付、积分、工作流、任务调度等...),一套简单好用的开源系统、一整套优质的开源生态内容体系。铭飞的使命就是降低开发成本提高开发效率,提供全方位的企业级开发解决方案。 特点: 免费完整开源:基于MIT协议,源代码完全开源,无商业限制,MS开发团队承诺将MCMS内容系统永久完整开源; 标签化建站:不需要专业的后台开发技能,只要使用系统提供的标签,就能轻松建设网站; html静态化:系统支持全站静态化; 跨终端:站点同时支持PC与移动端访问,同时会自动根据访问的终端切换到对应的界面,数据由系统统一管理; 海量模版:铭飞通过MStore(MS商城)分享更多免费、精美的企业网站模版,降低建站成本; 丰富插件:为了让MCms适应更多的业务场景,在MStore用户可以下载对应的插件,如:站群插件、微信插件、商城插件等; 每月更新:铭飞团队承诺每月28日为系统升级日,分享更多好用等模版与插件; 文档丰富:为了让用户更快速的使用MCms系统进行开发,铭飞团队持续更新开发相关文档,如标签文档、使用文档、视频教程等; 开发环境: 建议开发者使用以下环境,这样避免版本带来的问题 Windows、Linux Eclipse、Idea Mysql≧5.7 JDK≧8 Tomcat≧8   MCMS铭飞cms建站系统 更新日志: v5.2.1 【框架】sprintboot版本更新到2.2.13.RELEASE 【新增】全局异常处理 【优化】搜索功能优化 【优化】标签脚本优化 【修复】修复MStore功能 【修复】具体参考开源中国ISSUES 5.2.0升级5.2.1步骤( 1、同步代码; 2、导入5.2.0-up-5.2.1.sql)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值