- 浏览: 45086 次
- 性别:
- 来自: 无锡
最新评论
-
RainWu:
...
chx 学习jForum笔记十四 数据表四 jforum_groups及jforum_user_groups -
c_huabo:
这都被你发现了!!!
chx 学习jForum笔记十七 实现中文搜索 -
beermonkey:
感谢啊。。。。
chx 学习jForum笔记十七 实现中文搜索
==背景==
原论坛附件存放于d:\res\cibforum\500整\id\
====修改程序使之符合原规范====
修改\view\forum\common\AttachmentCommon.java中的makeStoreFilename(AttachmentInfo attInfo)
将
private String makeStoreFilename(AttachmentInfo attInfo) { Calendar cal = new GregorianCalendar(); cal.setTimeInMillis(System.currentTimeMillis()); cal.get(Calendar.YEAR); int year = Calendar.getInstance().get(Calendar.YEAR); int month = Calendar.getInstance().get(Calendar.MONTH) + 1; int day = Calendar.getInstance().get(Calendar.DAY_OF_MONTH); StringBuffer dir = new StringBuffer(256); dir.append(year).append('/').append(month).append('/').append(day).append('/');
改为
private String makeStoreFilename(AttachmentInfo attInfo,int postid) { StringBuffer dir = new StringBuffer(256); int id500 = postid-(postid%500)+500; dir.append(id500).append('/').append(postid).append('/');
从上面的情况可以看出,原先JFORUM将附件存放于年/月/日/目录下,现修改为与POST的ID相关的目录下。
将
return dir.append(MD5.crypt(attInfo.getRealFilename() + System.currentTimeMillis())) .append('_').append(SessionFacade.getUserSession().getUserId()).append('.') .append(attInfo.getExtension().getExtension()).append('_').toString();
改为
return dir.append(attInfo.getRealFilename()).append('_') .append(SessionFacade.getUserSession().getUserId()).append('.') .append(attInfo.getExtension().getExtension()) .append('_').toString();
从上面的情况可以看出,原先JFORUM将附件名为对文件名及当前时间进行MD5加密后生成的字符串加用户ID,现修改为真实文件名加用户ID。
向public void insertAttachments(final Post post)中增加
AttachmentInfo info = attachment.getInfo(); String savePath = this.makeStoreFilename(info,attachment.getPostId()); if (!info.getPhysicalFilename().equals(savePath)){ info.setPhysicalFilename(savePath); }
为了改变info的实际保存地址,在预处理时,postid=0,需在此进行调整
将public void preProcess()中的
String savePath = this.makeStoreFilename(info);
改为
String savePath = this.makeStoreFilename(info,userId);
对SystemGlobals.properties进行设置
attachments.store.dir = d:/res/cibforum
====添加附件时按钮无效的问题解决====
进入发帖的界面时,IE会报“网页有错误”
在发布帖子的时候,发现点击“附件”按钮没有效果。
这个问题也查了两天的时间,后来同事高手感觉是jquery没运行。看源码才发现jquery指向了外网,所以内网上会有问题。
看程序的源文件,其中带有jquery,指向程序源文件中的位置问题即可解决。
查找原文件中的所有"jquery"字样的语句。
将其中的
src="http://code.jquery.com/jquery-1.4.2.min.js"
改为
src="${contextPath}/javascript/jquery-1.4.2.min.js"
====建立原论坛的附件库====
由于原论坛的帖子已经全部导入了新库,但jforum对附件有相应的表需要新增记录。以下就在管理界面中增加一个同步按钮,用于对原论坛的贴子进行分析,有附件的就查一下物理磁盘上是否有相应文件,如果有的话,就向jforum的附件表中新增相应的记录。
1、修改attachments_config.htm文件,在
<input type="submit" value="${I18n.getMessage("Update")}" class="mainoption" />
前添加语句
<input class="mainoption" type="button" value="trans files" name="button" onclick="document.location = '${JForumContext.encodeURL("/${moduleName}/transfiles")}';" />
用于在管理界面中的“附件”中增加一个按钮。
2、在urlPattern.properties文件中,添加
adminAttachments.transfiles.0 =
这次吸取前次教训,向urlPattern.properties文件中注册一个action。
3、在generic_queries.sql中增加
PostModel.getMaxId = SELECT MAX(post_id) FROM jforum_posts;
取得所有POST的最大ID号,用于循环条件。
4、在AttachmentsAction.java中增加
public void transfiles(){ Post post ; StringBuffer resulttext; int codeIndex; int codeEndIndex; int nextStartPos; int maxId=0; String nonCodeResult; String codeResult; PostDAO pm = DataAccessDriver.getInstance().newPostDAO(); PreparedStatement p = null; ResultSet rs = null; try { p = JForumExecutionContext.getConnection() .prepareStatement(SystemGlobals.getSql("PostModel.getMaxId")); rs = p.executeQuery(); if (rs.next()){ //取最大ID号 maxId = rs.getInt(1); } } catch (SQLException e) { throw new DatabaseException(e); } finally { DbUtils.close(rs, p); } for (int postId=0; postId < maxId ; postId++){ //取POST post = pm.selectById(postId); if (post.getId()>0){ //分析POST中的内容 codeIndex = post.getText().indexOf("[link="); codeEndIndex = codeIndex > -1 ? post.getText().indexOf("[/link]") : -1; if (codeIndex > -1 && codeEndIndex > -1 && codeEndIndex > codeIndex) { nextStartPos = 0; //起始位置 resulttext = new StringBuffer(post.getText().length()); //替换成新内容 while (codeIndex > -1 && codeEndIndex > -1 && codeEndIndex > codeIndex) { codeEndIndex += "[/link]".length(); //结束位置 nonCodeResult = post.getText().substring(nextStartPos, codeIndex); //非附件内容 //附件处理 codeResult = ChxNew_parseCode(post.getText().substring(codeIndex, codeEndIndex),post); System.out.println(codeResult); //附件内容替换 resulttext.append(nonCodeResult).append(codeResult); nextStartPos = codeEndIndex; codeIndex = post.getText().indexOf("[link=", codeEndIndex); codeEndIndex = codeIndex > -1 ? post.getText().indexOf("[/link]", codeIndex) : -1; } if (nextStartPos > -1) { //尾部处理 nonCodeResult = post.getText().substring(nextStartPos); resulttext.append(nonCodeResult); } post.setText(resulttext.toString()); post.hasAttachments(true); pm.update(post);//保存post中的文本 } } } this.list();//返回原界面 }
以上内容为取每条POST,并分析其中的内容。将类似于[link=xxxx.xxx]xxxx[/link]的字符串交给下面的子函数处理。并用返回内容替换原有内容。
/* 分析link中的内容, 向附件表添加相应的记录 */ private static String ChxNew_parseCode(final String text,final Post post) { //text 应为类似于 [link=xxx.xls]xxxx[/link]的字符串 int index = text.indexOf("[link="); int index2 = text.indexOf("]"); int lastIndex = text.indexOf("[/link]", index2); if (index > -1 && index2 > index && lastIndex > index2) { String filename = text.substring(index+"[link=".length(),index2); String description = text.substring(index2+1,lastIndex); if (AttachmentCommon.insertAttachment(filename,description,post)) return "〔附件:"+description+"〕"; } return text; }
以上内容就是分析字符串,获取文件名及文件描述,交给下面的子函数进行处理,如果处理成功就返回一个替换原内容的字符串,如果失败则返回原字符串(即不替换原有内容)。
4.在AttachmentCommon.java中增加
static public boolean insertAttachment(final String filename,final String description,final Post post){ final int postid = post.getId(); final int id500 = postid-(postid%500)+500; final String PhysicalFilename=SystemGlobals.getValue(ConfigKeys.ATTACHMENTS_STORE_DIR) + "/" + id500 + "/"+postid+"/"+filename; final File file = new File(PhysicalFilename); if (file.exists()){//判断文件是否存在于磁盘上。 try{ final int userId = post.getUserId(); Attachment attachment = new Attachment(); attachment.setUserId(userId); attachment.setPostId(postid); AttachmentInfo info = new AttachmentInfo(); info.setFilesize(file.length()); info.setComment(description); info.setMimetype(new MimetypesFileTypeMap().getContentType(file)); info.setRealFilename(filename); info.setUploadTimeInMillis(post.getTime().getTime()); String extension = filename.substring(filename.lastIndexOf('.') + 1); AttachmentDAO attachmentDao=DataAccessDriver.getInstance().newAttachmentDAO(); AttachmentExtension ext = attachmentDao.selectExtension(extension.toLowerCase()); if (ext.isUnknown()) { ext.setExtension(extension); } info.setExtension(ext); info.setPhysicalFilename(PhysicalFilename); attachment.setInfo(info); attachmentDao.addAttachment(attachment);//调用程序原生的添加附件功能。 return true; } catch (Exception e){ System.out.println("error!"+e); return false; } } else { return false; } }
以上是根据参数判断文件是否存在,如果存在则生成相应记录加入附件表及附件信息表。
发表评论
-
chx 学习jForum笔记十九 jForum定时作业
2011-02-25 15:43 970参照jforum原有的两个定时作业SummarySchedul ... -
chx 学习jForum笔记十八 jForum与ms sqlserver
2011-02-23 16:39 7320jForum的原生数据库是mysql,但对sqlserver也 ... -
chx 学习jForum笔记十七 实现中文搜索
2011-02-23 16:04 1378最初测试的时候中文搜索一直都不成功。所以以为要对源程序进行大幅 ... -
chx 学习jForum笔记十五 实现用户及用户组同步
2011-02-23 15:25 1686==背景== 原先有一个随时维护的用户表rswk、权限表ci ... -
chx 学习jForum笔记十四 数据表四 jforum_groups及jforum_user_groups
2011-02-14 14:07 1434jforum_groups group_id ... -
chx 学习jForum笔记十三 数据表三 jforum_roles及jforum_role_values
2011-02-12 16:19 1256jforum_roles 权限表。是一张组与基本权限的对应表。 ... -
chx 学习jForum笔记十二 数据表二 jforum_categories及jforum_forums
2011-02-12 15:05 1312jforum_categories是子论坛的分类以下称为栏目。 ... -
chx 学习jForum笔记十一 实现单点登录SSO
2011-02-09 11:55 1939分为三部分: 1.导入原用户数据库. 2.修改SSO模块, ... -
chx 学习jForum笔记十 数据表一 jforum_users
2011-02-09 10:35 1240user_id bigint ... -
chx 学习jForum笔记九-ForumAction四,发现用户注册模块
2010-12-09 14:27 19422010.12.9接上午。继续看net.jforum.view ... -
chx 学习jForum笔记八-ForumAction三,发现用户认证模块。
2010-12-09 11:15 16792010.12.9。接昨天 在net.jforum.view ... -
chx 学习jForum笔记七-ForumAction二
2010-12-08 17:24 11402010.12.8 接昨天。 下面这句是存在于net.jfo ... -
chx 学习jForum笔记六-MostUsersEverOnline的结束及ForumAction-list的开始
2010-12-07 15:54 22412010.12.7 继续查找关键字MostUsersEverO ... -
chx 学习jForum笔记五-参数表的操作
2010-12-07 15:05 9722010.12.7 继续查找关键字MostUsersEverO ... -
chx 学习jForum笔记四
2010-12-06 15:21 9602010.12.6 接上午。在net.jforum.repos ... -
chx 学习jForum笔记三
2010-12-06 14:05 10002010.12.6 接上周日,继续。PermissionCon ... -
chx 学习jForum笔记二
2010-12-05 10:26 1198我的源程序是安道森练 ... -
chx 学习jForum笔记一
2010-12-05 09:37 1640目标:jForum二次开发,读懂源程序。 修改权限管理模块, ...
相关推荐
NULL 博文链接:https://caihexi.iteye.com/blog/919868
chx99个人主页源码_chx99
CHX轻巧的终端十六进制编辑器。可以在config.h中更改命令和键绑定
中文资料 英文资料 好重要的 很好很强大的哦
这是生物方面的资源,不感兴趣的人不建议下载
CHX-I防火墙官方教程-附带翻译终稿.pdf
HA-SoftEther-CHX虚拟专网HA-SoftEther-CHX虚拟专网HA-SoftEther-CHX虚拟专网HA-SoftEther-CHX虚拟专网
本软件是一个模似网卡和集线器的工具,可以模似集线器功能,实现VPN的功能。使得系统把此软件识别成一块网卡,有了这个东西,只要可以访问外网,都可以连接到虚拟HUB上与其他电脑组成局域网,在此虚拟的局域...
[CMS程序]chx99个人主页源码_chx99(ASP.NET源码).rar
CHX-3大手臂大法兰.SLDDRW
[CMS程序]chx99个人主页源码_chx99.zip源码ASP.NET网站源码打包下载[CMS程序]chx99个人主页源码_chx99.zip源码ASP.NET网站源码打包下载[CMS程序]chx99个人主页源码_chx99.zip源码ASP.NET网站源码打包下载[CMS程序]...
免责声明:资料部分来源于合法的互联网渠道收集和整理,部分自己学习积累成果,供大家学习参考与交流。收取的费用仅用于收集和整理资料耗费时间的酬劳。 本人尊重原创作者或出版方,资料版权归原作者或出版方所有,...
chx03_org05_MIPS_4b
本站采用.net2.0 Acess制件,采用了URL重写技术,但没有使用Ajax技术,准备以后修改添加上Ajax效果 本站所用的模板是从网上找的(只有效果图),DIV CSS布局是自己写的 只考虑了IE6和IE7的兼容问题,没考虑FF及其他浏览器 ...
CHX-I防火墙官方教程-附带翻译借鉴.pdf
1. Data dependences (also called true data dependences) 2. name dependences 3. c
HX612和STC15W408AS的测试程序。 触摸后从串口发送按键号。只打开短按键模式。 HX612接在P33、P34上。这个IC并不是I2C接口。
ASP.NET-[CMS程序]chx99个人主页源码.zip
北大计算机系高级计算机系统结构课件chx14-arch07-MT1
ASP.NET源码——[CMS程序]chx99个人主页源码.zip