KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > infoglue > cms > applications > cmstool > actions > ViewCMSAbstractToolAction


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.cmstool.actions;
25
26 import java.util.List JavaDoc;
27
28 import org.apache.log4j.Logger;
29 import org.infoglue.cms.applications.common.actions.InfoGlueAbstractAction;
30 import org.infoglue.cms.controllers.kernel.impl.simple.RepositoryController;
31 import org.infoglue.cms.entities.management.RepositoryVO;
32
33 /**
34  * This class implements the base class for a tool.
35  *
36  * @author Mattias Bogeblad
37  */

38
39 public abstract class ViewCMSAbstractToolAction extends InfoGlueAbstractAction
40 {
41     private final static Logger logger = Logger.getLogger(ViewCMSAbstractToolAction.class.getName());
42
43     private Integer JavaDoc repositoryId = null;
44     
45     public void setRepositoryId(Integer JavaDoc repositoryId)
46     {
47         this.repositoryId = repositoryId;
48     }
49
50     /**
51      * This method gets the repositoryId and if it'n not available we check first id it's located in the
52      * Session. If not we take the master repositoryId and also defaults it to that in the session.
53      */

54     
55     public Integer JavaDoc getRepositoryId()
56     {
57         try
58         {
59             if(this.repositoryId == null)
60             {
61                 logger.info("The repositoryId was null in ViewContentToolAction so we fetch it from the session");
62                 this.repositoryId = (Integer JavaDoc)getHttpSession().getAttribute("repositoryId");
63                 
64                 if(this.repositoryId == null)
65                 {
66                     List JavaDoc authorizedRepositoryVOList = RepositoryController.getController().getAuthorizedRepositoryVOList(this.getInfoGluePrincipal(), false);
67                     if(authorizedRepositoryVOList.size() > 0)
68                     {
69                         RepositoryVO repositoryVO = (RepositoryVO)authorizedRepositoryVOList.get(0);
70                         this.repositoryId = repositoryVO.getId();
71                         getHttpSession().setAttribute("repositoryId", this.repositoryId);
72                         logger.info("We set the defaultRepositoryId in the users session to " + this.repositoryId);
73                     }
74                     else
75                     {
76                         this.repositoryId = new Integer JavaDoc(-1);
77                         //getHttpSession().setAttribute("repositoryId", this.repositoryId);
78
logger.info("We set the defaultRepositoryId in the users session to " + this.repositoryId);
79                     }
80                 }
81             }
82         }
83         catch(Exception JavaDoc e)
84         {
85             logger.error("The master repository could not be fetched due to an error:" + e.getMessage(), e);
86         }
87                     
88         return this.repositoryId;
89     }
90  
91                
92 }
93
Popular Tags