KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > FavoriteThreadXML


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/FavoriteThreadXML.java,v 1.6 2006/04/14 17:36:28 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.6 $
5  * $Date: 2006/04/14 17:36:28 $
6  *
7  * ====================================================================
8  *
9  * Copyright (C) 2002-2006 by MyVietnam.net
10  *
11  * All copyright notices regarding mvnForum MUST remain
12  * intact in the scripts and in the outputted HTML.
13  * The "powered by" text/logo with a link back to
14  * http://www.mvnForum.com and http://www.MyVietnam.net in
15  * the footer of the pages MUST remain visible when the pages
16  * are viewed on the internet or intranet.
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 2 of the License, or
21  * any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program; if not, write to the Free Software
30  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31  *
32  * Support can be obtained from support forums at:
33  * http://www.mvnForum.com/mvnforum/index
34  *
35  * Correspondence and Marketing Questions can be sent to:
36  * info at MyVietnam net
37  *
38  * @author: Igor Manic
39  */

40 package com.mvnforum.admin;
41
42 import com.mvnforum.admin.importexport.XMLUtil;
43 import com.mvnforum.db.DAOFactory;
44 import net.myvietnam.mvncore.exception.*;
45
46 /**
47  * @author Igor Manic
48  * @version $Revision: 1.6 $, $Date: 2006/04/14 17:36:28 $
49  * <br/>
50  * <code>FavoriteThreadXML</code> todo Igor: enter description
51  *
52  */

53 public class FavoriteThreadXML {
54
55     /* There is no FavoriteThreadID!
56     private int favoriteThreadID;
57     ** Returns <code>FavoriteThreadID</code> of this favorite-thread or
58       * <code>-1</code> if favorite-thread is not created yet. *
59     public int getFavoriteThreadID() { return favoriteThreadID; } */

60
61     private int parentThreadID;
62     /** Returns <code>ThreadID</code> of this favorite-thread's parent thread or
63       * <code>-1</code> if this favorite-thread is not created yet. */

64     public int getParentThreadID() { return parentThreadID; }
65
66     private int parentForumID;
67     /** Returns <code>ForumID</code> of this favorite-thread's parent forum or
68       * <code>-1</code> if this favorite-thread is not created yet. */

69     public int getParentForumID() { return parentForumID; }
70
71     public FavoriteThreadXML() {
72         super();
73         //favoriteThreadID=-1;
74
parentThreadID=-1;
75         parentForumID=-1;
76     }
77
78     /*public void setFavoriteThreadID(String id) {
79         favoriteThreadID=XMLUtil.stringToIntDef(id, -1);
80     }*/

81
82     public void setParentThread(Object JavaDoc o)
83     throws ForeignKeyNotFoundException {
84         if (o instanceof ThreadXML) {
85             parentThreadID=((ThreadXML)o).getThreadID();
86         } else {
87             throw new ForeignKeyNotFoundException("Can't find parent thread's ID");
88         }
89     }
90
91     public void setParentThreadID(int value) {
92         if (value<0) parentThreadID=-1;
93         else parentThreadID=value;
94     }
95
96     public void setParentForum(Object JavaDoc o)
97     throws ForeignKeyNotFoundException {
98         if (o instanceof ThreadXML) {
99             parentForumID=((ThreadXML)o).getParentForumID();
100         } else {
101             throw new ForeignKeyNotFoundException("Can't find parent forum's ID");
102         }
103     }
104
105     public void setParentForumID(int value) {
106         if (value<0) parentForumID=-1;
107         else parentForumID=value;
108     }
109
110     /**
111      * Creates a favorite-thread. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
112      * are represented as <code>String</code>s, because of more convenient using
113      * of this method for XML parsing.
114      *
115      * @param memberName Member who owns this favorite-thread record.
116      * @param favoriteCreationDate Can be null.
117      * @param favoriteType Can be null.
118      * @param favoriteOption Can be null.
119      * @param favoriteStatus Can be null.
120      *
121      * @throws CreateException
122      * @throws DuplicateKeyException
123      * @throws ObjectNotFoundException
124      * @throws DatabaseException
125      * @throws ForeignKeyNotFoundException
126      *
127      */

128     public void addFavoriteThread(String JavaDoc memberName,
129                        String JavaDoc favoriteCreationDate, String JavaDoc favoriteType,
130                        String JavaDoc favoriteOption, String JavaDoc favoriteStatus)
131     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
132     DatabaseException, ForeignKeyNotFoundException {
133         if (parentThreadID<0) {
134             throw new CreateException("Can't create a favorite-thread, because no parent thread assigned yet.");
135         } else if (parentForumID<0) {
136             throw new CreateException("Can't create a favorite-thread, because no parent forum assigned yet.");
137         } else if ( (memberName==null) || (memberName.equals("")) ) {
138             throw new CreateException("Can't create a favorite-thread for a member with empty MemberName.");
139         } else {
140             java.sql.Timestamp JavaDoc favoriteCreationDate1;
141             int favoriteType1;
142             int favoriteOption1;
143             int favoriteStatus1;
144             try {
145                 favoriteCreationDate1= XMLUtil.stringToSqlTimestampDefNow(favoriteCreationDate);
146                 favoriteType1= XMLUtil.stringToIntDef(favoriteType, 0);
147                 favoriteOption1= XMLUtil.stringToIntDef(favoriteOption, 0);
148                 favoriteStatus1= XMLUtil.stringToIntDef(favoriteStatus, 0);
149             } catch (NumberFormatException JavaDoc e) {
150                 throw new CreateException("Invalid data for a favorite-thread. Expected a number.");
151             }
152
153             int memberID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
154             DAOFactory.getFavoriteThreadDAO().create(
155                           memberID, parentThreadID, parentForumID,
156                           favoriteCreationDate1, favoriteType1,
157                           favoriteOption1, favoriteStatus1);
158
159         }
160     }
161
162 }
163
164
Popular Tags