KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsTaskContentDialogPriority.java,v $
3 * Date : $Date: 2006/03/29 16:07:48 $
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.file.CmsGroup;
33 import org.opencms.file.CmsObject;
34 import org.opencms.file.CmsUser;
35 import org.opencms.i18n.CmsEncoder;
36 import org.opencms.main.CmsException;
37 import org.opencms.main.CmsLog;
38 import org.opencms.util.CmsDateUtil;
39 import org.opencms.workflow.CmsTask;
40 import org.opencms.workflow.CmsTaskService;
41
42 import com.opencms.core.I_CmsSession;
43 import com.opencms.legacy.CmsXmlTemplateLoader;
44 import com.opencms.template.A_CmsXmlContent;
45
46 import java.text.DateFormat JavaDoc;
47 import java.util.Date JavaDoc;
48 import java.util.Hashtable JavaDoc;
49 import java.util.List JavaDoc;
50 import java.util.Locale JavaDoc;
51 import java.util.Vector JavaDoc;
52
53 /**
54  * Template class for displaying OpenCms workplace task content screens.
55  * <P>
56  *
57  * @author Andreas Schouten
58  * @version $Revision: 1.5 $ $Date: 2006/03/29 16:07:48 $
59  * @see com.opencms.workplace.CmsXmlWpTemplateFile
60  *
61  * @deprecated Will not be supported past the OpenCms 6 release.
62  */

63
64 public class CmsTaskContentDialogPriority extends CmsWorkplaceDefault {
65
66
67     /**
68      * Constant for generating user javascriptlist
69      */

70     private final static String JavaDoc C_ALL_ROLES = "___all";
71
72
73     /**
74      * Constant for generating user javascriptlist
75      */

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

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

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

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

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

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

112     private static String JavaDoc C_USER_4 = null;
113
114
115     /**
116      * Constant for generating user javascriptlist
117      */

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

131
132     public byte[] getContent(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
133             Hashtable JavaDoc parameters, String JavaDoc templateSelector) throws CmsException {
134         if(CmsLog.getLog(this).isDebugEnabled() && C_DEBUG) {
135             CmsLog.getLog(this).debug("Getting content of element " + ((elementName==null)?"<root>":elementName));
136             CmsLog.getLog(this).debug("Template file is: " + templateFile);
137             CmsLog.getLog(this).debug("Selected template section is: " + ((templateSelector==null)?"<default>":templateSelector));
138         }
139         String JavaDoc taskName = "";
140         String JavaDoc taskDescription = "";
141         String JavaDoc due = "";
142         String JavaDoc paraAcceptation = "";
143         String JavaDoc paraAll = "";
144         String JavaDoc paraCompletion = "";
145         String JavaDoc paraDelivery = "";
146         String JavaDoc userIdxString = "";
147         String JavaDoc groupIdxString = "";
148         I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
149         CmsXmlWpTemplateFile xmlTemplateDocument = (CmsXmlWpTemplateFile)getOwnTemplateFile(cms,
150                 templateFile, elementName, parameters, templateSelector);
151
152         // are the constants read from the cms already?
153
if(C_ROLE == null) {
154
155             // declare the constants
156
initConstants(xmlTemplateDocument);
157         }
158         try {
159             String JavaDoc taskidstr = (String JavaDoc)parameters.get("taskid");
160             int taskid;
161             if(taskidstr == null || taskidstr == "") {
162                 Integer JavaDoc sessionTaskid = (Integer JavaDoc)session.getValue("taskid");
163                 taskid = sessionTaskid.intValue();
164             }
165             else {
166                 Integer JavaDoc taskidInt = new Integer JavaDoc(taskidstr);
167                 taskid = taskidInt.intValue();
168                 session.putValue("taskid", taskidInt);
169             }
170             CmsTaskService taskService = cms.getTaskService();
171             CmsTask task = taskService.readTask(taskid);
172             taskName = task.getName();
173             taskDescription = CmsTaskAction.getDescription(cms, task.getId());
174             paraAcceptation = taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ACCEPTATION);
175             paraAll = taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_ALL);
176             paraCompletion = taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_COMPLETION);
177             paraDelivery = taskService.getTaskPar(task.getId(), CmsWorkplaceDefault.C_TASKPARA_DELIVERY);
178             // we have to creagte a date in german date format, otherwise the redisplay in the dialogs does
179
// not work correctly.
180
due = CmsDateUtil.getDate(new Date JavaDoc(task.getTimeOut().getTime()), DateFormat.MEDIUM, new Locale JavaDoc("de"));
181
182             // preselect the old user and role in the dialog for forwarding and resurrection
183
// compute the indices of the user and role
184
String JavaDoc username = taskService.readAgent(task).getName();
185             String JavaDoc groupname = taskService.readGroup(task).getName();
186             int userindex = 0;
187             int groupindex = 0;
188             List JavaDoc groups = cms.getGroups();
189             List JavaDoc users = cms.getUsersOfGroup(groupname);
190             int n = 0;
191             for(int z = 0;z < groups.size();z++) {
192                 CmsGroup group = (CmsGroup)groups.get(z);
193                 if(group.getRole()) {
194                     n++;
195                     if(group.getName().equals(groupname)) {
196                         groupindex = n;
197                     }
198                 }
199             }
200             for(int z = 0;z < users.size();z++) {
201                 if(((CmsUser)users.get(z)).getName().equals(username)) {
202                     userindex = z + 1;
203                 }
204             }
205             userIdxString = (new Integer JavaDoc(userindex)).toString();
206             groupIdxString = (new Integer JavaDoc(groupindex)).toString();
207         }
208         catch(Exception JavaDoc exc) {
209
210
211         // unexpected exception - ignoring
212
}
213         xmlTemplateDocument.setData("task", CmsEncoder.escape(taskName,
214             cms.getRequestContext().getEncoding()));
215         xmlTemplateDocument.setData("description", CmsEncoder.escape(taskDescription,
216             cms.getRequestContext().getEncoding()));
217         xmlTemplateDocument.setData("due", due);
218         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_ACCEPTATION, paraAcceptation);
219         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_ALL, paraAll);
220         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_COMPLETION, paraCompletion);
221         xmlTemplateDocument.setData(CmsWorkplaceDefault.C_TASKPARA_DELIVERY, paraDelivery);
222         xmlTemplateDocument.setData("groupindex", groupIdxString);
223         xmlTemplateDocument.setData("userindex", userIdxString);
224
225         // Now load the template file and start the processing
226
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
227     }
228
229     /**
230      * Gets all priorities, that are defined for a project.
231      * <P>
232      * The given vectors <code>names</code> and <code>values</code> will
233      * be filled with the appropriate information to be used for building
234      * a select box.
235      *
236      * @param cms CmsObject Object for accessing system resources.
237      * @param names Vector to be filled with the appropriate values in this method.
238      * @param values Vector to be filled with the appropriate values in this method.
239      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
240      * @return Index representing the current value in the vectors.
241      * @throws CmsException
242      */

