001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/importexport/mvnforum/MvnForumForumXML.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.ForumXML;
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>MvnForumForumXML</code> class encapsulates processing of
050: * forums' 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>ForumXML</code> and other neccessary classes in order to perform
054: * the actual creation of a forum, as well as other related items (like
055: * forum watches).
056: */
057: public class MvnForumForumXML {
058:
059: private ForumXML forumXML = null;
060: private boolean forumCreated = false;
061: private MvnForumCategoryXML parentCategory = null;
062:
063: String lastPostMemberName = null;
064: String forumName = null;
065: String forumDesc = null;
066: String forumCreationDate = null;
067: String forumModifiedDate = null;
068: String forumLastPostDate = null;
069: String forumOrder = null;
070: String forumType = null;
071: String forumFormatOption = null;
072: String forumOption = null;
073: String forumStatus = null;
074: String forumModerationMode = null;
075: String forumPassword = null;
076: String forumThreadCount = null;
077: String forumPostCount = null;
078:
079: public MvnForumForumXML() {
080: super ();
081: forumXML = new ForumXML();
082: forumCreated = false;
083: parentCategory = null;
084: }
085:
086: public int getForumID() {
087: return forumXML.getForumID();
088: }
089:
090: public void setForumID(String id) {
091: forumXML.setForumID(id);
092: }
093:
094: /**
095: * This method simply calls <code>setForumID()</code>.
096: * It's defined only to avoid property-setter problems with digester
097: * (since it doesn't seem to recognize <code>setForumID()</code> as a setter
098: * method for <code>forumID</code> property).
099: */
100: public void setForumId(String id) {
101: setForumID(id);
102: }
103:
104: public int getParentCategoryID() {
105: return forumXML.getParentCategoryID(); //==parentCategory.getCategoryID();
106: }
107:
108: public void setParentCategory(Object o)
109: throws ForeignKeyNotFoundException {
110: if (o instanceof MvnForumCategoryXML) {
111: parentCategory = (MvnForumCategoryXML) o;
112: /* warning: parent category might not be added to database yet, so
113: * we don't have parentCategoryID now, and can't do this here:
114: * forumXML.setParentCategoryID(parentCategory.getCategoryID());
115: */
116: } else {
117: throw new ForeignKeyNotFoundException(
118: "Can't find parent category.");
119: }
120: }
121:
122: public void setForumLastPostMemberName(String value) {
123: lastPostMemberName = value;
124: }
125:
126: public void setForumName(String value) {
127: forumName = value;
128: }
129:
130: public void setForumDesc(String value) {
131: forumDesc = value;
132: }
133:
134: public void setForumCreationDate(String value) {
135: forumCreationDate = value;
136: }
137:
138: public void setForumModifiedDate(String value) {
139: forumModifiedDate = value;
140: }
141:
142: public void setForumLastPostDate(String value) {
143: forumLastPostDate = value;
144: }
145:
146: public void setForumOrder(String value) {
147: forumOrder = value;
148: }
149:
150: public void setForumType(String value) {
151: forumType = value;
152: }
153:
154: public void setForumFormatOption(String value) {
155: forumFormatOption = value;
156: }
157:
158: public void setForumOption(String value) {
159: forumOption = value;
160: }
161:
162: public void setForumStatus(String value) {
163: forumStatus = value;
164: }
165:
166: public void setForumModerationMode(String value) {
167: forumModerationMode = value;
168: }
169:
170: public void setForumPassword(String value) {
171: forumPassword = value;
172: }
173:
174: public void setForumThreadCount(String value) {
175: forumThreadCount = value;
176: }
177:
178: public void setForumPostCount(String value) {
179: forumPostCount = value;
180: }
181:
182: public void addForum() throws CreateException,
183: DuplicateKeyException, ObjectNotFoundException,
184: DatabaseException, ForeignKeyNotFoundException,
185: BadInputException {
186: /* First, check if the digester already called this method.
187: * It will happen even under normal circumstances, if this forum has
188: * subelements that need it already be defined, so they first call
189: * this method to create forum before creating data that refer him.
190: */
191: if (forumCreated)
192: return;
193: /* Second, create parent category if it's not yet created. */
194: if (parentCategory != null) {
195: parentCategory.addCategory();
196: forumXML
197: .setParentCategoryID(parentCategory.getCategoryID());
198: }
199:
200: ImportMvnForum
201: .addMessage("Adding forum \"" + forumName + "\".");
202: forumXML.addForum(lastPostMemberName, forumName, forumDesc,
203: forumCreationDate, forumModifiedDate,
204: forumLastPostDate, forumOrder, forumType,
205: forumFormatOption, forumOption, forumStatus,
206: forumModerationMode, forumPassword, forumThreadCount,
207: forumPostCount);
208: forumCreated = true;
209:
210: if (parentCategory != null) {
211: parentCategory.updateAddedForum(this );
212: }
213: }
214:
215: public void addMemberForumPermission(String memberName,
216: String forumPermission) throws CreateException,
217: DuplicateKeyException, ObjectNotFoundException,
218: DatabaseException, ForeignKeyNotFoundException,
219: BadInputException {
220: if ((!forumCreated) || (forumXML.getForumID() < 0)) {
221: addForum();
222: }
223: ImportMvnForum
224: .addMessage("Adding forum-specific permission for member \""
225: + memberName + "\".");
226: forumXML.addMemberForumPermission(memberName, forumPermission);
227: }
228:
229: public void addGroupForumPermission(String groupName,
230: String forumPermission) throws CreateException,
231: DuplicateKeyException, ObjectNotFoundException,
232: DatabaseException, ForeignKeyNotFoundException,
233: BadInputException {
234: if ((!forumCreated) || (forumXML.getForumID() < 0)) {
235: addForum();
236: }
237: ImportMvnForum
238: .addMessage("Adding forum-specific permission for group \""
239: + groupName + "\".");
240: forumXML.addGroupForumPermission(groupName, forumPermission);
241: }
242:
243: public void addForumWatch(String memberName, String watchType,
244: String watchOption, String watchStatus,
245: String watchCreationDate, String watchLastSentDate,
246: String watchEndDate) throws CreateException,
247: DuplicateKeyException, ObjectNotFoundException,
248: DatabaseException, ForeignKeyNotFoundException,
249: BadInputException {
250: if ((!forumCreated) || (forumXML.getForumID() < 0)) {
251: addForum();
252: }
253: ImportMvnForum.addMessage("Adding forum watch for member \""
254: + memberName + "\".");
255: forumXML.addForumWatch(memberName, watchType, watchOption,
256: watchStatus, watchCreationDate, watchLastSentDate,
257: watchEndDate);
258: }
259:
260: public void updateAddedThread(MvnForumThreadXML subThread) {
261: if ((!forumCreated) || (forumXML.getForumID() < 0))
262: return; //todo Igor: process this error
263: //do nothing; MVN Forum XML already has correct final values for these:
264: //forumXML.increaseThreadCount();
265: if (parentCategory != null) {
266: parentCategory.updateAddedThread(subThread);
267: }
268: }
269:
270: public void updateAddedPost(MvnForumPostXML subPost,
271: String postUsername, String postCreationDate) {
272: if ((!forumCreated) || (forumXML.getForumID() < 0))
273: return; //todo Igor: process this error
274: //do nothing; MVN Forum XML already has correct final values for these:
275: //forumXML.increasePostCount();
276: //forumXML.updateLastPostMemberName(postUsername);
277: //forumXML.updateLastPostDate(postCreationDate);
278: if (parentCategory != null) {
279: parentCategory.updateAddedPost(subPost);
280: }
281: }
282:
283: public void updateAddedAttachment(
284: MvnForumAttachmentXML subAttachment) {
285: if ((!forumCreated) || (forumXML.getForumID() < 0))
286: return; //todo Igor: process this error
287: //do nothing; MVN Forum XML already has correct final values for these:
288: // //check what is needed to be updated
289: if (parentCategory != null) {
290: parentCategory.updateAddedAttachment(subAttachment);
291: }
292: }
293:
294: }
|