001: /*
002: * File : $Source$
003: * Date : $Date$
004: * Version: $Revision$
005: *
006: * This library is part of OpenCms -
007: * the Open Source Content Management System
008: *
009: * Copyright (c) 2002 - 2008 Alkacon Software GmbH (http://www.alkacon.com)
010: *
011: * This library is free software; you can redistribute it and/or
012: * modify it under the terms of the GNU Lesser General Public
013: * License as published by the Free Software Foundation; either
014: * version 2.1 of the License, or (at your option) any later version.
015: *
016: * This library is distributed in the hope that it will be useful,
017: * but WITHOUT ANY WARRANTY; without even the implied warranty of
018: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: * Lesser General Public License for more details.
020: *
021: * For further information about Alkacon Software GmbH, please see the
022: * company website: http://www.alkacon.com
023: *
024: * For further information about OpenCms, please see the
025: * project website: http://www.opencms.org
026: *
027: * You should have received a copy of the GNU Lesser General Public
028: * License along with this library; if not, write to the Free Software
029: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
030: */
031:
032: package org.opencms.workplace.commons;
033:
034: import org.opencms.file.CmsGroup;
035: import org.opencms.jsp.CmsJspActionElement;
036: import org.opencms.main.CmsException;
037: import org.opencms.main.CmsRuntimeException;
038: import org.opencms.main.OpenCms;
039: import org.opencms.security.CmsPrincipal;
040: import org.opencms.util.CmsStringUtil;
041: import org.opencms.workplace.list.A_CmsListDefaultJsAction;
042: import org.opencms.workplace.list.A_CmsListDialog;
043: import org.opencms.workplace.list.CmsListColumnAlignEnum;
044: import org.opencms.workplace.list.CmsListColumnDefinition;
045: import org.opencms.workplace.list.CmsListDefaultAction;
046: import org.opencms.workplace.list.CmsListDirectAction;
047: import org.opencms.workplace.list.CmsListItem;
048: import org.opencms.workplace.list.CmsListMetadata;
049: import org.opencms.workplace.list.CmsListOrderEnum;
050: import org.opencms.workplace.tools.CmsToolMacroResolver;
051:
052: import java.util.ArrayList;
053: import java.util.Iterator;
054: import java.util.List;
055:
056: import javax.servlet.http.HttpServletRequest;
057: import javax.servlet.http.HttpServletResponse;
058: import javax.servlet.jsp.PageContext;
059:
060: /**
061: * Group selection dialog.<p>
062: *
063: * @author Michael Moossen
064: *
065: * @version $Revision$
066: *
067: * @since 6.0.0
068: */
069: public class CmsGroupSelectionList extends A_CmsListDialog {
070:
071: /** list action id constant. */
072: public static final String LIST_ACTION_ICON = "ai";
073:
074: /** list action id constant. */
075: public static final String LIST_ACTION_SELECT = "js";
076:
077: /** list column id constant. */
078: public static final String LIST_COLUMN_ICON = "ci";
079:
080: /** list column id constant. */
081: public static final String LIST_COLUMN_NAME = "cn";
082:
083: /** list id constant. */
084: public static final String LIST_ID = "lug";
085:
086: /** Stores the value of the request parameter for the flags. */
087: private String m_paramFlags;
088:
089: /** Stores the value of the request parameter for the organizational unit fqn. */
090: private String m_paramOufqn;
091:
092: /** Stores the value of the request parameter for the user name. */
093: private String m_paramUser;
094:
095: /**
096: * Public constructor.<p>
097: *
098: * @param jsp an initialized JSP action element
099: */
100: public CmsGroupSelectionList(CmsJspActionElement jsp) {
101:
102: super (jsp, LIST_ID, Messages.get().container(
103: Messages.GUI_GROUPSELECTION_LIST_NAME_0),
104: LIST_COLUMN_NAME, CmsListOrderEnum.ORDER_ASCENDING,
105: LIST_COLUMN_NAME);
106: }
107:
108: /**
109: * Public constructor with JSP variables.<p>
110: *
111: * @param context the JSP page context
112: * @param req the JSP request
113: * @param res the JSP response
114: */
115: public CmsGroupSelectionList(PageContext context,
116: HttpServletRequest req, HttpServletResponse res) {
117:
118: this (new CmsJspActionElement(context, req, res));
119: }
120:
121: /**
122: * @see org.opencms.workplace.tools.CmsToolDialog#dialogTitle()
123: */
124: public String dialogTitle() {
125:
126: // build title
127: StringBuffer html = new StringBuffer(512);
128: html.append("<div class='screenTitle'>\n");
129: html.append("\t<table width='100%' cellspacing='0'>\n");
130: html.append("\t\t<tr>\n");
131: html.append("\t\t\t<td>\n");
132: if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamUser())) {
133: html.append(Messages.get().getBundle(getLocale()).key(
134: Messages.GUI_GROUPSELECTION_USER_TITLE_1,
135: getParamUser()));
136: } else {
137: html.append(Messages.get().getBundle(getLocale()).key(
138: Messages.GUI_GROUPSELECTION_INTRO_TITLE_0));
139: }
140: html.append("\n\t\t\t</td>");
141: html.append("\t\t</tr>\n");
142: html.append("\t</table>\n");
143: html.append("</div>\n");
144: return CmsToolMacroResolver
145: .resolveMacros(html.toString(), this );
146: }
147:
148: /**
149: * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
150: */
151: public void executeListMultiActions() throws CmsRuntimeException {
152:
153: throwListUnsupportedActionException();
154: }
155:
156: /**
157: * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
158: */
159: public void executeListSingleActions() throws CmsRuntimeException {
160:
161: throwListUnsupportedActionException();
162: }
163:
164: /**
165: * Returns the flags parameter value.<p>
166: *
167: * @return the flags parameter value
168: */
169: public String getParamFlags() {
170:
171: return m_paramFlags;
172: }
173:
174: /**
175: * Returns the organizational unit fqn parameter.<p>
176: *
177: * @return the organizational unit fqn paramter
178: */
179: public String getParamOufqn() {
180:
181: return m_paramOufqn;
182: }
183:
184: /**
185: * Returns the user name parameter.<p>
186: *
187: * @return the user name paramter
188: */
189: public String getParamUser() {
190:
191: return m_paramUser;
192: }
193:
194: /**
195: * Sets the flags parameter value.<p>
196: *
197: * @param flags the flags parameter value to set
198: */
199: public void setParamFlags(String flags) {
200:
201: m_paramFlags = flags;
202: }
203:
204: /**
205: * Sets the organizational unit fqn.<p>
206: *
207: * @param ouFqn the organizational unit fqn to set
208: */
209: public void setParamOufqn(String ouFqn) {
210:
211: if (ouFqn == null) {
212: ouFqn = "";
213: }
214: m_paramOufqn = ouFqn;
215: }
216:
217: /**
218: * Sets the user name.<p>
219: *
220: * @param userName the user name to set
221: */
222: public void setParamUser(String userName) {
223:
224: m_paramUser = userName;
225: }
226:
227: /**
228: * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
229: */
230: protected void fillDetails(String detailId) {
231:
232: // noop
233: }
234:
235: /**
236: * Returns the groups to show for selection.<p>
237: *
238: * @return A list of group objects
239: *
240: * @throws CmsException if womething goes wrong
241: */
242: protected List getGroups() throws CmsException {
243:
244: List ret = new ArrayList();
245: if (getParamUser() != null) {
246: ret.addAll(getCms().getGroupsOfUser(getParamUser(), false));
247: } else {
248: ret.addAll(OpenCms.getRoleManager().getManageableGroups(
249: getCms(), "", true));
250: }
251: if (getParamFlags() != null) {
252: int flags = Integer.parseInt(getParamFlags());
253: ret = CmsPrincipal.filterFlag(ret, flags);
254: }
255: if ((getParamOufqn() != null)
256: && !getParamOufqn().equals("null")) {
257: Iterator itTempRet = ret.iterator();
258: while (itTempRet.hasNext()) {
259: CmsGroup group = (CmsGroup) itTempRet.next();
260: if (!group.getOuFqn().startsWith(getParamOufqn())) {
261: itTempRet.remove();
262: }
263: }
264: }
265: return ret;
266: }
267:
268: /**
269: * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
270: */
271: protected List getListItems() throws CmsException {
272:
273: List ret = new ArrayList();
274:
275: // get content
276: List groups = getGroups();
277: Iterator itGroups = groups.iterator();
278: while (itGroups.hasNext()) {
279: CmsGroup group = (CmsGroup) itGroups.next();
280: CmsListItem item = getList().newItem(
281: group.getId().toString());
282: item.set(LIST_COLUMN_NAME, group.getName());
283: ret.add(item);
284: }
285: return ret;
286: }
287:
288: /**
289: * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
290: */
291: protected void setColumns(CmsListMetadata metadata) {
292:
293: // create column for icon display
294: CmsListColumnDefinition iconCol = new CmsListColumnDefinition(
295: LIST_COLUMN_ICON);
296: iconCol.setName(Messages.get().container(
297: Messages.GUI_GROUPSELECTION_LIST_COLS_ICON_0));
298: iconCol.setHelpText(Messages.get().container(
299: Messages.GUI_GROUPSELECTION_LIST_COLS_ICON_HELP_0));
300: iconCol.setWidth("20");
301: iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER);
302: iconCol.setSorteable(false);
303: // set icon action
304: CmsListDirectAction iconAction = new CmsListDirectAction(
305: LIST_ACTION_ICON);
306: iconAction.setName(Messages.get().container(
307: Messages.GUI_GROUPSELECTION_LIST_ICON_NAME_0));
308: iconAction.setHelpText(Messages.get().container(
309: Messages.GUI_GROUPSELECTION_LIST_ICON_HELP_0));
310: iconAction.setIconPath("buttons/group.png");
311: iconAction.setEnabled(false);
312: iconCol.addDirectAction(iconAction);
313: // add it to the list definition
314: metadata.addColumn(iconCol);
315:
316: // create column for login
317: CmsListColumnDefinition nameCol = new CmsListColumnDefinition(
318: LIST_COLUMN_NAME);
319: nameCol.setName(Messages.get().container(
320: Messages.GUI_GROUPSELECTION_LIST_COLS_NAME_0));
321: nameCol.setWidth("100%");
322: CmsListDefaultAction selectAction = new A_CmsListDefaultJsAction(
323: LIST_ACTION_SELECT) {
324:
325: /**
326: * @see org.opencms.workplace.list.A_CmsListDirectJsAction#jsCode()
327: */
328: public String jsCode() {
329:
330: return "window.opener.setGroupFormValue('"
331: + getItem().get(LIST_COLUMN_NAME)
332: + "'); window.opener.focus(); window.close();";
333: }
334: };
335: selectAction.setName(Messages.get().container(
336: Messages.GUI_GROUPSELECTION_LIST_ACTION_SELECT_NAME_0));
337: selectAction.setHelpText(Messages.get().container(
338: Messages.GUI_GROUPSELECTION_LIST_ACTION_SELECT_HELP_0));
339: nameCol.addDefaultAction(selectAction);
340: // add it to the list definition
341: metadata.addColumn(nameCol);
342: }
343:
344: /**
345: * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
346: */
347: protected void setIndependentActions(CmsListMetadata metadata) {
348:
349: // no-op
350: }
351:
352: /**
353: * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
354: */
355: protected void setMultiActions(CmsListMetadata metadata) {
356:
357: // no-op
358: }
359:
360: /**
361: * @see org.opencms.workplace.list.A_CmsListDialog#validateParamaters()
362: */
363: protected void validateParamaters() throws Exception {
364:
365: try {
366: getCms().readUser(getParamUser()).getName();
367: } catch (Exception e) {
368: setParamUser(null);
369: }
370: try {
371: Integer.valueOf(getParamFlags());
372: } catch (Throwable e) {
373: setParamFlags(null);
374: }
375: }
376: }
|