KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > commons > CmsChaccBrowser


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/commons/CmsChaccBrowser.java,v $
3  * Date : $Date: 2006/03/27 14:52:18 $
4  * Version: $Revision: 1.14 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
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 Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

31
32 package org.opencms.workplace.commons;
33
34 import org.opencms.file.CmsGroup;
35 import org.opencms.file.CmsUser;
36 import org.opencms.jsp.CmsJspActionElement;
37 import org.opencms.workplace.CmsDialog;
38 import org.opencms.workplace.CmsWorkplaceSettings;
39
40 import java.util.List JavaDoc;
41 import java.util.Vector JavaDoc;
42
43 import javax.servlet.http.HttpServletRequest JavaDoc;
44 import javax.servlet.http.HttpServletResponse JavaDoc;
45 import javax.servlet.jsp.JspException JavaDoc;
46 import javax.servlet.jsp.PageContext JavaDoc;
47
48 /**
49  * Provides methods for building the groups and users popup window.<p>
50  *
51  * The following files use this class:
52  * <ul>
53  * <li>/commons/chaccbrowser.jsp
54  * </ul>
55  * <p>
56  *
57  * @author Andreas Zahner
58  *
59  * @version $Revision: 1.14 $
60  *
61  * @since 6.0.0
62  */

63 public class CmsChaccBrowser extends CmsDialog {
64
65     /** Constant for the frame name which is displayed: groups frame. */
66     public static final String JavaDoc DIALOG_FRAME_GROUPS = "groups";
67     /** Constant for the frame name which is displayed: users frame. */
68     public static final String JavaDoc DIALOG_FRAME_USERS = "users";
69
70     /** The dialog type. */
71     public static final String JavaDoc DIALOG_TYPE = "chaccbrowser";
72
73     /** Constant for the frame type which is displayed: default frame. */
74     public static final int FRAME_DEFAULT = 1;
75     /** Constant for the frame type which is displayed: groups frame. */
76     public static final int FRAME_GROUPS = 100;
77     /** Constant for the frame type which is displayed: users frame. */
78     public static final int FRAME_USERS = 200;
79
80     /** Request parameter name for the frame parameter. */
81     public static final String JavaDoc PARAM_FRAME = "frame";
82     private int m_frame;
83
84     private String JavaDoc m_paramFrame;
85
86     /**
87      * Public constructor.<p>
88      *
89      * @param jsp an initialized JSP action element
90      */

91     public CmsChaccBrowser(CmsJspActionElement jsp) {
92
93         super(jsp);
94     }
95
96     /**
97      * Public constructor with JSP variables.<p>
98      *
99      * @param context the JSP page context
100      * @param req the JSP request
101      * @param res the JSP response
102      */

103     public CmsChaccBrowser(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
104
105         this(new CmsJspActionElement(context, req, res));
106     }
107
108     /**
109      * Builds a list of all groups and returns an html string.<p>
110      *
111      * @return html code for a group list
112      * @throws JspException if problems including sub-elements occur
113      */

114     public String JavaDoc buildGroupList() throws JspException JavaDoc {
115
116         List JavaDoc groups = new Vector JavaDoc();
117         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(1024);
118         try {
119             groups = getCms().getGroups();
120         } catch (Throwable JavaDoc e) {
121             // should usually never happen
122
includeErrorpage(this, e);
123         }
124
125         for (int i = 0; i < groups.size(); i++) {
126             CmsGroup curGroup = (CmsGroup)groups.get(i);
127             retValue.append(buildEntryGroup(curGroup));
128         }
129         return retValue.toString();
130     }
131
132     /**
133      * Builds a list of all users and returns an html string.<p>
134      *
135      * @return html code for a user list
136      * @throws JspException if problems including sub-elements occur
137      */

138     public String JavaDoc buildUserList() throws JspException JavaDoc {
139
140         List JavaDoc users = new Vector JavaDoc();
141         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(1024);
142         try {
143             users = getCms().getUsers();
144         } catch (Throwable JavaDoc e) {
145             // should usually never happen
146
includeErrorpage(this, e);
147         }
148
149         for (int i = 0; i < users.size(); i++) {
150             CmsUser curUser = (CmsUser)users.get(i);
151             retValue.append(buildEntryUser(curUser));
152         }
153         return retValue.toString();
154     }
155
156     /**
157      * Returns the int representation of the frame parameter value.<p>
158      *
159      * @return int representing the frame parameter value
160      */

161     public int getFrame() {
162
163         return m_frame;
164     }
165
166     /**
167      * Returns the value of the frame parameter,
168      * or null if this parameter was not provided.<p>
169      *
170      * The frame parameter selects the frame which should be displayed.<p>
171      *
172      * @return the value of the target parameter
173      */

174     public String JavaDoc getParamFrame() {
175
176         return m_paramFrame;
177     }
178
179     /**
180      * Sets the int representation of the frame parameter value.<p>
181      *
182      * @param value the int value of the parameter
183      */

184     public void setFrame(int value) {
185
186         m_frame = value;
187     }
188
189     /**
190      * Sets the value of the frame parameter.<p>
191      *
192      * @param value the value to set
193      */

194     public void setParamFrame(String JavaDoc value) {
195
196         m_paramFrame = value;
197     }
198
199     /**
200      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
201      */

202     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
203
204         // fill the parameter values in the get/set methods
205
fillParamValues(request);
206         // set the dialog type
207
setParamDialogtype(DIALOG_TYPE);
208         if (DIALOG_FRAME_GROUPS.equals(getParamFrame())) {
209             setFrame(FRAME_GROUPS);
210         } else if (DIALOG_FRAME_USERS.equals(getParamFrame())) {
211             setFrame(FRAME_USERS);
212         } else {
213             setFrame(FRAME_DEFAULT);
214         }
215     }
216
217     /**
218      * Creates the html code for a single group entry.<p>
219      *
220      * @param group the CmsGroup
221      * @return the html code as StringBuffer
222      */

