KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsTaskNew.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.CmsUserSettings;
33 import org.opencms.file.CmsGroup;
34 import org.opencms.file.CmsObject;
35 import org.opencms.file.CmsUser;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsLog;
38 import org.opencms.workflow.CmsTaskService;
39
40 import com.opencms.template.A_CmsXmlContent;
41
42 import java.util.Hashtable JavaDoc;
43 import java.util.List JavaDoc;
44 import java.util.Vector JavaDoc;
45
46 /**
47  * Template class for displaying OpenCms workplace task new screens.
48  * <P>
49  *
50  * @author Andreas Schouten
51  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
52  * @see com.opencms.workplace.CmsXmlWpTemplateFile
53  *
54  * @deprecated Will not be supported past the OpenCms 6 release.
55  */

56
57 public class CmsTaskNew extends CmsWorkplaceDefault {
58
59
60     /**
61      * Constant for generating user javascriptlist
62      */

63     private final static String JavaDoc C_ALL_ROLES = "___all";
64
65
66     /**
67      * Constant for generating user javascriptlist
68      */

69     private static String JavaDoc C_ROLE = null;
70
71
72     /**
73      * Constant for generating user javascriptlist
74      */

75     private static String JavaDoc C_ROLE_1 = null;
76
77
78     /**
79      * Constant for generating user javascriptlist
80      */

81     private static String JavaDoc C_ROLE_2 = null;
82
83
84     /**
85      * Constant for generating user javascriptlist
86      */

87     private static String JavaDoc C_USER_1 = null;
88
89
90     /**
91      * Constant for generating user javascriptlist
92      */

93     private static String JavaDoc C_USER_2 = null;
94
95
96     /**
97      * Constant for generating user javascriptlist
98      */

99     private static String JavaDoc C_USER_3 = null;
100
101
102     /**
103      * Constant for generating user javascriptlist
104      */

105     private static String JavaDoc C_USER_4 = null;
106
107
108     /**
109      * Constant for generating user javascriptlist
110      */

111     private static String JavaDoc C_USER_5 = null;
112
113     /**
114      * Gets the content of a defined section in a given template file and its subtemplates
115      * with the given parameters.
116      *
117      * @see #getContent(CmsObject, String, String, Hashtable, String)
118      * @param cms CmsObject Object for accessing system resources.
119      * @param templateFile Filename of the template file.
120      * @param elementName Element name of this template in our parent template.
121      * @param parameters Hashtable with all template class parameters.
122      * @param templateSelector template section that should be processed.
123      */

124
125     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
126             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
127         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
128             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
129             CmsLog.getLog(this).debug("Template file is: " + templateFile);
130             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
131         }
132         CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
133                 templateFile, elementName, parameters, templateSelector);
134         String JavaDoc paraAcceptation = "checked";
135         String JavaDoc paraAll = "checked";
136         String JavaDoc paraCompletion = "checked";
137         String JavaDoc paraDelivery = "checked";
138         CmsUserSettings settings = new CmsUserSettings(cms);
139         
140         // the tasksettings exists - use them
141
int messageAt = settings.getTaskMessageValue();
142         if((messageAt & CmsTaskService.TASK_MESSAGES_ACCEPTED) != CmsTaskService.TASK_MESSAGES_ACCEPTED) {
143             paraAcceptation = "";
144         }
145         if((messageAt & CmsTaskService.TASK_MESSAGES_COMPLETED) != CmsTaskService.TASK_MESSAGES_COMPLETED) {
146             paraCompletion = "";
147         }
148         if((messageAt & CmsTaskService.TASK_MESSAGES_FORWARDED) != CmsTaskService.TASK_MESSAGES_FORWARDED) {
149             paraDelivery = "";
150         }
151         if((messageAt & CmsTaskService.TASK_MESSAGES_MEMBERS) != CmsTaskService.TASK_MESSAGES_MEMBERS) {
152             paraAll = "";
153         }
154
155         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_ACCEPTATION, paraAcceptation);
156         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_ALL, paraAll);
157         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_COMPLETION, paraCompletion);
158         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_DELIVERY, paraDelivery);
159
160         // are the constants read from the cms already?
161
if (C_ROLE == null) {
162
163             // declare the constants
164
initConstants(xmlTemplateDocument);
165         }
166
167         // create task, if ok was pressed
168
if(parameters.get("ok") != null) {
169
170             // try to create the task
171
try {
172                 CmsTaskAction.create(cms, (String JavaDoc)parameters.get("USER"),
173                         (String JavaDoc)parameters.get("TEAM"), (String JavaDoc)parameters.get("TASKNAME"),
174                         (String JavaDoc)parameters.get("DESCRIPTION"), (String JavaDoc)parameters.get("DATE"),
175                         (String JavaDoc)parameters.get("PRIO"), (String JavaDoc)parameters.get("MSG_ACCEPTATION"),
176                         (String JavaDoc)parameters.get("MSG_ALL"), (String JavaDoc)parameters.get("MSG_COMPLETION"),
177                         (String JavaDoc)parameters.get("MSG_DELIVERY"));
178                 templateSelector = "done";
179             }
180             catch(Exception JavaDoc exc) {
181                 if(CmsLog.getLog(this).isWarnEnabled() ) {
182                     CmsLog.getLog(this).warn("Could not create task", exc);
183                 }
184                 xmlTemplateDocument.setData("details", CmsException.getStackTraceAsString(exc));
185                 templateSelector = "error";
186             }
187         }
188
189         // Now load the template file and start the processing
190
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
191     }
192
193     /**
194      * Gets all groups, that may work for a project.
195      * <P>
196      * The given vectors <code>names</code> and <code>values</code> will
197      * be filled with the appropriate information to be used for building
198      * a select box.
199      *
200      * @param cms CmsObject Object for accessing system resources.
201      * @param names Vector to be filled with the appropriate values in this method.
202      * @param values Vector to be filled with the appropriate values in this method.
203      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
204      * @return Index representing the current value in the vectors.
205      * @throws CmsException
206      */

