KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mvnforum > admin > ForumXML


1 /*
2  * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ForumXML.java,v 1.12 2006/04/14 17:36:29 minhnn Exp $
3  * $Author: minhnn $
4  * $Revision: 1.12 $
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;
41
42 import java.io.IOException JavaDoc;
43 import java.sql.Timestamp JavaDoc;
44 import java.util.*;
45
46 import com.mvnforum.MVNForumConstant;
47 import com.mvnforum.admin.importexport.XMLUtil;
48 import com.mvnforum.admin.importexport.XMLWriter;
49 import com.mvnforum.auth.MVNForumPermission;
50 import com.mvnforum.db.*;
51 import net.myvietnam.mvncore.exception.*;
52 import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
53 import net.myvietnam.mvncore.filter.EnableHtmlTagFilter;
54
55 /**
56  * @author Igor Manic
57  * @version $Revision: 1.12 $, $Date: 2006/04/14 17:36:29 $
58  * <br/>
59  * <code>ForumXML</code> todo Igor: enter description
60  *
61  */

62 public class ForumXML {
63
64     private int forumID;
65     /** Returns <code>ForumID</code> of this forum or
66       * <code>-1</code> if forum is not created yet. */

67     public int getForumID() { return forumID; }
68
69     private int parentCategoryID;
70     /** Returns <code>CategoryID</code> of this forum's parent category or
71       * <code>-1</code> if this forum is not created yet. */

72     public int getParentCategoryID() { return parentCategoryID; }
73
74     public ForumXML() {
75         super();
76         forumID=-1;
77         parentCategoryID=-1;
78     }
79
80     public void setForumID(String JavaDoc id) {
81         forumID=XMLUtil.stringToIntDef(id, -1);
82     }
83
84     public void setParentCategory(CategoryXML parentCategory) {
85         parentCategoryID=parentCategory.getCategoryID();
86     }
87
88     public void setParentCategoryID(int value) {
89         if (value<0) parentCategoryID=-1;
90         else parentCategoryID=value;
91     }
92
93     /**
94      * Creates a forum. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
95      * are represented as <code>String</code>s, because of more convenient using
96      * of this method for XML parsing.
97      *
98      * @param lastPostMemberName Can be null.
99      * @param forumName Name of a forum to be created.
100      * @param forumDesc Can be null.
101      * @param forumCreationDate Can be null.
102      * @param forumModifiedDate Can be null.
103      * @param forumLastPostDate Can be null.
104      * @param forumOrder Can be null.
105      * @param forumType Can be null.
106      * @param forumFormatOption Can be null.
107      * @param forumOption Can be null.
108      * @param forumStatus Can be null.
109      * @param forumModerationMode Can be null.
110      * @param forumPassword Password of a forum to be created. Can be null (or empty "").
111      * @param forumThreadCount Can be null.
112      * @param forumPostCount Can be null.
113      *
114      * @throws CreateException
115      * @throws DuplicateKeyException
116      * @throws ObjectNotFoundException
117      * @throws DatabaseException
118      * @throws ForeignKeyNotFoundException
119      *
120      */

121     public void addForum(String JavaDoc lastPostMemberName, String JavaDoc forumName,
122                          String JavaDoc forumDesc, String JavaDoc forumCreationDate,
123                          String JavaDoc forumModifiedDate, String JavaDoc forumLastPostDate,
124                          String JavaDoc forumOrder, String JavaDoc forumType,
125                          String JavaDoc forumFormatOption, String JavaDoc forumOption,
126                          String JavaDoc forumStatus, String JavaDoc forumModerationMode,
127                          String JavaDoc forumPassword, String JavaDoc forumThreadCount,
128                          String JavaDoc forumPostCount)
129     throws CreateException, DuplicateKeyException, ObjectNotFoundException,
130     DatabaseException, ForeignKeyNotFoundException {
131         if (parentCategoryID<0) {
132             throw new CreateException("Can't create a forum, because no parent category assigned yet.");
133         }
134         if ((forumName==null) || (forumName.equals(""))) {
135             throw new CreateException("Can't create a forum with empty ForumName.");
136         } else {
137             java.sql.Timestamp JavaDoc forumCreationDate1;
138             java.sql.Timestamp JavaDoc forumModifiedDate1;
139             java.sql.Timestamp JavaDoc forumLastPostDate1;
140             int forumOrder1;
141             int forumType1;
142             int forumFormatOption1;
143             int forumOption1;
144             int forumStatus1;
145             int forumModerationMode1;
146             int forumThreadCount1;
147             int forumPostCount1;
148
149             try {
150                 if (lastPostMemberName==null) lastPostMemberName="";
151                 if (forumDesc==null) forumDesc="";
152                 forumCreationDate1= XMLUtil.stringToSqlTimestampDefNow(forumCreationDate);
153                 forumModifiedDate1= XMLUtil.stringToSqlTimestampDefNull(forumModifiedDate);
154                 forumLastPostDate1= XMLUtil.stringToSqlTimestampDefNull(forumLastPostDate);
155                 forumOrder1 = XMLUtil.stringToIntDef(forumOrder, 0);
156                 forumType1 = XMLUtil.stringToIntDef(forumType, 0);
157                 forumFormatOption1 = XMLUtil.stringToIntDef(forumFormatOption, 0);
158                 forumOption1 = XMLUtil.stringToIntDef(forumOption, 0);
159                 forumStatus1 = XMLUtil.stringToIntDef(forumStatus, 0);
160                 forumModerationMode1 = XMLUtil.stringToIntDef(forumModerationMode, 0);
161                 if (forumPassword==null) forumPassword="";
162                 forumThreadCount1 = XMLUtil.stringToIntDef(forumThreadCount, 0);
163                 forumPostCount1 = XMLUtil.stringToIntDef(forumPostCount, 0);
164             } catch (NumberFormatException JavaDoc e) {
165                 throw new CreateException("Invalid data for a forum. Expected a number.");
166             }
167
168             forumName=EnableHtmlTagFilter.filter(forumName);
169             forumDesc=EnableHtmlTagFilter.filter(forumDesc);
170             forumPassword=EnableHtmlTagFilter.filter(forumPassword);
171
172             DAOFactory.getForumDAO().create(
173                      parentCategoryID, lastPostMemberName,
174                      forumName, forumDesc,
175                      forumCreationDate1, forumModifiedDate1, forumLastPostDate1,
176                      forumOrder1, forumType1, forumFormatOption1,
177                      forumOption1, forumStatus1, forumModerationMode1,
178                      forumPassword, forumThreadCount1, forumPostCount1);
179
180             //todo Igor: Minh, you could move next piece of code into ForumWebHelper.getForumIDFromPrimaryKey method
181
Collection forums=DAOFactory.getForumDAO().getForums_inCategory(parentCategoryID);
182             Iterator iter=forums.iterator();
183             try {
184                 ForumBean forum=null;
185                 forumID=-1;
186                 while ( (forum=(ForumBean)iter.next() )!=null) {
187                     if ((forum.getForumName().equals(forumName)) && (forum.getCategoryID()==parentCategoryID)) {
188                         forumID=forum.getForumID();
189                         break;
190                     }
191                 }
192                 if (forumID<0) {
193                     throw new ObjectNotFoundException("Can't find forum I've just added.");
194                 }
195             } catch (NoSuchElementException e) {
196                 throw new ObjectNotFoundException("Can't find forum I've just added.");
197             }
198
199         }
200     }
201
202     /**
203      * Adds a forum-specific permission to a member. In order to know which forum we are
204      * reffering to, this method is supposed to be called after {@link #setForumID(String)} or
205      * {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
206      * have been called. Otherwise, this permission will be simply ignored.
207      *
208      * @param memberName Member we are assigning permissions to.
209      * @param permission Permission to be added.
210      *
211      * @throws CreateException
212      * @throws DatabaseException
213      * @throws ObjectNotFoundException
214      * @throws DuplicateKeyException
215      * @throws ForeignKeyNotFoundException
216      *
217      */

218     public void addMemberForumPermission(String JavaDoc memberName, String JavaDoc permission)
219         throws CreateException, DatabaseException, DuplicateKeyException,
220         ObjectNotFoundException, ForeignKeyNotFoundException {
221
222         if (forumID<0) {
223             throw new CreateException("Found member's forum-specific permission that is not assigned to any known forum.");
224         }
225         if ( (memberName==null) || (memberName.equals("")) ) {
226             throw new CreateException("Can't create a member's forum-specific permission for a member with empty MemberName.");
227         }
228
229         int permission1;
230         try {
231             permission1=XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
232         } catch (NumberFormatException JavaDoc e) {
233             throw new CreateException("Invalid data for a member forum-specific permission. Expected a number.");
234         }
235         int memberID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
236         try {
237             DAOFactory.getMemberForumDAO().create(memberID, forumID, permission1);
238         } catch (DuplicateKeyException e) {
239             //ignore if already had that permission
240
}
241     }
242
243     /**
244      * Adds a forum-specific permission to a group. In order to know which forum we are
245      * reffering to, this method is supposed to be called after {@link #setForumID(String)} or
246      * {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
247      * have been called. Otherwise, this permission will be simply ignored.
248      *
249      * @param groupName Group we are assigning permissions to.
250      * @param permission Permission to be added.
251      *
252      * @throws CreateException
253      * @throws DatabaseException
254      * @throws ObjectNotFoundException
255      * @throws DuplicateKeyException
256      * @throws ForeignKeyNotFoundException
257      *
258      */

259     public void addGroupForumPermission(String JavaDoc groupName, String JavaDoc permission)
260         throws CreateException, DatabaseException, ObjectNotFoundException,
261         DuplicateKeyException, ForeignKeyNotFoundException {
262
263         if (forumID < 0) {
264             throw new CreateException("Found group's forum-specific permission that is not assigned to any known forum.");
265         }
266         if ( (groupName == null) || (groupName.equals(""))) {
267             throw new CreateException("Can't create a group's forum-specific permission for a group with empty GroupName.");
268         }
269
270         int permission1;
271         try {
272             permission1 = XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
273         } catch (NumberFormatException JavaDoc e) {
274             throw new CreateException("Invalid data for a group forum-specific permission. Expected a number.");
275         }
276         int groupID = DAOFactory.getGroupsDAO().getGroupIDFromGroupName(groupName);
277         try {
278             DAOFactory.getGroupForumDAO().create(groupID, forumID, permission1);
279         } catch (DuplicateKeyException e) {
280             //ignore if already had that permission
281
}
282     }
283
284     public void addGuestMemberForumPermission(String JavaDoc permission)
285         throws CreateException, DatabaseException, ForeignKeyNotFoundException, DuplicateKeyException {
286
287         if (forumID<0) {
288             throw new CreateException("Found guest's forum-specific permission that is not assigned to any known forum.");
289         }
290         int permission1;
291         try {
292             permission1=XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
293         } catch (NumberFormatException JavaDoc e) {
294             throw new CreateException("Invalid data for a guest member forum-specific permission. Expected a number.");
295         }
296         try {
297             DAOFactory.getMemberForumDAO().create(MVNForumConstant.MEMBER_ID_OF_GUEST,
298                                                   forumID, permission1);
299         } catch (DuplicateKeyException e) {
300             //ignore if already had that permission
301
}
302     }
303
304     public void addRegisteredMembersGroupForumPermission(String JavaDoc permission)
305         throws CreateException, DatabaseException,
306         DuplicateKeyException, ForeignKeyNotFoundException {
307         if (forumID<0) {
308             throw new CreateException("Found group's forum-specific permission that is not assigned to any known forum.");
309         }
310         int permission1;
311         try {
312             permission1=XMLUtil.stringToIntDef(permission, MVNForumPermission.PERMISSION_NO_PERMISSIONS);
313         } catch (NumberFormatException JavaDoc e) {
314             throw new CreateException("Invalid data for a group forum-specific permission. Expected a number.");
315         }
316         try {
317             DAOFactory.getGroupForumDAO().create(MVNForumConstant.GROUP_ID_OF_REGISTERED_MEMBERS,
318                                                  forumID, permission1);
319         } catch (DuplicateKeyException e) {
320             //ignore if already had that permission
321
}
322     }
323
324     /**
325      * Creates a forum watch for this forum. In order to know which forum we are
326      * reffering to, this method is supposed to be called after {@link #setForumID(String)}
327      * or {@link #addForum(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
328      * have been called. Otherwise, this watch will be simply ignored.
329      *
330      * @param memberName
331      * @param watchType Can be null.
332      * @param watchOption Can be null.
333      * @param watchStatus Can be null.
334      * @param watchCreationDate Can be null.
335      * @param watchLastSentDate Can be null.
336      * @param watchEndDate Can be null.
337      *
338      * @throws BadInputException
339      * @throws CreateException
340      * @throws DatabaseException
341      * @throws ObjectNotFoundException
342      * @throws DuplicateKeyException
343      * @throws ForeignKeyNotFoundException
344      *
345      */

346     public void addForumWatch(String JavaDoc memberName,
347                 String JavaDoc watchType, String JavaDoc watchOption,
348                 String JavaDoc watchStatus, String JavaDoc watchCreationDate,
349                 String JavaDoc watchLastSentDate, String JavaDoc watchEndDate)
350         throws CreateException, DatabaseException, ObjectNotFoundException,
351         DuplicateKeyException, ForeignKeyNotFoundException {
352
353         if (forumID<0) {
354             throw new CreateException("Found forum watch that is not assigned to any known forum.");
355         }
356
357         int watchType1;
358         int watchOption1;
359         int watchStatus1;
360         java.sql.Timestamp JavaDoc watchCreationDate1;
361         java.sql.Timestamp JavaDoc watchLastSentDate1;
362         java.sql.Timestamp JavaDoc watchEndDate1;
363
364         try {
365             if (memberName==null) memberName="";
366             watchType1= XMLUtil.stringToIntDef(watchType, 0);
367             watchOption1= XMLUtil.stringToIntDef(watchOption, 0);
368             watchStatus1= XMLUtil.stringToIntDef(watchStatus, 0);
369             watchCreationDate1= XMLUtil.stringToSqlTimestampDefNow(watchCreationDate);
370             watchLastSentDate1= XMLUtil.stringToSqlTimestampDefNull(watchLastSentDate);
371             watchEndDate1= XMLUtil.stringToSqlTimestampDefNull(watchEndDate);
372         } catch (NumberFormatException JavaDoc e) {
373             throw new CreateException("Invalid data for a forum. Expected a number.");
374         }
375
376         //todo Igor: Shoud I allow memberID==0 here?
377
int memberID=0;
378         if (!memberName.equals("")) {
379             memberID=DAOFactory.getMemberDAO().getMemberIDFromMemberName(memberName);
380         }
381         DAOFactory.getWatchDAO().create(
382               memberID, 0/*categoryID*/, forumID, 0/*threadID*/,
383               watchType1, watchOption1, watchStatus1,
384               watchCreationDate1, watchLastSentDate1, watchEndDate1);
385     }
386
387
388     public void updateLastPostMemberName(String JavaDoc value)
389     throws ObjectNotFoundException, DatabaseException, ForeignKeyNotFoundException {
390         if (forumID<0) {
391             throw new ObjectNotFoundException("Can't update ForumLastPostMemberName on forum that is not created yet.");
392         }
393         DAOFactory.getForumDAO().updateLastPostMemberName(forumID, value);
394     }
395
396     public void updateLastPostDate(Timestamp JavaDoc value)
397     throws ObjectNotFoundException, DatabaseException {
398         if (forumID<0) {
399             throw new ObjectNotFoundException("Can't update ForumLastPostDate on forum that is not created yet.");
400         }
401         DAOFactory.getForumDAO().updateLastPostDate(forumID, value);
402     }
403
404     public void increaseThreadCount()
405     throws ObjectNotFoundException, DatabaseException {
406         if (forumID<0) {
407             throw new ObjectNotFoundException("Can't update ForumThreadCount on forum that is not created yet.");
408         }
409         DAOFactory.getForumDAO().increaseThreadCount(forumID);
410     }
411
412     public void increasePostCount()
413     throws ObjectNotFoundException, DatabaseException {
414         if (forumID<0) {
415             throw new ObjectNotFoundException("Can't update ForumPostCount on forum that is not created yet.");
416         }
417         DAOFactory.getForumDAO().increasePostCount(forumID);
418     }
419
420
421 // ===============================================================
422
// ==================== STATIC EXPORT METHODS ====================
423
// ===============================================================
424

425     public static void exportForumWatchesForForum(XMLWriter xmlWriter, int forumID)
426     throws IOException JavaDoc, ExportException, NumberFormatException JavaDoc, ObjectNotFoundException,
427     DatabaseException {
428         Collection forumWatches=ExportWebHelper.execSqlQuery(
429                    "SELECT MemberID, WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate, WatchEndDate"+
430                    " FROM "+WatchDAO.TABLE_NAME+
431                    " WHERE ThreadID=0"+ //AND CategoryID=0
432
" AND ForumID="+Integer.toString(forumID));
433         Iterator iter=forumWatches.iterator();
434         String JavaDoc[] forumWatch=null;
435         //try {
436
xmlWriter.startElement("ForumWatchList");
437             try {
438                 while ( (forumWatch=(String JavaDoc[])iter.next()) !=null) {
439                     if (forumWatch.length!=7) {
440                         throw new ExportException("Error while retrieving data about forum watch for forumID=="+forumID);
441                     }
442                     String JavaDoc memberName=DAOFactory.getMemberDAO().getMember_forPublic(Integer.parseInt(forumWatch[0])).getMemberName();
443                     xmlWriter.startElement("ForumWatch");
444                     xmlWriter.startElement("MemberName");
445                     xmlWriter.writeData(memberName);
446                     xmlWriter.endElement("MemberName");
447                     xmlWriter.startElement("WatchType");
448                     xmlWriter.writeData(forumWatch[1]);
449                     xmlWriter.endElement("WatchType");
450                     xmlWriter.startElement("WatchOption");
451                     xmlWriter.writeData(forumWatch[2]);
452                     xmlWriter.endElement("WatchOption");
453                     xmlWriter.startElement("WatchStatus");
454                     xmlWriter.writeData(forumWatch[3]);
455                     xmlWriter.endElement("WatchStatus");
456                     xmlWriter.startElement("WatchCreationDate");
457                     xmlWriter.writeData(forumWatch[4]);
458                     xmlWriter.endElement("WatchCreationDate");
459                     xmlWriter.startElement("WatchLastSentDate");
460                     xmlWriter.writeData(forumWatch[5]);
461                     xmlWriter.endElement("WatchLastSentDate");
462                     xmlWriter.startElement("WatchEndDate");
463                     xmlWriter.writeData(forumWatch[6]);
464                     xmlWriter.endElement("WatchEndDate");
465                     xmlWriter.endElement("ForumWatch");
466                 }
467             } catch (NoSuchElementException e) {
468                 //no more database records
469
}
470             xmlWriter.endElement("ForumWatchList");
471          //} catch throw exportexception
472
}
473
474     public static void exportMemberForumPermissionsForForum(XMLWriter xmlWriter, int forumID)
475     throws IOException JavaDoc, ExportException, NumberFormatException JavaDoc, ObjectNotFoundException,
476     DatabaseException {
477         Collection memberForumPermissions=ExportWebHelper.execSqlQuery(
478                    "SELECT MemberID, Permission"+
479                    " FROM "+MemberForumDAO.TABLE_NAME+
480                    " WHERE ForumID="+Integer.toString(forumID));
481         Iterator iter=memberForumPermissions.iterator();
482         String JavaDoc[] memberForumPermission=null;
483         //try {
484
xmlWriter.startElement("MemberForumPermissionList");
485             try {
486                 while ( (memberForumPermission=(String JavaDoc[])iter.next()) !=null) {
487                     if (memberForumPermission.length!=2) {
488                         throw new ExportException("Error while retrieving data about member forum-specific permissions for forumID=="+forumID);
489                     }
490                     String JavaDoc memberName=DAOFactory.getMemberDAO().getMember_forPublic(Integer.parseInt(memberForumPermission[0])).getMemberName();
491                     xmlWriter.startElement("MemberForumPermission");
492                     xmlWriter.startElement("MemberName");
493                     xmlWriter.writeData(memberName);
494                     xmlWriter.endElement("MemberName");
495                     xmlWriter.startElement("ForumPermission");
496                     xmlWriter.writeData(memberForumPermission[1]);
497                     xmlWriter.endElement("ForumPermission");
498                     xmlWriter.endElement("MemberForumPermission");
499                 }
500             } catch (NoSuchElementException e) {
501                 //no more database records
502
}
503             xmlWriter.endElement("MemberForumPermissionList");
504          //} catch throw exportexception
505
}
506
507     public static void exportGroupForumPermissionsForForum(XMLWriter xmlWriter, int forumID)
508     throws IOException JavaDoc, DatabaseException, ExportException {
509         Collection groupForumPermissions=ExportWebHelper.execSqlQuery(
510                    "SELECT G.GroupName, GF.Permission"+
511                    " FROM "+GroupForumDAO.TABLE_NAME+" AS GF, "+
512                    GroupsDAO.TABLE_NAME+" AS G "+
513                    " WHERE G.GroupID=GF.GroupID AND ForumID="+Integer.toString(forumID));
514         Iterator iter=groupForumPermissions.iterator();
515         String JavaDoc[] groupForumPermission=null;
516         //try {
517
xmlWriter.startElement("GroupForumPermissionList");
518             try {
519                 while ( (groupForumPermission=(String JavaDoc[])iter.next()) !=null) {
520                     if (groupForumPermission.length!=2) {
521                         throw new ExportException("Error while retrieving data about group forum-specific permissions for forumID=="+forumID);
522                     }
523                     xmlWriter.startElement("GroupForumPermission");
524                     xmlWriter.startElement("GroupName");
525                     xmlWriter.writeData(groupForumPermission[0]);
526                     xmlWriter.endElement("GroupName");
527                     xmlWriter.startElement("ForumPermission");
528                     xmlWriter.writeData(groupForumPermission[1]);
529                     xmlWriter.endElement("ForumPermission");
530                     xmlWriter.endElement("GroupForumPermission");
531                 }
532             } catch (NoSuchElementException e) {
533                 //no more database records
534
}
535             xmlWriter.endElement("GroupForumPermissionList");
536          //} catch throw exportexception
537
}
538
539     public static void exportForum(XMLWriter xmlWriter, int forumID)
540     throws NumberFormatException JavaDoc, IOException JavaDoc, ExportException, ObjectNotFoundException,
541     DatabaseException {
542         Collection forum1=ExportWebHelper.execSqlQuery(
543                    "SELECT LastPostMemberName, ForumName,"+
544                    " ForumDesc, ForumCreationDate, ForumModifiedDate, ForumLastPostDate,"+
545                    " ForumOrder, ForumType, ForumFormatOption, ForumOption,"+
546                    " ForumStatus, ForumModerationMode, ForumPassword,"+
547                    " ForumThreadCount, ForumPostCount"+
548                    " FROM "+ForumDAO.TABLE_NAME+
549                    " WHERE ForumID="+Integer.toString(forumID));
550         Iterator iter=forum1.iterator();
551         String JavaDoc[] forum=null;
552         //try {
553
try {
554                 if ( (forum=(String JavaDoc[])iter.next()) ==null) {
555                     throw new ExportException("Can't find data for forumID=="+forumID);
556                 }
557                 if (forum.length!=15) {
558                     throw new ExportException("Error while retrieving data about forum with forumID=="+forumID);
559                 }
560             } catch (NoSuchElementException e) {
561                 throw new ExportException("Can't find data for forumID=="+forumID);
562             }
563
564             //if I am here, that means I now have correct object forum
565
xmlWriter.startElement("Forum");
566
567             xmlWriter.startElement("ForumLastPostMemberName");
568             xmlWriter.writeData(forum[0]);
569             xmlWriter.endElement("ForumLastPostMemberName");
570             xmlWriter.startElement("ForumName");
571             xmlWriter.writeData(DisableHtmlTagFilter.filter(forum[1]));
572             xmlWriter.endElement("ForumName");
573             xmlWriter.startElement("ForumDesc");
574             xmlWriter.writeData(DisableHtmlTagFilter.filter(forum[2]));
575             xmlWriter.endElement("ForumDesc");
576             xmlWriter.startElement("ForumCreationDate");
577             xmlWriter.writeData(forum[3]);
578             xmlWriter.endElement("ForumCreationDate");
579             xmlWriter.startElement("ForumModifiedDate");
580             xmlWriter.writeData(forum[4]);
581             xmlWriter.endElement("ForumModifiedDate");
582
583             xmlWriter.startElement("ForumLastPostDate");
584             xmlWriter.writeData(forum[5]);
585             xmlWriter.endElement("ForumLastPostDate");
586             xmlWriter.startElement("ForumOrder");
587             xmlWriter.writeData(forum[6]);
588             xmlWriter.endElement("ForumOrder");
589             xmlWriter.startElement("ForumType");
590             xmlWriter.writeData(forum[7]);
591             xmlWriter.endElement("ForumType");
592             xmlWriter.startElement("ForumFormatOption");
593             xmlWriter.writeData(forum[8]);
594             xmlWriter.endElement("ForumFormatOption");
595             xmlWriter.startElement("ForumOption");
596             xmlWriter.writeData(forum[9]);
597             xmlWriter.endElement("ForumOption");
598
599             xmlWriter.startElement("ForumStatus");
600             xmlWriter.writeData(forum[10]);
601             xmlWriter.endElement("ForumStatus");
602             xmlWriter.startElement("ForumModerationMode");
603             xmlWriter.writeData(forum[11]);
604             xmlWriter.endElement("ForumModerationMode");
605             xmlWriter.startElement("ForumPassword");
606             xmlWriter.writeData(DisableHtmlTagFilter.filter(forum[12]));
607             xmlWriter.endElement("ForumPassword");
608             xmlWriter.startElement("ForumThreadCount");
609             xmlWriter.writeData(forum[13]);
610             xmlWriter.endElement("ForumThreadCount");
611             xmlWriter.startElement("ForumPostCount");
612             xmlWriter.writeData(forum[14]);
613             xmlWriter.endElement("ForumPostCount");
614
615             exportMemberForumPermissionsForForum(xmlWriter, forumID);
616             exportGroupForumPermissionsForForum(xmlWriter, forumID);
617             exportForumWatchesForForum(xmlWriter, forumID);
618             ThreadXML.exportThreadList(xmlWriter, forumID);
619             xmlWriter.endElement("Forum");
620          //} catch throw exportexception
621
}
622
623     //todo Igor important: merge exportForumList and exportForum so I use only one SQL query
624
//same for category(list), ...
625
public static void exportForumList(XMLWriter xmlWriter, int parentCategoryID)
626     throws IOException JavaDoc, ExportException, ObjectNotFoundException, DatabaseException {
627         Collection forumIDs=ExportWebHelper.execSqlQuery(
628                    "SELECT ForumID"+
629                    " FROM "+ForumDAO.TABLE_NAME+
630                    " WHERE CategoryID="+Integer.toString(parentCategoryID));
631         Iterator iter=forumIDs.iterator();
632         String JavaDoc[] forumID=null;
633         //try {
634
xmlWriter.startElement("ForumList");
635             try {
636                 while ( (forumID=(String JavaDoc[])iter.next()) !=null) {
637                     if (forumID.length!=1) {
638                         throw new ExportException("Error while retrieving list of forums.");
639                     }
640                     try {
641                         int i=Integer.parseInt(forumID[0]);
642                         exportForum(xmlWriter, i);
643                     } catch (NumberFormatException JavaDoc e) {
644                         throw new ExportException("Error while retrieving list of forums.");
645                     }
646                 }
647             } catch (NoSuchElementException e) {
648                 //no more database records
649
}
650             xmlWriter.endElement("ForumList");
651          //} catch throw exportexception
652
}
653
654
655 }
656
657
Popular Tags