KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > opencms > workplace > CmsTaskContent


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsTaskContent.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.5 $
5 *
6 * This library is part of OpenCms -
7 * the Open Source Content Mananagement System
8 *
9 * Copyright (C) 2001 The OpenCms Group
10 *
11 * This library is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU Lesser General Public
13 * License as published by the Free Software Foundation; either
14 * version 2.1 of the License, or (at your option) any later version.
15 *
16 * This library is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 * Lesser General Public License for more details.
20 *
21 * For further information about OpenCms, please see the
22 * OpenCms Website: http://www.opencms.org
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 */

28
29
30 package com.opencms.workplace;
31
32 import org.opencms.db.CmsDbUtil;
33 import org.opencms.file.CmsGroup;
34 import org.opencms.file.CmsObject;
35 import org.opencms.main.CmsException;
36 import org.opencms.main.CmsLog;
37 import org.opencms.workflow.CmsTaskService;
38
39 import com.opencms.core.I_CmsSession;
40 import com.opencms.legacy.CmsXmlTemplateLoader;
41 import com.opencms.template.CmsXmlTemplateFile;
42
43 import java.util.Hashtable JavaDoc;
44 import java.util.List JavaDoc;
45 import java.util.Vector JavaDoc;
46
47 /**
48  * Template class for displaying OpenCms workplace task content screens.
49  * <P>
50  *
51  * @author Andreas Schouten
52  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
53  * @see com.opencms.workplace.CmsXmlWpTemplateFile
54  *
55  * @deprecated Will not be supported past the OpenCms 6 release.
56  */

57
58 public class CmsTaskContent extends CmsWorkplaceDefault {
59     
60     /**
61      * Gets the content of a defined section in a given template file and its subtemplates
62      * with the given parameters.
63      *
64      * @see #getContent(CmsObject, String, String, Hashtable, String)
65      * @param cms CmsObject Object for accessing system resources.
66      * @param templateFile Filename of the template file.
67      * @param elementName Element name of this template in our parent template.
68      * @param parameters Hashtable with all template class parameters.
69      * @param templateSelector template section that should be processed.
70      */

71     
72     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
73             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
74         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
75             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
76             CmsLog.getLog(this).debug("Template file is: " + templateFile);
77             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
78         }
79         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
80         String JavaDoc taskid = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_PARA_STARTTASKID);
81         if(session.getValue(CmsWorkplaceDefault.C_PARA_STARTTASKID) != null) {
82             session.removeValue(CmsWorkplaceDefault.C_PARA_STARTTASKID);
83             session.removeValue(CmsWorkplaceDefault.C_PARA_VIEW);
84             CmsXmlWpConfigFile conf = new CmsXmlWpConfigFile(cms);
85             String JavaDoc actionPath = conf.getWorkplaceActionPath();
86             try {
87                 CmsXmlTemplateLoader.getResponse(cms.getRequestContext()).sendCmsRedirect(actionPath + "tasks_content_detail.html?taskid=" + taskid);
88             }
89             catch(Exception JavaDoc e) {
90                 if(CmsLog.getLog(this).isWarnEnabled()) {
91                     CmsLog.getLog(this).warn("Could not send redirect", e);
92                 }
93             }
94             return null;
95         }
96         CmsXmlTemplateFile xmlTemplateDocument = getOwnTemplateFile(cms, templateFile, elementName, parameters, templateSelector);
97         
98         // Now load the template file and start the processing
99
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
100     }
101     
102     /**
103      * Indicates if the results of this class are cacheable.
104      *
105      * @param cms CmsObject Object for accessing system resources
106      * @param templateFile Filename of the template file
107      * @param elementName Element name of this template in our parent template.
108      * @param parameters Hashtable with all template class parameters.
109      * @param templateSelector template section that should be processed.
110      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
111      */

112     
113     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
114             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
115         return false;
116     }
117     
118     /**
119      * Reads alls tasks for all roles of a user.
120      * @param cms The cms object.
121      * @param project The name of the project.
122      * @param taskType The type of the task to read.
123      * @param orderBy A order criteria.
124      * @param groupBy A sort criteria.
125      * @return a vector of tasks.
126      * @throws Throws a exception, if something goes wrong.
127      */

128     
129     private Vector JavaDoc readTasksForRole(CmsObject cms, int project, int taskType, String JavaDoc orderBy, String JavaDoc groupBy) throws CmsException {
130         String JavaDoc name = cms.getRequestContext().currentUser().getName();
131         List JavaDoc groups = cms.getGroupsOfUser(name);
132         CmsGroup group;
133         List JavaDoc tasks;
134         Vector JavaDoc allTasks = new Vector JavaDoc();
135         for(int i = 0;i < groups.size();i++) {
136             group = (CmsGroup)groups.get(i);
137             tasks = cms.getTaskService().readTasksForRole(project, group.getName(), taskType, orderBy, groupBy);
138             
139             // join the vectors
140
for(int z = 0;z < tasks.size();z++) {
141                 allTasks.addElement(tasks.get(z));
142             }
143         }
144         return allTasks;
145     }
146     
147     /**
148      * Gets the tasks.
149      *
150      * @param cms CmsObject Object for accessing system resources.
151      * @return Vector representing the tasks.
152      * @throws CmsException
153      */

