KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2 * File : $Source: /usr/local/cvs/opencms/src-modules/com/opencms/workplace/CmsAdminLoggedInUsers.java,v $
3 * Date : $Date: 2005/06/27 23:22:07 $
4 * Version: $Revision: 1.2 $
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.CmsObject;
33 import org.opencms.file.CmsProject;
34 import org.opencms.file.CmsUser;
35 import org.opencms.main.CmsException;
36 import org.opencms.main.CmsSessionInfo;
37 import org.opencms.main.OpenCms;
38 import org.opencms.util.CmsDateUtil;
39 import org.opencms.util.CmsStringUtil;
40 import org.opencms.util.PrintfFormat;
41
42 import java.util.Collections JavaDoc;
43 import java.util.Hashtable JavaDoc;
44 import java.util.Iterator JavaDoc;
45 import java.util.List JavaDoc;
46
47 /**
48  * Template class for displaying OpenCms workplace admin users screens.
49  * <P>
50  *
51  * @author Mario Stanke
52  * @version $Revision: 1.2 $ $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 CmsAdminLoggedInUsers 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
75         CmsXmlWpTemplateFile xmlTemplateDocument = new CmsXmlWpTemplateFile(cms, templateFile);
76
77         if (parameters.get("message") != null) {
78             // there is a message to all - send it
79
OpenCms.getSessionManager().sendBroadcast(cms, (String JavaDoc)parameters.get("message"));
80         }
81
82         List JavaDoc sessionInfos = OpenCms.getSessionManager().getSessionInfos();
83         // sort the session infos
84
Collections.sort(sessionInfos);
85         StringBuffer JavaDoc ret = new StringBuffer JavaDoc();
86         Iterator JavaDoc i = sessionInfos.iterator();
87         int count = 1;
88         PrintfFormat format = new PrintfFormat("%3.3d");
89         while (i.hasNext()) {
90             try {
91                 CmsSessionInfo info = (CmsSessionInfo)i.next();
92                 CmsUser cmsUser = info.getUser();
93                 CmsProject cmsProject = cms.readProject(info.getProject());
94                 xmlTemplateDocument.setData("username", cmsUser.getName());
95                 xmlTemplateDocument.setData("firstname", cmsUser.getFirstname());
96                 xmlTemplateDocument.setData("lastname", cmsUser.getLastname());
97                 xmlTemplateDocument.setData("email", cmsUser.getEmail());
98                 // misuse of deprecated current group for session time, until we get a new interface
99
xmlTemplateDocument.setData("currentgroup",
100                     format.sprintf(count)
101                     + " - "
102                     + CmsDateUtil.getDateTimeShort(info.getTimeCreated())
103                     + " - "
104                     + CmsStringUtil.formatRuntime(System.currentTimeMillis() - info.getTimeUpdated()));
105                 xmlTemplateDocument.setData("messagepending",
106                     String.valueOf(!info.getBroadcastQueue().isEmpty()));
107                 xmlTemplateDocument.setData("currentproject",
108                     cmsProject.getName()
109                     + " - "
110                     + info.getSiteRoot());
111                 ret.append(xmlTemplateDocument.getProcessedDataValue("line"));
112                 count++;
113             } catch (Exception JavaDoc exc) {
114                 // ignore all exceptions - don't show this user
115
}
116         }
117
118         xmlTemplateDocument.setData("all_lines", ret.toString());
119
120         // Now load the template file and start the processing
121
return startProcessing(cms, xmlTemplateDocument, elementName, parameters, templateSelector);
122     }
123 }
124
Popular Tags