由于原有模板是以.htm方式存在的,
在轉換成jsp方式時,對其中很多通用的代碼,可以通過替換的方式直接轉換為jstl語法的.
步驟如下:
1.首先將所有的htm文件名替換成jsp,
在命令行下運行 rename *.htm *.jsp即可.
2.將bbs\forumdata\cache\style_1.php中的css變量TABLEWIDTH等,
替換成類似${crtStyles['TABLEWIDTH']}的jstl語法.
全部只能手工替換
3.將*.jsp中的{lang forum_favorite}等替換成類似 <fmt:message key="faq" bundle="${forum_favorite}"/>
使用正則表達式進行替換:
editplus中的 查找內容為: {lang (.+)},替換內容為:<fmt:message key="faq" bundle="${\1}"/>
Jbuilder中的查找內容為 \{lang (.+)\},Pattern為:Regular Expressions,
替換內容為:(暫時未寫出來,打算寫程序進行替換操作)
用java程序替換的核心代碼為:
//替換樣式變量
content = content.replaceAll("FORMHASH", "formhash");
//替換樣式變量 ${crtStyle['TABLEWIDTH']}
content = content.replaceAll("\\{([A-Z0-9]+)\\}", "\\${crtStyle\\['$1'\\]}");
//替換國際化定義
//content = content.replaceAll("\\{lang (.+?)\\}",
// "<fmt:message key=\"$1\" bundle=\"\\$\\{templates\\}\"/>");
//對標簽屬性里的值暫時不替換
content = content.replaceAll("([^\"])\\{lang (.+?)\\}",
"$1<fmt:message key=\"$2\" bundle=\"\\$\\{templates\\}\"/>");
//替換單層的屬性訪問
content = content.replaceAll("\\$([a-z]+?)\\[([a-z]+?)\\]",
"\\$\\{$1\\['$2'\\]\\}");
//替換標題部分的聲明
content = content.replaceAll("\\{template header\\}",
"<%@page pageEncoding=\"UTF-8\" " +
"contentType=\"text/html;" +
" charset=UTF-8\"%>\n"
+ "<%@include file=\"/WEB-INF/" +
"inc/taglibs.jspf\"%>\n" +
"<jsp:include flush=\"true\" " +
"page=\"header.jsp\"/>\n");
////替換底部部分的聲明
content = content.replaceAll("\\{template footer\\}",
"\n<jsp:include flush=\"true\" " +
"page=\"footer.jsp\"/>");
//替換其它引用聲明
content = content.replaceAll("\\{template (.+?)\\}",
"\n<jsp:include flush=\"true\" " +
"page=\"$1.jsp\"/>");
//替換url定義
content = content.replaceAll("\\$indexname", "\\${settings.indexname}");
//替換網站名字
content = content.replaceAll("\\$bbname", "\\${settings.bbname}");
//替換導航標簽
content = content.replaceAll("\\$navigation", "\\${navigation}");
//替換一些變量
//content = content.replaceAll("\\$pid", "\\${pid}");
content = content.replaceAll("\\$([a-z_]+)(\"|<|\\))", "\\${$1}$2");