223     private StringBuffer JavaDoc buildEntryGroup(CmsGroup group) {
224
225         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(256);
226         retValue.append("<span class=\"dialogunmarked maxwidth\" onmouseover=\"className='dialogmarked maxwidth';\"");
227         retValue.append(" onmouseout=\"className='dialogunmarked maxwidth'\" onclick=\"top.selectForm('0','");
228         retValue.append(group.getName());
229         retValue.append("');\">");
230         retValue.append("<img SRC=\"");
231         retValue.append(getSkinUri());
232         retValue.append("commons/group.png\">&nbsp;");
233         retValue.append(group.getName());
234         retValue.append("</span>");
235         return retValue;
236     }
237
238     /**
239      * Creates the html code for a single user entry.<p>
240      *
241      * @param user the CmsUser
242      * @return the html code as StringBuffer
243      */

244     private StringBuffer JavaDoc buildEntryUser(CmsUser user) {
245
246         StringBuffer JavaDoc retValue = new StringBuffer JavaDoc(384);
247         retValue.append("<span class=\"dialogunmarked maxwidth\" onmouseover=\"className='dialogmarked maxwidth';\"");
248         retValue.append(" onmouseout=\"className='dialogunmarked maxwidth'\" onclick=\"top.selectForm('1','");
249         retValue.append(user.getName());
250         retValue.append("');\">");
251         retValue.append("<img SRC=\"" + getSkinUri() + "commons/user.png\">&nbsp;");
252         retValue.append(user.getName());
253         if (!"".equals(user.getFirstname()) || !"".equals(user.getLastname())) {
254             retValue.append(" (");
255             retValue.append(user.getFirstname());
256             retValue.append(" ");
257             retValue.append(user.getLastname());
258             retValue.append(")");
259         }
260         retValue.append("</span>");
261         return retValue;
262     }
263
264 }
265
Popular Tags