視圖層使用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中的 查找內(nèi)容為: {lang (.+)},替換內(nèi)容為:<fmt:message key="faq" bundle="${\1}"/>
Jbuilder中的查找內(nèi)容為 \{lang (.+)\},Pattern為:Regular Expressions,
替換內(nèi)容為:(暫時未寫出來,打算寫程序進行替換操作)
用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}");
//替換網(wǎng)站名字
content = content.replaceAll("\\$bbname", "\\${settings.bbname}");
//替換導(dǎo)航標簽
content = content.replaceAll("\\$navigation", "\\${navigation}");
//替換一些變量
//content = content.replaceAll("\\$pid", "\\${pid}");
content = content.replaceAll("\\$([a-z_]+)(\"|<|\\))", "\\${$1}$2");
2.風(fēng)格機制
使用.jsp,使用jstl語法,允許用戶寫jstl
依然按目錄存放到templates目錄下,每個風(fēng)格為一個文件夾.
3.緩存機制
使用oscache 標簽 來緩存頁面的方式.
4.特殊標簽的解析 hidden標簽,reply標簽
采取在顯示的時候,進行 jsp:include page="/tag/hidden.jsp" 這樣的方式來實現(xiàn).
5.日歷選擇框: 使用jscalendar
6.頁面gzip壓縮,使用專門的gzip過濾器.
7.全文檢索,使用compass.
8.視圖層的模板.
discuz 已經(jīng)使用了 mvc的模式,只是使用自己開發(fā)的模板技術(shù),
D:\xampp\htdocs\bbs\templates每個文件夾為一個主題,每個主題內(nèi)對應(yīng)的是各種視圖的htm.
因此在用java實現(xiàn)的時候,使用spring mvc ,
視圖層使用jsp來展示.
其中頁面的布局分為三段
{template header} 是最上面的導(dǎo)航部分
{template footer} 是最下方的版權(quán)申明等部分.
中間部分為各具體模塊的視圖.
后臺則是使用的固定框架,然后來合成內(nèi)容的.
9.國際化支持
discuz使用的是 .lang.php定義數(shù)組的方式實現(xiàn)的,而且一次只支持一種語言
而java開發(fā)則使用I18N方式.多種語言均使用同一個系統(tǒng).
1.php的array功能非常強大,而java中只能用map和list結(jié)合起來處理.
2.在一個http請求中php的變量幾乎都是全局生效,而jstl中,則可以放到requestScope中.
1.discuz的有些表的主鍵不是自動增長的,因此不能夠生成@GeneratedValue(strategy = GenerationType.AUTO)的注釋.
這些表有: new String[] {
"validating", "trades", "relatedthreads", "pushedthreads", "polls",
"onlinetime", "memberspaces", "memberfields", "forumfields",
"admingroups", "adminactions", "activities"}
2.mysql的hibernate dao單元測試中,insert是無法回滾的,而delete卻可以不操作數(shù)據(jù)庫,
因此crud單元測試的時候,導(dǎo)致不停的插入數(shù)據(jù)卻沒有刪除數(shù)據(jù).
解決辦法,在 crud 測試方法的最后加上一行代碼: this.setComplete();
3.mysql的jdbc需要幾個特殊設(shè)置
a.字符編碼集必須指定.
b.對于"0000-00-00" 這樣的默認日期,在轉(zhuǎn)化成java.sql.Date的時候會出錯,因此需要加上個zeroDateTimeBehavior屬性.
datasource.url=jdbc:mysql://localhost:3306/discuz?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull
4.mysql的jdbc驅(qū)動存在bug : http://bugs.mysql.com/bug.php?id=22215
在usergroups 表中, readaccess字段是 tinyint(3)類型,而有值為200的,mysql的jdbc就會報錯,說數(shù)字越界了.
java.sql.SQLException: '200' in column '1' is outside valid range for the
datatype TINYINT.
暫時無解決辦法,采取修改200為20回避之.
(update:后來使用Short代替byte類型)
discuz 已經(jīng)使用了 mvc的模式,只是使用自己開發(fā)的模板技術(shù),
D:\xampp\htdocs\bbs\templates每個文件夾為一個主題,每個主題內(nèi)對應(yīng)的是各種視圖的htm.
因此在用java實現(xiàn)的時候,使用spring mvc ,
視圖層使用jspx來展示.
其中頁面的布局分為三段
{template header} 是最上面的導(dǎo)航部分
{template footer} 是最下方的版權(quán)申明等部分.
中間部分為各具體模塊的視圖.
后臺則是使用的固定框架,然后來合成內(nèi)容的.