207
208     public Integer JavaDoc getTeams(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values,
209             Hashtable JavaDoc parameters) throws CmsException {
210
211         // get all groups
212
List JavaDoc groups = cms.getGroups();
213         CmsGroup group;
214         names.addElement(lang.getLanguageValue("task.label.emptyrole"));
215         values.addElement(lang.getLanguageValue("task.label.emptyrole"));
216
217         // fill the names and values
218
for(int z = 0;z < groups.size();z++) {
219             group = (CmsGroup)groups.get(z);
220
221             // is the group a role?
222
if(group.getRole()) {
223                 String JavaDoc name = group.getName();
224                 names.addElement(name);
225                 values.addElement(name);
226             }
227         }
228         // TODO: CW: "all roles" not possible any longer, since a user has no default group(= default role) anymore
229
// names.addElement(lang.getLanguageValue("task.label.allroles"));
230
// values.addElement(C_ALL_ROLES);
231

232         // no current group, set index to -1
233
return new Integer JavaDoc(-1);
234     }
235
236     /**
237      * @param cms CmsObject Object for accessing system resources.
238      * @param tagcontent Unused in this special case of a user method. Can be ignored.
239      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document <em>(not used here)</em>.
240      * @param userObj Hashtable with parameters <em>(not used here)</em>.
241      * @return String with the pics URL.
242      * @throws CmsException
243      */

244
245     public Object JavaDoc getUsers(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc, Object JavaDoc userObj) throws CmsException {
246         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc();
247         retValue.append(C_ROLE);
248
249         // get the language for choose-user
250
String JavaDoc chooseUser = (new CmsXmlLanguageFile(cms)).getLanguageValue("task.label.emptyuser");
251
252         // get all groups
253
List JavaDoc groups = cms.getGroups();
254         for(int n = 0;n < groups.size();n++) {
255             if(((CmsGroup)groups.get(n)).getRole()) {
256                 String JavaDoc groupname = ((CmsGroup)groups.get(n)).getName();
257
258                 // get users of this group
259
List JavaDoc users = cms.getUsersOfGroup(groupname);
260
261                 // create entry for role
262
retValue.append(C_ROLE_1 + groupname + C_ROLE_2);
263                 retValue.append(C_USER_1 + groupname + C_USER_2 + 0 + C_USER_3 + chooseUser + C_USER_4 + C_USER_5);
264                 for(int m = 0;m < users.size();m++) {
265                     CmsUser user = (CmsUser)users.get(m);
266
267                     // create entry for user
268
retValue.append(C_USER_1 + groupname + C_USER_2 + (m + 1) + C_USER_3 + user.getName() + C_USER_4 + user.getName() + C_USER_5);
269                 }
270             }
271         }
272
273         // generate output for all users
274
// TODO: CW: "all roles" not possible any longer, since a user has no default group(= default role) anymore
275
/*
276         retValue.append(C_ROLE_1 + C_ALL_ROLES + C_ROLE_2);
277         retValue.append(C_USER_1 + C_ALL_ROLES + C_USER_2 + 0 + C_USER_3 + chooseUser + C_USER_4 + C_USER_5);
278         Vector users = cms.getUsers();
279         for(int m = 0;m < users.size();m++) {
280             CmsUser user = (CmsUser)users.elementAt(m);
281
282             // create entry for user
283             retValue.append(C_USER_1 + C_ALL_ROLES + C_USER_2 + (m + 1) + C_USER_3 + user.getName() + C_USER_4 + user.getName() + C_USER_5);
284         }
285         */

286         return retValue.toString();
287     }
288
289     /**
290      * This method initializes all constants, that are needed for genrating this pages.
291      *
292      * @param document The xml-document to get the constant content from.
293      */

294
295     private void initConstants(CmsXmlWpTemplateFile document) {
296         try {
297             C_ROLE = document.getDataValue("role");
298             C_ROLE_1 = document.getDataValue("role_1");
299             C_ROLE_2 = document.getDataValue("role_2");
300             C_USER_1 = document.getDataValue("user_1");
301             C_USER_2 = document.getDataValue("user_2");
302             C_USER_3 = document.getDataValue("user_3");
303             C_USER_4 = document.getDataValue("user_4");
304             C_USER_5 = document.getDataValue("user_5");
305         }
306         catch(CmsException exc) {
307             if(CmsLog.getLog(this).isWarnEnabled() ) {
308                 CmsLog.getLog(this).warn("Couldn't get xml datablocks for CmsTaskNew", exc);
309             }
310         }
311     }
312
313     /**
314      * Indicates if the results of this class are cacheable.
315      *
316      * @param cms CmsObject Object for accessing system resources
317      * @param templateFile Filename of the template file
318      * @param elementName Element name of this template in our parent template.
319      * @param parameters Hashtable with all template class parameters.
320      * @param templateSelector template section that should be processed.
321      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
322      */

323
324     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName, Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
325         return false;
326     }
327 }
328
Popular Tags