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


001:        /*
002:         * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/categorytree/impl/CategoryTreePath.java,v 1.12 2007/12/17 09:09:39 minhnn Exp $
003:         * $Author: minhnn $
004:         * $Revision: 1.12 $
005:         * $Date: 2007/12/17 09:09:39 $
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: Phuong Pham Dinh Duy
039:         */
040:        package com.mvnforum.categorytree.impl;
041:
042:        import java.io.IOException;
043:        import java.util.*;
044:
045:        import net.myvietnam.mvncore.exception.DatabaseException;
046:        import net.myvietnam.mvncore.exception.ObjectNotFoundException;
047:        import net.myvietnam.mvncore.service.MvnCoreServiceFactory;
048:        import net.myvietnam.mvncore.service.URLResolverService;
049:        import net.myvietnam.mvncore.util.I18nUtil;
050:        import net.myvietnam.mvncore.web.*;
051:
052:        import org.apache.commons.logging.Log;
053:        import org.apache.commons.logging.LogFactory;
054:
055:        import com.mvnforum.MVNForumConfig;
056:        import com.mvnforum.MVNForumResourceBundle;
057:        import com.mvnforum.auth.*;
058:        import com.mvnforum.categorytree.CategoryTreeEvent;
059:        import com.mvnforum.db.*;
060:
061:        import freemarker.cache.ClassTemplateLoader;
062:        import freemarker.cache.TemplateLoader;
063:        import freemarker.template.*;
064:
065:        public class CategoryTreePath extends FtlCategoryTreeListener {
066:
067:            private static Log log = LogFactory.getLog(CategoryTreePath.class);
068:
069:            public final static int FORUMID_IN_LIST_CATEGORY_CASE = 0;
070:
071:            private OnlineUser onlineUser;
072:
073:            private static Template template;
074:            private URLResolverService urlResolver = MvnCoreServiceFactory
075:                    .getMvnCoreService().getURLResolverService();
076:            private GenericRequest request;
077:            private GenericResponse response;
078:            private int forumID;
079:            private int categoryID;
080:            private List path;
081:            private int depthOfPath;
082:            private Locale locale;
083:            private boolean showAllForumsURL = false;
084:
085:            //addpost
086:            private String mode;
087:            private String action;
088:            private String display;
089:
090:            static {
091:                Configuration conf = new Configuration();
092:                TemplateLoader loader = new ClassTemplateLoader(
093:                        CategorySelector.class);
094:                conf.setTemplateLoader(loader);
095:                try {
096:                    template = conf.getTemplate("categorytreepath.ftl");
097:                } catch (IOException e) {
098:                    log.error("Cannot load template for CategorySelector", e);
099:                }
100:            }
101:
102:            public CategoryTreePath(GenericRequest request,
103:                    GenericResponse response, int forumID, int categoryID,
104:                    String display) throws DatabaseException,
105:                    ObjectNotFoundException, AuthenticationException {
106:                this .request = request;
107:                this .response = response;
108:                this .forumID = forumID;
109:                this .categoryID = categoryID;
110:                this .display = display;
111:                showAllForumsURL = ((display != null) && (display.equals("") == false));
112:                onlineUser = OnlineUserManager.getInstance().getOnlineUser(
113:                        request);
114:                locale = I18nUtil.getLocaleInRequest(request);
115:
116:                path = new ArrayList();
117:                findPath();
118:
119:                init(template);
120:            }
121:
122:            public CategoryTreePath(GenericRequest request,
123:                    GenericResponse response, int forumID, String mode,
124:                    String action, String display) throws DatabaseException,
125:                    ObjectNotFoundException, AuthenticationException {
126:                this .request = request;
127:                this .response = response;
128:                this .forumID = forumID;
129:                this .mode = mode;
130:                this .action = action;
131:                this .display = display;
132:                showAllForumsURL = true;
133:                onlineUser = OnlineUserManager.getInstance().getOnlineUser(
134:                        request);
135:                locale = I18nUtil.getLocaleInRequest(request);
136:
137:                path = new ArrayList();
138:                findPath();
139:
140:                init(template);
141:            }
142:
143:            public void setDepthOfPath(int depthOfPath) {
144:                this .depthOfPath = depthOfPath;
145:            }
146:
147:            public int getDepthOfPath() {
148:                return this .depthOfPath;
149:            }
150:
151:            private void findPath() throws DatabaseException,
152:                    ObjectNotFoundException {
153:
154:                int categoryIDTMP = 0;
155:
156:                if (forumID != FORUMID_IN_LIST_CATEGORY_CASE) {
157:                    /*
158:                     * In this case [e.g: listthreads], we will find the path from forumID
159:                     */
160:                    ForumBean forumBean = ForumCache.getInstance().getBean(
161:                            forumID);
162:
163:                    categoryIDTMP = forumBean.getCategoryID();
164:                } else {
165:                    /*
166:                     * In this case [e.g: listforums], we will find the path from categoryID
167:                     */
168:                    categoryIDTMP = categoryID;
169:                }
170:
171:                CategoryBean categoryBeanTMP = null;
172:                while (categoryIDTMP != 0) {
173:                    categoryBeanTMP = CategoryCache.getInstance().getBean(
174:                            categoryIDTMP);
175:                    path.add(categoryBeanTMP);
176:                    categoryIDTMP = categoryBeanTMP.getParentCategoryID();
177:                }
178:
179:                Collections.reverse(path);
180:                //setDepthOfPath((MVNForumConfig.getEnablePortalLikeIndexPage()) ? path.size() + 1 : path.size());
181:                setDepthOfPath(path.size());
182:            }
183:
184:            private boolean isInPath(int categoryID) {
185:                //check if the category with categoryID is in the path
186:                if (path != null) {
187:                    Iterator iter = path.iterator();
188:                    while (iter.hasNext()) {
189:                        CategoryBean bean = (CategoryBean) iter.next();
190:                        if (categoryID == bean.getCategoryID()) {
191:                            return true;
192:                        }
193:                    }
194:                }
195:                return false;
196:            }
197:
198:            public String drawHeader(CategoryTreeEvent event) {
199:                SimpleHash subRoot = new SimpleHash();
200:                subRoot.put("name", "header");
201:
202:                String index_desc = MVNForumResourceBundle.getString(locale,
203:                        "mvnforum.common.nav.index");
204:                subRoot.put("index_desc", index_desc);
205:
206:                String indexURL = urlResolver.encodeURL(request, response,
207:                        "index");
208:                subRoot.put("indexURL", indexURL);
209:                subRoot.put("ContextPath", request.getContextPath());
210:
211:                subRoot.put("enablePortalLikeIndexPage", new Boolean(
212:                        MVNForumConfig.getEnablePortalLikeIndexPage()));
213:                if (MVNForumConfig.getEnablePortalLikeIndexPage()) {
214:                    String listForums = MVNForumResourceBundle.getString(
215:                            onlineUser.getLocale(),
216:                            "mvnforum.user.listforums.title");
217:                    subRoot.put("listForums", listForums);
218:
219:                    String listForumsLink = urlResolver.encodeURL(request,
220:                            response, "listforums",
221:                            URLResolverService.RENDER_URL);
222:                    subRoot.put("listForumsLink", listForumsLink);
223:
224:                }
225:                rows.add(subRoot);
226:                return "";
227:            }
228:
229:            public String drawCategory(CategoryTreeEvent event) {
230:                CategoryBean categoryBean = (CategoryBean) event.getSource();
231:
232:                if (isInPath(categoryBean.getCategoryID()) == false) {
233:                    return "";
234:                }
235:                SimpleHash subRoot = new SimpleHash();
236:                subRoot.put("name", "category");
237:
238:                String categoryURL = urlResolver.encodeURL(request, response,
239:                        "listforums?category=" + categoryBean.getCategoryID()
240:                                + "&other_category_invisible=true");
241:                subRoot.put("CategoryURL", categoryURL);
242:                subRoot.put("CategoryName", categoryBean.getCategoryName());
243:
244:                //int spacer = event.getLevel() + (MVNForumConfig.getEnablePortalLikeIndexPage() ? 2 : 1);
245:                int spacer = event.getLevel() + 1;
246:                subRoot.put("Spacer", new Integer(spacer));
247:
248:                subRoot.put("ContextPath", request.getContextPath());
249:
250:                String categoryPrefix = MVNForumResourceBundle.getString(
251:                        locale, "mvnforum.common.category");
252:                subRoot.put("CategoryPrefix", categoryPrefix);
253:
254:                rows.add(subRoot);
255:                return "";
256:            }
257:
258:            public String drawForum(CategoryTreeEvent event) {
259:                ForumBean forumBean = (ForumBean) event.getSource();
260:
261:                /*
262:                 * In listforums, we don't need to draw forums
263:                 */
264:                if ((forumBean.getForumID() != forumID)
265:                        || (forumID == FORUMID_IN_LIST_CATEGORY_CASE)) {
266:                    return "";
267:                }
268:
269:                SimpleHash subRoot = new SimpleHash();
270:                subRoot.put("name", "forum");
271:
272:                subRoot.put("ForumName", forumBean.getForumName());
273:                subRoot.put("Spacer", new Integer(getDepthOfPath()));
274:                subRoot.put("ContextPath", request.getContextPath());
275:                subRoot.put("ShowAllForumsURL", new Boolean(showAllForumsURL));
276:
277:                if (showAllForumsURL) {
278:                    String forumURL = urlResolver.encodeURL(request, response,
279:                            "listthreads?forum=" + forumID);
280:                    subRoot.put("ForumURL", forumURL);
281:                }
282:
283:                String forumPrefix = MVNForumResourceBundle.getString(locale,
284:                        "mvnforum.common.forum");
285:                subRoot.put("ForumPrefix", forumPrefix);
286:
287:                rows.add(subRoot);
288:                return "";
289:            }
290:
291:            public String drawFooter(CategoryTreeEvent event) {
292:                SimpleHash subRoot = new SimpleHash();
293:                subRoot.put("ShowAllForumsURL", new Boolean(showAllForumsURL));
294:                subRoot.put("name", "footer");
295:
296:                if (showAllForumsURL == false) {
297:                    return "";
298:                }
299:
300:                int spacer;
301:                if ((forumID == FORUMID_IN_LIST_CATEGORY_CASE)
302:                        || (path.size() == 0)) {
303:                    /*
304:                     * - No listthreads
305:                     * - /mvnforum_enterprise/mvnforum/listforums
306:                     */
307:                    spacer = getDepthOfPath();
308:                } else {
309:                    spacer = getDepthOfPath() + 1;
310:                }
311:                subRoot.put("Spacer", new Integer(spacer));
312:                subRoot.put("ContextPath", request.getContextPath());
313:
314:                boolean isAddPostType = (mode != null) && (action != null)
315:                        && (display != null);
316:                subRoot.put("isAddPostType", new Boolean(isAddPostType));
317:
318:                boolean isViewThreadType = (mode == null) && (action == null)
319:                        && (display != null);
320:                subRoot.put("isViewThreadType", new Boolean(isViewThreadType));
321:
322:                String content = "";
323:                if (isAddPostType) {
324:                    //addpost
325:                    content = mode + " : " + display;
326:                    if (action.equals("addnew")) {
327:                        if (display.equals("") == false) {
328:                            content = mode + ": " + display;
329:                        } else {
330:                            content = mode;
331:                        }
332:                    } else if (action.equals("update")) {
333:                        content = mode + ": " + display;
334:                    }
335:                } else if (isViewThreadType) {
336:                    //viewthread or addattachment or deleteaddtachment
337:                    content = display;
338:                    //subRoot.put("ThreadTopic", display);
339:                }
340:                subRoot.put("Content", content);
341:
342:                rows.add(subRoot);
343:                return "";
344:            }
345:
346:            public String drawSeparator(CategoryTreeEvent event) {
347:                return "";
348:            }
349:
350:            public void setDepthTree(int depth) {
351:
352:            }
353:
354:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.