jForum版块增加公共的还是私的属性方法:

4 篇文章 0 订阅
3 篇文章 0 订阅
jForum版块增加公共的还是私的属性方法:


首先在数据库中修改表结构:
alter table jforum_forums add(is_private  number(10) default(0));


把实体Forum.java
/*
 * Copyright (c) JForum Team
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, 
 * with or without modification, are permitted provided 
 * that the following conditions are met:
 * 
 * 1) Redistributions of source code must retain the above 
 * copyright notice, this list of conditions and the 
 * following  disclaimer.
 * 2)  Redistributions in binary form must reproduce the 
 * above copyright notice, this list of conditions and 
 * the following disclaimer in the documentation and/or 
 * other materials provided with the distribution.
 * 3) Neither the name of "Rafael Steil" nor 
 * the names of its contributors may be used to endorse 
 * or promote products derived from this software without 
 * specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
 * IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 * 
 * This file creating date: Feb 23, 2003 / 12:25:04 PM
 * The JForum Project
 * http://www.jforum.net
 */
package net.jforum.entities;


import java.io.Serializable;
import java.util.List;


import net.jforum.repository.ForumRepository;


/**
 * Represents a specific forum.
 * 
 * @author Rafael Steil
 * @version $Id: Forum.java,v 1.13 2007/07/28 14:17:09 rafaelsteil Exp $
 */
public class Forum implements Serializable
{
private int id;
private int idCategories;
private String name;
private String description;
private int order;
private int totalTopics;
private int totalPosts;
private int lastPostId;
private boolean moderated;
private boolean unread;
private LastPostInfo lpi;


public Forum() { }

public Forum(int forumId) {
this.id = forumId;
}

public Forum(Forum f)
{
this.description = f.getDescription();
this.id = f.getId();
this.idCategories = f.getCategoryId();
this.lastPostId = f.getLastPostId();
this.moderated = f.isModerated();
this.name = f.getName();
this.order = f.getOrder();
this.totalPosts = f.getTotalPosts();
this.totalTopics = f.getTotalTopics();
this.unread = f.getUnread();
this.lpi = f.getLastPostInfo();
}

public void setLastPostInfo(LastPostInfo lpi) {
this.lpi = lpi;
}

public LastPostInfo getLastPostInfo() {
return this.lpi;
}

public List getModeratorList() 
{
return ForumRepository.getModeratorList(this.id);
}

/**
* Gets the forum's description

* @return String with the description
*/
public String getDescription() {
return this.description;
}


/**
* Gets the forum's ID

* @return int value representing the ID
*/
public int getId() {
return this.id;
}


/**
* Gets the category which the forum belongs to

* @return int value representing the ID of the category 
*/
public int getCategoryId() {
return this.idCategories;
}


/**
* Gets the ID of the last post

* @return int value representing the ID of the post
*/
public int getLastPostId() {
return this.lastPostId;
}


/**
* Checks if is a moderated forum

* @return boolean value. <code>true</code> if the forum is moderated, <code>false</code> if not.
*/
public boolean isModerated() {
return this.moderated;
}


/**
* Gets the name of the forum

* @return String with the name
*/
public String getName() {
return this.name;
}


/**
* Gets the order

* @return int value representing the order of the forum
*/
public int getOrder() {
return this.order;
}


/**
* Gets the total number of topics posted in the forum

* @return int value with the total number of the topics
*/
public int getTotalTopics() {
return this.totalTopics;
}

public boolean getUnread() {
return this.unread;
}


/**
* Sets the description.

* @param description The description to set
*/
public void setDescription(String description) {
this.description = description;
}


/**
* Sets the id.

* @param id The id to set
*/
public void setId(int id) {
this.id = id;
}


/**
* Sets the category id

* @param idCategories The ID of the category  to set to the forum
*/
public void setIdCategories(int idCategories) {
this.idCategories = idCategories;
}


/**
* Sets the ID of the last post

* @param lastPostId The post id
*/
public void setLastPostId(int lastPostId) {
this.lastPostId = lastPostId;
}


/**
* Sets the moderated flag to the forum

* @param moderated <code>true</code> or <code>false</code>
*/
public void setModerated(boolean moderated) {
this.moderated = moderated;
}


/**
* Sets the name of the forum

* @param name The name to set
*/
public void setName(String name) {
this.name = name;
}


/**
* Sets the order.

* @param order The order to set
*/
public void setOrder(int order) {
this.order = order;
}

public void setUnread(boolean status) {
this.unread = status;
}


/**
* Sets the total number of topics

* @param totalTopics int value with the total number of topics
*/
public void setTotalTopics(int totalTopics) {
this.totalTopics = totalTopics;
}

public int getTotalPosts() {
return this.totalPosts;
}

public void setTotalPosts(int totalPosts) {
this.totalPosts = totalPosts;
}

/** 
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) 
{
return ((o instanceof Forum) && (((Forum)o).getId() == this.id));
}


/** 
* @see java.lang.Object#hashCode()
*/
public int hashCode() 
{
return this.id;
}

/** 
* @see java.lang.Object#toString()
*/
public String toString() {
return "[" + this.name + ", id=" + this.id + ", order=" + this.order + "]";
}
}


修改为下面的代码:
/*
 * Copyright (c) JForum Team
 * All rights reserved.
 * 
 * Redistribution and use in source and binary forms, 
 * with or without modification, are permitted provided 
 * that the following conditions are met:
 * 
 * 1) Redistributions of source code must retain the above 
 * copyright notice, this list of conditions and the 
 * following  disclaimer.
 * 2)  Redistributions in binary form must reproduce the 
 * above copyright notice, this list of conditions and 
 * the following disclaimer in the documentation and/or 
 * other materials provided with the distribution.
 * 3) Neither the name of "Rafael Steil" nor 
 * the names of its contributors may be used to endorse 
 * or promote products derived from this software without 
 * specific prior written permission.
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
 * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
 * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
 * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
 * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
 * IN CONTRACT, STRICT LIABILITY, OR TORT 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 * 
 * This file creating date: Feb 23, 2003 / 12:25:04 PM
 * The JForum Project
 * http://www.jforum.net
 */
package net.jforum.entities;


import java.io.Serializable;
import java.util.List;


import net.jforum.repository.ForumRepository;


/**
 * Represents a specific forum.
 * 
 * @author Rafael Steil
 * @version $Id: Forum.java,v 1.13 2007/07/28 14:17:09 rafaelsteil Exp $
 */
