?? forumxml.java
字號(hào):
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ForumXML.java,v 1.6 2004/07/04 14:57:55 imanic Exp $
* $Author: imanic $
* $Revision: 1.6 $
* $Date: 2004/07/04 14:57:55 $
*
* ====================================================================
*
* Copyright (C) 2002-2004 by MyVietnam.net
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or any later version.
*
* All copyright notices regarding mvnForum MUST remain intact
* in the scripts and in the outputted HTML.
* The "powered by" text/logo with a link back to
* http://www.mvnForum.com and http://www.MyVietnam.net in the
* footer of the pages MUST remain visible when the pages
* are viewed on the internet or intranet.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* Support can be obtained from support forums at:
* http://www.mvnForum.com/mvnforum/index
*
* Correspondence and Marketing Questions can be sent to:
* info@MyVietnam.net
*
* @author: Igor Manic imanic@users.sourceforge.net
*/
package com.mvnforum.admin;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.*;
import com.mvnforum.MVNForumConstant;
import com.mvnforum.admin.importexport.XMLUtil;
import com.mvnforum.admin.importexport.XMLWriter;
import com.mvnforum.auth.MVNForumPermission;
import com.mvnforum.db.*;
import net.myvietnam.mvncore.exception.*;
import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
import net.myvietnam.mvncore.filter.EnableHtmlTagFilter;
/**
* @author <a href="mailto:imanic@users.sourceforge.net">Igor Manic</a>
* @version $Revision: 1.6 $, $Date: 2004/07/04 14:57:55 $
* <br/>
* <code>ForumXML</code> todo Igor: enter description
*
*/
public class ForumXML {
private int forumID;
/** Returns <code>ForumID</code> of this forum or
* <code>-1</code> if forum is not created yet. */
public int getForumID() { return forumID; }
private int parentCategoryID;
/** Returns <code>CategoryID</code> of this forum's parent category or
* <code>-1</code> if this forum is not created yet. */
public int getParentCategoryID() { return parentCategoryID; }
public ForumXML() {
super();
forumID=-1;
parentCategoryID=-1;
}
public void setForumID(String id) {
forumID=XMLUtil.stringToIntDef(id, -1);
}
public void setParentCategory(CategoryXML parentCategory)
throws ForeignKeyNotFoundException {
parentCategoryID=parentCategory.getCategoryID();
}
public void setParentCategoryID(int value) {
if (value<0) parentCategoryID=-1;
else parentCategoryID=value;
}
/**
* Creates a forum. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
* are represented as <code>String</code>s, because of more convenient using
* of this method for XML parsing.
*
* @param lastPostMemberName Can be null.
* @param forumName Name of a forum to be created.
* @param forumDesc Can be null.
* @param forumCreationDate Can be null.
* @param forumModifiedDate Can be null.
* @param forumLastPostDate Can be null.
* @param forumOrder Can be null.
* @param forumType Can be null.
* @param forumFormatOption Can be null.
* @param forumOption Can be null.
* @param forumStatus Can be null.
* @param forumModerationMode Can be null.
* @param forumPassword Password of a forum to be created. Can be null (or empty "").
* @param forumThreadCount Can be null.
* @param forumPostCount Can be null.
*
* @throws CreateException
* @throws DuplicateKeyException
* @throws ObjectNotFoundException
* @throws DatabaseException
* @throws ForeignKeyNotFoundException
*
*/
public void addForum(String lastPostMemberName, String forumName,
String forumDesc, String forumCreationDate,
String forumModifiedDate, String forumLastPostDate,
String forumOrder, String forumType,
String forumFormatOption, String forumOption,
String forumStatus, String forumModerationMode,
String forumPassword, String forumThreadCount,
String forumPostCount)
throws CreateException, DuplicateKeyException, ObjectNotFoundException,
DatabaseException, ForeignKeyNotFoundException {
if (parentCategoryID<0) {
throw new CreateException("Can't create a forum, because no parent category assigned yet.");
}
if ((forumName==null) || (forumName.equals(""))) {
throw new CreateException("Can't create a forum with empty ForumName.");
} else {
java.sql.Timestamp forumCreationDate1;
java.sql.Timestamp forumModifiedDate1;
java.sql.Timestamp forumLastPostDate1;
int forumOrder1;
int forumType1;
int forumFormatOption1;
int forumOption1;
int forumStatus1;
int forumModerationMode1;
int forumThreadCount1;
int forumPostCount1;
try {
if (lastPostMemberName==null) lastPostMemberName="";
if (forumDesc==null) forumDesc="";
forumCreationDate1= XMLUtil.stringToSqlTimestampDefNow(forumCreationDate);
forumModifiedDate1= XMLUtil.stringToSqlTimestampDefNull(forumModifiedDate);
forumLastPostDate1= XMLUtil.stringToSqlTimestampDefNull(forumLastPostDate);
forumOrder1 = XMLUtil.stringToIntDef(forumOrder, 0);
forumType1 = XMLUtil.stringToIntDef(forumType, 0);
forumFormatOption1 = XMLUtil.stringToIntDef(forumFormatOption, 0);
forumOption1 = XMLUtil.stringToIntDef(forumOption, 0);
forumStatus1 = XMLUtil.stringToIntDef(forumStatus, 0);
forumModerationMode1 = XMLUtil.stringToIntDef(forumModerationMode, 0);
if (forumPassword==null) forumPassword="";
forumThreadCount1 = XMLUtil.stringToIntDef(forumThreadCount, 0);
forumPostCount1 = XMLUtil.stringToIntDef(forumPostCount, 0);
} catch (NumberFormatException e) {
throw new CreateException("Invalid data for a forum. Expected a number.");
}
forumName=EnableHtmlTagFilter.filter(forumName);
forumDesc=EnableHtmlTagFilter.filter(forumDesc);
forumPassword=EnableHtmlTagFilter.filter(forumPassword);
DAOFactory.getForumDAO().create(
parentCategoryID, lastPostMemberName,
forumName, forumDesc,
forumCreationDate1, forumModifiedDate1, forumLastPostDate1,
forumOrder1, forumType1, forumFormatOption1,
forumOption1, forumStatus1, forumModerationMode1,
forumPassword, forumThreadCount1, forumPostCount1);
//todo Igor: Minh, you could move next piece of code into ForumWebHelper.getForumIDFromPrimaryKey method
Collection forums=DAOFactory.getForumDAO().getBeans_inCategory(parentCategoryID);
Iterator iter=forums.iterator();
try {
ForumBean forum=null;
forumID=-1;
while ( (forum=(ForumBean)iter.next() )!=null) {
if ((forum.getForumName().equals(forumName)) && (forum.getCategoryID()==parentCategoryID)) {
forumID=forum.getForumID();
break;
}
}
if (forumID<0) {
throw new ObjectNotFoundException("Can't find forum I've just added.");
}
} catch (NoSuchElementException e) {
throw new ObjectNotFoundException("Can't find forum I've just added.");
}
}
}
/**
* Adds a forum-specific permission to a member. In order to know which forum we are
* reffering to, this method is supposed to be called after {@link #setForumID(String)} or
* {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
* have been called. Otherwise, this permission will be simply ignored.
*
* @param memberName Member we are assigning permissions to.
* @param permission Permission to be added.
*
* @throws CreateException
* @throws DatabaseException
* @throws ObjectNotFoundException
* @throws DuplicateKeyException
* @throws ForeignKeyNotFoundException
*
*/
public void addMemberForumPermission(String memberName, String permission)
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -