lizongbo 的 編程學習

          http://618119.com

          BlogJava 首頁 新隨筆 聯系 聚合 管理
            23 Posts :: 1 Stories :: 78 Comments :: 0 Trackbacks

          由于原有模板是以.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");

          posted on 2007-08-29 09:42 lizongbo 的編程學習 閱讀(768) 評論(1)  編輯  收藏 所屬分類: java discuz
          主站蜘蛛池模板: 兰西县| 博客| 枝江市| 延津县| 厦门市| 固镇县| 泸定县| 林口县| 荆门市| 铜川市| 呼图壁县| 玉龙| 梁河县| 蒙山县| 龙里县| 仁化县| 盐源县| 类乌齐县| 孝感市| 铜陵市| 新源县| 湖南省| 静安区| 武宣县| 高碑店市| 都江堰市| 齐齐哈尔市| 石嘴山市| 河池市| 彭阳县| 宜宾县| 云和县| 龙南县| 资阳市| 谢通门县| 灵寿县| 肇源县| 台州市| 青岛市| 麻城市| 章丘市|