001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/FavoriteThreadXML.java,v 1.8 2007/10/09 11:09:12 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.8 $
005: * $Date: 2007/10/09 11:09:12 $
006: *
007: * ====================================================================
008: *
009: * Copyright (C) 2002-2007 by MyVietnam.net
010: *
011: * All copyright notices regarding mvnForum MUST remain
012: * intact in the scripts and in the outputted HTML.
013: * The "powered by" text/logo with a link back to
014: * http://www.mvnForum.com and http://www.MyVietnam.net in
015: * the footer of the pages MUST remain visible when the pages
016: * are viewed on the internet or intranet.
017: *
018: * This program is free software; you can redistribute it and/or modify
019: * it under the terms of the GNU General Public License as published by
020: * the Free Software Foundation; either version 2 of the License, or
021: * any later version.
022: *
023: * This program is distributed in the hope that it will be useful,
024: * but WITHOUT ANY WARRANTY; without even the implied warranty of
025: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
026: * GNU General Public License for more details.
027: *
028: * You should have received a copy of the GNU General Public License
029: * along with this program; if not, write to the Free Software
030: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
031: *
032: * Support can be obtained from support forums at:
033: * http://www.mvnForum.com/mvnforum/index
034: *
035: * Correspondence and Marketing Questions can be sent to:
036: * info at MyVietnam net
037: *
038: * @author: Igor Manic
039: */
040: package com.mvnforum.admin;
041:
042: import com.mvnforum.admin.importexport.XMLUtil;
043: import com.mvnforum.db.DAOFactory;
044: import net.myvietnam.mvncore.exception.*;
045:
046: /**
047: * @author Igor Manic
048: * @version $Revision: 1.8 $, $Date: 2007/10/09 11:09:12 $
049: * <br/>
050: * <code>FavoriteThreadXML</code> todo Igor: enter description
051: *
052: */
053: public class FavoriteThreadXML {
054:
055: /* There is no FavoriteThreadID!
056: private int favoriteThreadID;
057: ** Returns <code>FavoriteThreadID</code> of this favorite-thread or
058: * <code>-1</code> if favorite-thread is not created yet. *
059: public int getFavoriteThreadID() { return favoriteThreadID; } */
060:
061: private int parentThreadID;
062:
063: /** Returns <code>ThreadID</code> of this favorite-thread's parent thread or
064: * <code>-1</code> if this favorite-thread is not created yet. */
065: public int getParentThreadID() {
066: return parentThreadID;
067: }
068:
069: private int parentForumID;
070:
071: /** Returns <code>ForumID</code> of this favorite-thread's parent forum or
072: * <code>-1</code> if this favorite-thread is not created yet. */
073: public int getParentForumID() {
074: return parentForumID;
075: }
076:
077: public FavoriteThreadXML() {
078: super ();
079: //favoriteThreadID=-1;
080: parentThreadID = -1;
081: parentForumID = -1;
082: }
083:
084: /*public void setFavoriteThreadID(String id) {
085: favoriteThreadID=XMLUtil.stringToIntDef(id, -1);
086: }*/
087:
088: public void setParentThread(Object o)
089: throws ForeignKeyNotFoundException {
090: if (o instanceof ThreadXML) {
091: parentThreadID = ((ThreadXML) o).getThreadID();
092: } else {
093: throw new ForeignKeyNotFoundException(
094: "Can't find parent thread's ID");
095: }
096: }
097:
098: public void setParentThreadID(int value) {
099: if (value < 0)
100: parentThreadID = -1;
101: else
102: parentThreadID = value;
103: }
104:
105: public void setParentForum(Object o)
106: throws ForeignKeyNotFoundException {
107: if (o instanceof ThreadXML) {
108: parentForumID = ((ThreadXML) o).getParentForumID();
109: } else {
110: throw new ForeignKeyNotFoundException(
111: "Can't find parent forum's ID");
112: }
113: }
114:
115: public void setParentForumID(int value) {
116: if (value < 0)
117: parentForumID = -1;
118: else
119: parentForumID = value;
120: }
121:
122: /**
123: * Creates a favorite-thread. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
124: * are represented as <code>String</code>s, because of more convenient using
125: * of this method for XML parsing.
126: *
127: * @param memberName Member who owns this favorite-thread record.
128: * @param favoriteCreationDate Can be null.
129: * @param favoriteType Can be null.
130: * @param favoriteOption Can be null.
131: * @param favoriteStatus Can be null.
132: *
133: * @throws CreateException
134: * @throws DuplicateKeyException
135: * @throws ObjectNotFoundException
136: * @throws DatabaseException
137: * @throws ForeignKeyNotFoundException
138: *
139: */
140: public void addFavoriteThread(String memberName,
141: String favoriteCreationDate, String favoriteType,
142: String favoriteOption, String favoriteStatus)
143: throws CreateException, DuplicateKeyException,
144: ObjectNotFoundException, DatabaseException,
145: ForeignKeyNotFoundException {
146: if (parentThreadID < 0) {
147: throw new CreateException(
148: "Can't create a favorite-thread, because no parent thread assigned yet.");
149: } else if (parentForumID < 0) {
150: throw new CreateException(
151: "Can't create a favorite-thread, because no parent forum assigned yet.");
152: } else if ((memberName == null) || (memberName.equals(""))) {
153: throw new CreateException(
154: "Can't create a favorite-thread for a member with empty MemberName.");
155: } else {
156: java.sql.Timestamp favoriteCreationDate1;
157: int favoriteType1;
158: int favoriteOption1;
159: int favoriteStatus1;
160: try {
161: favoriteCreationDate1 = XMLUtil
162: .stringToSqlTimestampDefNow(favoriteCreationDate);
163: favoriteType1 = XMLUtil.stringToIntDef(favoriteType, 0);
164: favoriteOption1 = XMLUtil.stringToIntDef(
165: favoriteOption, 0);
166: favoriteStatus1 = XMLUtil.stringToIntDef(
167: favoriteStatus, 0);
168: } catch (NumberFormatException e) {
169: throw new CreateException(
170: "Invalid data for a favorite-thread. Expected a number.");
171: }
172:
173: int memberID = DAOFactory.getMemberDAO()
174: .getMemberIDFromMemberName(memberName);
175: DAOFactory.getFavoriteThreadDAO().create(memberID,
176: parentThreadID, parentForumID,
177: favoriteCreationDate1, favoriteType1,
178: favoriteOption1, favoriteStatus1);
179:
180: }
181: }
182:
183: }
|