public class Forum implements Serializable
{
private int id;
private int idCategories;
private String name;
private String description;
private int order;
private int totalTopics;
private int totalPosts;
private int lastPostId;
private boolean moderated;
private boolean unread;
private LastPostInfo lpi;

private boolean isPrivate;


public Forum() { }

public Forum(int forumId) {
this.id = forumId;
}

public Forum(Forum f)
{
this.description = f.getDescription();
this.id = f.getId();
this.idCategories = f.getCategoryId();
this.lastPostId = f.getLastPostId();
this.moderated = f.isModerated();
this.name = f.getName();
this.order = f.getOrder();
this.totalPosts = f.getTotalPosts();
this.totalTopics = f.getTotalTopics();
this.unread = f.getUnread();
this.lpi = f.getLastPostInfo();
this.isPrivate=f.isPrivate();
}

public void setLastPostInfo(LastPostInfo lpi) {
this.lpi = lpi;
}

public LastPostInfo getLastPostInfo() {
return this.lpi;
}

public List getModeratorList() 
{
return ForumRepository.getModeratorList(this.id);
}

/**
* Gets the forum's description

* @return String with the description
*/
public String getDescription() {
return this.description;
}


/**
* Gets the forum's ID

* @return int value representing the ID
*/
public int getId() {
return this.id;
}


/**
* Gets the category which the forum belongs to

* @return int value representing the ID of the category 
*/
public int getCategoryId() {
return this.idCategories;
}


/**
* Gets the ID of the last post

* @return int value representing the ID of the post
*/
public int getLastPostId() {
return this.lastPostId;
}


/**
* Checks if is a moderated forum

* @return boolean value. <code>true</code> if the forum is moderated, <code>false</code> if not.
*/
public boolean isModerated() {
return this.moderated;
}


/**
* Gets the name of the forum

* @return String with the name
*/
public String getName() {
return this.name;
}


/**
* Gets the order

* @return int value representing the order of the forum
*/
public int getOrder() {
return this.order;
}


/**
* Gets the total number of topics posted in the forum

* @return int value with the total number of the topics
*/
public int getTotalTopics() {
return this.totalTopics;
}

public boolean getUnread() {
return this.unread;
}


/**
* Sets the description.

* @param description The description to set
*/
public void setDescription(String description) {
this.description = description;
}


/**
* Sets the id.

* @param id The id to set
*/
public void setId(int id) {
this.id = id;
}


/**
* Sets the category id

* @param idCategories The ID of the category  to set to the forum
*/
public void setIdCategories(int idCategories) {
this.idCategories = idCategories;
}


/**
* Sets the ID of the last post

* @param lastPostId The post id
*/
public void setLastPostId(int lastPostId) {
this.lastPostId = lastPostId;
}


/**
* Sets the moderated flag to the forum

* @param moderated <code>true</code> or <code>false</code>
*/
public void setModerated(boolean moderated) {
this.moderated = moderated;
}


/**
* Sets the name of the forum

* @param name The name to set
*/
public void setName(String name) {
this.name = name;
}


/**
* Sets the order.

* @param order The order to set
*/
public void setOrder(int order) {
this.order = order;
}

public void setUnread(boolean status) {
this.unread = status;
}


/**
* Sets the total number of topics

* @param totalTopics int value with the total number of topics
*/
public void setTotalTopics(int totalTopics) {
this.totalTopics = totalTopics;
}

public int getTotalPosts() {
return this.totalPosts;
}

public void setTotalPosts(int totalPosts) {
this.totalPosts = totalPosts;
}

/** 
* @see java.lang.Object#equals(java.lang.Object)
*/
public boolean equals(Object o) 
{
return ((o instanceof Forum) && (((Forum)o).getId() == this.id));
}


/** 
* @see java.lang.Object#hashCode()
*/
public int hashCode() 
{
return this.id;
}

/** 
* @see java.lang.Object#toString()
*/
public String toString() {
return "[" + this.name + ", id=" + this.id + ", order=" + this.order + "]";
}

public boolean isPrivate(){
return this.isPrivate;
}

public void setIsPrivate(boolean isPrivate){
this.isPrivate=isPrivate;
}
}






在templates/default/admin/forum_form.htm中增加公共还是私有的更新界面,在127行增加代码:
<tr>
<td class="row1"><span class="gen">公共版块还是私有版块?</span></td>
<td class="row2">
<span class="gensmall">
<input class="post" type="radio" name="isPrivate" value="0" <#if forum?exists><#if !forum.isPrivate()>checked</#if><#else>checked</#if>/>公共的
<input class="post" type="radio" name="isPrivate" value="1" <#if forum?exists && forum.isPrivate()>checked</#if>/>私有的
</span>
</td>
</tr>


修改后台更新保存方法:ForumAction.java中editSave()方法:
增加语句:f.setIsPrivate("1".equals(this.request.getParameter("isPrivate")));
public void editSave()
{
System.out.println("editSave:");
ForumDAO forumDao = DataAccessDriver.getInstance().newForumDAO();
Forum f = forumDao.selectById(this.request.getIntParameter("forum_id"));

boolean moderated = f.isModerated();
int categoryId = f.getCategoryId();

f.setDescription(this.request.getParameter("description"));
f.setIdCategories(this.request.getIntParameter("categories_id"));
f.setName(this.request.getParameter("forum_name"));
f.setModerated("1".equals(this.request.getParameter("moderate")));
f.setIsPrivate("1".equals(this.request.getParameter("isPrivate")));
System.out.println("isPrivate:"+this.request.getParameter("isPrivate"));


forumDao.update(f);


if (moderated != f.isModerated()) {
new ModerationCommon().setTopicModerationStatus(f.getId(), f.isModerated());
}

if (categoryId != f.getCategoryId()) {
f.setIdCategories(categoryId);
ForumRepository.removeForum(f);

f.setIdCategories(this.request.getIntParameter("categories_id"));
ForumRepository.addForum(f);
}
else {
ForumRepository.reloadForum(f.getId());
}

//this.handleMailIntegration();

this.list();
}


