001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ForumXML.java,v 1.16 2007/10/09 11:09:13 lexuanttkhtn Exp $
003: * $Author: lexuanttkhtn $
004: * $Revision: 1.16 $
005: * $Date: 2007/10/09 11:09:13 $
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;
041:
042: import java.io.IOException;
043: import java.sql.Timestamp;
044: import java.util.*;
045:
046: import com.mvnforum.MVNForumConstant;
047: import com.mvnforum.admin.importexport.XMLUtil;
048: import com.mvnforum.admin.importexport.XMLWriter;
049: import com.mvnforum.auth.MVNForumPermission;
050: import com.mvnforum.db.*;
051: import net.myvietnam.mvncore.exception.*;
052: import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
053: import net.myvietnam.mvncore.filter.EnableHtmlTagFilter;
054:
055: /**
056: * @author Igor Manic
057: * @version $Revision: 1.16 $, $Date: 2007/10/09 11:09:13 $
058: * <br/>
059: * <code>ForumXML</code> todo Igor: enter description
060: *
061: */
062: public class ForumXML {
063:
064: private int forumID;
065:
066: /** Returns <code>ForumID</code> of this forum or
067: * <code>-1</code> if forum is not created yet. */
068: public int getForumID() {
069: return forumID;
070: }
071:
072: private int parentCategoryID;
073:
074: /** Returns <code>CategoryID</code> of this forum's parent category or
075: * <code>-1</code> if this forum is not created yet. */
076: public int getParentCategoryID() {
077: return parentCategoryID;
078: }
079:
080: public ForumXML() {
081: super ();
082: forumID = -1;
083: parentCategoryID = -1;
084: }
085:
086: public void setForumID(String id) {
087: forumID = XMLUtil.stringToIntDef(id, -1);
088: }
089:
090: public void setParentCategory(CategoryXML parentCategory) {
091: parentCategoryID = parentCategory.getCategoryID();
092: }
093:
094: public void setParentCategoryID(int value) {
095: if (value < 0)
096: parentCategoryID = -1;
097: else
098: parentCategoryID = value;
099: }
100:
101: /**
102: * Creates a forum. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
103: * are represented as <code>String</code>s, because of more convenient using
104: * of this method for XML parsing.
105: *
106: * @param lastPostMemberName Can be null.
107: * @param forumName Name of a forum to be created.
108: * @param forumDesc Can be null.
109: * @param forumCreationDate Can be null.
110: * @param forumModifiedDate Can be null.
111: * @param forumLastPostDate Can be null.
112: * @param forumOrder Can be null.
113: * @param forumType Can be null.
114: * @param forumFormatOption Can be null.
115: * @param forumOption Can be null.
116: * @param forumStatus Can be null.
117: * @param forumModerationMode Can be null.
118: * @param forumPassword Password of a forum to be created. Can be null (or empty "").
119: * @param forumThreadCount Can be null.
120: * @param forumPostCount Can be null.
121: *
122: * @throws CreateException
123: * @throws DuplicateKeyException
124: * @throws ObjectNotFoundException
125: * @throws DatabaseException
126: * @throws ForeignKeyNotFoundException
127: *
128: */
129: public void addForum(String lastPostMemberName, String forumName,
130: String forumDesc, String forumCreationDate,
131: String forumModifiedDate, String forumLastPostDate,
132: String forumOrder, String forumType,
133: String forumFormatOption, String forumOption,
134: String forumStatus, String forumModerationMode,
135: String forumPassword, String forumThreadCount,
136: String forumPostCount) throws CreateException,
137: DuplicateKeyException, ObjectNotFoundException,
138: DatabaseException, ForeignKeyNotFoundException {
139: if (parentCategoryID < 0) {
140: throw new CreateException(
141: "Can't create a forum, because no parent category assigned yet.");
142: }
143: if ((forumName == null) || (forumName.equals(""))) {
144: throw new CreateException(
145: "Can't create a forum with empty ForumName.");
146: } else {
147: java.sql.Timestamp forumCreationDate1;
148: java.sql.Timestamp forumModifiedDate1;
149: java.sql.Timestamp forumLastPostDate1;
150: int forumOrder1;
151: int forumType1;
152: int forumFormatOption1;
153: int forumOption1;
154: int forumStatus1;
155: int forumModerationMode1;
156: int forumThreadCount1;
157: int forumPostCount1;
158:
159: try {
160: if (lastPostMemberName == null)
161: lastPostMemberName = "";
162: if (forumDesc == null)
163: forumDesc = "";
164: forumCreationDate1 = XMLUtil
165: .stringToSqlTimestampDefNow(forumCreationDate);
166: forumModifiedDate1 = XMLUtil
167: .stringToSqlTimestampDefNull(forumModifiedDate);
168: forumLastPostDate1 = XMLUtil
169: .stringToSqlTimestampDefNull(forumLastPostDate);
170: forumOrder1 = XMLUtil.stringToIntDef(forumOrder, 0);
171: forumType1 = XMLUtil.stringToIntDef(forumType, 0);
172: forumFormatOption1 = XMLUtil.stringToIntDef(
173: forumFormatOption, 0);
174: forumOption1 = XMLUtil.stringToIntDef(forumOption, 0);
175: forumStatus1 = XMLUtil.stringToIntDef(forumStatus, 0);
176: forumModerationMode1 = XMLUtil.stringToIntDef(
177: forumModerationMode, 0);
178: if (forumPassword == null)
179: forumPassword = "";
180: forumThreadCount1 = XMLUtil.stringToIntDef(
181: forumThreadCount, 0);
182: forumPostCount1 = XMLUtil.stringToIntDef(
183: forumPostCount, 0);
184: } catch (NumberFormatException e) {
185: throw new CreateException(
186: "Invalid data for a forum. Expected a number.");
187: }
188:
189: forumName = EnableHtmlTagFilter.filter(forumName);
190: forumDesc = EnableHtmlTagFilter.filter(forumDesc);
191: forumPassword = EnableHtmlTagFilter.filter(forumPassword);
192:
193: DAOFactory.getForumDAO().create(parentCategoryID, null,
194: lastPostMemberName, forumName, forumDesc,
195: forumCreationDate1, forumModifiedDate1,
196: forumLastPostDate1, forumOrder1, forumType1,
197: forumFormatOption1, forumOption1, forumStatus1,
198: forumModerationMode1, forumPassword,
199: forumThreadCount1, forumPostCount1);
200:
201: //todo Igor: Minh, you could move next piece of code into ForumWebHelper.getForumIDFromPrimaryKey method
202: Collection forums = DAOFactory.getForumDAO()
203: .getForums_inCategory(parentCategoryID);
204: Iterator iter = forums.iterator();
205: try {
206: ForumBean forum = null;
207: forumID = -1;
208: while ((forum = (ForumBean) iter.next()) != null) {
209: if ((forum.getForumName().equals(forumName))
210: && (forum.getCategoryID() == parentCategoryID)) {
211: forumID = forum.getForumID();
212: break;
213: }
214: }
215: if (forumID < 0) {
216: throw new ObjectNotFoundException(
217: "Can't find forum I've just added.");
218: }
219: } catch (NoSuchElementException e) {
220: throw new ObjectNotFoundException(
221: "Can't find forum I've just added.");
222: }
223:
224: }
225: }
226:
227: /**
228: * Adds a forum-specific permission to a member. In order to know which forum we are
229: * reffering to, this method is supposed to be called after {@link #setForumID(String)} or
230: * {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
231: * have been called. Otherwise, this permission will be simply ignored.
232: *
233: * @param memberName Member we are assigning permissions to.
234: * @param permission Permission to be added.
235: *
236: * @throws CreateException
237: * @throws DatabaseException
238: * @throws ObjectNotFoundException
239: * @throws DuplicateKeyException
240: * @throws ForeignKeyNotFoundException
241: *
242: */
243: public void addMemberForumPermission(String memberName,
244: String permission) throws CreateException,
245: DatabaseException, DuplicateKeyException,
246: ObjectNotFoundException, ForeignKeyNotFoundException {
247:
248: if (forumID < 0) {
249: throw new CreateException(
250: "Found member's forum-specific permission that is not assigned to any known forum.");
251: }
252: if ((memberName == null) || (memberName.equals(""))) {
253: throw new CreateException(
254: "Can't create a member's forum-specific permission for a member with empty MemberName.");
255: }
256:
257: int permission1;
258: try {
259: permission1 = XMLUtil.stringToIntDef(permission,
260: MVNForumPermission.PERMISSION_NO_PERMISSIONS);
261: } catch (NumberFormatException e) {
262: throw new CreateException(
263: "Invalid data for a member forum-specific permission. Expected a number.");
264: }
265: int memberID = DAOFactory.getMemberDAO()
266: .getMemberIDFromMemberName(memberName);
267: try {
268: DAOFactory.getMemberForumDAO().create(memberID, forumID,
269: permission1);
270: } catch (DuplicateKeyException e) {
271: //ignore if already had that permission
272: }
273: }
274:
275: /**
276: * Adds a forum-specific permission to a group. In order to know which forum we are
277: * reffering to, this method is supposed to be called after {@link #setForumID(String)} or
278: * {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
279: * have been called. Otherwise, this permission will be simply ignored.
280: *
281: * @param groupName Group we are assigning permissions to.
282: * @param permission Permission to be added.
283: *
284: * @throws CreateException
285: * @throws DatabaseException
286: * @throws ObjectNotFoundException
287: * @throws DuplicateKeyException
288: * @throws ForeignKeyNotFoundException
289: *
290: */
291: public void addGroupForumPermission(String groupName,
292: String permission) throws CreateException,
293: DatabaseException, ObjectNotFoundException,
294: DuplicateKeyException, ForeignKeyNotFoundException {
295:
296: if (forumID < 0) {
297: throw new CreateException(
298: "Found group's forum-specific permission that is not assigned to any known forum.");
299: }
300: if ((groupName == null) || (groupName.equals(""))) {
301: throw new CreateException(
302: "Can't create a group's forum-specific permission for a group with empty GroupName.");
303: }
304:
305: int permission1;
306: try {
307: permission1 = XMLUtil.stringToIntDef(permission,
308: MVNForumPermission.PERMISSION_NO_PERMISSIONS);
309: } catch (NumberFormatException e) {
310: throw new CreateException(
311: "Invalid data for a group forum-specific permission. Expected a number.");
312: }
313: int groupID = DAOFactory.getGroupsDAO()
314: .getGroupIDFromGroupName(groupName);
315: try {
316: DAOFactory.getGroupForumDAO().create(groupID, forumID,
317: permission1);
318: } catch (DuplicateKeyException e) {
319: //ignore if already had that permission
320: }
321: }
322:
323: public void addGuestMemberForumPermission(String permission)
324: throws CreateException, DatabaseException,
325: ForeignKeyNotFoundException, DuplicateKeyException {
326:
327: if (forumID < 0) {
328: throw new CreateException(
329: "Found guest's forum-specific permission that is not assigned to any known forum.");
330: }
331: int permission1;
332: try {
333: permission1 = XMLUtil.stringToIntDef(permission,
334: MVNForumPermission.PERMISSION_NO_PERMISSIONS);
335: } catch (NumberFormatException e) {
336: throw new CreateException(
337: "Invalid data for a guest member forum-specific permission. Expected a number.");
338: }
339: try {
340: DAOFactory.getMemberForumDAO().create(
341: MVNForumConstant.MEMBER_ID_OF_GUEST, forumID,
342: permission1);
343: } catch (DuplicateKeyException e) {
344: //ignore if already had that permission
345: }
346: }
347:
348: public void addRegisteredMembersGroupForumPermission(
349: String permission) throws CreateException,
350: DatabaseException, DuplicateKeyException,
351: ForeignKeyNotFoundException {
352: if (forumID < 0) {
353: throw new CreateException(
354: "Found group's forum-specific permission that is not assigned to any known forum.");
355: }
356: int permission1;
357: try {
358: permission1 = XMLUtil.stringToIntDef(permission,
359: MVNForumPermission.PERMISSION_NO_PERMISSIONS);
360: } catch (NumberFormatException e) {
361: throw new CreateException(
362: "Invalid data for a group forum-specific permission. Expected a number.");
363: }
364: try {
365: DAOFactory.getGroupForumDAO().create(
366: MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS,
367: forumID, permission1);
368: } catch (DuplicateKeyException e) {
369: //ignore if already had that permission
370: }
371: }
372:
373: /**
374: * Creates a forum watch for this forum. In order to know which forum we are
375: * reffering to, this method is supposed to be called after {@link #setForumID(String)}
376: * or {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
377: * have been called. Otherwise, this watch will be simply ignored.
378: *
379: * @param memberName
380: * @param watchType Can be null.
381: * @param watchOption Can be null.
382: * @param watchStatus Can be null.
383: * @param watchCreationDate Can be null.
384: * @param watchLastSentDate Can be null.
385: * @param watchEndDate Can be null.
386: *
387: * @throws BadInputException
388: * @throws CreateException
389: * @throws DatabaseException
390: * @throws ObjectNotFoundException
391: * @throws DuplicateKeyException
392: * @throws ForeignKeyNotFoundException
393: *
394: */
395: public void addForumWatch(String memberName, String watchType,
396: String watchOption, String watchStatus,
397: String watchCreationDate, String watchLastSentDate,
398: String watchEndDate) throws CreateException,
399: DatabaseException, ObjectNotFoundException,
400: DuplicateKeyException, ForeignKeyNotFoundException {
401:
402: if (forumID < 0) {
403: throw new CreateException(
404: "Found forum watch that is not assigned to any known forum.");
405: }
406:
407: int watchType1;
408: int watchOption1;
409: int watchStatus1;
410: java.sql.Timestamp watchCreationDate1;
411: java.sql.Timestamp watchLastSentDate1;
412: java.sql.Timestamp watchEndDate1;
413:
414: try {
415: if (memberName == null)
416: memberName = "";
417: watchType1 = XMLUtil.stringToIntDef(watchType, 0);
418: watchOption1 = XMLUtil.stringToIntDef(watchOption, 0);
419: watchStatus1 = XMLUtil.stringToIntDef(watchStatus, 0);
420: watchCreationDate1 = XMLUtil
421: .stringToSqlTimestampDefNow(watchCreationDate);
422: watchLastSentDate1 = XMLUtil
423: .stringToSqlTimestampDefNull(watchLastSentDate);
424: watchEndDate1 = XMLUtil
425: .stringToSqlTimestampDefNull(watchEndDate);
426: } catch (NumberFormatException e) {
427: throw new CreateException(
428: "Invalid data for a forum. Expected a number.");
429: }
430:
431: //todo Igor: Shoud I allow memberID==0 here?
432: int memberID = 0;
433: if (!memberName.equals("")) {
434: memberID = DAOFactory.getMemberDAO()
435: .getMemberIDFromMemberName(memberName);
436: }
437: DAOFactory.getWatchDAO().create(memberID, 0/*categoryID*/,
438: forumID, 0/*threadID*/, watchType1, watchOption1,
439: watchStatus1, watchCreationDate1, watchLastSentDate1,
440: watchEndDate1);
441: }
442:
443: public void updateLastPostMemberName(String value)
444: throws ObjectNotFoundException, DatabaseException,
445: ForeignKeyNotFoundException {
446: if (forumID < 0) {
447: throw new ObjectNotFoundException(
448: "Can't update ForumLastPostMemberName on forum that is not created yet.");
449: }
450: DAOFactory.getForumDAO().updateLastPostMemberName(forumID,
451: value);
452: }
453:
454: public void updateLastPostDate(Timestamp value)
455: throws ObjectNotFoundException, DatabaseException {
456: if (forumID < 0) {
457: throw new ObjectNotFoundException(
458: "Can't update ForumLastPostDate on forum that is not created yet.");
459: }
460: DAOFactory.getForumDAO().updateLastPostDate(forumID, value);
461: }
462:
463: public void increaseThreadCount() throws ObjectNotFoundException,
464: DatabaseException {
465: if (forumID < 0) {
466: throw new ObjectNotFoundException(
467: "Can't update ForumThreadCount on forum that is not created yet.");
468: }
469: DAOFactory.getForumDAO().increaseThreadCount(forumID);
470: }
471:
472: public void increasePostCount() throws ObjectNotFoundException,
473: DatabaseException {
474: if (forumID < 0) {
475: throw new ObjectNotFoundException(
476: "Can't update ForumPostCount on forum that is not created yet.");
477: }
478: DAOFactory.getForumDAO().increasePostCount(forumID);
479: }
480:
481: // ===============================================================
482: // ==================== STATIC EXPORT METHODS ====================
483: // ===============================================================
484:
485: public static void exportForumWatchesForForum(XMLWriter xmlWriter,
486: int forumID) throws IOException, ExportException,
487: NumberFormatException, ObjectNotFoundException,
488: DatabaseException {
489: Collection forumWatches = ExportWebHelper
490: .execSqlQuery("SELECT MemberID, WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate, WatchEndDate"
491: + " FROM "
492: + WatchDAO.TABLE_NAME
493: + " WHERE ThreadID=0" + //AND CategoryID=0
494: " AND ForumID=" + Integer.toString(forumID));
495: Iterator iter = forumWatches.iterator();
496: String[] forumWatch = null;
497: //try {
498: xmlWriter.startElement("ForumWatchList");
499: try {
500: while ((forumWatch = (String[]) iter.next()) != null) {
501: if (forumWatch.length != 7) {
502: throw new ExportException(
503: "Error while retrieving data about forum watch for forumID=="
504: + forumID);
505: }
506: String memberName = DAOFactory.getMemberDAO()
507: .getMember(Integer.parseInt(forumWatch[0]))
508: .getMemberName();
509: xmlWriter.startElement("ForumWatch");
510: xmlWriter.startElement("MemberName");
511: xmlWriter.writeData(memberName);
512: xmlWriter.endElement("MemberName");
513: xmlWriter.startElement("WatchType");
514: xmlWriter.writeData(forumWatch[1]);
515: xmlWriter.endElement("WatchType");
516: xmlWriter.startElement("WatchOption");
517: xmlWriter.writeData(forumWatch[2]);
518: xmlWriter.endElement("WatchOption");
519: xmlWriter.startElement("WatchStatus");
520: xmlWriter.writeData(forumWatch[3]);
521: xmlWriter.endElement("WatchStatus");
522: xmlWriter.startElement("WatchCreationDate");
523: xmlWriter.writeData(forumWatch[4]);
524: xmlWriter.endElement("WatchCreationDate");
525: xmlWriter.startElement("WatchLastSentDate");
526: xmlWriter.writeData(forumWatch[5]);
527: xmlWriter.endElement("WatchLastSentDate");
528: xmlWriter.startElement("WatchEndDate");
529: xmlWriter.writeData(forumWatch[6]);
530: xmlWriter.endElement("WatchEndDate");
531: xmlWriter.endElement("ForumWatch");
532: }
533: } catch (NoSuchElementException e) {
534: //no more database records
535: }
536: xmlWriter.endElement("ForumWatchList");
537: //} catch throw exportexception
538: }
539:
540: public static void exportMemberForumPermissionsForForum(
541: XMLWriter xmlWriter, int forumID) throws IOException,
542: ExportException, NumberFormatException,
543: ObjectNotFoundException, DatabaseException {
544: Collection memberForumPermissions = ExportWebHelper
545: .execSqlQuery("SELECT MemberID, Permission" + " FROM "
546: + MemberForumDAO.TABLE_NAME + " WHERE ForumID="
547: + Integer.toString(forumID));
548: Iterator iter = memberForumPermissions.iterator();
549: String[] memberForumPermission = null;
550: //try {
551: xmlWriter.startElement("MemberForumPermissionList");
552: try {
553: while ((memberForumPermission = (String[]) iter.next()) != null) {
554: if (memberForumPermission.length != 2) {
555: throw new ExportException(
556: "Error while retrieving data about member forum-specific permissions for forumID=="
557: + forumID);
558: }
559: String memberName = DAOFactory
560: .getMemberDAO()
561: .getMember(
562: Integer
563: .parseInt(memberForumPermission[0]))
564: .getMemberName();
565: xmlWriter.startElement("MemberForumPermission");
566: xmlWriter.startElement("MemberName");
567: xmlWriter.writeData(memberName);
568: xmlWriter.endElement("MemberName");
569: xmlWriter.startElement("ForumPermission");
570: xmlWriter.writeData(memberForumPermission[1]);
571: xmlWriter.endElement("ForumPermission");
572: xmlWriter.endElement("MemberForumPermission");
573: }
574: } catch (NoSuchElementException e) {
575: //no more database records
576: }
577: xmlWriter.endElement("MemberForumPermissionList");
578: //} catch throw exportexception
579: }
580:
581: public static void exportGroupForumPermissionsForForum(
582: XMLWriter xmlWriter, int forumID) throws IOException,
583: DatabaseException, ExportException {
584: Collection groupForumPermissions = ExportWebHelper
585: .execSqlQuery("SELECT G.GroupName, GF.Permission"
586: + " FROM " + GroupForumDAO.TABLE_NAME
587: + " AS GF, " + GroupsDAO.TABLE_NAME + " AS G "
588: + " WHERE G.GroupID=GF.GroupID AND ForumID="
589: + Integer.toString(forumID));
590: Iterator iter = groupForumPermissions.iterator();
591: String[] groupForumPermission = null;
592: //try {
593: xmlWriter.startElement("GroupForumPermissionList");
594: try {
595: while ((groupForumPermission = (String[]) iter.next()) != null) {
596: if (groupForumPermission.length != 2) {
597: throw new ExportException(
598: "Error while retrieving data about group forum-specific permissions for forumID=="
599: + forumID);
600: }
601: xmlWriter.startElement("GroupForumPermission");
602: xmlWriter.startElement("GroupName");
603: xmlWriter.writeData(groupForumPermission[0]);
604: xmlWriter.endElement("GroupName");
605: xmlWriter.startElement("ForumPermission");
606: xmlWriter.writeData(groupForumPermission[1]);
607: xmlWriter.endElement("ForumPermission");
608: xmlWriter.endElement("GroupForumPermission");
609: }
610: } catch (NoSuchElementException e) {
611: //no more database records
612: }
613: xmlWriter.endElement("GroupForumPermissionList");
614: //} catch throw exportexception
615: }
616:
617: public static void exportForum(XMLWriter xmlWriter, int forumID)
618: throws NumberFormatException, IOException, ExportException,
619: ObjectNotFoundException, DatabaseException {
620: Collection forum1 = ExportWebHelper
621: .execSqlQuery("SELECT LastPostMemberName, ForumName,"
622: + " ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate,"
623: + " ForumOrder, ForumType, ForumFormatOption, ForumOption,"
624: + " ForumStatus, ForumModerationMode, ForumPassword,"
625: + " ForumThreadCount, ForumPostCount"
626: + " FROM " + ForumDAO.TABLE_NAME
627: + " WHERE ForumID=" + Integer.toString(forumID));
628: Iterator iter = forum1.iterator();
629: String[] forum = null;
630: //try {
631: try {
632: if ((forum = (String[]) iter.next()) == null) {
633: throw new ExportException(
634: "Can't find data for forumID==" + forumID);
635: }
636: if (forum.length != 15) {
637: throw new ExportException(
638: "Error while retrieving data about forum with forumID=="
639: + forumID);
640: }
641: } catch (NoSuchElementException e) {
642: throw new ExportException("Can't find data for forumID=="
643: + forumID);
644: }
645:
646: //if I am here, that means I now have correct object forum
647: xmlWriter.startElement("Forum");
648:
649: xmlWriter.startElement("ForumLastPostMemberName");
650: xmlWriter.writeData(forum[0]);
651: xmlWriter.endElement("ForumLastPostMemberName");
652: xmlWriter.startElement("ForumName");
653: xmlWriter.writeData(DisableHtmlTagFilter.filter(forum[1]));
654: xmlWriter.endElement("ForumName");
655: xmlWriter.startElement("ForumDesc");
656: xmlWriter.writeData(DisableHtmlTagFilter.filter(forum[2]));
657: xmlWriter.endElement("ForumDesc");
658: xmlWriter.startElement("ForumCreationDate");
659: xmlWriter.writeData(forum[3]);
660: xmlWriter.endElement("ForumCreationDate");
661: xmlWriter.startElement("ForumModifiedDate");
662: xmlWriter.writeData(forum[4]);
663: xmlWriter.endElement("ForumModifiedDate");
664:
665: xmlWriter.startElement("ForumLastPostDate");
666: xmlWriter.writeData(forum[5]);
667: xmlWriter.endElement("ForumLastPostDate");
668: xmlWriter.startElement("ForumOrder");
669: xmlWriter.writeData(forum[6]);
670: xmlWriter.endElement("ForumOrder");
671: xmlWriter.startElement("ForumType");
672: xmlWriter.writeData(forum[7]);
673: xmlWriter.endElement("ForumType");
674: xmlWriter.startElement("ForumFormatOption");
675: xmlWriter.writeData(forum[8]);
676: xmlWriter.endElement("ForumFormatOption");
677: xmlWriter.startElement("ForumOption");
678: xmlWriter.writeData(forum[9]);
679: xmlWriter.endElement("ForumOption");
680:
681: xmlWriter.startElement("ForumStatus");
682: xmlWriter.writeData(forum[10]);
683: xmlWriter.endElement("ForumStatus");
684: xmlWriter.startElement("ForumModerationMode");
685: xmlWriter.writeData(forum[11]);
686: xmlWriter.endElement("ForumModerationMode");
687: xmlWriter.startElement("ForumPassword");
688: xmlWriter.writeData(DisableHtmlTagFilter.filter(forum[12]));
689: xmlWriter.endElement("ForumPassword");
690: xmlWriter.startElement("ForumThreadCount");
691: xmlWriter.writeData(forum[13]);
692: xmlWriter.endElement("ForumThreadCount");
693: xmlWriter.startElement("ForumPostCount");
694: xmlWriter.writeData(forum[14]);
695: xmlWriter.endElement("ForumPostCount");
696:
697: exportMemberForumPermissionsForForum(xmlWriter, forumID);
698: exportGroupForumPermissionsForForum(xmlWriter, forumID);
699: exportForumWatchesForForum(xmlWriter, forumID);
700: ThreadXML.exportThreadList(xmlWriter, forumID);
701: xmlWriter.endElement("Forum");
702: //} catch throw exportexception
703: }
704:
705: //todo Igor important: merge exportForumList and exportForum so I use only one SQL query
706: //same for category(list), ...
707: public static void exportForumList(XMLWriter xmlWriter,
708: int parentCategoryID) throws IOException, ExportException,
709: ObjectNotFoundException, DatabaseException {
710: Collection forumIDs = ExportWebHelper
711: .execSqlQuery("SELECT ForumID" + " FROM "
712: + ForumDAO.TABLE_NAME + " WHERE CategoryID="
713: + Integer.toString(parentCategoryID));
714: Iterator iter = forumIDs.iterator();
715: String[] forumID = null;
716: //try {
717: xmlWriter.startElement("ForumList");
718: try {
719: while ((forumID = (String[]) iter.next()) != null) {
720: if (forumID.length != 1) {
721: throw new ExportException(
722: "Error while retrieving list of forums.");
723: }
724: try {
725: int i = Integer.parseInt(forumID[0]);
726: exportForum(xmlWriter, i);
727: } catch (NumberFormatException e) {
728: throw new ExportException(
729: "Error while retrieving list of forums.");
730: }
731: }
732: } catch (NoSuchElementException e) {
733: //no more database records
734: }
735: xmlWriter.endElement("ForumList");
736: //} catch throw exportexception
737: }
738:
739: }
|