KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsTaskList.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 package com.opencms.workplace;
30
31 import org.opencms.file.CmsGroup;
32 import org.opencms.file.CmsObject;
33 import org.opencms.file.CmsProject;
34 import org.opencms.file.CmsRequestContext;
35 import org.opencms.file.CmsUser;
36 import org.opencms.main.CmsException;
37 import org.opencms.util.CmsDateUtil;
38 import org.opencms.workflow.CmsTask;
39 import org.opencms.workflow.CmsTaskService;
40
41 import com.opencms.legacy.CmsLegacyException;
42 import com.opencms.template.A_CmsXmlContent;
43
44 import java.lang.reflect.InvocationTargetException JavaDoc;
45 import java.lang.reflect.Method JavaDoc;
46 import java.util.ArrayList JavaDoc;
47 import java.util.Calendar JavaDoc;
48 import java.util.Date JavaDoc;
49 import java.util.GregorianCalendar JavaDoc;
50 import java.util.Hashtable JavaDoc;
51 import java.util.List JavaDoc;
52
53 import org.w3c.dom.Element JavaDoc;
54
55 /**
56  * Class for building task list. <BR>
57  * Called by CmsXmlTemplateFile for handling the special XML tag <code>&lt;tasklist&gt;</code>.
58  *
59  * @author Andreas Schouten
60  * @author Mario Stanke
61  * @version $Revision: 1.5 $ $Date: 2005/06/27 23:22:07 $
62  * @see com.opencms.workplace.CmsXmlWpTemplateFile
63  *
64  * @deprecated Will not be supported past the OpenCms 6 release.
65  */

