Source Code Cross Referenced for ThreadXML.java in  » Forum » mvnforum-1.1 » com » mvnforum » admin » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Forum » mvnforum 1.1 » com.mvnforum.admin 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/admin/ThreadXML.java,v 1.15 2007/10/09 11:09:14 lexuanttkhtn Exp $
003:         * $Author: lexuanttkhtn $
004:         * $Revision: 1.15 $
005:         * $Date: 2007/10/09 11:09:14 $
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.admin.importexport.XMLUtil;
047:        import com.mvnforum.admin.importexport.XMLWriter;
048:        import com.mvnforum.db.*;
049:        import net.myvietnam.mvncore.exception.*;
050:        import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
051:        import net.myvietnam.mvncore.filter.EnableHtmlTagFilter;
052:
053:        /**
054:         * @author Igor Manic
055:         * @version $Revision: 1.15 $, $Date: 2007/10/09 11:09:14 $
056:         * <br/>
057:         * <code>ThreadXML</code> todo Igor: enter description
058:         *
059:         */
060:        public class ThreadXML {
061:
062:            private int threadID;
063:
064:            /** Returns <code>ThreadID</code> of this thread or
065:             * <code>-1</code> if thread is not created yet. */
066:            public int getThreadID() {
067:                return threadID;
068:            }
069:
070:            private int parentForumID;
071:
072:            /** Returns <code>ForumID</code> of this thread's parent forum or
073:             * <code>-1</code> if this thread is not created yet. */
074:            public int getParentForumID() {
075:                return parentForumID;
076:            }
077:
078:            private int parentCategoryID;
079:
080:            /** Returns <code>CategoryID</code> of this thread's parent category or
081:             * <code>-1</code> if this thread is not created yet. */
082:            public int getParentCategoryID() {
083:                return parentCategoryID;
084:            }
085:
086:            public ThreadXML() {
087:                super ();
088:                threadID = -1;
089:                parentForumID = -1;
090:                parentCategoryID = -1;
091:            }
092:
093:            public void setThreadID(String id) {
094:                threadID = XMLUtil.stringToIntDef(id, -1);
095:            }
096:
097:            public void setParentForum(Object o)
098:                    throws ForeignKeyNotFoundException {
099:                if (o instanceof  ForumXML) {
100:                    parentForumID = ((ForumXML) o).getForumID();
101:                } else {
102:                    throw new ForeignKeyNotFoundException(
103:                            "Can't find parent forum's ID");
104:                }
105:            }
106:
107:            public void setParentForumID(int value) {
108:                if (value < 0)
109:                    parentForumID = -1;
110:                else
111:                    parentForumID = value;
112:            }
113:
114:            public void setParentCategory(Object o)
115:                    throws ForeignKeyNotFoundException {
116:                if (o instanceof  ForumXML) {
117:                    parentCategoryID = ((ForumXML) o).getParentCategoryID();
118:                } else {
119:                    throw new ForeignKeyNotFoundException(
120:                            "Can't find parent category's ID");
121:                }
122:            }
123:
124:            public void setParentCategoryID(int value) {
125:                if (value < 0)
126:                    parentCategoryID = -1;
127:                else
128:                    parentCategoryID = value;
129:            }
130:
131:            /**
132:             * Creates a thread. All argument values (<code>int</code>s, <code>Timestamp</code>s, ...)
133:             * are represented as <code>String</code>s, because of more convenient using
134:             * of this method for XML parsing.
135:             *
136:             * @param memberName Member that created the thread. Can be null.
137:             * @param lastPostMemberName Can be null.
138:             * @param threadTopic Thread topic.
139:             * @param threadBody Thread body (description).
140:             * @param threadVoteCount Can be null.
141:             * @param threadVoteTotalStars Can be null.
142:             * @param threadCreationDate Can be null.
143:             * @param threadLastPostDate Can be null.
144:             * @param threadType Can be null.
145:             * @param threadOption Can be null.
146:             * @param threadStatus Can be null.
147:             * @param threadHasPoll Can be null.
148:             * @param threadViewCount Can be null.
149:             * @param threadReplyCount Can be null.
150:             * @param threadIcon Can be null.
151:             * @param threadDuration Can be null.
152:             *
153:             * @throws CreateException
154:             * @throws DuplicateKeyException
155:             * @throws ObjectNotFoundException
156:             * @throws DatabaseException
157:             * @throws ForeignKeyNotFoundException
158:             */
159:            public void addThread(String memberName, String lastPostMemberName,
160:                    String threadTopic, String threadBody,
161:                    String threadVoteCount, String threadVoteTotalStars,
162:                    String threadCreationDate, String threadLastPostDate,
163:                    String threadType, String threadPriority,
164:                    String threadOption, String threadStatus,
165:                    String threadHasPoll, String threadViewCount,
166:                    String threadReplyCount, String threadIcon,
167:                    String threadDuration, String threadAttachCount)
168:                    throws CreateException, ObjectNotFoundException,
169:                    DatabaseException, ForeignKeyNotFoundException {
170:
171:                if (parentForumID < 0) {
172:                    throw new CreateException(
173:                            "Can't create a thread, because no parent forum assigned yet.");
174:                } else if (parentCategoryID < 0) {
175:                    throw new CreateException(
176:                            "Can't create a thread, because no parent category assigned yet.");
177:                } else if ((threadTopic == null) || (threadBody == null)) {
178:                    throw new CreateException(
179:                            "Can't create a thread with empty ThreadTopic or empty ThreadBody.");
180:                } else {
181:                    int threadVoteCount1;
182:                    int threadVoteTotalStars1;
183:                    java.sql.Timestamp threadCreationDate1;
184:                    java.sql.Timestamp threadLastPostDate1;
185:                    int threadType1;
186:                    int threadPriority1;
187:                    int threadOption1;
188:                    int threadStatus1;
189:                    int threadHasPoll1;
190:                    int threadViewCount1;
191:                    int threadReplyCount1;
192:                    int threadDuration1;
193:                    int threadAttachCount1;
194:
195:                    try {
196:                        if (memberName == null)
197:                            memberName = "";
198:                        if (lastPostMemberName == null)
199:                            lastPostMemberName = "";
200:                        threadVoteCount1 = XMLUtil.stringToIntDef(
201:                                threadVoteCount, 0);
202:                        threadVoteTotalStars1 = XMLUtil.stringToIntDef(
203:                                threadVoteTotalStars, 0);
204:                        threadCreationDate1 = XMLUtil
205:                                .stringToSqlTimestampDefNow(threadCreationDate);
206:                        threadLastPostDate1 = XMLUtil
207:                                .stringToSqlTimestampDefNull(threadLastPostDate);
208:                        threadType1 = XMLUtil.stringToIntDef(threadType, 0);
209:                        threadPriority1 = XMLUtil.stringToIntDef(
210:                                threadPriority, 0);
211:                        threadOption1 = XMLUtil.stringToIntDef(threadOption, 0);
212:                        threadStatus1 = XMLUtil.stringToIntDef(threadStatus, 0);
213:                        threadHasPoll1 = XMLUtil.stringToIntDef(threadHasPoll,
214:                                0);
215:                        threadViewCount1 = XMLUtil.stringToIntDef(
216:                                threadViewCount, 0);
217:                        threadReplyCount1 = XMLUtil.stringToIntDef(
218:                                threadReplyCount, 0);
219:                        threadAttachCount1 = XMLUtil.stringToIntDef(
220:                                threadAttachCount, 0);
221:                        if (threadIcon == null)
222:                            threadIcon = "";
223:                        threadDuration1 = XMLUtil.stringToIntDef(
224:                                threadDuration, 0);
225:                    } catch (NumberFormatException e) {
226:                        throw new CreateException(
227:                                "Invalid data for a thread. Expected a number.");
228:                    }
229:
230:                    threadTopic = EnableHtmlTagFilter.filter(threadTopic);
231:                    threadBody = EnableHtmlTagFilter.filter(threadBody);
232:                    threadIcon = EnableHtmlTagFilter.filter(threadIcon);
233:                    this .threadID = DAOFactory.getThreadDAO().createThread(
234:                            parentForumID, memberName, lastPostMemberName,
235:                            threadTopic, threadBody, threadVoteCount1,
236:                            threadVoteTotalStars1, threadCreationDate1,
237:                            threadLastPostDate1, threadType1, threadPriority1,
238:                            threadOption1, threadStatus1, threadHasPoll1,
239:                            threadViewCount1, threadReplyCount1, threadIcon,
240:                            threadDuration1, threadAttachCount1);
241:                }
242:            }
243:
244:            /**
245:             * Creates a thread watch for this thread. In order to know which thread we are
246:             * reffering to, this method is supposed to be called after {@link #setThreadID(String)},
247:             * {@link #addThread(String, String, String, String, String, String, String, String, String, String, String, String, String, String, String, String)}
248:             * have been called. Otherwise, this watch will be simply ignored.
249:             *
250:             * @param memberName
251:             * @param watchType Can be null.
252:             * @param watchOption Can be null.
253:             * @param watchStatus Can be null.
254:             * @param watchCreationDate Can be null.
255:             * @param watchLastSentDate Can be null.
256:             * @param watchEndDate Can be null.
257:             *
258:             * @throws BadInputException
259:             * @throws CreateException
260:             * @throws DatabaseException
261:             * @throws ObjectNotFoundException
262:             * @throws DuplicateKeyException
263:             * @throws ForeignKeyNotFoundException
264:             */
265:            public void addThreadWatch(String memberName, String watchType,
266:                    String watchOption, String watchStatus,
267:                    String watchCreationDate, String watchLastSentDate,
268:                    String watchEndDate) throws CreateException,
269:                    DatabaseException, ObjectNotFoundException,
270:                    DuplicateKeyException, ForeignKeyNotFoundException {
271:
272:                if (threadID < 0) {
273:                    throw new CreateException(
274:                            "Found thread watch that is not assigned to any known thread.");
275:                }
276:
277:                int watchType1;
278:                int watchOption1;
279:                int watchStatus1;
280:                java.sql.Timestamp watchCreationDate1;
281:                java.sql.Timestamp watchLastSentDate1;
282:                java.sql.Timestamp watchEndDate1;
283:
284:                try {
285:                    if (memberName == null)
286:                        memberName = "";
287:                    watchType1 = XMLUtil.stringToIntDef(watchType, 0);
288:                    watchOption1 = XMLUtil.stringToIntDef(watchOption, 0);
289:                    watchStatus1 = XMLUtil.stringToIntDef(watchStatus, 0);
290:                    watchCreationDate1 = XMLUtil
291:                            .stringToSqlTimestampDefNow(watchCreationDate);
292:                    watchLastSentDate1 = XMLUtil
293:                            .stringToSqlTimestampDefNull(watchLastSentDate);
294:                    watchEndDate1 = XMLUtil
295:                            .stringToSqlTimestampDefNull(watchEndDate);
296:                } catch (NumberFormatException e) {
297:                    throw new CreateException(
298:                            "Invalid data for a thread watch. Expected a number.");
299:                }
300:
301:                //todo Igor: Shoud I allow memberID==0 here?
302:                int memberID = 0;
303:                if (!memberName.equals("")) {
304:                    memberID = DAOFactory.getMemberDAO()
305:                            .getMemberIDFromMemberName(memberName);
306:                }
307:                DAOFactory.getWatchDAO().create(memberID, 0/*categoryID*/,
308:                        threadID, 0/*forumID*/, watchType1, watchOption1,
309:                        watchStatus1, watchCreationDate1, watchLastSentDate1,
310:                        watchEndDate1);
311:            }
312:
313:            public void addFavoriteThread(String memberName,
314:                    String favoriteCreationDate, String favoriteType,
315:                    String favoriteOption, String favoriteStatus)
316:                    throws CreateException, DatabaseException,
317:                    ObjectNotFoundException, DuplicateKeyException,
318:                    ForeignKeyNotFoundException {
319:
320:                if (threadID < 0) {
321:                    throw new CreateException(
322:                            "Found favorite-thread record that is not assigned to any known thread.");
323:                } else if (parentForumID < 0) {
324:                    throw new CreateException(
325:                            "Can't create a favorite-thread, because no parent forum assigned yet.");
326:                }
327:
328:                java.sql.Timestamp favoriteCreationDate1;
329:                int favoriteType1;
330:                int favoriteOption1;
331:                int favoriteStatus1;
332:
333:                try {
334:                    if (memberName == null)
335:                        memberName = "";
336:                    favoriteCreationDate1 = XMLUtil
337:                            .stringToSqlTimestampDefNow(favoriteCreationDate);
338:                    favoriteType1 = XMLUtil.stringToIntDef(favoriteType, 0);
339:                    favoriteOption1 = XMLUtil.stringToIntDef(favoriteOption, 0);
340:                    favoriteStatus1 = XMLUtil.stringToIntDef(favoriteStatus, 0);
341:                } catch (NumberFormatException e) {
342:                    throw new CreateException(
343:                            "Invalid data for a favorite-thread. Expected a number.");
344:                }
345:
346:                //todo Igor: Shoud I allow memberID==0 here?
347:                int memberID = 0;
348:                if (!memberName.equals("")) {
349:                    memberID = DAOFactory.getMemberDAO()
350:                            .getMemberIDFromMemberName(memberName);
351:                }
352:                DAOFactory.getFavoriteThreadDAO().create(memberID, threadID,
353:                        parentForumID, favoriteCreationDate1, favoriteType1,
354:                        favoriteOption1, favoriteStatus1);
355:            }
356:
357:            public void increaseReplyCount() throws ObjectNotFoundException,
358:                    DatabaseException {
359:
360:                if (threadID < 0) {
361:                    throw new ObjectNotFoundException(
362:                            "Can't update ThreadReplyCount on thread that is not created yet.");
363:                }
364:                DAOFactory.getThreadDAO().increaseReplyCount(threadID);
365:            }
366:
367:            public void updateLastPostMemberName(String value)
368:                    throws ObjectNotFoundException, DatabaseException,
369:                    ForeignKeyNotFoundException {
370:                if (threadID < 0) {
371:                    throw new ObjectNotFoundException(
372:                            "Can't update LastPostMemberName on thread that is not created yet.");
373:                }
374:                DAOFactory.getThreadDAO().updateLastPostMemberName(threadID,
375:                        value);
376:            }
377:
378:            public void updateLastPostDate(Timestamp value)
379:                    throws ObjectNotFoundException, DatabaseException {
380:                if (threadID < 0) {
381:                    throw new ObjectNotFoundException(
382:                            "Can't update ThreadLastPostDate on thread that is not created yet.");
383:                }
384:                DAOFactory.getThreadDAO().updateLastPostDate(threadID, value);
385:            }
386:
387:            // ===============================================================
388:            // ==================== STATIC EXPORT METHODS ====================
389:            // ===============================================================
390:            public static void exportThreadWatchesForThread(
391:                    XMLWriter xmlWriter, int threadID) throws IOException,
392:                    ExportException, NumberFormatException,
393:                    ObjectNotFoundException, DatabaseException {
394:                Collection threadWatches = ExportWebHelper
395:                        .execSqlQuery("SELECT MemberID, WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate, WatchEndDate"
396:                                + " FROM "
397:                                + WatchDAO.TABLE_NAME
398:                                + " WHERE ThreadID="
399:                                + Integer.toString(threadID));//AND ForumID=0 AND CategoryID=0
400:                Iterator iter = threadWatches.iterator();
401:                String[] threadWatch = null;
402:                //try {
403:                xmlWriter.startElement("ThreadWatchList");
404:                try {
405:                    while ((threadWatch = (String[]) iter.next()) != null) {
406:                        if (threadWatch.length != 7) {
407:                            throw new ExportException(
408:                                    "Error while retrieving data about thread watch for threadID=="
409:                                            + threadID);
410:                        }
411:                        String memberName = DAOFactory.getMemberDAO()
412:                                .getMember(Integer.parseInt(threadWatch[0]))
413:                                .getMemberName();
414:                        xmlWriter.startElement("ThreadWatch");
415:                        xmlWriter.startElement("MemberName");
416:                        xmlWriter.writeData(memberName);
417:                        xmlWriter.endElement("MemberName");
418:                        xmlWriter.startElement("WatchType");
419:                        xmlWriter.writeData(threadWatch[1]);
420:                        xmlWriter.endElement("WatchType");
421:                        xmlWriter.startElement("WatchOption");
422:                        xmlWriter.writeData(threadWatch[2]);
423:                        xmlWriter.endElement("WatchOption");
424:                        xmlWriter.startElement("WatchStatus");
425:                        xmlWriter.writeData(threadWatch[3]);
426:                        xmlWriter.endElement("WatchStatus");
427:                        xmlWriter.startElement("WatchCreationDate");
428:                        xmlWriter.writeData(threadWatch[4]);
429:                        xmlWriter.endElement("WatchCreationDate");
430:                        xmlWriter.startElement("WatchLastSentDate");
431:                        xmlWriter.writeData(threadWatch[5]);
432:                        xmlWriter.endElement("WatchLastSentDate");
433:                        xmlWriter.startElement("WatchEndDate");
434:                        xmlWriter.writeData(threadWatch[6]);
435:                        xmlWriter.endElement("WatchEndDate");
436:                        xmlWriter.endElement("ThreadWatch");
437:                    }
438:                } catch (NoSuchElementException e) {
439:                    //no more database records
440:                }
441:                xmlWriter.endElement("ThreadWatchList");
442:                //} catch throw exportexception
443:            }
444:
445:            public static void exportFavoriteThreadsForThread(
446:                    XMLWriter xmlWriter, int threadID) throws IOException,
447:                    ExportException, NumberFormatException,
448:                    ObjectNotFoundException, DatabaseException {
449:                Collection favoriteThreads = ExportWebHelper
450:                        .execSqlQuery("SELECT MemberID, FavoriteCreationDate,"
451:                                + " FavoriteType, FavoriteOption, FavoriteStatus"
452:                                + " FROM " + FavoriteThreadDAO.TABLE_NAME
453:                                + " WHERE ThreadID="
454:                                + Integer.toString(threadID));
455:                Iterator iter = favoriteThreads.iterator();
456:                String[] favoriteThread = null;
457:                //try {
458:                xmlWriter.startElement("FavoriteThreadList");
459:                try {
460:                    while ((favoriteThread = (String[]) iter.next()) != null) {
461:                        if (favoriteThread.length != 5) {
462:                            throw new ExportException(
463:                                    "Error while retrieving data about favorite-thread records for threadID=="
464:                                            + threadID);
465:                        }
466:                        String memberName = DAOFactory.getMemberDAO()
467:                                .getMember(Integer.parseInt(favoriteThread[0]))
468:                                .getMemberName();
469:                        xmlWriter.startElement("FavoriteThread");
470:                        xmlWriter.startElement("MemberName");
471:                        xmlWriter.writeData(memberName);
472:                        xmlWriter.endElement("MemberName");
473:                        xmlWriter.startElement("FavoriteCreationDate");
474:                        xmlWriter.writeData(favoriteThread[1]);
475:                        xmlWriter.endElement("FavoriteCreationDate");
476:                        xmlWriter.startElement("FavoriteType");
477:                        xmlWriter.writeData(favoriteThread[2]);
478:                        xmlWriter.endElement("FavoriteType");
479:                        xmlWriter.startElement("FavoriteOption");
480:                        xmlWriter.writeData(favoriteThread[3]);
481:                        xmlWriter.endElement("FavoriteOption");
482:                        xmlWriter.startElement("FavoriteStatus");
483:                        xmlWriter.writeData(favoriteThread[4]);
484:                        xmlWriter.endElement("FavoriteStatus");
485:                        xmlWriter.endElement("FavoriteThread");
486:                    }
487:                } catch (NoSuchElementException e) {
488:                    //no more database records
489:                }
490:                xmlWriter.endElement("FavoriteThreadList");
491:                //} catch throw exportexception
492:            }
493:
494:            public static void exportThread(XMLWriter xmlWriter, int threadID)
495:                    throws NumberFormatException, IOException, ExportException,
496:                    ObjectNotFoundException, DatabaseException {
497:                Collection thread1 = ExportWebHelper
498:                        .execSqlQuery("SELECT MemberName, LastPostMemberName,"
499:                                + " ThreadTopic, ThreadBody, ThreadVoteCount, ThreadVoteTotalStars,"
500:                                + " ThreadCreationDate, ThreadLastPostDate, ThreadType, ThreadOption,"
501:                                + " ThreadStatus, ThreadHasPoll, ThreadViewCount, ThreadReplyCount,"
502:                                + " ThreadIcon, ThreadDuration, ThreadAttachCount"
503:                                + " FROM " + ThreadDAO.TABLE_NAME
504:                                + " WHERE ThreadID="
505:                                + Integer.toString(threadID));
506:                Iterator iter = thread1.iterator();
507:                String[] thread = null;
508:                //try {
509:                try {
510:                    if ((thread = (String[]) iter.next()) == null) {
511:                        throw new ExportException(
512:                                "Can't find data for threadID==" + threadID);
513:                    }
514:                    if (thread.length != 17) {
515:                        throw new ExportException(
516:                                "Error while retrieving data about thread with threadID=="
517:                                        + threadID);
518:                    }
519:                } catch (NoSuchElementException e) {
520:                    throw new ExportException("Can't find data for threadID=="
521:                            + threadID);
522:                }
523:
524:                //if I am here, that means I now have correct object thread
525:                xmlWriter.startElement("Thread");
526:
527:                xmlWriter.startElement("MemberName");
528:                xmlWriter.writeData(thread[0]);
529:                xmlWriter.endElement("MemberName");
530:                xmlWriter.startElement("ThreadLastPostMemberName");
531:                xmlWriter.writeData(thread[1]);
532:                xmlWriter.endElement("ThreadLastPostMemberName");
533:                xmlWriter.startElement("ThreadTopic");
534:                xmlWriter.writeData(DisableHtmlTagFilter.filter(thread[2]));
535:                xmlWriter.endElement("ThreadTopic");
536:                xmlWriter.startElement("ThreadBody");
537:                xmlWriter.writeData(DisableHtmlTagFilter.filter(thread[3]));
538:                xmlWriter.endElement("ThreadBody");
539:                xmlWriter.startElement("ThreadVoteCount");
540:                xmlWriter.writeData(thread[4]);
541:                xmlWriter.endElement("ThreadVoteCount");
542:
543:                xmlWriter.startElement("ThreadVoteTotalStars");
544:                xmlWriter.writeData(thread[5]);
545:                xmlWriter.endElement("ThreadVoteTotalStars");
546:                xmlWriter.startElement("ThreadCreationDate");
547:                xmlWriter.writeData(thread[6]);
548:                xmlWriter.endElement("ThreadCreationDate");
549:                xmlWriter.startElement("ThreadLastPostDate");
550:                xmlWriter.writeData(thread[7]);
551:                xmlWriter.endElement("ThreadLastPostDate");
552:                xmlWriter.startElement("ThreadType");
553:                xmlWriter.writeData(thread[8]);
554:                xmlWriter.endElement("ThreadType");
555:                xmlWriter.startElement("ThreadOption");
556:                xmlWriter.writeData(thread[9]);
557:                xmlWriter.endElement("ThreadOption");
558:
559:                xmlWriter.startElement("ThreadStatus");
560:                xmlWriter.writeData(thread[10]);
561:                xmlWriter.endElement("ThreadStatus");
562:                xmlWriter.startElement("ThreadHasPoll");
563:                xmlWriter.writeData(thread[11]);
564:                xmlWriter.endElement("ThreadHasPoll");
565:                xmlWriter.startElement("ThreadViewCount");
566:                xmlWriter.writeData(thread[12]);
567:                xmlWriter.endElement("ThreadViewCount");
568:                xmlWriter.startElement("ThreadReplyCount");
569:                xmlWriter.writeData(thread[13]);
570:                xmlWriter.endElement("ThreadReplyCount");
571:                xmlWriter.startElement("ThreadIcon");
572:                xmlWriter.writeData(DisableHtmlTagFilter.filter(thread[14]));
573:                xmlWriter.endElement("ThreadIcon");
574:
575:                xmlWriter.startElement("ThreadDuration");
576:                xmlWriter.writeData(thread[15]);
577:                xmlWriter.endElement("ThreadDuration");
578:
579:                xmlWriter.startElement("ThreadAttachCount");
580:                xmlWriter.writeData(thread[16]);
581:                xmlWriter.endElement("ThreadAttachCount");
582:                exportThreadWatchesForThread(xmlWriter, threadID);
583:                exportFavoriteThreadsForThread(xmlWriter, threadID);
584:                PostXML.exportPostList(xmlWriter, threadID);
585:
586:                xmlWriter.endElement("Thread");
587:                //} catch throw exportexception
588:            }
589:
590:            //todo Igor important: merge exportThreadList and exportThread so I use only one SQL query
591:            //same for category(list), ...
592:            public static void exportThreadList(XMLWriter xmlWriter,
593:                    int parentForumID) throws IOException, ExportException,
594:                    ObjectNotFoundException, DatabaseException {
595:                Collection threadIDs = ExportWebHelper
596:                        .execSqlQuery("SELECT ThreadID" + " FROM "
597:                                + ThreadDAO.TABLE_NAME + " WHERE ForumID="
598:                                + Integer.toString(parentForumID));
599:                Iterator iter = threadIDs.iterator();
600:                String[] threadID = null;
601:                //try {
602:                xmlWriter.startElement("ThreadList");
603:                try {
604:                    while ((threadID = (String[]) iter.next()) != null) {
605:                        if (threadID.length != 1) {
606:                            throw new ExportException(
607:                                    "Error while retrieving list of threads.");
608:                        }
609:                        try {
610:                            int i = Integer.parseInt(threadID[0]);
611:                            exportThread(xmlWriter, i);
612:                        } catch (NumberFormatException e) {
613:                            throw new ExportException(
614:                                    "Error while retrieving list of threads.");
615:                        }
616:                    }
617:                } catch (NoSuchElementException e) {
618:                    //no more database records
619:                }
620:                xmlWriter.endElement("ThreadList");
621:                //} catch throw exportexception
622:            }
623:
624:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.