Source Code Cross Referenced for ForumWebHandler.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/ForumWebHandler.java,v 1.77 2008/01/22 06:47:02 phuongpdd Exp $
003:         * $Author: phuongpdd $
004:         * $Revision: 1.77 $
005:         * $Date: 2008/01/22 06:47:02 $
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: Minh Nguyen
039:         * @author: Mai  Nguyen
040:         */
041:        package com.mvnforum.admin;
042:
043:        import java.sql.Timestamp;
044:        import java.util.Locale;
045:
046:        import net.myvietnam.mvncore.exception.*;
047:        import net.myvietnam.mvncore.filter.DisableHtmlTagFilter;
048:        import net.myvietnam.mvncore.security.SecurityUtil;
049:        import net.myvietnam.mvncore.service.EventLogService;
050:        import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
051:        import net.myvietnam.mvncore.util.*;
052:        import net.myvietnam.mvncore.web.GenericRequest;
053:        import net.myvietnam.mvncore.web.GenericResponse;
054:
055:        import com.mvnforum.*;
056:        import com.mvnforum.auth.*;
057:        import com.mvnforum.categorytree.*;
058:        import com.mvnforum.common.AttachmentUtil;
059:        import com.mvnforum.db.*;
060:        import com.mvnforum.search.post.DeletePostIndexTask;
061:        import com.mvnforum.search.post.PostIndexer;
062:        import com.mvnforum.service.CategoryService;
063:        import com.mvnforum.service.MvnForumServiceFactory;
064:
065:        public class ForumWebHandler {
066:
067:            private OnlineUserManager onlineUserManager = OnlineUserManager
068:                    .getInstance();
069:
070:            private static CategoryService categoryService = MvnForumServiceFactory
071:                    .getMvnForumService().getCategoryService();
072:            private static EventLogService eventLogService = MvnCoreServiceFactory
073:                    .getMvnCoreService().getEventLogService();
074:
075:            public ForumWebHandler() {
076:            }
077:
078:            public void prepareAdd(GenericRequest request,
079:                    GenericResponse response) throws DatabaseException,
080:                    AuthenticationException {
081:
082:                OnlineUser onlineUser = onlineUserManager
083:                        .getOnlineUser(request);
084:                MVNForumPermission permission = onlineUser.getPermission();
085:                permission.ensureCanAddForum();
086:
087:                CategoryBuilder builder = new DefaultCategoryBuilder();
088:                CategoryTree tree = new CategoryTree(builder);
089:                CategoryTreeListener listener = categoryService
090:                        .getManagementCategorySelector(request, response, true,
091:                                null);
092:                tree.addCategeoryTreeListener(listener);
093:                request.setAttribute("Result", tree.build());
094:            }
095:
096:            public void processAdd(GenericRequest request,
097:                    GenericResponse response) throws BadInputException,
098:                    CreateException, DatabaseException, DuplicateKeyException,
099:                    ForeignKeyNotFoundException, AuthenticationException,
100:                    ObjectNotFoundException {
101:
102:                SecurityUtil.checkHttpPostMethod(request);
103:
104:                OnlineUser onlineUser = onlineUserManager
105:                        .getOnlineUser(request);
106:                MVNForumPermission permission = onlineUser.getPermission();
107:                permission.ensureCanAddForum();
108:
109:                MyUtil.saveVNTyperMode(request, response);
110:                Timestamp now = DateUtil.getCurrentGMTTimestamp();
111:
112:                int categoryID = GenericParamUtil.getParameterInt(request,
113:                        "CategoryID");
114:                String forumOwnerName = GenericParamUtil.getParameterSafe(
115:                        request, "ForumOwnerName", false);
116:                StringUtil.checkGoodName(forumOwnerName);
117:                String forumName = GenericParamUtil.getParameterSafe(request,
118:                        "ForumName", true);
119:                forumName = DisableHtmlTagFilter.filter(forumName);
120:                String forumDesc = GenericParamUtil.getParameterSafe(request,
121:                        "ForumDesc", false);
122:                forumDesc = DisableHtmlTagFilter.filter(forumDesc);
123:                int forumType = GenericParamUtil.getParameterInt(request,
124:                        "ForumType");
125:                int forumFormatOption = 0; // @todo review and support it later
126:                int forumOption = 0; // @todo review and support it later
127:                int forumStatus = GenericParamUtil.getParameterInt(request,
128:                        "ForumStatus");
129:                int forumModerationMode = GenericParamUtil.getParameterInt(
130:                        request, "ForumModerationMode");
131:                String forumPassword = ""; // @todo review and support it later
132:
133:                // check valid
134:                ForumBean.validateForumType(forumType);
135:                ForumBean.validateForumFormatOption(forumFormatOption);
136:                ForumBean.validateForumOption(forumOption);
137:                ForumBean.validateForumStatus(forumStatus);
138:                ForumBean.validateForumModerationMode(forumModerationMode);
139:
140:                // validate forumOwnerName
141:                if (forumOwnerName == null) {
142:                    forumOwnerName = "";
143:                }
144:
145:                Locale locale = I18nUtil.getLocaleInRequest(request);
146:                if (forumOwnerName.length() > 0) {
147:                    try {
148:                        forumOwnerName = DAOFactory.getMemberDAO()
149:                                .findByAlternateKey_MemberName(forumOwnerName);
150:                    } catch (ObjectNotFoundException e) {
151:                        String localizedMessage = MVNForumResourceBundle
152:                                .getString(
153:                                        locale,
154:                                        "mvncore.exception.ObjectNotFoundException.membername_not_exists",
155:                                        new Object[] { forumOwnerName });
156:                        throw new ObjectNotFoundException(localizedMessage);
157:                    }
158:                }
159:
160:                int forumID = DAOFactory
161:                        .getForumDAO()
162:                        .createForum(categoryID, forumOwnerName,
163:                                ""/*lastPostMemberName*/, forumName,
164:                                forumDesc, now/*forumCreationDate*/,
165:                                now/*forumModifiedDate*/,
166:                                now/*forumLastPostDate*/, 0/*forumOrder*/,
167:                                forumType, forumFormatOption, forumOption,
168:                                forumStatus, forumModerationMode,
169:                                forumPassword, 0/*forumThreadCount*/, 0/*forumPostCount*/);
170:
171:                // Check if the user created forum should be the owner (ForumAdmin) of that forum
172:                // This is used for KG
173:                if (MVNForumConfig.getEnableAutoForumOwner()) {
174:                    int memberID = onlineUser.getMemberID();
175:                    DAOFactory.getMemberForumDAO().create(memberID, forumID,
176:                            MVNForumPermission.PERMISSION_FORUM_ADMIN);
177:                    onlineUser.reloadPermission();
178:                }
179:
180:                String actionDesc = MVNForumResourceBundle
181:                        .getString(MVNForumConfig.getEventLogLocale(),
182:                                "mvnforum.eventlog.desc.AddForum",
183:                                new Object[] { new Integer(forumID),
184:                                        new Integer(categoryID) });
185:                eventLogService.logEvent(onlineUser.getMemberName(), request
186:                        .getRemoteAddr(),
187:                        MVNForumConstant.EVENT_LOG_MAIN_MODULE,
188:                        MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
189:                        "add forum", actionDesc, EventLogService.MEDIUM);
190:
191:                // Now clear the cache
192:                ForumCache.getInstance().clear();
193:
194:                request.setAttribute("ForumName", forumName);
195:
196:            }
197:
198:            public void prepareDelete(GenericRequest request)
199:                    throws BadInputException, ObjectNotFoundException,
200:                    DatabaseException, AuthenticationException {
201:
202:                OnlineUser onlineUser = onlineUserManager
203:                        .getOnlineUser(request);
204:                MVNForumPermission permission = onlineUser.getPermission();
205:
206:                // primary key column(s)
207:                int forumID = GenericParamUtil
208:                        .getParameterInt(request, "forum");
209:
210:                permission.ensureCanDeleteForum(forumID);
211:
212:                ForumBean forumBean = null;
213:                try {
214:                    forumBean = DAOFactory.getForumDAO().getForum(forumID);
215:                } catch (ObjectNotFoundException e) {
216:                    Locale locale = I18nUtil.getLocaleInRequest(request);
217:                    String localizedMessage = MVNForumResourceBundle
218:                            .getString(
219:                                    locale,
220:                                    "mvncore.exception.ObjectNotFoundException.forumid_not_exists",
221:                                    new Object[] { new Integer(forumID) });
222:                    throw new ObjectNotFoundException(localizedMessage);
223:                }
224:                int numberOfThreads = DAOFactory.getThreadDAO()
225:                        .getNumberOfEnableThreads_inForum(forumID);
226:                int numberOfPosts = DAOFactory.getPostDAO()
227:                        .getNumberOfEnablePosts_inForum(forumID);
228:
229:                int numberOfPendingThreads = DAOFactory.getThreadDAO()
230:                        .getNumberOfDisableThreads_inForum(forumID);
231:                int numberOfPendingPosts = DAOFactory.getPostDAO()
232:                        .getNumberOfDisablePosts_inForum(forumID);
233:
234:                request.setAttribute("ForumBean", forumBean);
235:                request.setAttribute("NumberOfThreads", new Integer(
236:                        numberOfThreads));
237:                request.setAttribute("NumberOfPosts",
238:                        new Integer(numberOfPosts));
239:                request.setAttribute("NumberOfPendingThreads", new Integer(
240:                        numberOfPendingThreads));
241:                request.setAttribute("NumberOfPendingPosts", new Integer(
242:                        numberOfPendingPosts));
243:            }
244:
245:            public void processDelete(GenericRequest request)
246:                    throws BadInputException, ObjectNotFoundException,
247:                    DatabaseException, AuthenticationException {
248:
249:                SecurityUtil.checkHttpPostMethod(request);
250:
251:                OnlineUser onlineUser = onlineUserManager
252:                        .getOnlineUser(request);
253:                MVNForumPermission permission = onlineUser.getPermission();
254:
255:                // primary key column(s)
256:                int forumID = GenericParamUtil
257:                        .getParameterInt(request, "forum");
258:
259:                // user must have been authenticated before he can delete
260:                permission.ensureIsAuthenticated();
261:
262:                permission.ensureCanDeleteForum(forumID);
263:
264:                // now check the password
265:                MyUtil.ensureCorrectCurrentPassword(request);
266:
267:                // Delete all attachments in this forum,
268:                // we must call this before any attempt to delete the post/thread/forum
269:                // That is, the order when delete is VERY IMPORTANT
270:                AttachmentUtil.deleteAttachments_inForum(forumID);
271:
272:                DAOFactory.getGroupForumDAO().delete_inForum(forumID);
273:                DAOFactory.getMemberForumDAO().delete_inForum(forumID);
274:
275:                DAOFactory.getFavoriteThreadDAO().delete_inForum(forumID);
276:
277:                DAOFactory.getWatchDAO().delete_inForum(forumID);
278:
279:                DAOFactory.getPostDAO().delete_inForum(forumID);
280:                DAOFactory.getThreadDAO().delete_inForum(forumID);
281:
282:                // now delete the forum, note that we delete it after delete all child objects
283:                DAOFactory.getForumDAO().delete(forumID);
284:
285:                String actionDesc = MVNForumResourceBundle.getString(
286:                        MVNForumConfig.getEventLogLocale(),
287:                        "mvnforum.eventlog.desc.DeleteForum",
288:                        new Object[] { new Integer(forumID) });
289:                eventLogService.logEvent(onlineUser.getMemberName(), request
290:                        .getRemoteAddr(),
291:                        MVNForumConstant.EVENT_LOG_MAIN_MODULE,
292:                        MVNForumConstant.EVENT_LOG_SUB_MODULE_ADMIN,
293:                        "delete forum", actionDesc, EventLogService.CRITICAL);
294:
295:                // now update the search index
296:                PostIndexer.scheduleDeletePostTask(forumID,
297:                        DeletePostIndexTask.OBJECT_TYPE_FORUM);
298:
299:                // Clear cache
300:                PostCache.getInstance().clear();
301:                ThreadCache.getInstance().clear();
302:                ForumCache.getInstance().clear();
303:            }
304:
305:            public void prepareEdit(GenericRequest request,
306:                    GenericResponse response) throws BadInputException,
307:                    ObjectNotFoundException, DatabaseException,
308:                    AuthenticationException {
309:
310:                OnlineUser onlineUser = onlineUserManager
311:                        .getOnlineUser(request);
312:                MVNForumPermission permission = onlineUser.getPermission();
313:
314:                // primary key column(s)
315:                int forumID = GenericParamUtil
316:                        .getParameterInt(request, "forum");
317:
318:                permission.ensureCanEditForum(forumID);
319:
320:                ForumBean forumBean = null;
321:                Locale locale = I18nUtil.getLocaleInRequest(request);
322:                try {
323:                    forumBean = DAOFactory.getForumDAO().getForum(forumID);
324:                } catch (ObjectNotFoundException e) {
325:                    String localizedMessage = MVNForumResourceBundle
326:                            .getString(
327:                                    locale,
328:                                    "mvncore.exception.ObjectNotFoundException.forumid_not_exists",
329:                                    new Object[] { new Integer(forumID) });
330:                    throw new ObjectNotFoundException(localizedMessage);
331:                }
332:
333:                request.setAttribute("ForumBean", forumBean);
334:
335:                CategoryBuilder builder = new DefaultCategoryBuilder();
336:                CategoryTree tree = new CategoryTree(builder);
337:                CategoryTreeListener listener = categoryService
338:                        .getManagementCategorySelector(request, response,
339:                                forumBean);
340:                tree.addCategeoryTreeListener(listener);
341:                request.setAttribute("Result", tree.build());
342:            }
343:
344:            public void processUpdate(GenericRequest request,
345:                    GenericResponse response) throws BadInputException,
346:                    ObjectNotFoundException, DatabaseException,
347:                    DuplicateKeyException, ForeignKeyNotFoundException,
348:                    AuthenticationException {
349:
350:                SecurityUtil.checkHttpPostMethod(request);
351:
352:                OnlineUser onlineUser = onlineUserManager
353:                        .getOnlineUser(request);
354:                MVNForumPermission permission = onlineUser.getPermission();
355:
356:                // primary key column(s)
357:                int forumID = GenericParamUtil.getParameterInt(request,
358:                        "ForumID");
359:
360:                permission.ensureCanEditForum(forumID);
361:                MyUtil.ensureCorrectCurrentPassword(request);
362:
363:                MyUtil.saveVNTyperMode(request, response);
364:
365:                Timestamp now = DateUtil.getCurrentGMTTimestamp();
366:
367:                // column(s) to update
368:                int categoryID = GenericParamUtil.getParameterInt(request,
369:                        "CategoryID");
370:                String forumOwnerName = GenericParamUtil.getParameterSafe(
371:                        request, "ForumOwnerName", false);
372:                StringUtil.checkGoodName(forumOwnerName);
373:                String forumName = GenericParamUtil.getParameterFilter(request,
374:                        "ForumName", true);
375:                String forumDesc = GenericParamUtil.getParameterFilter(request,
376:                        "ForumDesc", false);
377:                Timestamp forumModifiedDate = now;
378:                int forumOrder = GenericParamUtil.getParameterUnsignedInt(
379:                        request, "ForumOrder");
380:                int forumType = GenericParamUtil.getParameterInt(request,
381:                        "ForumType");
382:                int forumFormatOption = 0;//GenericParamUtil.getParameterInt(request, "ForumFormatOption");
383:                int forumOption = 0;//GenericParamUtil.getParameterInt(request, "ForumOption");
384:                int forumStatus = GenericParamUtil.getParameterInt(request,
385:                        "ForumStatus");
386:                int forumModerationMode = GenericParamUtil.getParameterInt(
387:                        request, "ForumModerationMode");
388:
389:                // check valid
390:                ForumBean.validateForumType(forumType);
391:                ForumBean.validateForumFormatOption(forumFormatOption);
392:                ForumBean.validateForumOption(forumOption);
393:                ForumBean.validateForumStatus(forumStatus);
394:                ForumBean.validateForumModerationMode(forumModerationMode);
395:
396:                // validate forumOwnerName
397:                if (forumOwnerName == null) {
398:                    forumOwnerName = "";
399:                }
400:
401:                Locale locale = I18nUtil.getLocaleInRequest(request);
402:                if (forumOwnerName.length() > 0) {
403:                    try {
404:                        forumOwnerName = DAOFactory.getMemberDAO()
405:                                .findByAlternateKey_MemberName(forumOwnerName);
406:                    } catch (ObjectNotFoundException e) {
407:                        String localizedMessage = MVNForumResourceBundle
408:                                .getString(
409:                                        locale,
410:                                        "mvncore.exception.ObjectNotFoundException.membername_not_exists",
411:                                        new Object[] { forumOwnerName });
412:                        throw new ObjectNotFoundException(localizedMessage);
413:                    }
414:                }
415:
416:                DAOFactory.getForumDAO().update(
417:                        forumID, // primary key
418:                        categoryID, forumOwnerName, forumName, forumDesc,
419:                        forumModifiedDate, forumOrder, forumType,
420:                        forumFormatOption, forumOption, forumStatus,
421:                        forumModerationMode);
422:
423:                // Now clear the cache
424:                ForumCache.getInstance().clear();
425:            }
426:
427:            /*
428:             * @todo: check permission
429:             */
430:            public void processUpdateForumOrder(GenericRequest request)
431:                    throws BadInputException, DatabaseException,
432:                    ObjectNotFoundException, AuthenticationException {
433:
434:                OnlineUser onlineUser = onlineUserManager
435:                        .getOnlineUser(request);
436:                MVNForumPermission permission = onlineUser.getPermission();
437:
438:                Locale locale = I18nUtil.getLocaleInRequest(request);
439:
440:                // primary key column(s)
441:                int forumID = GenericParamUtil
442:                        .getParameterInt(request, "forum");
443:
444:                permission.ensureCanEditForum(forumID);
445:
446:                Timestamp now = DateUtil.getCurrentGMTTimestamp();
447:
448:                String action = GenericParamUtil.getParameterSafe(request,
449:                        "action", true);
450:                if (action.equals("up")) {
451:                    DAOFactory.getForumDAO().decreaseForumOrder(forumID, now);
452:                } else if (action.equals("down")) {
453:                    DAOFactory.getForumDAO().increaseForumOrder(forumID, now);
454:                } else {
455:                    String localizedMessage = MVNForumResourceBundle
456:                            .getString(
457:                                    locale,
458:                                    "mvncore.exception.BadInputException.cannot_update_order.unknown_action",
459:                                    new Object[] { action });
460:                    throw new BadInputException(localizedMessage);
461:                    //throw new BadInputException("Cannot update ForumOrder: unknown action: " + action);
462:                }
463:
464:                // Now clear the cache
465:                ForumCache.getInstance().clear();
466:            }
467:
468:            public void prepareForumManagement(GenericRequest request,
469:                    GenericResponse response) throws DatabaseException,
470:                    AuthenticationException {
471:
472:                OnlineUser onlineUser = onlineUserManager
473:                        .getOnlineUser(request);
474:                MVNForumPermission permission = onlineUser.getPermission();
475:
476:                if ((permission.canEditAnyForum() == false)
477:                        && (permission.canAddForum() == false)) {
478:                    permission.ensureCanEditAnyForum(); // is this the correct permission
479:                    permission.ensureCanAddForum();
480:                }
481:
482:                CategoryBuilder builder = new DefaultCategoryBuilder();
483:                CategoryTree tree = new CategoryTree(builder);
484:                CategoryTreeListener listener = categoryService
485:                        .getManagementCategoryTree(request, response);
486:                tree.addCategeoryTreeListener(listener);
487:                request.setAttribute("Result", tree.build());
488:            }
489:
490:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.