KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > importexport > mvnforum > MvnForumThreadXML


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumThreadXML.java,v 1.7 2006/04/14 17:36:29 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.7 $
5  * $Date: 2006/04/14 17:36:29 $
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.importexport.mvnforum;
41
42 import com.mvnforum.admin.ThreadXML;
43 import net.myvietnam.mvncore.exception.*;
44
45 /**
46  * @author Igor Manic
47  * @version $Revision: 1.7 $, $Date: 2006/04/14 17:36:29 $
48  * <br/>
49  * <code>MvnForumThreadXML</code> class encapsulates processing of
50  * threads' definitions found in the backup XML file. It implements
51  * methods to be called from XML parsing routine, adds some additional
52  * processing and checking, and calls corresponding methods of
53  * <code>ThreadXML</code> and other neccessary classes in order to perform
54  * the actual creation of a thread, as well as other related items (like
55  * favorite threads and thread watches).
56  */

57 public class MvnForumThreadXML {
58
59     private ThreadXML threadXML=null;
60     private boolean threadCreated=false;
61     private MvnForumForumXML parentForum =null;
62
63     String JavaDoc threadMemberName =null;
64     String JavaDoc threadLastPostMemberName =null;
65     String JavaDoc threadTopic =null;
66     String JavaDoc threadBody =null;
67     String JavaDoc threadVoteCount =null;
68     String JavaDoc threadVoteTotalStars =null;
69     String JavaDoc threadCreationDate =null;
70     String JavaDoc threadLastPostDate =null;
71     String JavaDoc threadType =null;
72     String JavaDoc threadOption =null;
73     String JavaDoc threadStatus =null;
74     String JavaDoc threadHasPoll =null;
75     String JavaDoc threadViewCount =null;
76     String JavaDoc threadReplyCount =null;
77     String JavaDoc threadIcon =null;
78     String JavaDoc threadDuration =null;
79     String JavaDoc threadAttachCount =null;
80
81     public MvnForumThreadXML() {
82         super();
83         threadXML=new ThreadXML();
84         threadCreated=false;
85         parentForum=null;
86     }
87
88     public int getThreadID() {
89         return threadXML.getThreadID();
90     }
91
92     public void setThreadID(String JavaDoc id) {
93         threadXML.setThreadID(id);
94     }
95
96     /**
97      * This method simply calls <code>setThreadID()</code>.
98      * It's defined only to avoid property-setter problems with digester
99      * (since it doesn't seem to recognize <code>setThreadID()</code> as a setter
100      * method for <code>threadID</code> property).
101      */

102     public void setThreadId(String JavaDoc id) {
103         setThreadID(id);
104     }
105
106     public int getParentCategoryID() {
107         return threadXML.getParentCategoryID(); //==parentForum.getParentCategoryID();
108
}
109
110     public int getParentForumID() {
111         return threadXML.getParentForumID(); //==parentForum.getForumID();
112
}
113
114     public void setParentForum(Object JavaDoc o)
115     throws ForeignKeyNotFoundException {
116         if (o instanceof MvnForumForumXML) {
117             parentForum=(MvnForumForumXML)o;
118             //warning: parent forum might be not added to database yet
119
} else {
120             throw new ForeignKeyNotFoundException("Can't find parent forum.");
121         }
122     }
123
124     public void setThreadMemberName(String JavaDoc value) {
125         threadMemberName=value;
126     }
127
128     public void setThreadLastPostMemberName(String JavaDoc value) {
129         threadLastPostMemberName=value;
130     }
131
132     public void setThreadTopic(String JavaDoc value) {
133         threadTopic=value;
134     }
135
136     public void setThreadBody(String JavaDoc value) {
137         threadBody=value;
138     }
139
140     public void setThreadVoteCount(String JavaDoc value) {
141         threadVoteCount=value;
142     }
143
144     public void setThreadVoteTotalStars(String JavaDoc value) {
145         threadVoteTotalStars=value;
146     }
147
148     public void setThreadCreationDate(String JavaDoc value) {
149         threadCreationDate=value;
150     }
151
152     public void setThreadLastPostDate(String JavaDoc value) {
153         threadLastPostDate=value;
154     }
155
156     public void setThreadType(String JavaDoc value) {
157         threadType=value;
158     }
159
160     public void setThreadOption(String JavaDoc value) {
161         threadOption=value;
162     }
163
164     public void setThreadStatus(String JavaDoc value) {
165         threadStatus=value;
166     }
167
168     public void setThreadHasPoll(String JavaDoc value) {
169         threadHasPoll=value;
170     }
171
172     public void setThreadViewCount(String JavaDoc value) {
173         threadViewCount=value;
174     }
175
176     public void setThreadReplyCount(String JavaDoc value) {
177         threadReplyCount=value;
178     }
179
180     public void setThreadIcon(String JavaDoc value) {
181         threadIcon=value;
182     }
183
184     public void setThreadDuration(String JavaDoc value) {
185         threadDuration=value;
186     }
187
188     public void setThreadAttachCount(String JavaDoc value) {
189         threadAttachCount=value;
190     }
191
192     public void addThread() throws CreateException, DuplicateKeyException,
193     ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException, BadInputException {
194         /* First, check if the digester already called this method.
195          * It will happen even under normal circumstances, if this thread has
196          * subelements that need it already be defined, so they first call
197          * this method to create thread before creating data that refer him.
198          */

199         if (threadCreated) return;
200         /* Second, create parent forum if it's not yet created. */
201         if (parentForum!=null) {
202             parentForum.addForum();
203             threadXML.setParentForumID(parentForum.getForumID());
204             threadXML.setParentCategoryID(parentForum.getParentCategoryID());
205         }
206
207         ImportMvnForum.addMessage("Adding thread \""+threadTopic+"\".");
208         threadXML.addThread(threadMemberName, threadLastPostMemberName,
209                             threadTopic, threadBody,
210                             threadVoteCount, threadVoteTotalStars,
211                             threadCreationDate, threadLastPostDate,
212                             threadType, threadOption,
213                             threadStatus, threadHasPoll,
214                             threadViewCount, threadReplyCount,
215                             threadIcon, threadDuration, threadAttachCount);
216         threadCreated=true;
217
218         if (parentForum!=null) {
219             parentForum.updateAddedThread(this);
220         }
221     }
222
223     public void addThreadWatch(String JavaDoc memberName,
224                 String JavaDoc watchType, String JavaDoc watchOption,
225                 String JavaDoc watchStatus, String JavaDoc watchCreationDate,
226                 String JavaDoc watchLastSentDate, String JavaDoc watchEndDate)
227     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
228     DatabaseException, ForeignKeyNotFoundException, BadInputException {
229         if ( (!threadCreated) || (threadXML.getThreadID()<0) ) {
230             addThread();
231         }
232         ImportMvnForum.addMessage("Adding thread watch for member \""+memberName+"\".");
233         threadXML.addThreadWatch(memberName,
234                   watchType, watchOption, watchStatus,
235                   watchCreationDate, watchLastSentDate, watchEndDate);
236     }
237
238     public void addFavoriteThread(String JavaDoc memberName,
239                 String JavaDoc favoriteCreationDate, String JavaDoc favoriteType,
240                 String JavaDoc favoriteOption, String JavaDoc favoriteStatus)
241     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
242     DatabaseException, ForeignKeyNotFoundException, BadInputException {
243         if ( (!threadCreated) || (threadXML.getThreadID()<0) ) {
244             addThread();
245         }
246         ImportMvnForum.addMessage("Adding favorite-thread for member \""+memberName+"\".");
247         threadXML.addFavoriteThread(memberName,
248                   favoriteCreationDate, favoriteType,
249                   favoriteOption, favoriteStatus);
250     }
251
252     public void updateAddedPost(MvnForumPostXML subPost, String JavaDoc postUsername, String JavaDoc postCreationDate) {
253         if ((!threadCreated) || (threadXML.getThreadID()<0)) return; //todo Igor: process this error
254
//do nothing; MVN Forum XML already has correct final values for these:
255
//if (subPost.getParentPostID()!=0) {//reply to a post in thread, so we increase the ThreadReplyCount
256
// threadXML.increaseReplyCount();
257
//}
258
//threadXML.updateLastPostMemberName(postUsername);
259
//threadXML.updateLastPostDate(postCreationDate);
260
if (parentForum!=null) {
261             parentForum.updateAddedPost(subPost, postUsername, postCreationDate);
262         }
263     }
264
265     public void updateAddedAttachment(MvnForumAttachmentXML subAttachment) {
266         if ((!threadCreated) || (threadXML.getThreadID()<0)) return; //todo Igor: process this error
267
//do nothing; MVN Forum XML already has correct final values for these:
268
// //check what is needed to be updated
269
if (parentForum!=null) {
270             parentForum.updateAddedAttachment(subAttachment);
271         }
272     }
273
274
275 }
276
Popular Tags