001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumThreadXML.java,v 1.9 2007/01/15 10:27:35 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.9 $
005: * $Date: 2007/01/15 10:27:35 $
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.importexport.mvnforum;
041:
042: import com.mvnforum.admin.ThreadXML;
043: import net.myvietnam.mvncore.exception.*;
044:
045: /**
046: * @author Igor Manic
047: * @version $Revision: 1.9 $, $Date: 2007/01/15 10:27:35 $
048: * <br/>
049: * <code>MvnForumThreadXML</code> class encapsulates processing of
050: * threads' definitions found in the backup XML file. It implements
051: * methods to be called from XML parsing routine, adds some additional
052: * processing and checking, and calls corresponding methods of
053: * <code>ThreadXML</code> and other neccessary classes in order to perform
054: * the actual creation of a thread, as well as other related items (like
055: * favorite threads and thread watches).
056: */
057: public class MvnForumThreadXML {
058:
059: private ThreadXML threadXML = null;
060: private boolean threadCreated = false;
061: private MvnForumForumXML parentForum = null;
062:
063: String threadMemberName = null;
064: String threadLastPostMemberName = null;
065: String threadTopic = null;
066: String threadBody = null;
067: String threadVoteCount = null;
068: String threadVoteTotalStars = null;
069: String threadCreationDate = null;
070: String threadLastPostDate = null;
071: String threadType = null;
072: String threadPriority = null;
073: String threadOption = null;
074: String threadStatus = null;
075: String threadHasPoll = null;
076: String threadViewCount = null;
077: String threadReplyCount = null;
078: String threadIcon = null;
079: String threadDuration = null;
080: String threadAttachCount = null;
081:
082: public MvnForumThreadXML() {
083: super ();
084: threadXML = new ThreadXML();
085: threadCreated = false;
086: parentForum = null;
087: }
088:
089: public int getThreadID() {
090: return threadXML.getThreadID();
091: }
092:
093: public void setThreadID(String id) {
094: threadXML.setThreadID(id);
095: }
096:
097: /**
098: * This method simply calls <code>setThreadID()</code>.
099: * It's defined only to avoid property-setter problems with digester
100: * (since it doesn't seem to recognize <code>setThreadID()</code> as a setter
101: * method for <code>threadID</code> property).
102: */
103: public void setThreadId(String id) {
104: setThreadID(id);
105: }
106:
107: public int getParentCategoryID() {
108: return threadXML.getParentCategoryID(); //==parentForum.getParentCategoryID();
109: }
110:
111: public int getParentForumID() {
112: return threadXML.getParentForumID(); //==parentForum.getForumID();
113: }
114:
115: public void setParentForum(Object o)
116: throws ForeignKeyNotFoundException {
117: if (o instanceof MvnForumForumXML) {
118: parentForum = (MvnForumForumXML) o;
119: //warning: parent forum might be not added to database yet
120: } else {
121: throw new ForeignKeyNotFoundException(
122: "Can't find parent forum.");
123: }
124: }
125:
126: public void setThreadMemberName(String value) {
127: threadMemberName = value;
128: }
129:
130: public void setThreadLastPostMemberName(String value) {
131: threadLastPostMemberName = value;
132: }
133:
134: public void setThreadTopic(String value) {
135: threadTopic = value;
136: }
137:
138: public void setThreadBody(String value) {
139: threadBody = value;
140: }
141:
142: public void setThreadVoteCount(String value) {
143: threadVoteCount = value;
144: }
145:
146: public void setThreadVoteTotalStars(String value) {
147: threadVoteTotalStars = value;
148: }
149:
150: public void setThreadCreationDate(String value) {
151: threadCreationDate = value;
152: }
153:
154: public void setThreadLastPostDate(String value) {
155: threadLastPostDate = value;
156: }
157:
158: public void setThreadType(String value) {
159: threadType = value;
160: }
161:
162: public void setThreadOption(String value) {
163: threadOption = value;
164: }
165:
166: public void setThreadStatus(String value) {
167: threadStatus = value;
168: }
169:
170: public void setThreadHasPoll(String value) {
171: threadHasPoll = value;
172: }
173:
174: public void setThreadViewCount(String value) {
175: threadViewCount = value;
176: }
177:
178: public void setThreadReplyCount(String value) {
179: threadReplyCount = value;
180: }
181:
182: public void setThreadIcon(String value) {
183: threadIcon = value;
184: }
185:
186: public void setThreadDuration(String value) {
187: threadDuration = value;
188: }
189:
190: public void setThreadAttachCount(String value) {
191: threadAttachCount = value;
192: }
193:
194: public String getThreadPriority() {
195: return threadPriority;
196: }
197:
198: public void setThreadPriority(String threadPriority) {
199: this .threadPriority = threadPriority;
200: }
201:
202: public void addThread() throws CreateException,
203: DuplicateKeyException, ObjectNotFoundException,
204: DatabaseException, ForeignKeyNotFoundException,
205: BadInputException {
206: /* First, check if the digester already called this method.
207: * It will happen even under normal circumstances, if this thread has
208: * subelements that need it already be defined, so they first call
209: * this method to create thread before creating data that refer him.
210: */
211: if (threadCreated)
212: return;
213: /* Second, create parent forum if it's not yet created. */
214: if (parentForum != null) {
215: parentForum.addForum();
216: threadXML.setParentForumID(parentForum.getForumID());
217: threadXML.setParentCategoryID(parentForum
218: .getParentCategoryID());
219: }
220:
221: ImportMvnForum.addMessage("Adding thread \"" + threadTopic
222: + "\".");
223: threadXML.addThread(threadMemberName, threadLastPostMemberName,
224: threadTopic, threadBody, threadVoteCount,
225: threadVoteTotalStars, threadCreationDate,
226: threadLastPostDate, threadType, threadPriority,
227: threadOption, threadStatus, threadHasPoll,
228: threadViewCount, threadReplyCount, threadIcon,
229: threadDuration, threadAttachCount);
230: threadCreated = true;
231:
232: if (parentForum != null) {
233: parentForum.updateAddedThread(this );
234: }
235: }
236:
237: public void addThreadWatch(String memberName, String watchType,
238: String watchOption, String watchStatus,
239: String watchCreationDate, String watchLastSentDate,
240: String watchEndDate) throws CreateException,
241: DuplicateKeyException, ObjectNotFoundException,
242: DatabaseException, ForeignKeyNotFoundException,
243: BadInputException {
244: if ((!threadCreated) || (threadXML.getThreadID() < 0)) {
245: addThread();
246: }
247: ImportMvnForum.addMessage("Adding thread watch for member \""
248: + memberName + "\".");
249: threadXML.addThreadWatch(memberName, watchType, watchOption,
250: watchStatus, watchCreationDate, watchLastSentDate,
251: watchEndDate);
252: }
253:
254: public void addFavoriteThread(String memberName,
255: String favoriteCreationDate, String favoriteType,
256: String favoriteOption, String favoriteStatus)
257: throws CreateException, DuplicateKeyException,
258: ObjectNotFoundException, DatabaseException,
259: ForeignKeyNotFoundException, BadInputException {
260: if ((!threadCreated) || (threadXML.getThreadID() < 0)) {
261: addThread();
262: }
263: ImportMvnForum
264: .addMessage("Adding favorite-thread for member \""
265: + memberName + "\".");
266: threadXML.addFavoriteThread(memberName, favoriteCreationDate,
267: favoriteType, favoriteOption, favoriteStatus);
268: }
269:
270: public void updateAddedPost(MvnForumPostXML subPost,
271: String postUsername, String postCreationDate) {
272: if ((!threadCreated) || (threadXML.getThreadID() < 0))
273: return; //todo Igor: process this error
274: //do nothing; MVN Forum XML already has correct final values for these:
275: //if (subPost.getParentPostID()!=0) {//reply to a post in thread, so we increase the ThreadReplyCount
276: // threadXML.increaseReplyCount();
277: //}
278: //threadXML.updateLastPostMemberName(postUsername);
279: //threadXML.updateLastPostDate(postCreationDate);
280: if (parentForum != null) {
281: parentForum.updateAddedPost(subPost, postUsername,
282: postCreationDate);
283: }
284: }
285:
286: public void updateAddedAttachment(
287: MvnForumAttachmentXML subAttachment) {
288: if ((!threadCreated) || (threadXML.getThreadID() < 0))
289: return; //todo Igor: process this error
290: //do nothing; MVN Forum XML already has correct final values for these:
291: // //check what is needed to be updated
292: if (parentForum != null) {
293: parentForum.updateAddedAttachment(subAttachment);
294: }
295: }
296:
297: }
|