66
67 public class CmsTaskList extends A_CmsWpElement implements I_CmsWpElement {
68
69     /**
70      * Handling of the special workplace <CODE>&lt;TASKLIST&gt;</CODE> tags.
71      * <P>
72      * Returns the processed code with the actual elements.
73      * <P>
74      * Projectlists can be referenced in any workplace template by <br>
75      * <CODE>&lt;TASKLIST method="methodname"/&gt;</CODE>
76      *
77      * @param cms CmsObject Object for accessing resources.
78      * @param n XML element containing the <code>&lt;ICON&gt;</code> tag.
79      * @param doc Reference to the A_CmsXmlContent object of the initiating XLM document.
80      * @param callingObject reference to the calling object <em>(not used here)</em>.
81      * @param parameters Hashtable containing all user parameters <em>(not used here)</em>.
82      * @param lang CmsXmlLanguageFile conataining the currently valid language file.
83      * @return Processed button.
84      * @throws CmsException if somethign goes wrong
85      */

86
87     public Object JavaDoc handleSpecialWorkplaceTag(
88         CmsObject cms,
89         Element JavaDoc n,
90         A_CmsXmlContent doc,
91         Object JavaDoc callingObject,
92         Hashtable JavaDoc parameters,
93         CmsXmlLanguageFile lang) throws CmsException {
94
95         // Get list definition values
96
CmsXmlWpTemplateFile listdef = getTaskListDefinitions(cms);
97         CmsRequestContext context = cms.getRequestContext();
98         String JavaDoc listMethod = n.getAttribute("method");
99
100         // call the method for generating projectlist elements
101
Method JavaDoc callingMethod = null;
102         List JavaDoc list = new ArrayList JavaDoc();
103         try {
104             callingMethod = callingObject.getClass().getMethod(
105                 listMethod,
106                 new Class JavaDoc[] {CmsObject.class, CmsXmlLanguageFile.class});
107             list = (List JavaDoc)callingMethod.invoke(callingObject, new Object JavaDoc[] {cms, lang});
108         } catch (NoSuchMethodException JavaDoc exc) {
109
110             // The requested method was not found.
111
throwException("Could not find method "
112                 + listMethod
113                 + " in calling class "
114                 + callingObject.getClass().getName()
115                 + " for generating lasklist content.", CmsLegacyException.C_NOT_FOUND);
116         } catch (InvocationTargetException JavaDoc targetEx) {
117
118             // the method could be invoked, but throwed a exception
119
// itself. Get this exception and throw it again.
120
Throwable JavaDoc e = targetEx.getTargetException();
121             if (!(e instanceof CmsException)) {
122
123                 // Only print an error if this is NO CmsException
124
throwException("User method "
125                     + listMethod
126                     + " in calling class "
127                     + callingObject.getClass().getName()
128                     + " throwed an exception. "
129                     + e);
130             } else {
131
132                 // This is a CmsException
133
// Error printing should be done previously.
134
throw (CmsException)e;
135             }
136         } catch (Exception JavaDoc exc2) {
137             throwException("User method "
138                 + listMethod
139                 + " in calling class "
140                 + callingObject.getClass().getName()
141                 + " was found but could not be invoked. "
142                 + exc2, CmsLegacyException.C_XML_NO_USER_METHOD);
143         }
144
145         /** StringBuffer for the generated output */
146         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
147         String JavaDoc priority;
148         String JavaDoc projectname;
149         String JavaDoc stateIcon;
150         String JavaDoc style;
151         String JavaDoc contextmenu;
152         long startTime;
153         long timeout;
154         GregorianCalendar JavaDoc cal = new GregorianCalendar JavaDoc();
155         cal.setTime(new Date JavaDoc(System.currentTimeMillis()));
156         cal.set(Calendar.HOUR, 0);
157         cal.set(Calendar.MINUTE, 0);
158         cal.set(Calendar.SECOND, 0);
159         cal.set(Calendar.MILLISECOND, 0);
160         GregorianCalendar JavaDoc newcal = new GregorianCalendar JavaDoc(
161             cal.get(Calendar.YEAR),
162             cal.get(Calendar.MONTH),
163             cal.get(Calendar.DAY_OF_MONTH),
164             0,
165             0,
166             0);
167         long now = newcal.getTime().getTime();
168         CmsTaskService taskService = cms.getTaskService();
169         for (int i = 0; i < list.size(); i++) {
170
171             // get the actual project
172
CmsTask task = (CmsTask)list.get(i);
173             CmsProject project = null;
174             projectname = "?";
175             try {
176                 project = taskService.readProject(task);
177             } catch (Exception JavaDoc exc) {
178
179                 // no project - continue with next task
180
continue;
181             }
182             if ((project == null) || (project.getFlags() == com.opencms.core.I_CmsConstants.C_PROJECT_STATE_ARCHIVE)) {
183
184                 // project was published - continue
185
continue;
186             }
187             projectname = project.getName();
188             priority = listdef.getProcessedDataValue("priority" + task.getPriority(), callingObject);
189             startTime = task.getStartTime().getTime();
190             timeout = task.getTimeOut().getTime();
191             listdef.setData("taskid", task.getId() + "");
192             listdef.setData("count", i + "");
193
194             // making the context menus depending on the state of the task and
195
// the role of the user
196
CmsUser owner = null;
197             String JavaDoc ownerName = "";
198             try {
199                 owner = taskService.readOwner(task);
200                 ownerName = owner.getName();
201             } catch (Exception JavaDoc exc) {
202
203                 // ignore the exception
204
}
205             CmsUser editor = null;
206             try {
207                 editor = taskService.readAgent(task);
208             } catch (Exception JavaDoc exc) {
209
210                 // ignore the exception
211
}
212             CmsGroup role = null;
213             String JavaDoc roleName = "";
214             try {
215                 role = taskService.readGroup(task);
216                 roleName = role.getName();
217             } catch (Exception JavaDoc exc) {
218
219                 // ignore the exception
220
}
221             boolean isOwner = context.currentUser().equals(owner);
222             boolean isEditor = context.currentUser().equals(editor);
223             boolean isInRole = false;
224             try {
225                 isInRole = cms.userInGroup(context.currentUser().getName(), roleName);
226             } catch (Exception JavaDoc exc) {
227
228                 // ignore the exception
229
}
230
231             // now decide which contex menu is appropriate
232
if (task.getState() == CmsTaskService.TASK_STATE_ENDED) {
233                 if (isOwner) {
234                     contextmenu = "task1";
235                 } else {
236                     if (isEditor) {
237                         contextmenu = "task2";
238                     } else {
239                         if (isInRole) {
240                             contextmenu = "task3";
241                         } else {
242                             contextmenu = "task3";
243                         }
244                     }
245                 }
246                 listdef.setData("contextmenu", contextmenu);
247                 stateIcon = listdef.getProcessedDataValue("ok", callingObject);
248                 style = listdef.getProcessedDataValue("style_ok", callingObject);
249             } else {
250                 if (task.getPercentage() == 0) {
251                     if (isOwner && isEditor) {
252                         contextmenu = "task4";
253                     } else {
254                         if (isOwner) {
255                             contextmenu = "task5";
256                         } else {
257                             if (isEditor) {
258                                 contextmenu = "task6";
259                             } else {
260                                 if (isInRole) {
261                                     contextmenu = "task7";
262                                 } else {
263                                     contextmenu = "task8";
264                                 }
265                             }
266                         }
267                     }
268                     listdef.setData("contextmenu", contextmenu);
269                     if (timeout < now) {
270                         stateIcon = listdef.getProcessedDataValue("alert", callingObject);
271                         style = listdef.getProcessedDataValue("style_alert", callingObject);
272                     } else {
273                         stateIcon = listdef.getProcessedDataValue("new", callingObject);
274                         style = listdef.getProcessedDataValue("style_new", callingObject);
275                     }
276                 } else {
277                     if (isOwner && isEditor) {
278                         contextmenu = "task9";
279                     } else {
280                         if (isOwner) {
281                             contextmenu = "task10";
282                         } else {
283                             if (isEditor) {
284                                 contextmenu = "task11";
285                             } else {
286                                 if (isInRole) {
287                                     contextmenu = "task12";
288                                 } else {
289                                     contextmenu = "task13";
290                                 }
291                             }
292                         }
293                     }
294                     listdef.setData("contextmenu", contextmenu);
295                     if (timeout < now) {
296                         stateIcon = listdef.getProcessedDataValue("alert", callingObject);
297                         style = listdef.getProcessedDataValue("style_alert", callingObject);
298                     } else {
299                         stateIcon = listdef.getProcessedDataValue("activ", callingObject);
300                         style = listdef.getProcessedDataValue("style_activ", callingObject);
301                     }
302                 }
303             }
304             String JavaDoc agent = "";
305             String JavaDoc group = "";
306             String JavaDoc due = "";
307             String JavaDoc from = "";
308             try {
309                 agent = taskService.readAgent(task).getName();
310             } catch (Exception JavaDoc exc) {
311
312                 // ignore the exception
313
}
314             try {
315                 group = taskService.readGroup(task).getName();
316             } catch (Exception JavaDoc exc) {
317
318                 // ignore the exception
319
}
320             try {
321                 due = CmsDateUtil.getDateShort(timeout);
322             } catch (Exception JavaDoc exc) {
323
324                 // ignore the exception
325
}
326             try {
327                 from = CmsDateUtil.getDateShort(startTime);
328             } catch (Exception JavaDoc exc) {
329
330                 // ignore the exception
331
}
332
333             // get the processed list.
334
listdef.setData("stateicon", stateIcon);
335             listdef.setData("style", style);
336             listdef.setData("priority", priority);
337             listdef.setData("taskid", task.getId() + "");
338             listdef.setData("task", task.getName());
339             listdef.setData("foruser", agent);
340             listdef.setData("forrole", group);
341             listdef.setData("actuator", ownerName);
342             listdef.setData("due", due);
343             listdef.setData("from", from);
344             listdef.setData("project", projectname);
345             result.append(listdef.getProcessedDataValue("defaulttasklist", callingObject, parameters));
346         }
347         return result.toString();
348     }
349
350     /**
351      * Indicates if the results of this class are cacheable.
352      *
353      * @param cms CmsObject Object for accessing system resources
354      * @param templateFile Filename of the template file
355      * @param elementName Element name of this template in our parent template.
356      * @param parameters Hashtable with all template class parameters.
357      * @param templateSelector template section that should be processed.
358      * @return <EM>true</EM> if cacheable, <EM>false</EM> otherwise.
359      */

360
361     public boolean isCacheable(
362         CmsObject cms,
363         String JavaDoc templateFile,
364         String JavaDoc elementName,
365         Hashtable JavaDoc parameters,
366         String JavaDoc templateSelector) {
367
368         return false;
369     }
370 }
371
Popular Tags