KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > contenttool > actions > ViewContentToolMenuHtmlAction


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.applications.contenttool.actions;
25
26 import java.net.URLEncoder JavaDoc;
27 import java.util.List JavaDoc;
28
29 import org.apache.log4j.Logger;
30 import org.infoglue.cms.applications.common.actions.TreeViewAbstractAction;
31 import org.infoglue.cms.controllers.kernel.impl.simple.ContentTypeDefinitionController;
32 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
33 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryLanguageController;
34 import org.infoglue.cms.entities.management.RepositoryVO;
35 import org.infoglue.cms.treeservice.ss.ContentNodeSupplier;
36 import org.infoglue.cms.treeservice.ss.ContentNodeVersionSupplier;
37 import org.infoglue.cms.util.CmsPropertyHandler;
38
39 import com.frovi.ss.Tree.BaseNode;
40 import com.frovi.ss.Tree.INodeSupplier;
41
42 public class ViewContentToolMenuHtmlAction extends TreeViewAbstractAction
43 {
44     private final static Logger logger = Logger.getLogger(ViewContentToolMenuHtmlAction.class.getName());
45
46     private static final long serialVersionUID = 1L;
47     
48     private Integer JavaDoc repositoryId;
49     private String JavaDoc showVersions;
50     private String JavaDoc showLeafs = "yes";
51     private String JavaDoc treeMode = "classic";
52     private Integer JavaDoc select;
53     private BaseNode rootNode = null;
54     private String JavaDoc[] allowedContentTypeIds = null;
55     private String JavaDoc bodyClass;
56         
57     /* Experiment 2003-09-11 TODO:
58      * Provide a list of content-type definition, so that
59      * we can populate a contenxt menu, to support the
60      * creation of new contents.
61      *
62      */

63     
64     
65     public String JavaDoc doBindingView() throws Exception JavaDoc
66     {
67         super.doExecute();
68         
69         return "bindingView";
70     }
71     
72     /**
73      * @see org.infoglue.cms.applications.common.actions.TreeViewAbstractAction#getNodeSupplier()
74      */

75     protected INodeSupplier getNodeSupplier() throws Exception JavaDoc, org.infoglue.cms.exception.SystemException
76     {
77         if (this.showVersions == null || this.showVersions.equals(""))
78         {
79             this.showVersions = (String JavaDoc)getRequest().getSession().getAttribute("htmlTreeShowVersions");
80         }
81         else
82         {
83             getRequest().getSession().setAttribute("htmlTreeShowVersions", this.showVersions);
84         }
85         
86         /*
87         Cookie[] cookies = getRequest().getCookies();
88         if(cookies != null)
89             for (int i=0; i < cookies.length; i++)
90                 if (cookies[i].getName().compareTo("showversions") == 0)
91                     if (cookies[i].getValue().compareTo("yes") == 0)
92                     {
93                         setShowVersions("yes");
94                         return new ContentNodeVersionSupplier(getRepositoryId(), this.getInfoGluePrincipal().getName());
95                     }
96                     */

97         
98         INodeSupplier sup = null;
99         if (this.showVersions != null && this.showVersions.equalsIgnoreCase("yes"))
100         {
101             sup = new ContentNodeVersionSupplier(getRepositoryId(), this.getInfoGluePrincipal().getName());
102         }
103         else
104         {
105             ContentNodeSupplier contentNodeSupplier = new ContentNodeSupplier(getRepositoryId(), this.getInfoGluePrincipal());
106             contentNodeSupplier.setShowLeafs(showLeafs.compareTo("yes")==0);
107             contentNodeSupplier.setAllowedContentTypeIds(allowedContentTypeIds);
108             sup = contentNodeSupplier;
109         }
110         
111         String JavaDoc treeMode = CmsPropertyHandler.getTreeMode();
112         if(treeMode != null) setTreeMode(treeMode);
113         
114
115         rootNode = sup.getRootNode();
116         return sup;
117     }
118
119     public List JavaDoc getAvailableLanguages() throws Exception JavaDoc
120     {
121         return RepositoryLanguageController.getController().getRepositoryLanguageVOListWithRepositoryId(this.repositoryId);
122     }
123
124     public List JavaDoc getContentTypeDefinitions() throws Exception JavaDoc
125     {
126         return ContentTypeDefinitionController.getController().getContentTypeDefinitionVOList();
127     }
128
129     /**
130      * Returns the repositoryId.
131      * @return Integer
132      */

133     public Integer JavaDoc getRepositoryId()
134     {
135         if(this.repositoryId == null)
136         {
137             try
138             {
139                 List JavaDoc repositoryVOList = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
140                 if(repositoryVOList != null && repositoryVOList.size() > 0)
141                 {
142                     this.repositoryId = ((RepositoryVO)repositoryVOList.get(0)).getId();
143                 }
144             }
145             catch(Exception JavaDoc e)
146             {
147                 logger.error("Could not fetch the master repository for the principal:" + e.getMessage(), e);
148             }
149         }
150             
151         return repositoryId;
152     }
153
154     /**
155      * Sets the repositoryId.
156      * @param repositoryId The repositoryId to set
157      */

158     public void setRepositoryId(Integer JavaDoc repositoryId)
159     {
160         this.repositoryId = repositoryId;
161     }
162
163     /**
164      * Returns the showVersions.
165      * @return String
166      */

167     public String JavaDoc getShowVersions()
168     {
169         return showVersions;
170     }
171
172     /**
173      * Sets the showVersions.
174      * @param showVersions The showVersions to set
175      */

176     public void setShowVersions(String JavaDoc showVersions)
177     {
178         this.showVersions = showVersions;
179     }
180
181     /**
182      * Returns the showLeafs.
183      * @return String
184      */

185     public String JavaDoc getShowLeafs()
186     {
187         return showLeafs;
188     }
189
190     /**
191      * Sets the showLeafs.
192      * @param showLeafs The showLeafs to set
193      */

194     public void setShowLeafs(String JavaDoc showLeafs)
195     {
196         this.showLeafs = showLeafs;
197     }
198
199     /**
200      * Returns the select.
201      * @return Integer
202      */

203     public Integer JavaDoc getSelect()
204     {
205         return select;
206     }
207
208     /**
209      * Sets the select.
210      * @param select The select to set
211      */

212     public void setSelect(Integer JavaDoc select)
213     {
214         this.select = select;
215     }
216
217     public BaseNode getRootNode()
218     {
219         return rootNode;
220     }
221     
222     public void setRootNode(BaseNode rootNode)
223     {
224         this.rootNode = rootNode;
225     }
226     
227     public String JavaDoc getTreeMode()
228     {
229         return treeMode;
230     }
231     
232     public void setTreeMode(String JavaDoc treeMode)
233     {
234         this.treeMode = treeMode;
235     }
236     
237     public String JavaDoc[] getAllowedContentTypeIds()
238     {
239         return allowedContentTypeIds;
240     }
241     
242     public void setAllowedContentTypeIds(String JavaDoc[] allowedContentTypeIds)
243     {
244         this.allowedContentTypeIds = allowedContentTypeIds;
245     }
246     
247     public String JavaDoc getAllowedContentTypeIdsAsUrlEncodedString() throws Exception JavaDoc
248     {
249         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
250         
251         for(int i=0; i<allowedContentTypeIds.length; i++)
252         {
253             if(i > 0)
254                 sb.append("&");
255             
256             sb.append("allowedContentTypeIds=" + URLEncoder.encode(allowedContentTypeIds[i], "UTF-8"));
257         }
258
259         return sb.toString();
260     }
261     
262     public String JavaDoc getBodyClass()
263     {
264         return bodyClass;
265     }
266     
267     public void setBodyClass(String JavaDoc bodyClass)
268     {
269         this.bodyClass = bodyClass;
270     }
271 }
272
Popular Tags