001: /*
002: * $Header: /cvsroot/mvnforum/mvnforum/src/com/mvnforum/categorytree/ExtensionCategoryBuilder.java,v 1.4 2007/12/17 09:09:42 minhnn Exp $
003: * $Author: minhnn $
004: * $Revision: 1.4 $
005: * $Date: 2007/12/17 09:09:42 $
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;
041:
042: import java.util.*;
043:
044: import com.mvnforum.db.CategoryBean;
045:
046: import net.myvietnam.mvncore.exception.DatabaseException;
047:
048: public class ExtensionCategoryBuilder extends CategoryBuilder {
049:
050: private CategoryBean categoryBean;
051:
052: public ExtensionCategoryBuilder() throws DatabaseException {
053: //call CategoryBuilder constructor
054: }
055:
056: public CategoryBean getCategoryBean() {
057: return this .categoryBean;
058: }
059:
060: public void changeCategoryBean(CategoryBean categoryBean) {
061: this .categoryBean = categoryBean;
062: setChanged();
063: notifyObservers(categoryBean);
064: }
065:
066: public void drawBody() {
067: //draw category tree
068: if (root != null) {
069: recursive(tree, root, 0, "/");
070: } else {
071: Collection topCategories = getTopCategories();
072: for (Iterator iter = topCategories.iterator(); iter
073: .hasNext();) {
074: CategoryBean category = (CategoryBean) iter.next();
075: recursive(tree, category, 0, "/");
076: }
077: }
078:
079: }
080:
081: private void recursive(StringBuffer html, CategoryBean category,
082: int level, String parentPrefix) {
083:
084: String prefix = "";
085: Collection children = this .getChildrenByCategoryId(category
086: .getCategoryID());
087: Collection forumChildren = this .getForumsByCategoryId(category
088: .getCategoryID());
089:
090: if (category != null) {
091: prefix = parentPrefix + "/" + category.getCategoryID();
092: if (rootID == category.getCategoryID()) {
093: ID = prefix;
094: }
095: }
096:
097: CategoryTreeEvent event = new CategoryTreeEvent(category);
098: event.setHasSubCategory(children.isEmpty() == false);
099: event.setDepth(this .depth);
100: event.setLevel(level);
101: event.setIdsPath(prefix);
102: event.setHasForum(forumChildren.isEmpty() == false);
103: html.append(listener.drawCategory(event));
104:
105: for (Iterator iterator = children.iterator(); iterator
106: .hasNext();) {
107: CategoryBean bean = (CategoryBean) iterator.next();
108: recursive(html, bean, level + 1, prefix);
109: }
110: //CategoryBuilder extends Observable
111: //CategoryTreeListener extends Observer
112: addObserver(listener);
113: changeCategoryBean((CategoryBean) event.getSource());
114: for (Iterator iterator = forumChildren.iterator(); iterator
115: .hasNext();) {
116: CategoryTreeEvent e = new CategoryTreeEvent(iterator.next());
117: e.setDepth(this.depth);
118: e.setLevel(level);
119: e.setIdsPath(prefix);
120: html.append(listener.drawForum(e));
121: }
122:
123: }
124: }
|