Source Code Cross Referenced for WatchUtil.java in  » Forum » mvnforum-1.1 » com » mvnforum » user » 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.user 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/user/WatchUtil.java,v 1.13 2007/12/17 09:09:41 minhnn Exp $
003:         * $Author: minhnn $
004:         * $Revision: 1.13 $
005:         * $Date: 2007/12/17 09:09:41 $
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:         * @author: Cord         cord_sw@lupinex.com
041:         */
042:        package com.mvnforum.user;
043:
044:        import java.util.*;
045:
046:        import com.mvnforum.db.*;
047:
048:        import net.myvietnam.mvncore.exception.DatabaseException;
049:        import net.myvietnam.mvncore.exception.ObjectNotFoundException;
050:
051:        public final class WatchUtil {
052:
053:            // prevent instantiation
054:            private WatchUtil() {
055:            }
056:
057:            private static boolean isCategoryInWatchs(int categoryID,
058:                    ArrayList categoryWatchs) {
059:                for (int catIndex = 0; catIndex < categoryWatchs.size(); catIndex++) {
060:                    WatchBean watchBean = (WatchBean) categoryWatchs
061:                            .get(catIndex);
062:                    int currentCategoryID = watchBean.getCategoryID();
063:                    if (currentCategoryID == categoryID) {
064:                        return true;
065:                    }
066:                }
067:                return false;
068:            }
069:
070:            /**
071:             * Optimize the watch collection, note that the thread is not optimized
072:             * @param watchBeans
073:             * @return the watch collection that has been optimized
074:             */
075:            static Collection optimize(Collection watchBeans)
076:                    throws DatabaseException, ObjectNotFoundException {
077:
078:                // now check the global watch first
079:                Collection globalWatchs = getGlobalWatchs(watchBeans);
080:                if (globalWatchs.size() == 1) {
081:                    return globalWatchs;
082:                }
083:
084:                ArrayList categoryWatchs = getCategoryWatchs(watchBeans);
085:
086:                // next, set it to the category watch beans
087:                ArrayList optimizedWatchs = new ArrayList();// MUST use ArrayList for the optimizedWatchs
088:                optimizedWatchs.addAll(categoryWatchs);
089:
090:                // now remove the redundant forum watch beans
091:                ArrayList forumWatchs = getForumWatchs(watchBeans);
092:                ForumCache forumCache = ForumCache.getInstance();
093:                for (int forumIndex = 0; forumIndex < forumWatchs.size(); forumIndex++) {
094:                    WatchBean forumWatch = (WatchBean) forumWatchs
095:                            .get(forumIndex);
096:                    ForumBean forumBean = forumCache.getBean(forumWatch
097:                            .getForumID());
098:                    int categoryID = forumBean.getCategoryID();
099:
100:                    // now check if the categoryID is in categoryWatchs or not
101:                    if (isCategoryInWatchs(categoryID, categoryWatchs) == false) {
102:                        optimizedWatchs.add(forumWatch);
103:                    }
104:                }
105:
106:                // finally, add the thread watches (not optimize thread) (why not optimize thread ???)
107:                ArrayList threadWatchs = getThreadWatchs(watchBeans);
108:                optimizedWatchs.addAll(threadWatchs);
109:
110:                return optimizedWatchs;
111:            }
112:
113:            static ArrayList getGlobalWatchs(Collection watchBeans) {
114:
115:                ArrayList globalWatchs = new ArrayList(1);//maximum is 1 global watch
116:
117:                for (Iterator iterator = watchBeans.iterator(); iterator
118:                        .hasNext();) {
119:                    WatchBean watchBean = (WatchBean) iterator.next();
120:                    if ((watchBean.getCategoryID() == 0)
121:                            && (watchBean.getForumID() == 0)
122:                            && (watchBean.getThreadID() == 0)) {
123:                        globalWatchs.add(watchBean);
124:                    }
125:                }
126:                return globalWatchs;
127:            }
128:
129:            static ArrayList getCategoryWatchs(Collection watchBeans) {
130:
131:                ArrayList categoryWatchs = new ArrayList();
132:
133:                for (Iterator iterator = watchBeans.iterator(); iterator
134:                        .hasNext();) {
135:                    WatchBean watchBean = (WatchBean) iterator.next();
136:                    if (watchBean.getCategoryID() != 0) {
137:                        if ((watchBean.getForumID() == 0)
138:                                && (watchBean.getThreadID() == 0)) {
139:                            categoryWatchs.add(watchBean);
140:                        } else {
141:                            //TODO: should we delete watch here ???
142:                        }
143:                    }
144:                }
145:                return categoryWatchs;
146:            }
147:
148:            static ArrayList getForumWatchs(Collection watchBeans) {
149:                ArrayList forumWatchs = new ArrayList();
150:                Iterator iterator = watchBeans.iterator();
151:                while (iterator.hasNext()) {
152:                    WatchBean watchBean = (WatchBean) iterator.next();
153:                    if (watchBean.getForumID() != 0) {
154:                        if ((watchBean.getCategoryID() == 0)
155:                                && (watchBean.getThreadID() == 0)) {
156:                            forumWatchs.add(watchBean);
157:                        } else {
158:                            //TODO: delete watch here
159:                        }
160:                    }
161:                }
162:                return forumWatchs;
163:            }
164:
165:            static ArrayList getThreadWatchs(Collection watchBeans) {
166:                ArrayList threadWatchs = new ArrayList();
167:                Iterator iterator = watchBeans.iterator();
168:                while (iterator.hasNext()) {
169:                    WatchBean watchBean = (WatchBean) iterator.next();
170:                    if (watchBean.getThreadID() != 0) {
171:                        if ((watchBean.getCategoryID() == 0)
172:                                && (watchBean.getForumID() == 0)) {
173:                            threadWatchs.add(watchBean);
174:                        } else {
175:                            //TODO: delete watch here
176:                        }
177:                    }
178:                }
179:                return threadWatchs;
180:            }
181:
182:            public static boolean isWatched(int memberID, int categoryID,
183:                    int forumID, int threadID) throws DatabaseException {
184:                try {
185:                    DAOFactory
186:                            .getWatchDAO()
187:                            .findByAlternateKey_MemberID_CategoryID_ForumID_ThreadID(
188:                                    memberID, categoryID, forumID, threadID);
189:                } catch (ObjectNotFoundException e) {
190:                    return false;
191:                }
192:                return true;
193:            }
194:
195:            public static boolean isGlobalWatched(int memberID)
196:                    throws DatabaseException {
197:                return isWatched(memberID, 0, 0, 0);
198:            }
199:
200:            public static boolean isCategoryWatched(int memberID,
201:                    CategoryBean categoryBean) throws DatabaseException,
202:                    ObjectNotFoundException {
203:                int parentCategoryID = categoryBean.getParentCategoryID();
204:                if (parentCategoryID != 0) {
205:                    CategoryBean parentCategoryBean = CategoryCache
206:                            .getInstance().getBean(parentCategoryID);
207:                    if (isCategoryWatched(memberID, parentCategoryBean)) {
208:                        //temporarily comment out until we implement category hierarchy watching
209:                        //return true;
210:                    }
211:                }
212:                return isWatched(memberID, categoryBean.getCategoryID(), 0, 0)
213:                        || isGlobalWatched(memberID);
214:            }
215:
216:            public static boolean isForumWatched(int memberID,
217:                    ForumBean forumBean) throws DatabaseException,
218:                    ObjectNotFoundException {
219:                int categoryID = forumBean.getCategoryID();
220:                CategoryBean categoryBean = CategoryCache.getInstance()
221:                        .getBean(categoryID);
222:                return isWatched(memberID, 0, forumBean.getForumID(), 0)
223:                        || isCategoryWatched(memberID, categoryBean);
224:            }
225:
226:            public static boolean isThreadWatched(int memberID,
227:                    ThreadBean threadBean, ForumBean forumBean)
228:                    throws DatabaseException, ObjectNotFoundException {
229:                return isWatched(memberID, 0, 0, threadBean.getThreadID())
230:                        || isForumWatched(memberID, forumBean);
231:            }
232:
233:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.