KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > importexport > jive > JiveThreadXML


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/jive/JiveThreadXML.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.jive;
41
42 import java.sql.Timestamp JavaDoc;
43 import java.util.Vector JavaDoc;
44
45 import com.mvnforum.admin.PostXML;
46 import com.mvnforum.admin.ThreadXML;
47 import net.myvietnam.mvncore.exception.*;
48
49 /**
50  * @author Igor Manic
51  * @version $Revision: 1.7 $, $Date: 2006/04/14 17:36:29 $
52  * <br/>
53  * <code>JiveThreadXML</code> class encapsulates processing of
54  * threads' definitions found in the Jive XML file. It implements
55  * methods to be called from XML parsing routine, adds some additional
56  * processing and checking, and calls corresponding methods of
57  * <code>ThreadXML</code> and other neccessary classes in order to perform
58  * the actual creation of a thread, as well as thread watches.
59  */

60 public class JiveThreadXML {
61
62     private ThreadXML threadXML=null;
63     private boolean threadCreated=false;
64     private Vector JavaDoc threadWatchesToAddLater=new Vector JavaDoc();
65     private JiveForumXML parentForum =null;
66
67     public JiveThreadXML() {
68         super();
69         threadXML=new ThreadXML();
70         threadCreated=false;
71         parentForum=null;
72     }
73
74     public void setThreadID(String JavaDoc id) {
75         threadXML.setThreadID(id);
76     }
77
78     /**
79      * This method simply calls <code>setThreadID()</code>.
80      * It's defined only to avoid property-setter problems with digester
81      * (since it doesn't seem to recognize <code>setThreadID()</code> as a setter
82      * method for <code>threadID</code> property).
83      */

84     public void setThreadId(String JavaDoc id) {
85         setThreadID(id);
86     }
87
88     public int getThreadID() { return threadXML.getThreadID(); }
89
90     public int getParentCategoryID() {
91         return threadXML.getParentCategoryID();
92     }
93
94     public int getParentForumID() {
95         return threadXML.getParentForumID();
96     }
97
98     public void setParentForum(Object JavaDoc o)
99     throws ForeignKeyNotFoundException {
100         if (o instanceof JiveForumXML) {
101             parentForum=(JiveForumXML)o;
102             //warning: parent forum might not be added to database yet
103
} else {
104             throw new ForeignKeyNotFoundException("Can't find parent forum.");
105         }
106     }
107
108     private String JavaDoc threadTopic=null;
109     public void setTopic(String JavaDoc value) throws CreateException {
110         if ( (value==null) || (value.equals("")) ) {
111             throw new CreateException("Cannot create a thread with an empty ThreadTopic.");
112         } else this.threadTopic=value;
113     }
114
115     private String JavaDoc threadBody=null;
116     public void setBody(String JavaDoc value) throws CreateException {
117         if ( (value==null) || (value.equals("")) ) {
118             throw new CreateException("Cannot create a thread with an empty ThreadBody.");
119         } else this.threadBody=value;
120     }
121
122     private String JavaDoc threadUsername=null;
123     public void setUsername(String JavaDoc value) throws CreateException {
124         this.threadUsername=value;
125     }
126
127     private String JavaDoc threadCreationDate=null;
128     public void setCreationDate(String JavaDoc value) throws CreateException {
129         this.threadCreationDate=value;
130     }
131
132     private String JavaDoc threadModifiedDate=null;
133     public void setModifiedDate(String JavaDoc value) throws CreateException {
134         this.threadModifiedDate=value;
135     }
136
137     public void addJiveThread() throws BadInputException, CreateException,
138     DatabaseException, ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
139         /* This method is here because of the digester rule it could fire it, but
140          * actually, this shouldn't happen, because the first <Message> of the thread
141          * will call addJiveThread(firstMessageUsername, firstMessageSubject, firstMessageBody)
142          * so this method will be called only after threadCreated is already
143          * set to true (because of that previous executions of the other addJiveThread method).
144          */

145         if (!threadCreated) addJiveThread(threadUsername, threadTopic, threadBody);
146     }
147
148     public void addJiveThread(String JavaDoc firstMessageUsername, String JavaDoc firstMessageSubject, String JavaDoc firstMessageBody)
149     throws BadInputException, CreateException,
150     DatabaseException, ObjectNotFoundException, DuplicateKeyException, ForeignKeyNotFoundException {
151         /* First check if the digester already called this method.
152          * It will happen even under normal circumstances, if this thread has
153          * subelements that need it already be defined, so they first call
154          * this method to create thread before creating data that refer him.
155          */

156         if (threadCreated) return;
157         setUsername(firstMessageUsername);
158         setTopic(firstMessageSubject);
159         setBody(firstMessageBody);
160         /* Second, create parent forum if it's not yet created. */
161         if (parentForum!=null) {
162             parentForum.addJiveForum();
163             threadXML.setParentForumID(parentForum.getForumID());
164             threadXML.setParentCategoryID(parentForum.getParentCategoryID());
165         }
166
167         ImportJive.addMessage("Adding Jive thread \""+threadTopic+"\".");
168         threadXML.addThread(threadUsername, threadUsername/*lastPostMemberName*/,
169                             threadTopic, threadBody,
170                             null/*threadVoteCount*/, null/*threadVoteTotalStars*/,
171                             threadCreationDate, threadModifiedDate/*threadLastPostDate*/,
172                             null/*threadType*/, null/*threadOption*/,
173                             null/*threadStatus*/, null/*threadHasPoll*/,
174                             null/*threadViewCount*/, null/*threadReplyCount*/,
175                             null/*threadIcon*/, null/*threadDuration*/, null/*threadAttachCount*/ );
176         threadCreated=true;
177
178         for (int i=0; i<threadWatchesToAddLater.size(); i++) {
179             String JavaDoc memberName= (String JavaDoc)threadWatchesToAddLater.elementAt(i);
180             ImportJive.addMessage("Adding thread watch for member \""+memberName+"\".");
181             threadXML.addThreadWatch(memberName,
182                       null/*watchType*/, null/*watchOption*/,
183                       null/*watchStatus*/, null/*watchCreationDate*/,
184                       null/*watchLastSentDate*/, null/*watchEndDate*/);
185         }
186         threadWatchesToAddLater.clear();
187
188         if (parentForum!=null) {
189             parentForum.updateAddedThread(threadXML); //update parents
190
}
191     }
192
193     public void addJiveThreadWatch(String JavaDoc type, String JavaDoc expirable, String JavaDoc username)
194     throws CreateException {
195         /* expirable and type are ignored
196          * expirable is "true" or "false", default is "true"
197          * type is "NORMAL_WATCH" or "EMAIL_NOTIFY_WATCH"
198          * MVN Forum supports only email notify watches
199          */

200         threadWatchesToAddLater.add(username);
201     }
202
203     public void updateAddedPost(PostXML postXML, String JavaDoc postUsername, Timestamp JavaDoc postCreationDate)
204     throws ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
205         if (postXML.getParentPostID()!=0) {//reply to a post in thread, so we increase the ThreadReplyCount
206
threadXML.increaseReplyCount();
207         }
208         threadXML.updateLastPostMemberName(postUsername);
209         threadXML.updateLastPostDate(postCreationDate);
210         if (parentForum!=null) {
211             //update parents
212
parentForum.updateAddedPost(postXML, postUsername, postCreationDate);
213         }
214     }
215
216
217 }
218
219
220
Popular Tags