同理,修改新增保存方法:在insertSave()中增加语句:f.setIsPrivate("1".equals(this.request.getParameter("isPrivate")));
// A new one
public void insertSave()
{
Forum f = new Forum();
f.setDescription(this.request.getParameter("description"));
f.setIdCategories(this.request.getIntParameter("categories_id"));
f.setName(this.request.getParameter("forum_name"));
f.setModerated("1".equals(this.request.getParameter("moderate")));
f.setIsPrivate("1".equals(this.request.getParameter("isPrivate")));

int forumId = DataAccessDriver.getInstance().newForumDAO().addNew(f);
f.setId(forumId);

ForumRepository.addForum(f);

GroupSecurityDAO gmodel = DataAccessDriver.getInstance().newGroupSecurityDAO();
PermissionControl pc = new PermissionControl();
pc.setSecurityModel(gmodel);

String[] allGroups = this.request.getParameterValues("groups");

// Access
String[] groups = this.request.getParameterValues("groupsAccess");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_FORUM, f.getId(), groups);
}
else {
this.addRole(pc, SecurityConstants.PERM_FORUM, f.getId(), allGroups);
}

// Anonymous posts
groups = this.request.getParameterValues("groupsAnonymous");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_ANONYMOUS_POST, f.getId(), groups);
}
else {
this.addRole(pc, SecurityConstants.PERM_ANONYMOUS_POST, f.getId(), allGroups);
}

// Read-only
groups = this.request.getParameterValues("groupsReadOnly");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_READ_ONLY_FORUMS, f.getId(), groups);
}
else {
this.addRole(pc, SecurityConstants.PERM_READ_ONLY_FORUMS, f.getId(), allGroups);
}

// Reply-only
this.addRole(pc, SecurityConstants.PERM_REPLY_ONLY, f.getId(), allGroups);

// HTML
groups = this.request.getParameterValues("groupsHtml");
if (groups != null) {
this.addRole(pc, SecurityConstants.PERM_HTML_DISABLED, f.getId(), groups);
}
else {
this.addRole(pc, SecurityConstants.PERM_HTML_DISABLED, f.getId(), allGroups);
}

SecurityRepository.clean();
RolesRepository.clear();

//this.handleMailIntegration();


this.list();
}


在generic_queries.sql中修改更新sql:

ForumModel.update = UPDATE jforum_forums SET categories_id = ?, forum_name = ?, forum_desc = ?, moderated = ? WHERE forum_id = ?
修改为下面的语句:
ForumModel.update = UPDATE jforum_forums SET categories_id = ?, forum_name = ?, forum_desc = ?, moderated = ?,is_private=? WHERE forum_id = ?


修改新增语句:
把下面的语句
ForumModel.addNew = INSERT INTO jforum_forums (categories_id, forum_name, forum_desc, forum_order, moderated) VALUES (?, ?, ?, ?, ?)
修改为:
ForumModel.addNew = INSERT INTO jforum_forums (categories_id, forum_name, forum_desc, forum_order, moderated,is_private) VALUES (?, ?, ?, ?, ?,?)





ForumModel.selectById = SELECT forum_id, forum_name, categories_id, forum_desc, forum_order, forum_topics, forum_last_post_id, moderated \
FROM jforum_forums \
WHERE forum_id = ?
修改为下面的语句:
ForumModel.selectById = SELECT forum_id, forum_name, categories_id, forum_desc, forum_order, forum_topics, forum_last_post_id, moderated,is_private \
FROM jforum_forums \
WHERE forum_id = ?



