KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > structuretool > actions > ViewStructureToolHeaderAction


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.structuretool.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 siteNode tool.
38  *
39  * @author Mattias Bogeblad
40  */

41
42 public class ViewStructureToolHeaderAction extends InfoGlueAbstractAction
43 {
44     private static final long serialVersionUID = 1L;
45      
46     private List JavaDoc repositories;
47     private String JavaDoc tree;
48     private Integer JavaDoc repositoryId;
49     
50     public String JavaDoc doExecute() throws Exception JavaDoc
51     {
52         // Get / Set tree preferance
53
if (tree != null)
54         {
55             // This action was called with parameter to set tree preferance
56
// Add a cookie for the tree setting
57
Cookie JavaDoc t = new Cookie JavaDoc("tree", tree);
58             getResponse().addCookie(t);
59         }
60         else
61         {
62         // First try to get user cookie for tree-mode
63
Cookie JavaDoc[] cookies = getRequest().getCookies();
64             if(cookies != null)
65                 for (int i=0; i < cookies.length; i++)
66                     if (cookies[i].getName().compareTo("tree") == 0)
67                         setTree(cookies[i].getValue());
68         }
69
70         // If that fails, try global properties for default tree
71
if (tree == null)
72             setTree(CmsPropertyHandler.getTree());
73
74         // Still no tree, force applet version
75
if (tree == null)
76             setTree("applet");
77         
78         this.repositories = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
79         
80         return "success";
81     }
82     
83     public List JavaDoc getRepositories()
84     {
85         return this.repositories;
86     }
87     
88     public Integer JavaDoc getTopRepositoryId()
89     {
90         if (repositoryId != null)
91             return repositoryId;
92         
93         if(this.repositories.size() > 0)
94         {
95             return ((RepositoryVO)this.repositories.get(0)).getRepositoryId();
96         }
97         
98         return null;
99     }
100     /**
101      * Returns the repositoryId.
102      * @return Integer
103      */

104     public Integer JavaDoc getRepositoryId()
105     {
106         try
107         {
108             if(this.repositoryId == null)
109             {
110                 this.repositoryId = (Integer JavaDoc)getHttpSession().getAttribute("repositoryId");
111                 
112                 if(this.repositoryId == null)
113                 {
114                     this.repositoryId = getTopRepositoryId();
115                     getHttpSession().setAttribute("repositoryId", this.repositoryId);
116                 }
117             }
118         }
119         catch(Exception JavaDoc e)
120         {
121         }
122    
123         return repositoryId;
124     }
125
126     /**
127      * Returns the repositoryName.
128      * @return String
129      */

130     public String JavaDoc getRepositoryName()
131     {
132         String JavaDoc repositoryName = "";
133         try
134         {
135             Integer JavaDoc repositoryId = this.getRepositoryId();
136             repositoryName = RepositoryController.getController().getRepositoryVOWithId(repositoryId).getName();
137         }
138         catch(Exception JavaDoc e)
139         {
140         }
141         
142         return repositoryName;
143     }
144
145     /**
146      * Returns the tree.
147      * @return String
148      */

149     public String JavaDoc getTree() {
150         return tree;
151     }
152
153     /**
154      * Sets the repositoryId.
155      * @param repositoryId The repositoryId to set
156      */

157     public void setRepositoryId(Integer JavaDoc repositoryId) {
158         this.repositoryId = repositoryId;
159     }
160
161     /**
162      * Sets the tree.
163      * @param tree The tree to set
164      */

165     public void setTree(String JavaDoc tree) {
166         this.tree = tree;
167     }
168
169 }
170
Popular Tags