154     
155     public List JavaDoc taskList(CmsObject cms, CmsXmlLanguageFile lang) throws CmsException {
156         String JavaDoc orderBy = "";
157         String JavaDoc groupBy = "";
158         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
159         Object JavaDoc allProjects = session.getValue(CmsWorkplaceDefault.C_SESSION_TASK_ALLPROJECTS);
160         int project = cms.getRequestContext().currentProject().getId();
161         String JavaDoc filter = (String JavaDoc)session.getValue(CmsWorkplaceDefault.C_SESSION_TASK_FILTER);
162         List JavaDoc retValue;
163         
164         // was the allprojects checkbox checked?
165
if((allProjects != null) && (((Boolean JavaDoc)allProjects).booleanValue())) {
166             project = CmsDbUtil.UNKNOWN_ID;
167         }
168         if(filter == null) {
169             filter = "a1";
170         }
171         int filterNum = Integer.parseInt(filter, 16);
172         String JavaDoc userName = cms.getRequestContext().currentUser().getName();
173         switch(filterNum) {
174         case 0xa1:
175             retValue = cms.getTaskService().readTasksForUser(project, userName, CmsTaskService.TASKS_NEW, orderBy, groupBy);
176             break;
177         
178         case 0xa2:
179             retValue = cms.getTaskService().readTasksForUser(project, userName, CmsTaskService.TASKS_ACTIVE, orderBy, groupBy);
180             break;
181         
182         case 0xa3:
183             retValue = cms.getTaskService().readTasksForUser(project, userName, CmsTaskService.TASKS_DONE, orderBy, groupBy);
184             break;
185         
186         case 0xb1:
187             retValue = readTasksForRole(cms, project, CmsTaskService.TASKS_NEW, orderBy, groupBy);
188             break;
189         
190         case 0xb2:
191             retValue = readTasksForRole(cms, project, CmsTaskService.TASKS_ACTIVE, orderBy, groupBy);
192             break;
193         
194         case 0xb3:
195             retValue = readTasksForRole(cms, project, CmsTaskService.TASKS_DONE, orderBy, groupBy);
196             break;
197         
198         case 0xc1:
199             retValue = cms.getTaskService().readTasksForProject(project, CmsTaskService.TASKS_NEW, orderBy, groupBy);
200             break;
201         
202         case 0xc2:
203             retValue = cms.getTaskService().readTasksForProject(project, CmsTaskService.TASKS_ACTIVE, orderBy, groupBy);
204             break;
205         
206         case 0xc3:
207             retValue = cms.getTaskService().readTasksForProject(project, CmsTaskService.TASKS_DONE, orderBy, groupBy);
208             break;
209         
210         case 0xd1:
211             retValue = cms.getTaskService().readGivenTasks(project, userName, CmsTaskService.TASKS_NEW, orderBy, groupBy);
212             break;
213         
214         case 0xd2:
215             retValue = cms.getTaskService().readGivenTasks(project, userName, CmsTaskService.TASKS_ACTIVE, orderBy, groupBy);
216             break;
217         
218         case 0xd3:
219             retValue = cms.getTaskService().readGivenTasks(project, userName, CmsTaskService.TASKS_DONE, orderBy, groupBy);
220             break;
221         
222         default:
223             retValue = cms.getTaskService().readTasksForUser(project, userName, CmsTaskService.TASKS_ALL, orderBy, groupBy);
224             break;
225         }
226         if(retValue == null) {
227             return new Vector JavaDoc();
228         }
229         else {
230             return retValue;
231         }
232     }
233     
234     /**
235      * @see com.opencms.workplace.CmsWorkplaceDefault#startProcessing(org.opencms.file.CmsObject, com.opencms.template.CmsXmlTemplateFile, java.lang.String, java.util.Hashtable, java.lang.String)
236      */

237     protected byte[] startProcessing(
238         CmsObject cms,
239         CmsXmlTemplateFile xmlTemplateDocument,
240         String JavaDoc elementName,
241         Hashtable JavaDoc parameters,
242         String JavaDoc templateSelector) throws CmsException {
243
244         // workaround to display the task id
245
if ((parameters != null) && (parameters.size() > 0) && (parameters.containsKey("taskid"))) {
246             I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
247             session.putValue(CmsWorkplaceDefault.C_PARA_STARTTASKID, parameters.get("taskid"));
248         }
249      
250         return super.startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
251     }
252 }
253
Popular Tags