KickJava   Java API By Example, From Geeks To Geeks.

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


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  */

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.Iterator JavaDoc;
29 import java.util.List JavaDoc;
30
31 import org.infoglue.cms.controllers.kernel.impl.simple.ContentController;
32 import org.infoglue.cms.controllers.kernel.impl.simple.ContentControllerProxy;
33 import org.infoglue.cms.controllers.kernel.impl.simple.ContentVersionController;
34 import org.infoglue.cms.entities.content.ContentVO;
35 import org.infoglue.cms.entities.content.ContentVersionVO;
36 import org.infoglue.cms.exception.ConstraintException;
37 import org.infoglue.cms.exception.SystemException;
38
39 import com.frovi.ss.Tree.BaseNode;
40 import com.frovi.ss.Tree.BaseNodeSupplier;
41
42 /**
43  * ContentNodeSupplier.java
44  * Created on 2002-sep-30
45  * @author Stefan Sik, ss@frovi.com
46  * ss
47  */

48 public class ContentNodeVersionSupplier extends BaseNodeSupplier
49 {
50
51     // private BaseNode rootNode;
52
private ArrayList JavaDoc cacheLeafs;
53
54     
55     public ContentNodeVersionSupplier(Integer JavaDoc repositoryId, String JavaDoc userName) throws SystemException
56     {
57         ContentVO vo =null;
58         try
59         {
60             vo = ContentControllerProxy.getController().getRootContentVO(repositoryId, userName);
61             BaseNode rootNode = new ContentNodeImpl();
62             rootNode.setChildren(true);
63             rootNode.setId(vo.getId());
64             rootNode.setTitle(vo.getName());
65             rootNode.setContainer(vo.getIsBranch().booleanValue());
66             setRootNode(rootNode);
67         }
68         catch (ConstraintException e)
69         {
70         }
71         catch (SystemException e)
72         {
73         }
74             
75     }
76     /**
77      * @see com.frovi.ss.Tree.BaseNodeSupplier#hasChildren()
78      */

79     public boolean hasChildren()
80     {
81         return false;
82     }
83
84     /**
85      * @see com.frovi.ss.Tree.INodeSupplier#getChildContainerNodes(Integer)
86      */

87     public Collection JavaDoc getChildContainerNodes(Integer JavaDoc parentNode)
88     {
89         ArrayList JavaDoc ret = new ArrayList JavaDoc();
90         cacheLeafs = new ArrayList JavaDoc();
91         
92         if (parentNode.intValue() < 0 )
93         {
94             return ret;
95         }
96         
97         List JavaDoc l = null;
98         try
99         {
100             l = ContentController.getContentController().getContentChildrenVOList(parentNode);
101         }
102         catch (ConstraintException e)
103         {
104         }
105         catch (SystemException e)
106         {
107         }
108         
109         // Do it in two loops to get sorting right
110
Iterator JavaDoc i = l.iterator();
111         while(i.hasNext())
112         {
113             ContentVO vo = (ContentVO) i.next();
114             if (vo.getIsBranch().booleanValue())
115             {
116                 BaseNode node = new ContentNodeImpl();
117                 node.setId(vo.getId());
118                 node.setContainer(true);
119                 
120                 node.setChildren((vo.getChildCount().intValue() > 0)); //
121

122                 node.setTitle(vo.getName());
123                 
124                 ret.add(node);
125             }
126         }
127         i = l.iterator();
128         while(i.hasNext())
129         {
130             ContentVO vo = (ContentVO) i.next();
131             if (!vo.getIsBranch().booleanValue())
132             {
133                 // Betrakta dessa som container nodes
134

135                 BaseNode node = new ContentNodeImpl();
136                 node.setId( new Integer JavaDoc(- vo.getId().intValue()) );
137                 node.setContainer(true);
138                 node.setTitle(vo.getName());
139                 node.setChildren((vo.getChildCount().intValue() > 0));
140                 ret.add(node);
141             }
142         }
143         
144         return ret;
145     }
146
147     /**
148      * @see com.frovi.ss.Tree.INodeSupplier#getChildLeafNodes(Integer)
149      */

150     public Collection JavaDoc getChildLeafNodes(Integer JavaDoc parentNode)
151     {
152         ArrayList JavaDoc ret = new ArrayList JavaDoc();
153         if (parentNode.intValue() >= 0)
154             return ret;
155         
156         List JavaDoc l = null;
157         try
158         {
159             l = ContentVersionController.getContentVersionController().getContentVersionVOWithParent(new Integer JavaDoc(- parentNode.intValue()));
160         }
161         catch (SystemException e)
162         {
163         }
164         
165         Iterator JavaDoc i = l.iterator();
166         while(i.hasNext())
167         {
168             ContentVersionVO vo = (ContentVersionVO) i.next();
169             ContentNodeImpl node = new ContentNodeImpl();
170             node.setId(vo.getId());
171             node.setState(vo.getStateId());
172             node.setContainer(false);
173             node.setTitle(vo.getVersionComment() + " (" + vo.getModifiedDateTime() + ")");
174             node.getParameters().put("languageId", vo.getLanguageId());
175             node.getParameters().put("languageName", vo.getLanguageName());
176
177             ret.add(node);
178             
179         }
180         
181         return ret;
182     }
183
184 }
185
Popular Tags