243
244     public Integer JavaDoc getPriority(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values,
245             Hashtable JavaDoc parameters) throws CmsException {
246
247         // get session for current taskid
248
I_CmsSession session = CmsXmlTemplateLoader.getSession(cms.getRequestContext(), true);
249
250         // read current task for priority-level
251
CmsTask task = cms.getTaskService().readTask(((Integer JavaDoc)session.getValue("taskid")).intValue());
252
253         // add names for priority
254
names.addElement(lang.getLanguageValue("task.label.prioritylevel.high"));
255         names.addElement(lang.getLanguageValue("task.label.prioritylevel.middle"));
256         names.addElement(lang.getLanguageValue("task.label.prioritylevel.low"));
257
258         // add values for priority
259
values.addElement(org.opencms.workflow.CmsTaskService.TASK_PRIORITY_HIGH + "");
260         values.addElement(CmsTaskService.TASK_PRIORITY_NORMAL + "");
261         values.addElement(org.opencms.workflow.CmsTaskService.TASK_PRIORITY_LOW + "");
262
263         // return the current priority
264
return new Integer JavaDoc(task.getPriority() - 1);
265     }
266
267     /**
268      * Gets all groups, that may work for a project.
269      * <P>
270      * The given vectors <code>names</code> and <code>values</code> will
271      * be filled with the appropriate information to be used for building
272      * a select box.
273      *
274      * @param cms CmsObject Object for accessing system resources.
275      * @param names Vector to be filled with the appropriate values in this method.
276      * @param values Vector to be filled with the appropriate values in this method.
277      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
278      * @return Index representing the current value in the vectors.
279      * @throws CmsException
280      */

