001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumPostXML.java,v 1.7 2007/01/15 10:27:35 dungbtm Exp $
003: * $Author: dungbtm $
004: * $Revision: 1.7 $
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.PostXML;
043: import net.myvietnam.mvncore.exception.*;
044:
045: /**
046: * @author Igor Manic
047: * @version $Revision: 1.7 $, $Date: 2007/01/15 10:27:35 $
048: * <br/>
049: * <code>MvnForumPostXML</code> class encapsulates processing of
050: * posts' 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>PostXML</code> and other neccessary classes in order to perform
054: * the actual creation of a post.
055: */
056: public class MvnForumPostXML {
057:
058: private PostXML postXML = null;
059: private boolean postCreated = false;
060: //only one of parentPost and parentThread will be defined (later), and the other will be null
061: private MvnForumThreadXML parentThread = null;
062: private MvnForumPostXML parentPost = null;
063:
064: String postMemberName = null;
065: String postLastEditMemberName = null;
066: String postTopic = null;
067: String postBody = null;
068: String postCreationDate = null;
069: String postLastEditDate = null;
070: String postCreationIP = null;
071: String postLastEditIP = null;
072: String postEditCount = null;
073: String postFormatOption = null;
074: String postOption = null;
075: String postStatus = null;
076: String postIcon = null;
077: String postAttachCount = null;
078:
079: public MvnForumPostXML() {
080: super ();
081: postXML = new PostXML();
082: postCreated = false;
083: parentThread = null;
084: parentPost = null;
085: }
086:
087: public int getPostID() {
088: return postXML.getPostID();
089: }
090:
091: public void setPostID(String id) {
092: postXML.setPostID(id);
093: }
094:
095: /**
096: * This method simply calls <code>setPostID()</code>.
097: * It's defined only to avoid property-setter problems with digester
098: * (since it doesn't seem to recognize <code>setPostID()</code> as a setter
099: * method for <code>postID</code> property).
100: */
101: public void setPostId(String 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 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(
133: "Can't find neither parent thread nor post.");
134: }
135: }
136:
137: public void setPostMemberName(String value) {
138: postMemberName = value;
139: }
140:
141: public void setPostLastEditMemberName(String value) {
142: postLastEditMemberName = value;
143: }
144:
145: public void setPostTopic(String value) {
146: postTopic = value;
147: }
148:
149: public void setPostBody(String value) {
150: postBody = value;
151: }
152:
153: public void setPostCreationDate(String value) {
154: postCreationDate = value;
155: }
156:
157: public void setPostLastEditDate(String value) {
158: postLastEditDate = value;
159: }
160:
161: public void setPostCreationIP(String value) {
162: postCreationIP = value;
163: }
164:
165: public void setPostLastEditIP(String value) {
166: postLastEditIP = value;
167: }
168:
169: public void setPostEditCount(String value) {
170: postEditCount = value;
171: }
172:
173: public void setPostFormatOption(String value) {
174: postFormatOption = value;
175: }
176:
177: public void setPostOption(String value) {
178: postOption = value;
179: }
180:
181: public void setPostStatus(String value) {
182: postStatus = value;
183: }
184:
185: public void setPostIcon(String value) {
186: postIcon = value;
187: }
188:
189: public void setPostAttachCount(String value) {
190: postAttachCount = value;
191: }
192:
193: public void addPost() throws CreateException,
194: DuplicateKeyException, ObjectNotFoundException,
195: DatabaseException, ForeignKeyNotFoundException,
196: BadInputException {
197: /* First, check if the digester already called this method.
198: * It will happen even under normal circumstances, if this post has
199: * subelements that need it already be defined, so they first call
200: * this method to create post before creating data that refer him.
201: */
202: if (postCreated)
203: return;
204: /* Second, create parent thread and/or post if they are not yet created. */
205: if (parentPost != null) {
206: parentPost.addPost();
207: postXML.setParentPostID(parentPost.getPostID());
208: postXML.setParentThreadID(parentPost.getParentThreadID());
209: postXML.setParentForumID(parentPost.getParentForumID());
210: postXML.setParentCategoryID(parentPost
211: .getParentCategoryID());
212: } else if (parentThread != null) {
213: parentThread.addThread();
214: //postXML.setParentPostID(0) is not neccessary
215: postXML.setParentThreadID(parentThread.getThreadID());
216: postXML.setParentForumID(parentThread.getParentForumID());
217: postXML.setParentCategoryID(parentThread
218: .getParentCategoryID());
219: }
220:
221: ImportMvnForum.addMessage("Adding post \"" + postTopic + "\".");
222: postXML.addPost(postMemberName, postLastEditMemberName,
223: postTopic, postBody, postCreationDate,
224: postLastEditDate, postCreationIP, postLastEditIP,
225: postEditCount, postFormatOption, postOption,
226: postStatus, postIcon, postAttachCount);
227: postCreated = true;
228:
229: if (parentPost != null) {
230: parentPost.updateAddedReply(this , postMemberName,
231: postCreationDate);
232: } else if (parentThread != null) {
233: parentThread.updateAddedPost(this , postMemberName,
234: postCreationDate);
235: }
236: }
237:
238: public void updateAddedReply(MvnForumPostXML subPost,
239: String postUsername, String postCreationDate) {
240: if ((!postCreated) || (postXML.getPostID() < 0))
241: return; //todo Igor: process this error
242: //do nothing; MVN Forum XML already has correct final values for these:
243: //if (subPost.getParentPostID()!=0) {//reply to a post in thread, so we increase the ThreadReplyCount
244: // threadXML.increaseReplyCount();
245: //}
246: //threadXML.updateLastPostMemberName(postUsername);
247: //threadXML.updateLastPostDate(postCreationDate);
248: if (parentPost != null) {
249: parentPost.updateAddedReply(subPost, postUsername,
250: postCreationDate);
251: } else if (parentThread != null) {
252: parentThread.updateAddedPost(subPost, postUsername,
253: postCreationDate);
254: }
255: }
256:
257: public void updateAddedAttachment(
258: MvnForumAttachmentXML subAttachment) {
259: if ((!postCreated) || (postXML.getPostID() < 0))
260: return; //todo Igor: process this error
261: //do nothing; MVN Forum XML already has correct final values for these:
262: // //check what is needed to be updated
263: if (parentPost != null) {
264: parentPost.updateAddedAttachment(subAttachment);
265: } else if (parentThread != null) {
266: parentThread.updateAddedAttachment(subAttachment);
267: }
268: }
269:
270: }
|