JForum使用心得及总结

当前位置:

JForum使用心得及总结

作者:邓华锋于2010-12-23发布在 分类:jforum / 阅读17675 次 / 共有0条评论  

这个星期研究了下JForum.因为项目需要个论坛.最后算是被我整合到项目中去了,效果也还可以.可惜最后公司说用discuz.为了对得起这个星期的研究成果.我需要记录下来.

JForum的安装:jforum/install.jsp

有意使用版本控制软件SVN,对安装后进行查看,发现安装后修改文件:

1.重新整理WEB-INF\config\modulesMapping.properties
2.添加WEB-INF\config\jforum-custom.confs
3.修改WEB-INF\config\database\oracle\oracle.properties
4.添加WEB-INF\jforumLuceneIndex\segments.gen和segments_1

JForum中添加一个模块(页面):

1.modulesMapping.properties:添加模块Action类

mydwbi=com.mydwbi.MydwbiAction

2.templatesMapping.properties:添加Action方法显示页面

mydwbi.contact = contact.htm
mydwbi.advertisement = advertisement.htm

3.urlPattern.properties:添加Action参数

mydwbi.contact.0 =
mydwbi.advertisement.0 =

4.net.jforum.util.preferences.TemplateKeys:添加Template中Key映射

public static final String MYDWBI_CONTACT = "mydwbi.contact";
public static final String MYDWBI_AD = "mydwbi.advertisement";

5.编写对应Action:com.mydwbi.MydwbiAction


public class MydwbiAction extends Command {  
    public void list() {  
    }  
    public void contact() {  
        this.setTemplateName(TemplateKeys.MYDWBI_CONTACT);  
    }  
    public void advertisement() {  
        this.setTemplateName(TemplateKeys.MYDWBI_AD);  
    }  
}


6.jforum\templates\default\header.htm:添加模块标题链接


7.zh_CN.properties:定义${I18n.getMessage()}国际标准化显示

mydwbi.contact="联系我们"
mydwbi.Advertisement="广告代理"

8.添加对应Html页面在目录:jforum\templates\default\下

两个文件contact.htm,advertisement.htm :
contact.htm:

   <#include "header.htm"/> 
   <center> 
   ${I18n.getMessage("mydwbi.contactDesc")}:admin@mydwbi.com 
   </center> 
   <#include "bottom.htm"/>


advertisement.htm

   <#include "header.htm"/> 
   <center> 
       ${I18n.getMessage("mydwbi.adDesc")}:admin@mydwbi.com 
   </center> 
   <#include "bottom.htm"/>

实现系统单点登录(SSO):使用网上讨论比较多的Cookie方式(当系统与论坛处于同一系统中时可考虑session形式,Cookie方式限制比较多,而且只能用文本)

创建了一个CookieUserSSO
Java代码

package net.jforum.sso;
import javax.servlet.http.Cookie;
import net.jforum.ControllerUtils;
import net.jforum.context.RequestContext;
import net.jforum.entities.UserSession;
import net.jforum.util.preferences.ConfigKeys;
import net.jforum.util.preferences.SystemGlobals;
import org.apache.log4j.Logger;
/**
 * jforum 与 web 项目整合的的处理类
 * @author Rafael Steil
 * @version $Id: $
 */
public class CookieUserSSO implements SSO{
 static final Logger logger = Logger.getLogger(CookieUserSSO.class.getName());
 
 public String authenticateUser(RequestContext request) {
  // login cookie set by my web LOGIN application
//  Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals.getValue(ConfigKeys.COOKIE_NAME_USER));//这种写法会获取null,不解啊
  Cookie cookieNameUser = ControllerUtils.getCookie("jforumSSOCookieNameUser");
  String username = null;
  if (cookieNameUser != null) {
  username = cookieNameUser.getValue();
  }
  System.out.println(cookieNameUser+" ======== "+username+" ==========");
  return username; // return username for jforum
  // jforum will use this name to regist database or set in HttpSession
 }
 public boolean isSessionValid(UserSession userSession,
   RequestContext request) {
  Cookie cookieNameUser = ControllerUtils.getCookie(SystemGlobals
    .getValue(ConfigKeys.COOKIE_NAME_USER)); // user cookie
    String remoteUser = null;
    if (cookieNameUser != null) {
    remoteUser = cookieNameUser.getValue(); // jforum username
    }
    if (remoteUser == null
    && userSession.getUserId() != SystemGlobals
    .getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
    // user has since logged out
    return false;
    } else if (remoteUser != null
    && userSession.getUserId() == SystemGlobals
    .getIntValue(ConfigKeys.ANONYMOUS_USER_ID)) {
    // anonymous user has logged in
    return false;
    } else if (remoteUser != null
    && !remoteUser.equals(userSession.getUsername())) {
    // not the same user (cookie and session)
    return false;
    }
    return true; // myapp user and forum user the same. valid user.
 }
}

修改systemglobals.properties文件中的SSO片段
Java代码

#############################
# SSO / User authentication
#############################
# Auhentication type: use one of the following options
#
# sso: SSO based authentication. The called class will be the one
# specified by the key "sso.implementation", whic must be an implementation
#  of net.jforum.sso.SSO
#
# default: Non-SSO authentication, which relies on the key
# "login.authenticator" to validate users. For more information, please see
# net.jforum.sso.LoginAuthenticator and the default implementation.