281
282     public Integer JavaDoc getTeams(CmsObject cms, CmsXmlLanguageFile lang, Vector JavaDoc names, Vector JavaDoc values,
283             Hashtable JavaDoc parameters) throws CmsException {
284
285         // get all groups
286
List JavaDoc groups = cms.getGroups();
287         CmsGroup group;
288         names.addElement(lang.getLanguageValue("task.label.emptyrole"));
289         values.addElement(lang.getLanguageValue("task.label.emptyrole"));
290
291         // fill the names and values
292
for(int z = 0;z < groups.size();z++) {
293             group = (CmsGroup)groups.get(z);
294
295             // is the group a role?
296
if(group.getRole()) {
297                 String JavaDoc name = group.getName();
298                 names.addElement(name);
299                 values.addElement(name);
300             }
301         }
302         names.addElement(lang.getLanguageValue("task.label.allroles"));
303         values.addElement(C_ALL_ROLES);
304
305         // no current group, set index to -1
306
return new Integer JavaDoc(-1);
307     }
308
309     /**
310      * @param cms CmsObject Object for accessing system resources.
311      * @param tagcontent Unused in this special case of a user method. Can be ignored.
312      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document <em>(not used here)</em>.
313      * @param userObj Hashtable with parameters <em>(not used here)</em>.
314      * @return String with the pics URL.
315      * @throws CmsException
316      */

317
318     public Object JavaDoc getUsers(CmsObject cms, String JavaDoc tagcontent, A_CmsXmlContent doc,
319             Object JavaDoc userObj) throws CmsException {
320         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc();
321         retValue.append(C_ROLE);
322
323         // get the language for choose-user
324
String JavaDoc chooseUser = (new CmsXmlLanguageFile(cms)).getLanguageValue("task.label.emptyuser");
325
326         // get all groups
327
List JavaDoc groups = cms.getGroups();
328         for(int n = 0;n < groups.size();n++) {
329             if(((CmsGroup)groups.get(n)).getRole()) {
330                 String JavaDoc groupname = ((CmsGroup)groups.get(n)).getName();
331
332                 // get users of this group
333
List JavaDoc users = cms.getUsersOfGroup(groupname);
334
335                 // create entry for role
336
retValue.append(C_ROLE_1 + groupname + C_ROLE_2);
337                 retValue.append(C_USER_1 + groupname + C_USER_2 + 0 + C_USER_3 + chooseUser + C_USER_4 + C_USER_5);
338                 for(int m = 0;m < users.size();m++) {
339                     CmsUser user = (CmsUser)users.get(m);
340
341                     // create entry for user
342
retValue.append(C_USER_1 + groupname + C_USER_2 + (m + 1) + C_USER_3
343                             + user.getName() + C_USER_4 + user.getName() + C_USER_5);
344                 }
345             }
346         }
347
348         // generate output for all users
349
retValue.append(C_ROLE_1 + C_ALL_ROLES + C_ROLE_2);
350         retValue.append(C_USER_1 + C_ALL_ROLES + C_USER_2 + 0 + C_USER_3 + chooseUser + C_USER_4 + C_USER_5);
351         List JavaDoc users = cms.getUsers();
352         for(int m = 0;m < users.size();m++) {
353             CmsUser user = (CmsUser)users.get(m);
354
355             // create entry for user
356
retValue.append(C_USER_1 + C_ALL_ROLES + C_USER_2 + (m + 1) + C_USER_3
357                     + user.getName() + C_USER_4 + user.getName() + C_USER_5);
358         }
359         return retValue.toString();
360     }
361
362     /**
363      * This method initializes all constants, that are needed for genrating this pages.
364      *
365      * @param document The xml-document to get the constant content from.
366      */

367
368     private void initConstants(CmsXmlWpTemplateFile document) {
369         try {
370
371             // exists the needed datablocks?
372
if(document.hasData("role")) {
373
374                 // YES: initialize the constants
375
C_ROLE = document.getDataValue("role");
376                 C_ROLE_1 = document.getDataValue("role_1");
377                 C_ROLE_2 = document.getDataValue("role_2");
378                 C_USER_1 = document.getDataValue("user_1");
379                 C_USER_2 = document.getDataValue("user_2");
380                 C_USER_3 = document.getDataValue("user_3");
381                 C_USER_4 = document.getDataValue("user_4");
382                 C_USER_5 = document.getDataValue("user_5");
383             }
384         }
385         catch(CmsException exc) {
386             if(CmsLog.getLog(this).isWarnEnabled() ) {
387                 CmsLog.getLog(this).warn("Couldn't get xml datablocks for CmsTaskNew", exc);
388             }
389         }
390     }
391
392     /**
393      * Indicates if the results of this class are cacheable.
394      *
395      * @param cms CmsObject Object for accessing system resources
396      * @param templateFile Filename of the template file
397      * @param elementName Element name of this template in our parent template.
398      * @param parameters Hashtable with all template class parameters.
399      * @param templateSelector template section that should be processed.
400      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
401      */

402
403     public boolean isCacheable(CmsObject cms, String JavaDoc templateFile, String JavaDoc elementName,
404             Hashtable JavaDoc parameters, String JavaDoc templateSelector) {
405         return false;
406     }
407 }
408
Popular Tags