001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software GmbH & Co. KG, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.workplace.tools.accounts; 029 030import org.opencms.file.CmsGroup; 031import org.opencms.jsp.CmsJspActionElement; 032import org.opencms.main.CmsException; 033import org.opencms.main.CmsIllegalArgumentException; 034import org.opencms.main.OpenCms; 035import org.opencms.util.CmsStringUtil; 036import org.opencms.util.CmsUUID; 037import org.opencms.widgets.CmsDisplayWidget; 038import org.opencms.workplace.CmsWidgetDialog; 039import org.opencms.workplace.CmsWidgetDialogParameter; 040 041import java.util.ArrayList; 042 043import javax.servlet.http.HttpServletRequest; 044import javax.servlet.http.HttpServletResponse; 045import javax.servlet.jsp.PageContext; 046 047/** 048 * The group overview and group info widget dialog.<p> 049 * 050 * @since 6.0.0 051 */ 052public class CmsGroupOverviewDialog extends CmsWidgetDialog { 053 054 /** localized messages Keys prefix. */ 055 public static final String KEY_PREFIX = "group.ov"; 056 057 /** Defines which pages are valid for this dialog. */ 058 public static final String[] PAGES = {"page1"}; 059 060 /** Request parameter name for the user id. */ 061 public static final String PARAM_GROUPID = "groupid"; 062 063 /** The user object that is edited on this dialog. */ 064 protected CmsGroup m_group; 065 066 /** Stores the value of the request parameter for the group id. */ 067 private String m_paramGroupid; 068 069 /** Auxiliary Property for better representation of the bean parentId property. */ 070 private String m_parentGroup; 071 072 /** 073 * Public constructor with JSP action element.<p> 074 * 075 * @param jsp an initialized JSP action element 076 */ 077 public CmsGroupOverviewDialog(CmsJspActionElement jsp) { 078 079 super(jsp); 080 081 } 082 083 /** 084 * Public constructor with JSP variables.<p> 085 * 086 * @param context the JSP page context 087 * @param req the JSP request 088 * @param res the JSP response 089 */ 090 public CmsGroupOverviewDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) { 091 092 this(new CmsJspActionElement(context, req, res)); 093 } 094 095 /** 096 * Commits the edited group to the db.<p> 097 */ 098 @Override 099 public void actionCommit() { 100 101 // no saving needed 102 setCommitErrors(new ArrayList<Throwable>()); 103 } 104 105 /** 106 * Returns the description of the parent ou.<p> 107 * 108 * @return the description of the parent ou 109 */ 110 public String getAssignedOu() { 111 112 try { 113 return OpenCms.getOrgUnitManager().readOrganizationalUnit(getCms(), m_group.getOuFqn()).getDisplayName( 114 getLocale()); 115 } catch (CmsException e) { 116 return null; 117 } 118 } 119 120 /** 121 * Returns the localized description of the group if the description is a message key.<p> 122 * 123 * @return the localized description of the group if the description is a message key 124 */ 125 public String getDescription() { 126 127 return m_group.getDescription(getLocale()); 128 } 129 130 /** 131 * Returns the simple name of the user object.<p> 132 * 133 * @return the simple name of the user object 134 */ 135 public String getName() { 136 137 return m_group.getSimpleName(); 138 } 139 140 /** 141 * Returns the groups nice name.<p> 142 * 143 * @return the groups nice name 144 */ 145 public String getNiceName() { 146 147 return OpenCms.getWorkplaceManager().translateGroupName(m_group.getName(), false); 148 } 149 150 /** 151 * Returns the user id parameter value.<p> 152 * 153 * @return the user id parameter value 154 */ 155 public String getParamGroupid() { 156 157 return m_paramGroupid; 158 } 159 160 /** 161 * Returns the parent Group name.<p> 162 * 163 * @return the parent Group name 164 */ 165 public String getParentGroup() { 166 167 return m_parentGroup; 168 } 169 170 /** 171 * Setter for widget definition.<p> 172 * 173 * @param assignedOu the ou description 174 */ 175 public void setAssignedOu(String assignedOu) { 176 177 assignedOu.length(); 178 } 179 180 /** 181 * Sets the description of the group.<p> 182 * 183 * @param description the description of the group 184 */ 185 public void setDescription(String description) { 186 187 m_group.setDescription(description); 188 } 189 190 /** 191 * Sets the name of the user object.<p> 192 * 193 * @param name the name of the user object 194 */ 195 public void setName(String name) { 196 197 name.length(); 198 } 199 200 /** 201 * Dummy setter for the nice name property.<p> 202 * 203 * @param name a name string 204 */ 205 public void setNiceName(String name) { 206 207 // if this method doesn't exist, the constructor of CmsWidgetDialogParameter throws an exception; not sure why 208 } 209 210 /** 211 * Sets the user id parameter value.<p> 212 * 213 * @param userId the user id parameter value 214 */ 215 public void setParamGroupid(String userId) { 216 217 m_paramGroupid = userId; 218 } 219 220 /** 221 * Sets the parent Group name.<p> 222 * 223 * @param parentGroup the parent Group name to set 224 */ 225 public void setParentGroup(String parentGroup) { 226 227 if (CmsStringUtil.isEmpty(parentGroup) || parentGroup.equals("null") || parentGroup.equals("none")) { 228 parentGroup = null; 229 } 230 if (parentGroup != null) { 231 try { 232 getCms().readGroup(parentGroup); 233 } catch (CmsException e) { 234 throw new CmsIllegalArgumentException(e.getMessageContainer()); 235 } 236 } 237 m_parentGroup = parentGroup; 238 } 239 240 /** 241 * Creates the dialog HTML for all defined widgets of the named dialog (page).<p> 242 * 243 * This overwrites the method from the super class to create a layout variation for the widgets.<p> 244 * 245 * @param dialog the dialog (page) to get the HTML for 246 * @return the dialog HTML for all defined widgets of the named dialog (page) 247 */ 248 @Override 249 protected String createDialogHtml(String dialog) { 250 251 StringBuffer result = new StringBuffer(1024); 252 253 // create widget table 254 result.append(createWidgetTableStart()); 255 256 // show error header once if there were validation errors 257 result.append(createWidgetErrorHeader()); 258 259 int n = (!isOverview() ? 2 : 4); 260 if (dialog.equals(PAGES[0])) { 261 // create the widgets for the first dialog page 262 result.append(dialogBlockStart(key(Messages.GUI_GROUP_EDITOR_LABEL_IDENTIFICATION_BLOCK_0))); 263 result.append(createWidgetTableStart()); 264 result.append(createDialogRowsHtml(0, n)); 265 result.append(createWidgetTableEnd()); 266 result.append(dialogBlockEnd()); 267 } 268 269 // close widget table 270 result.append(createWidgetTableEnd()); 271 272 return result.toString(); 273 } 274 275 /** 276 * @see org.opencms.workplace.CmsWidgetDialog#defaultActionHtmlEnd() 277 */ 278 @Override 279 protected String defaultActionHtmlEnd() { 280 281 return ""; 282 } 283 284 /** 285 * Creates the list of widgets for this dialog.<p> 286 */ 287 @Override 288 protected void defineWidgets() { 289 290 // initialize the user object to use for the dialog 291 initGroupObject(); 292 293 setKeyPrefix(KEY_PREFIX); 294 295 // widgets to display 296 if (!isOverview()) { 297 addWidget(new CmsWidgetDialogParameter(this, "name", PAGES[0], new CmsDisplayWidget())); 298 addWidget(new CmsWidgetDialogParameter(this, "description", PAGES[0], new CmsDisplayWidget())); 299 addWidget(new CmsWidgetDialogParameter(this, "assignedOu", PAGES[0], new CmsDisplayWidget())); 300 } else { 301 addWidget(new CmsWidgetDialogParameter(this, "niceName", "name", PAGES[0], new CmsDisplayWidget())); 302 addWidget(new CmsWidgetDialogParameter(this, "description", PAGES[0], new CmsDisplayWidget())); 303 addWidget(new CmsWidgetDialogParameter(this, "assignedOu", PAGES[0], new CmsDisplayWidget())); 304 addWidget(new CmsWidgetDialogParameter(this, "parentGroup", PAGES[0], new CmsDisplayWidget())); 305 addWidget(new CmsWidgetDialogParameter(m_group, "enabled", PAGES[0], new CmsDisplayWidget())); 306 } 307 } 308 309 /** 310 * @see org.opencms.workplace.CmsWidgetDialog#getPageArray() 311 */ 312 @Override 313 protected String[] getPageArray() { 314 315 return PAGES; 316 } 317 318 /** 319 * Initializes the group object.<p> 320 */ 321 protected void initGroupObject() { 322 323 try { 324 // edit an existing group, get the group object from db 325 m_group = getCms().readGroup(new CmsUUID(getParamGroupid())); 326 setParentGroup(getCms().readGroup(m_group.getParentId()).getName()); 327 } catch (CmsException e) { 328 // should never happen 329 } 330 } 331 332 /** 333 * @see org.opencms.workplace.CmsWorkplace#initMessages() 334 */ 335 @Override 336 protected void initMessages() { 337 338 // add specific dialog resource bundle 339 addMessages(Messages.get().getBundleName()); 340 // add default resource bundles 341 super.initMessages(); 342 } 343 344 /** 345 * Overridden to set the online help path for this dialog.<p> 346 * 347 * @see org.opencms.workplace.CmsWorkplace#initWorkplaceMembers(org.opencms.jsp.CmsJspActionElement) 348 */ 349 @Override 350 protected void initWorkplaceMembers(CmsJspActionElement jsp) { 351 352 super.initWorkplaceMembers(jsp); 353 setOnlineHelpUriCustom("/accounts/groups/overview/"); 354 } 355 356 /** 357 * @see org.opencms.workplace.CmsWidgetDialog#validateParamaters() 358 */ 359 @Override 360 protected void validateParamaters() throws Exception { 361 362 // test the needed parameters 363 getCms().readGroup(new CmsUUID(getParamGroupid())).getName(); 364 } 365 366 /** 367 * Checks if the group overview has to be displayed.<p> 368 * 369 * @return <code>true</code> if the group overview has to be displayed 370 */ 371 private boolean isOverview() { 372 373 return getCurrentToolPath().endsWith("/groups/edit"); 374 } 375}