KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumPostXML.java,v 1.6 2006/04/14 17:36:29 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.6 $
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.PostXML;
43 import net.myvietnam.mvncore.exception.*;
44
45 /**
46  * @author Igor Manic
47  * @version $Revision: 1.6 $, $Date: 2006/04/14 17:36:29 $
48  * <br/>
49  * <code>MvnForumPostXML</code> class encapsulates processing of
50  * posts' 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>PostXML</code> and other neccessary classes in order to perform
54  * the actual creation of a post.
55  */

56 public class MvnForumPostXML {
57
58     private PostXML postXML=null;
59     private boolean postCreated=false;
60     //only one of parentPost and parentThread will be defined (later), and the other will be null
61
private MvnForumThreadXML parentThread =null;
62     private MvnForumPostXML parentPost =null;
63
64     String JavaDoc postMemberName = null;
65     String JavaDoc postLastEditMemberName = null;
66     String JavaDoc postTopic = null;
67     String JavaDoc postBody = null;
68     String JavaDoc postCreationDate = null;
69     String JavaDoc postLastEditDate = null;
70     String JavaDoc postCreationIP = null;
71     String JavaDoc postLastEditIP = null;
72     String JavaDoc postEditCount = null;
73     String JavaDoc postFormatOption = null;
74     String JavaDoc postOption = null;
75     String JavaDoc postStatus = null;
76     String JavaDoc postIcon = null;
77     String JavaDoc postAttachCount = null;
78
79     public MvnForumPostXML() {
80         super();
81         postXML=new PostXML();
82         postCreated=false;
83         parentThread=null;
84         parentPost=null;
85     }
86
87     public int getPostID() {
88         return postXML.getPostID();
89     }
90
91     public void setPostID(String JavaDoc id) {
92         postXML.setPostID(id);
93     }
94
95     /**
96      * This method simply calls <code>setPostID()</code>.
97      * It's defined only to avoid property-setter problems with digester
98      * (since it doesn't seem to recognize <code>setPostID()</code> as a setter
99      * method for <code>postID</code> property).
100      */

101     public void setPostId(String JavaDoc id) {
102         setPostID(id);
103     }
104
105     public int getParentCategoryID() {
106         return postXML.getParentCategoryID();
107     }
108
109     public int getParentForumID() {
110         return postXML.getParentForumID();
111     }
112
113     public int getParentThreadID() {
114         return postXML.getParentThreadID();
115     }
116
117     public int getParentPostID() {
118         return postXML.getParentPostID();
119     }
120
121     public void setParentThreadOrPost(Object JavaDoc o)
122     throws ForeignKeyNotFoundException {
123         if (o instanceof MvnForumThreadXML) {
124             parentThread=(MvnForumThreadXML)o;
125             //warning: parent thread might be not added to database yet
126
parentPost=null;
127         } else if (o instanceof MvnForumPostXML) {
128             parentPost=(MvnForumPostXML)o;
129             //warning: parent post might be not added to database yet
130
parentThread=null;
131         } else {
132             throw new ForeignKeyNotFoundException("Can't find neither parent thread nor post.");
133         }
134     }
135
136     public void setPostMemberName(String JavaDoc value) {
137         postMemberName=value;
138     }
139
140     public void setPostLastEditMemberName(String JavaDoc value) {
141         postLastEditMemberName=value;
142     }
143
144     public void setPostTopic(String JavaDoc value) {
145         postTopic=value;
146     }
147
148     public void setPostBody(String JavaDoc value) {
149         postBody=value;
150     }
151
152     public void setPostCreationDate(String JavaDoc value) {
153         postCreationDate=value;
154     }
155
156     public void setPostLastEditDate(String JavaDoc value) {
157         postLastEditDate=value;
158     }
159
160     public void setPostCreationIP(String JavaDoc value) {
161         postCreationIP=value;
162     }
163
164     public void setPostLastEditIP(String JavaDoc value) {
165         postLastEditIP=value;
166     }
167
168     public void setPostEditCount(String JavaDoc value) {
169         postEditCount=value;
170     }
171
172     public void setPostFormatOption(String JavaDoc value) {
173         postFormatOption=value;
174     }
175
176     public void setPostOption(String JavaDoc value) {
177         postOption=value;
178     }
179
180     public void setPostStatus(String JavaDoc value) {
181         postStatus=value;
182     }
183
184     public void setPostIcon(String JavaDoc value) {
185         postIcon=value;
186     }
187
188     public void setPostAttachCount(String JavaDoc value) {
189         postAttachCount=value;
190     }
191
192     public void addPost() 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 post has
196          * subelements that need it already be defined, so they first call
197          * this method to create post before creating data that refer him.
198          */

199         if (postCreated) return;
200         /* Second, create parent thread and/or post if they are not yet created. */
201         if (parentPost!=null) {
202             parentPost.addPost();
203             postXML.setParentPostID(parentPost.getPostID());
204             postXML.setParentThreadID(parentPost.getParentThreadID());
205             postXML.setParentForumID(parentPost.getParentForumID());
206             postXML.setParentCategoryID(parentPost.getParentCategoryID());
207         } else if (parentThread!=null) {
208             parentThread.addThread();
209             //postXML.setParentPostID(0) is not neccessary
210
postXML.setParentThreadID(parentThread.getThreadID());
211             postXML.setParentForumID(parentThread.getParentForumID());
212             postXML.setParentCategoryID(parentThread.getParentCategoryID());
213         }
214
215         ImportMvnForum.addMessage("Adding post \""+postTopic+"\".");
216         postXML.addPost(postMemberName, postLastEditMemberName,
217                         postTopic, postBody,
218                         postCreationDate, postLastEditDate,
219                         postCreationIP, postLastEditIP,
220                         postEditCount, postFormatOption,
221                         postOption, postStatus,
222                         postIcon, postAttachCount);
223         postCreated=true;
224
225         if (parentPost!=null) {
226             parentPost.updateAddedReply(this, postMemberName, postCreationDate);
227         } else if (parentThread!=null) {
228             parentThread.updateAddedPost(this, postMemberName, postCreationDate);
229         }
230     }
231
232     public void updateAddedReply(MvnForumPostXML subPost, String JavaDoc postUsername, String JavaDoc postCreationDate) {
233         if ((!postCreated) || (postXML.getPostID()<0)) return; //todo Igor: process this error
234
//do nothing; MVN Forum XML already has correct final values for these:
235
//if (subPost.getParentPostID()!=0) {//reply to a post in thread, so we increase the ThreadReplyCount
236
// threadXML.increaseReplyCount();
237
//}
238
//threadXML.updateLastPostMemberName(postUsername);
239
//threadXML.updateLastPostDate(postCreationDate);
240
if (parentPost!=null) {
241             parentPost.updateAddedReply(subPost, postUsername, postCreationDate);
242         } else if (parentThread!=null) {
243             parentThread.updateAddedPost(subPost, postUsername, postCreationDate);
244         }
245     }
246
247     public void updateAddedAttachment(MvnForumAttachmentXML subAttachment) {
248         if ((!postCreated) || (postXML.getPostID()<0)) return; //todo Igor: process this error
249
//do nothing; MVN Forum XML already has correct final values for these:
250
// //check what is needed to be updated
251
if (parentPost!=null) {
252             parentPost.updateAddedAttachment(subAttachment);
253         } else if (parentThread!=null) {
254             parentThread.updateAddedAttachment(subAttachment);
255         }
256     }
257
258
259 }
260
Popular Tags