#authentication.type = default
authentication.type = sso

# The above key will be used when "authentication.type" is set to "default"
# Can be any implementation of net.jforum.sso.LoginAuthenticator
#
# For LDAP authentication, set the value to net.jforum.sso.LDAPAuthenticator. Also,
# see the LDAP section below
login.authenticator = net.jforum.sso.DefaultLoginAuthenticator

# When using authentication.type = default, you may choose to disable
# the automatic login feature, which will prevents users to get
# automatic logged in when they come back to the forum
auto.login.enabled = true

# The above key will be be used then "authentication.type" is set to "sso"
# The default implementation (used here) only checks if request.getRemoteUser()
# is not null. This may be enough for many situations.

#sso.implementation = net.jforum.sso.RemoteUserSSO
sso.implementation = net.jforum.sso.CookieUserSSO
#cookie.name.user = jforumSSOCookieNameUser这里不需要重写cookie.name.user了,因为在下面还有一个这个属性,直接修改就可以了

# Special attributes used when creating a new user
# Only if auhentication.type = sso
# The attribute name to search in the session for the password.
sso.password.attribute = password

# Same as above
sso.email.attribute = email

# The default email to use if sso.email.attribute is empty
sso.default.email = sso@user

# The default password to use if sso.password.attribute is empty
sso.default.password = sso

# Optional redirect for SSO
#
# If a value is set, the user will be redirected to the defined
# URL, using the following logic:
#
# ${sso.redirect}?returnUrl=${forum.link} +
#
# The value MUST start with the protocol (http:// or https://)
#
sso.redirect = http://localhost:8080/jforum

然后,在web项目的登陆处理中加入cookie的设置
Java代码

//与jforum整合代码,设置cookic
   Cookie cookie = new Cookie("jforumSSOCookieNameUser", username);
      cookie.setMaxAge(-1);
      cookie.setPath("/");
      response.addCookie(cookie);

退出处理类中,加入
Java代码

Cookie cookie = new Cookie("jforumSSOCookieNameUser", "");
     cookie.setMaxAge(0); // delete the cookie.
     cookie.setPath("/");
     response.addCookie(cookie);


其他相关问题总结:

1.禁止anonymous的登录:简历一个权限组,取消所有权限,将anonymous移动到此组中.

2.不插入默认的论坛板块和论坛帖("super - please read")这些信息.由于网上相关信息没找到.故自己摸索了下原本以为所有信息都是数据文件中执行的,因为发现论坛板块和论坛主题是在oracle_data_dump.sql文件中定义的.然后搜素内容后,发现在jforum.script脚本中有定于.于是修改两个文件.安装后发现仍然存在默认帖子.再次搜索,发现个很变态的行为,那个帖子内容竟然是在InstallAction.java文件里写死的.修改后OK了

3.修改版权信息:修改bottom.htm 11行.

4.将发贴时"pool","attachments","options"改成中文:

-添加国际化属性
mydwbi.Options=\u9009\u9879
mydwbi.Pool=\u6295\u7968
mydwbi.Attach=\u9644\u4ef6

-修改模板
将post_form.htm中第369,372,375行"pool","attachments","options"改成:
${I18n.getMessage("mydwbi.Options")}
${I18n.getMessage("mydwbi.Pool")}
${I18n.getMessage("mydwbi.Attach")}

5.进入板块后显示主题列表页面发表人栏显示帖子发表时间:

进入板块后显示主题列表页面指: /forums/show/xxxx.page 页面
forum_show.htm页面224行改成:

<span class="postdetails">${topic.firstPostTime}<br /><a > 
176行改成:width=140

6.bmp图片也显示缩略图:

用户经常用print screen键拷贝屏幕图片,并发到帖子上,是bmp格式,不能显示缩略图,要下载才能看,不太方便。这里改一下可显示缩略图 。
AttachmentCommon.java 254行添加:"bmp".equals(extension) ||

7.解决在线用户列表同一用户名显示N次问题:


ForumAction.java
this.context.put("userSessions", onlineUsersList); 这一行前添加:
removeDuplicate(onlineUsersList);

ForumAction.java
添加一个方法:

public static void removeDuplicate(List list) { 
 for (int i = 0; i < list.size() - 1; i++) { 
  for (int j = list.size() - 1; j > i; j--) { 
     String jName = ((UserSession) list.get(j)).getUsername(); 
     String iName = ((UserSession) list.get(i)).getUsername(); 
  if (jName.equals(iName)) { 
      list.remove(j); 
   } 
} 
} 
// System.out.println(list); 
}


8.将整个论坛页面宽度由满屏改为固定宽度:header.htm 31行: <table width="950" border="0" ALIGN="center">

9.将论坛跳转下拉框放到上面:


post_show.htm 等页面 90 行,加上下面代码:
 

  • 标签: jforum 总结 使用心得
  • 该日志于 2010-12-23 14:13 由 邓华锋 发表在 邓华锋 上,你除了可以发表评论外,还可以转载"JForum使用心得及总结"日志到你的网站或博客,但是请保留源地址及作者信息,谢谢!!
  • 版权所有:《邓华锋》 => 《JForum使用心得及总结
    本文地址:http://dhf.ink/post-62.html
    除非注明,文章均为 《邓华锋》 原创,欢迎转载!转载请注明本文地址,谢谢。