KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.List JavaDoc;
27
28 import javax.servlet.http.Cookie JavaDoc;
29
30 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
31 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
32 import org.infoglue.cms.entities.management.RepositoryVO;
33 import org.infoglue.cms.util.CmsPropertyHandler;
34
35
36 /**
37  * This class implements the action class for the header in the content tool.
38  *
39  * @author Mattias Bogeblad
40  */

41
42 public class ViewContentToolHeaderAction extends InfoGlueAbstractAction
43 {
44     private static final long serialVersionUID = 1L;
45     
46     private String JavaDoc tree;
47     private String JavaDoc showVersions;
48     private String JavaDoc exp=""; // for html tree support to start expanded
49

50     private Integer JavaDoc repositoryId;
51      
52     private List JavaDoc repositories;
53     
54     public String JavaDoc doExecute() throws Exception JavaDoc
55     {
56         if (this.showVersions == null || this.showVersions.equals(""))
57             this.showVersions = (String JavaDoc)getRequest().getSession().getAttribute("htmlTreeShowVersions");
58         else
59             getRequest().getSession().setAttribute("htmlTreeShowVersions", this.showVersions);
60         
61         if (showVersions != null)
62         {
63             Cookie JavaDoc t = new Cookie JavaDoc("showversions", showVersions);
64             getResponse().addCookie(t);
65         }
66
67         // Get / Set tree preferance
68
if (tree != null)
69         {
70             // This action was called with parameter to set tree preferance
71
// Add a cookie for the tree setting
72
Cookie JavaDoc t = new Cookie JavaDoc("tree", tree);
73             getResponse().addCookie(t);
74         }
75         else
76         {
77         // First try to get user cookie for tree-mode
78
Cookie JavaDoc[] cookies = getRequest().getCookies();
79             if(cookies != null)
80                 for (int i=0; i < cookies.length; i++)
81                 {
82                     if (cookies[i].getName().compareTo("tree") == 0)
83                         setTree(cookies[i].getValue());
84
85                     if (cookies[i].getName().compareTo("showversions") == 0)
86                         setShowVersions(cookies[i].getValue());
87                 }
88         }
89
90         // If that fails, try global properties for default tree
91
if (tree == null)
92             setTree(CmsPropertyHandler.getTree());
93
94         // Still no tree, force applet version
95
if (tree == null)
96             setTree("applet");
97
98         if (showVersions == null)
99             setShowVersions("no");
100                 
101         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
102
103         return "success";
104     }
105     
106     public List JavaDoc getRepositories()
107     {
108         return this.repositories;
109     }
110     
111     public Integer JavaDoc getTopRepositoryId()
112     {
113         Integer JavaDoc topRepositoryId = null;
114         
115         if (repositoryId != null)
116             topRepositoryId = repositoryId;
117         
118         if(this.repositories.size() > 0)
119         {
120             topRepositoryId = ((RepositoryVO)this.repositories.get(0)).getRepositoryId();
121         }
122             
123         return topRepositoryId;
124     }
125
126     /**
127      * Returns the tree.
128      * @return String
129      */

130     public String JavaDoc getTree() {
131         return tree;
132     }
133
134     /**
135      * Sets the tree.
136      * @param tree The tree to set
137      */

138     public void setTree(String JavaDoc tree) {
139         this.tree = tree;
140     }
141
142     /**
143      * Returns the repositoryId.
144      * @return Integer
145      */

146     public Integer JavaDoc getRepositoryId()
147     {
148         try
149         {
150             if(this.repositoryId == null)
151             {
152                 this.repositoryId = (Integer JavaDoc)getHttpSession().getAttribute("repositoryId");
153                 
154                 if(this.repositoryId == null)
155                 {
156                     this.repositoryId = getTopRepositoryId();
157                     getHttpSession().setAttribute("repositoryId", this.repositoryId);
158                 }
159             }
160         }
161         catch(Exception JavaDoc e)
162         {
163         }
164         
165         return repositoryId;
166     }
167     
168     /**
169      * Returns the repositoryName.
170      * @return String
171      */

172     public String JavaDoc getRepositoryName()
173     {
174         String JavaDoc repositoryName = "";
175         try
176         {
177             Integer JavaDoc repositoryId = this.getRepositoryId();
178             repositoryName = RepositoryController.getController().getRepositoryVOWithId(repositoryId).getName();
179         }
180         catch(Exception JavaDoc e)
181         {
182         }
183         
184         return repositoryName;
185     }
186
187     /**
188      * Sets the repositoryId.
189      * @param repositoryId The repositoryId to set
190      */

191     public void setRepositoryId(Integer JavaDoc repositoryId)
192     {
193         this.repositoryId = repositoryId;
194     }
195
196     /**
197      * Returns the showVersions.
198      * @return String
199      */

200     public String JavaDoc getShowVersions()
201     {
202         return showVersions;
203     }
204
205     /**
206      * Sets the showVersions.
207      * @param showVersions The showVersions to set
208      */

209     public void setShowVersions(String JavaDoc showVersions)
210     {
211         this.showVersions = showVersions;
212     }
213
214     /**
215      * Returns the exp.
216      * @return String
217      */

218     public String JavaDoc getExp()
219     {
220         return exp;
221     }
222
223     /**
224      * Sets the exp.
225      * @param exp The exp to set
226      */

227     public void setExp(String JavaDoc exp)
228     {
229         this.exp = exp;
230     }
231
232 }
233
Popular Tags