ForumModel.selectAll = SELECT forum_id, forum_name, categories_id, forum_desc, forum_order, forum_topics, forum_last_post_id, moderated \
FROM jforum_forums \
ORDER BY forum_order ASC
修改为:
ForumModel.selectAll = SELECT forum_id, forum_name, categories_id, forum_desc, forum_order, forum_topics, forum_last_post_id, moderated,is_private \
FROM jforum_forums \
ORDER BY forum_order ASC


修改GenericForumDAO.java中更新和新增方法:
在update方法中增加语句:p.setInt(5,forum.isPrivate()?1:0);
把p.setInt(5, forum.getId());改为:p.setInt(6, forum.getId());
public void update(Forum forum)
{
System.out.println("forum update():");
PreparedStatement p = null;
try {
p = JForumExecutionContext.getConnection().prepareStatement(SystemGlobals.getSql("ForumModel.update"));


p.setInt(1, forum.getCategoryId());
p.setString(2, forum.getName());
p.setString(3, forum.getDescription());
p.setInt(4, forum.isModerated() ? 1 : 0);
System.out.println("isPrivate:"+forum.isPrivate());
p.setInt(5,forum.isPrivate()?1:0);
p.setInt(6, forum.getId());



p.executeUpdate();
}
catch (SQLException e) {
throw new DatabaseException(e);
}
finally {
DbUtils.close(p);
}
}


在addNew方法中增加语句:pOrder.setInt(6,forum.isPrivate()?1:0);
public int addNew(Forum forum)
{
System.out.println("forum addNew():");
// Gets the higher order
PreparedStatement pOrder = null;
ResultSet rs = null;
try {
pOrder = JForumExecutionContext.getConnection().prepareStatement(
SystemGlobals.getSql("ForumModel.getMaxOrder"));
rs = pOrder.executeQuery();


if (rs.next()) {
forum.setOrder(rs.getInt(1) + 1);
}


rs.close();
rs = null;
pOrder.close();
pOrder = null;


pOrder = this.getStatementForAutoKeys("ForumModel.addNew");


pOrder.setInt(1, forum.getCategoryId());
pOrder.setString(2, forum.getName());
pOrder.setString(3, forum.getDescription());
pOrder.setInt(4, forum.getOrder());
pOrder.setInt(5, forum.isModerated() ? 1 : 0);
pOrder.setInt(6,forum.isPrivate()?1:0);


this.setAutoGeneratedKeysQuery(SystemGlobals.getSql("ForumModel.lastGeneratedForumId"));
int forumId = this.executeAutoKeysQuery(pOrder);


forum.setId(forumId);
return forumId;
}
catch (SQLException e) {
throw new DatabaseException(e);
}
finally {
DbUtils.close(rs, pOrder);
}
}


最后,还要修改读取is_private字段的内容:
修改GenericForumDAO.java中fillForum方法,增加语句:f.setIsPrivate(rs.getInt("is_private")>0);
protected Forum fillForum(ResultSet rs) throws SQLException
{
Forum f = new Forum();


f.setId(rs.getInt("forum_id"));
f.setIdCategories(rs.getInt("categories_id"));
f.setName(rs.getString("forum_name"));
f.setDescription(rs.getString("forum_desc"));
f.setOrder(rs.getInt("forum_order"));
f.setTotalTopics(rs.getInt("forum_topics"));
f.setLastPostId(rs.getInt("forum_last_post_id"));
f.setModerated(rs.getInt("moderated") > 0);
f.setTotalPosts(this.countForumPosts(f.getId()));
f.setIsPrivate(rs.getInt("is_private")>0);


return f;
}


修改之后,发现新增版面时,保存出错,跟踪调试发现,新增的sql调用的是database/oracle/oracle.sql中的语句;
修改
ForumModel.addNew = INSERT INTO jforum_forums (forum_id, categories_id, forum_name, forum_desc, forum_order, moderated) VALUES (jforum_forums_seq.nextval, ?, ?, ?, ?, ?)
为下面的语句:
ForumModel.addNew = INSERT INTO jforum_forums (forum_id, categories_id, forum_name, forum_desc, forum_order, moderated,is_private) VALUES (jforum_forums_seq.nextval, ?, ?, ?, ?, ?,?)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值