?? threadxml.java
字號:
/*
* $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ThreadXML.java,v 1.5 2004/06/27 01:20:38 skoehler Exp $
* $Author: skoehler $
* $Revision: 1.5 $
* $Date: 2004/06/27 01:20:38 $
*
* ====================================================================
*
* 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.admin.importexport.XMLUtil;
import com.mvnforum.admin.importexport.XMLWriter;
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.5 $, $Date: 2004/06/27 01:20:38 $
* <br/>
* <code>ThreadXML</code> todo Igor: enter description
*
*/
public class ThreadXML {
private int threadID;
/** Returns <code>ThreadID</code> of this thread or
* <code>-1</code> if thread is not created yet. */
public int getThreadID() { return threadID; }
private int parentForumID;
/** Returns <code>ForumID</code> of this thread's parent forum or
* <code>-1</code> if this thread is not created yet. */
public int getParentForumID() { return parentForumID; }
private int parentCategoryID;
/** Returns <code>CategoryID</code> of this thread's parent category or
* <code>-1</code> if this thread is not created yet. */
public int getParentCategoryID() { return parentCategoryID; }
public ThreadXML() {
super();
threadID=-1;
parentForumID=-1;
parentCategoryID=-1;
}
public void setThreadID(String id) {
threadID=XMLUtil.stringToIntDef(id, -1);
}
public void setParentForum(Object o)
throws ForeignKeyNotFoundException {
if (o instanceof ForumXML) {
parentForumID=((ForumXML)o).getForumID();
} else {
throw new ForeignKeyNotFoundException("Can't find parent forum's ID");
}
}
public void setParentForumID(int value) {
if (value<0) parentForumID=-1;
else parentForumID=value;
}
public void setParentCategory(Object o)
throws ForeignKeyNotFoundException {
if (o instanceof ForumXML) {
parentCategoryID=((ForumXML)o).getParentCategoryID();
} else {
throw new ForeignKeyNotFoundException("Can't find parent category's ID");
}
}
public void setParentCategoryID(int value) {
if (value<0) parentCategoryID=-1;
else parentCategoryID=value;
}
/**
* Creates a thread. 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 memberName Member that created the thread. Can be null.
* @param lastPostMemberName Can be null.
* @param threadTopic Thread topic.
* @param threadBody Thread body (description).
* @param threadVoteCount Can be null.
* @param threadVoteTotalStars Can be null.
* @param threadCreationDate Can be null.
* @param threadLastPostDate Can be null.
* @param threadType Can be null.
* @param threadOption Can be null.
* @param threadStatus Can be null.
* @param threadHasPoll Can be null.
* @param threadViewCount Can be null.
* @param threadReplyCount Can be null.
* @param threadIcon Can be null.
* @param threadDuration Can be null.
*
* @throws CreateException
* @throws DuplicateKeyException
* @throws ObjectNotFoundException
* @throws DatabaseException
* @throws ForeignKeyNotFoundException
*/
public void addThread(String memberName, String lastPostMemberName,
String threadTopic, String threadBody,
String threadVoteCount, String threadVoteTotalStars,
String threadCreationDate, String threadLastPostDate,
String threadType, String threadOption,
String threadStatus, String threadHasPoll,
String threadViewCount, String threadReplyCount,
String threadIcon, String threadDuration)
throws CreateException, DuplicateKeyException, ObjectNotFoundException,
DatabaseException, ForeignKeyNotFoundException {
if (parentForumID<0) {
throw new CreateException("Can't create a thread, because no parent forum assigned yet.");
} else if (parentCategoryID<0) {
throw new CreateException("Can't create a thread, because no parent category assigned yet.");
} else if ((threadTopic==null) || (threadBody==null)) {
throw new CreateException("Can't create a thread with empty ThreadTopic or empty ThreadBody.");
} else {
int threadVoteCount1;
int threadVoteTotalStars1;
java.sql.Timestamp threadCreationDate1;
java.sql.Timestamp threadLastPostDate1;
int threadType1;
int threadOption1;
int threadStatus1;
int threadHasPoll1;
int threadViewCount1;
int threadReplyCount1;
int threadDuration1;
try {
if (memberName==null) memberName="";
if (lastPostMemberName==null) lastPostMemberName="";
threadVoteCount1= XMLUtil.stringToIntDef(threadVoteCount, 0);
threadVoteTotalStars1= XMLUtil.stringToIntDef(threadVoteTotalStars, 0);
threadCreationDate1= XMLUtil.stringToSqlTimestampDefNow(threadCreationDate);
threadLastPostDate1= XMLUtil.stringToSqlTimestampDefNull(threadLastPostDate);
threadType1 = XMLUtil.stringToIntDef(threadType, 0);
threadOption1 = XMLUtil.stringToIntDef(threadOption, 0);
threadStatus1 = XMLUtil.stringToIntDef(threadStatus, 0);
threadHasPoll1 = XMLUtil.stringToIntDef(threadHasPoll, 0);
threadViewCount1 = XMLUtil.stringToIntDef(threadViewCount, 0);
threadReplyCount1 = XMLUtil.stringToIntDef(threadReplyCount, 0);
if (threadIcon==null) threadIcon="";
threadDuration1 = XMLUtil.stringToIntDef(threadDuration, 0);
} catch (NumberFormatException e) {
throw new CreateException("Invalid data for a thread. Expected a number.");
}
threadTopic=EnableHtmlTagFilter.filter(threadTopic);
threadBody=EnableHtmlTagFilter.filter(threadBody);
threadIcon=EnableHtmlTagFilter.filter(threadIcon);
this.threadID = DAOFactory.getThreadDAO().createThread(parentForumID,
memberName, lastPostMemberName,
threadTopic, threadBody,
threadVoteCount1, threadVoteTotalStars1,
threadCreationDate1, threadLastPostDate1,
threadType1, threadOption1, threadStatus1,
threadHasPoll1, threadViewCount1, threadReplyCount1,
threadIcon, threadDuration1);
}
}
/**
* Creates a thread watch for this thread. In order to know which thread we are
* reffering to, this method is supposed to be called after {@link #setThreadID(String)},
* {@link #addThread(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
* have been called. Otherwise, this watch will be simply ignored.
*
* @param memberName
* @param watchType Can be null.
* @param watchOption Can be null.
* @param watchStatus Can be null.
* @param watchCreationDate Can be null.
* @param watchLastSentDate Can be null.
* @param watchEndDate Can be null.
*
* @throws BadInputException
* @throws CreateException
* @throws DatabaseException
* @throws ObjectNotFoundException
* @throws DuplicateKeyException
* @throws ForeignKeyNotFoundException
*/
public void addThreadWatch(String memberName,
String watchType, String watchOption,
String watchStatus, String watchCreationDate,
String watchLastSentDate, String watchEndDate)
throws BadInputException, CreateException, DatabaseException,
ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
if (threadID<0) {
throw new CreateException("Found thread watch that is not assigned to any known thread.");
}
int watchType1;
int watchOption1;
int watchStatus1;
java.sql.Timestamp watchCreationDate1;
java.sql.Timestamp watchLastSentDate1;
java.sql.Timestamp watchEndDate1;
try {
if (memberName==null) memberName="";
watchType1= XMLUtil.stringToIntDef(watchType, 0);
watchOption1= XMLUtil.stringToIntDef(watchOption, 0);
watchStatus1= XMLUtil.stringToIntDef(watchStatus, 0);
watchCreationDate1= XMLUtil.stringToSqlTimestampDefNow(watchCreationDate);
watchLastSentDate1= XMLUtil.stringToSqlTimestampDefNull(watchLastSentDate);
watchEndDate1= XMLUtil.stringToSqlTimestampDefNull(watchEndDate);
} catch (NumberFormatException e) {
throw new CreateException("Invalid data for a thread watch. Expected a number.");
}
//todo Igor: Shoud I allow memberID==0 here?
int memberID=0;
if (!memberName.equals("")) {
memberID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
}
DAOFactory.getWatchDAO().create(
memberID, 0/*categoryID*/, threadID, 0/*forumID*/,
watchType1, watchOption1, watchStatus1,
watchCreationDate1, watchLastSentDate1, watchEndDate1);
}
public void addFavoriteThread(String memberName,
String favoriteCreationDate, String favoriteType,
String favoriteOption, String favoriteStatus)
throws BadInputException, CreateException, DatabaseException,
ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
if (threadID<0) {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -