KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > treeservice > ss > CategoryNodeSupplier


1 /* ===============================================================================
2  *
3  * Part of the InfoGlue Content Management Platform (www.infoglue.org)
4  *
5  * ===============================================================================
6  *
7  * Copyright (C)
8  *
9  * This program is free software; you can redistribute it and/or modify it under
10  * the terms of the GNU General Public License version 2, as published by the
11  * Free Software Foundation. See the file LICENSE.html for more information.
12  *
13  * This program is distributed in the hope that it will be useful, but WITHOUT
14  * ANY WARRANTY, including the implied warranty of MERCHANTABILITY or FITNESS
15  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along with
18  * this program; if not, write to the Free Software Foundation, Inc. / 59 Temple
19  * Place, Suite 330 / Boston, MA 02111-1307 / USA.
20  *
21  * ===============================================================================
22  * $Id: CategoryNodeSupplier.java,v 1.3 2006/03/06 16:52:20 mattias Exp $
23  */

24 package org.infoglue.cms.treeservice.ss;
25
26 import java.util.ArrayList JavaDoc;
27 import java.util.Collection JavaDoc;
28 import java.util.Collections JavaDoc;
29 import java.util.Iterator JavaDoc;
30 import java.util.List JavaDoc;
31
32 import org.apache.log4j.Logger;
33 import org.infoglue.cms.controllers.kernel.impl.simple.CategoryController;
34 import org.infoglue.cms.entities.management.CategoryVO;
35 import org.infoglue.cms.exception.SystemException;
36
37 import com.frovi.ss.Tree.BaseNode;
38 import com.frovi.ss.Tree.BaseNodeSupplier;
39
40 /**
41  * @author Frank Febbraro (frank@phase2technology.com)
42  */

43 public class CategoryNodeSupplier extends BaseNodeSupplier
44 {
45     private final static Logger logger = Logger.getLogger(CategoryNodeSupplier.class.getName());
46
47     public static final Integer JavaDoc ROOT = new Integer JavaDoc(-1);
48
49     private CategoryController controller = CategoryController.getController();
50
51     private ArrayList JavaDoc cacheLeafs;
52
53     public CategoryNodeSupplier()
54     {
55         BaseNode rootNode = new ContentNodeImpl();
56         rootNode.setChildren(true);
57         rootNode.setId(ROOT); // There is no BASE category so make it up
58
rootNode.setTitle("Categories");
59         rootNode.setContainer(true);
60         setRootNode(rootNode);
61     }
62
63     public boolean hasChildren()
64     {
65         return true;
66     }
67
68     public Collection JavaDoc getChildContainerNodes(Integer JavaDoc parentNode)
69     {
70         ArrayList JavaDoc ret = new ArrayList JavaDoc();
71         cacheLeafs = new ArrayList JavaDoc();
72
73         List JavaDoc children = null;
74         try
75         {
76             children = (ROOT.equals(parentNode))
77                             ? controller.findRootCategories()
78                             : controller.findActiveByParent(parentNode);
79         }
80         catch (SystemException e)
81         {
82             logger.warn("Error getting Category Children", e);
83         }
84
85         for (Iterator JavaDoc i = children.iterator(); i.hasNext();)
86         {
87             CategoryVO vo = (CategoryVO) i.next();
88
89             List JavaDoc grandkids = getGrandKids(vo.getId());
90
91             BaseNode node = new CategoryNodeImpl();
92             node.setId(vo.getId());
93             node.setTitle(vo.getName());
94             node.setContainer(true);
95             node.setChildren(!grandkids.isEmpty());
96             ret.add(node);
97         }
98
99         return ret;
100     }
101
102     private List JavaDoc getGrandKids(Integer JavaDoc childId)
103     {
104         try
105         {
106             return controller.findActiveByParent(childId);
107         }
108         catch (SystemException e)
109         {
110             return Collections.EMPTY_LIST;
111         }
112     }
113
114     /**
115      * @see com.frovi.ss.Tree.INodeSupplier#getChildLeafNodes(Integer)
116      */

117     public Collection JavaDoc getChildLeafNodes(Integer JavaDoc parentNode)
118     {
119         return Collections.EMPTY_LIST;
120     }
121
122 }
123
Popular Tags