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.CmsUser; 031import org.opencms.jsp.CmsJspActionElement; 032import org.opencms.main.CmsException; 033import org.opencms.main.CmsRuntimeException; 034import org.opencms.main.OpenCms; 035import org.opencms.security.CmsPasswordEncryptionException; 036import org.opencms.security.CmsRole; 037import org.opencms.util.CmsStringUtil; 038import org.opencms.util.CmsUUID; 039import org.opencms.util.CmsXsltUtil; 040import org.opencms.workplace.CmsDialog; 041import org.opencms.workplace.CmsWorkplaceSettings; 042import org.opencms.workplace.list.CmsListColumnAlignEnum; 043import org.opencms.workplace.list.CmsListColumnDefinition; 044import org.opencms.workplace.list.CmsListDirectAction; 045import org.opencms.workplace.list.CmsListItem; 046import org.opencms.workplace.list.CmsListItemDetails; 047import org.opencms.workplace.list.CmsListMetadata; 048import org.opencms.workplace.list.CmsListMultiAction; 049import org.opencms.workplace.list.I_CmsListFormatter; 050 051import java.io.BufferedReader; 052import java.io.File; 053import java.io.FileReader; 054import java.io.IOException; 055import java.lang.reflect.InvocationTargetException; 056import java.lang.reflect.Method; 057import java.util.ArrayList; 058import java.util.HashMap; 059import java.util.Hashtable; 060import java.util.Iterator; 061import java.util.List; 062import java.util.Locale; 063import java.util.Map; 064 065import javax.servlet.ServletException; 066import javax.servlet.http.HttpServletRequest; 067import javax.servlet.http.HttpServletResponse; 068import javax.servlet.jsp.JspException; 069import javax.servlet.jsp.PageContext; 070 071/** 072 * Main system user account management view.<p> 073 * 074 * @since 6.5.6 075 */ 076public class CmsUserDataImportList extends A_CmsUsersList { 077 078 /** Value for the delete action. */ 079 public static final int ACTION_IMPORT = 121; 080 081 /** Request parameter value for the import action. */ 082 public static final String IMPORT_ACTION = "import"; 083 084 /** list action id constant. */ 085 public static final String LIST_ACTION_VALIDATION = "av"; 086 087 /** list column id constant. */ 088 public static final String LIST_COLUMN_VALIDATION = "cv"; 089 090 /** list column id constant. */ 091 public static final String LIST_COLUMN_VALIDATION_HIDDEN = "cvh"; 092 093 /** list item detail id constant. */ 094 public static final String LIST_DETAIL_REASON = "dre"; 095 096 /** list id constant. */ 097 public static final String LIST_ID = "lsudi"; 098 099 /** list action id constant. */ 100 public static final String LIST_MACTION_SELECT = "ms"; 101 102 /** Stores the value of the request parameter for the group list. */ 103 private String m_paramGroups; 104 105 /** Stores the value of the request parameter for the import file. */ 106 private String m_paramImportfile; 107 108 /** Stores the value of the request parameter for the organizational unit fqn. */ 109 private String m_paramOufqn; 110 111 /** Stores the value of the request parameter for the default password. */ 112 private String m_paramPassword; 113 114 /** Stores the value of the request parameter for the role list. */ 115 private String m_paramRoles; 116 117 /** Stores the reasons why users may not be imported. */ 118 private Map m_reasons; 119 120 /** The file to upload. */ 121 private File m_uploadFile; 122 123 /** 124 * Public constructor.<p> 125 * 126 * @param jsp an initialized JSP action element 127 */ 128 public CmsUserDataImportList(CmsJspActionElement jsp) { 129 130 super(jsp, LIST_ID, Messages.get().container(Messages.GUI_IMPORTLISTCSV_LIST_NAME_0), false); 131 getList().setSortedColumn(LIST_COLUMN_VALIDATION_HIDDEN); 132 } 133 134 /** 135 * Public constructor with JSP variables.<p> 136 * 137 * @param context the JSP page context 138 * @param req the JSP request 139 * @param res the JSP response 140 */ 141 public CmsUserDataImportList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 142 143 this(new CmsJspActionElement(context, req, res)); 144 } 145 146 /** 147 * @see org.opencms.workplace.list.A_CmsListDialog#actionDialog() 148 */ 149 @Override 150 public void actionDialog() throws JspException, ServletException, IOException { 151 152 switch (getAction()) { 153 case ACTION_IMPORT: 154 List users = getUsers(); 155 Iterator itUsers = users.iterator(); 156 while (itUsers.hasNext()) { 157 CmsUser user = (CmsUser)itUsers.next(); 158 if (((m_reasons == null) || !m_reasons.containsKey(user.getName())) 159 && !isAlreadyAvailable(user.getName())) { 160 161 String password = user.getPassword(); 162 if (password.indexOf("_") == -1) { 163 try { 164 password = OpenCms.getPasswordHandler().digest(password); 165 } catch (CmsPasswordEncryptionException e) { 166 throw new CmsRuntimeException( 167 Messages.get().container(Messages.ERR_DIGEST_PASSWORD_0), 168 e); 169 } 170 } else { 171 password = password.substring(password.indexOf("_") + 1); 172 } 173 CmsUser createdUser; 174 try { 175 createdUser = getCms().importUser( 176 new CmsUUID().toString(), 177 getParamOufqn() + user.getName(), 178 password, 179 user.getFirstname(), 180 user.getLastname(), 181 user.getEmail(), 182 user.getFlags(), 183 System.currentTimeMillis(), 184 user.getAdditionalInfo()); 185 } catch (CmsException e) { 186 throw new CmsRuntimeException(Messages.get().container(Messages.ERR_IMPORT_USER_0), e); 187 } 188 189 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamGroups())) { 190 List groups = CmsStringUtil.splitAsList(getParamGroups(), ","); 191 Iterator itGroups = groups.iterator(); 192 while (itGroups.hasNext()) { 193 try { 194 getCms().addUserToGroup(createdUser.getName(), (String)itGroups.next()); 195 } catch (CmsException e) { 196 throw new CmsRuntimeException( 197 Messages.get().container(Messages.ERR_ADD_USER_TO_GROUP_0), 198 e); 199 } 200 } 201 } 202 203 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamRoles())) { 204 List roles = CmsStringUtil.splitAsList(getParamRoles(), ","); 205 Iterator itRoles = roles.iterator(); 206 while (itRoles.hasNext()) { 207 try { 208 OpenCms.getRoleManager().addUserToRole( 209 getCms(), 210 CmsRole.valueOfGroupName((String)itRoles.next()), 211 createdUser.getName()); 212 } catch (CmsException e) { 213 throw new CmsRuntimeException( 214 Messages.get().container(Messages.ERR_ADD_USER_TO_ROLE_0), 215 e); 216 } 217 } 218 } 219 } 220 } 221 setAction(ACTION_CANCEL); 222 actionCloseDialog(); 223 break; 224 default: 225 super.actionDialog(); 226 } 227 } 228 229 /** 230 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#executeListMultiActions() 231 */ 232 @Override 233 public void executeListMultiActions() throws CmsRuntimeException { 234 235 if (getParamListAction().equals(LIST_MACTION_SELECT)) { 236 Iterator itItems = getSelectedItems().iterator(); 237 while (itItems.hasNext()) { 238 CmsListItem listItem = (CmsListItem)itItems.next(); 239 String userName = listItem.get(LIST_COLUMN_DISPLAY).toString(); 240 List users = getUsers(); 241 Iterator itUsers = users.iterator(); 242 while (itUsers.hasNext()) { 243 CmsUser user = (CmsUser)itUsers.next(); 244 try { 245 if (user.getName().equals(userName) 246 && ((m_reasons == null) || !m_reasons.containsKey(userName)) 247 && !isAlreadyAvailable(user.getName())) { 248 249 String password = user.getPassword(); 250 if (password.indexOf("_") == -1) { 251 password = OpenCms.getPasswordHandler().digest(password); 252 } else { 253 password = password.substring(password.indexOf("_") + 1); 254 } 255 256 CmsUser createdUser = getCms().importUser( 257 new CmsUUID().toString(), 258 getParamOufqn() + user.getName(), 259 password, 260 user.getFirstname(), 261 user.getLastname(), 262 user.getEmail(), 263 user.getFlags(), 264 System.currentTimeMillis(), 265 user.getAdditionalInfo()); 266 267 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamGroups())) { 268 List groups = CmsStringUtil.splitAsList(getParamGroups(), ","); 269 Iterator itGroups = groups.iterator(); 270 while (itGroups.hasNext()) { 271 getCms().addUserToGroup(createdUser.getName(), (String)itGroups.next()); 272 } 273 } 274 275 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(getParamRoles())) { 276 List roles = CmsStringUtil.splitAsList(getParamRoles(), ","); 277 Iterator itRoles = roles.iterator(); 278 while (itRoles.hasNext()) { 279 OpenCms.getRoleManager().addUserToRole( 280 getCms(), 281 CmsRole.valueOfGroupName((String)itRoles.next()), 282 createdUser.getName()); 283 } 284 } 285 286 break; 287 } 288 } catch (CmsException e) { 289 // noop 290 } 291 } 292 } 293 Map params = new HashMap(); 294 params.put(A_CmsOrgUnitDialog.PARAM_OUFQN, getParamOufqn()); 295 params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL); 296 297 try { 298 getToolManager().jspForwardTool(this, getParentPath(), params); 299 } catch (ServletException e) { 300 throw new CmsRuntimeException(Messages.get().container(Messages.ERR_FORWARDING_TO_PARENT_TOOL_0), e); 301 } catch (IOException e) { 302 throw new CmsRuntimeException(Messages.get().container(Messages.ERR_FORWARDING_TO_PARENT_TOOL_0), e); 303 } 304 305 } else { 306 throwListUnsupportedActionException(); 307 } 308 listSave(); 309 } 310 311 /** 312 * Returns the paramGroups.<p> 313 * 314 * @return the paramGroups 315 */ 316 public String getParamGroups() { 317 318 return m_paramGroups; 319 } 320 321 /** 322 * Returns the paramImportfile.<p> 323 * 324 * @return the paramImportfile 325 */ 326 public String getParamImportfile() { 327 328 return m_paramImportfile; 329 } 330 331 /** 332 * Returns the organizational unit fqn parameter value.<p> 333 * 334 * @return the organizational unit fqn parameter value 335 */ 336 @Override 337 public String getParamOufqn() { 338 339 return m_paramOufqn; 340 } 341 342 /** 343 * Returns the paramPassword.<p> 344 * 345 * @return the paramPassword 346 */ 347 public String getParamPassword() { 348 349 return m_paramPassword; 350 } 351 352 /** 353 * Returns the paramRoles.<p> 354 * 355 * @return the paramRoles 356 */ 357 public String getParamRoles() { 358 359 return m_paramRoles; 360 } 361 362 /** 363 * Returns the reasons.<p> 364 * 365 * @return the reasons 366 */ 367 public Map getReasons() { 368 369 return m_reasons; 370 } 371 372 /** 373 * Sets the paramGroups.<p> 374 * 375 * @param paramGroups the paramGroups to set 376 */ 377 public void setParamGroups(String paramGroups) { 378 379 m_paramGroups = paramGroups; 380 } 381 382 /** 383 * Sets the paramImportfile.<p> 384 * 385 * @param paramImportfile the paramImportfile to set 386 */ 387 public void setParamImportfile(String paramImportfile) { 388 389 m_paramImportfile = paramImportfile; 390 } 391 392 /** 393 * Sets the organizational unit fqn parameter value.<p> 394 * 395 * @param ouFqn the organizational unit fqn parameter value 396 */ 397 @Override 398 public void setParamOufqn(String ouFqn) { 399 400 if (ouFqn == null) { 401 ouFqn = ""; 402 } 403 m_paramOufqn = ouFqn; 404 } 405 406 /** 407 * Sets the paramPassword.<p> 408 * 409 * @param paramPassword the paramPassword to set 410 */ 411 public void setParamPassword(String paramPassword) { 412 413 m_paramPassword = paramPassword; 414 } 415 416 /** 417 * Sets the paramRoles.<p> 418 * 419 * @param paramRoles the paramRoles to set 420 */ 421 public void setParamRoles(String paramRoles) { 422 423 m_paramRoles = paramRoles; 424 } 425 426 /** 427 * Sets the reasons.<p> 428 * 429 * @param reasons the reasons to set 430 */ 431 public void setReasons(Map reasons) { 432 433 m_reasons = reasons; 434 } 435 436 /** 437 * @see org.opencms.workplace.list.A_CmsListDialog#customHtmlEnd() 438 */ 439 @Override 440 protected String customHtmlEnd() { 441 442 StringBuffer result = new StringBuffer(512); 443 result.append(super.customHtmlEnd()); 444 result.append("<form name='actions' method='post' action='"); 445 result.append(getDialogRealUri()); 446 result.append("' class='nomargin' onsubmit=\"return submitAction('ok', null, 'actions');\">\n"); 447 result.append(allParamsAsHidden()); 448 result.append(dialogButtonRow(HTML_START)); 449 result.append("<input name='"); 450 result.append(IMPORT_ACTION); 451 result.append("' type='button' value='"); 452 result.append(key(org.opencms.workplace.Messages.GUI_DIALOG_BUTTON_OK_0)); 453 result.append("' onclick=\"submitAction('"); 454 result.append(IMPORT_ACTION); 455 result.append("', form);\" class='dialogbutton'>\n"); 456 dialogButtonsHtml(result, BUTTON_CANCEL, ""); 457 result.append(dialogButtonRow(HTML_END)); 458 result.append("</form>\n"); 459 return result.toString(); 460 } 461 462 /** 463 * @see org.opencms.workplace.list.A_CmsListDialog#customHtmlStart() 464 */ 465 @Override 466 protected String customHtmlStart() { 467 468 StringBuffer result = new StringBuffer(1024); 469 result.append(dialogBlockStart(key(Messages.GUI_USERDATA_IMPORT_LABEL_HINT_BLOCK_0))); 470 result.append(key(Messages.GUI_IMPORTLISTCSV_IMPORT_LABEL_HINT_TEXT_0)); 471 result.append(dialogBlockEnd()); 472 result.append("<div class=\"dialogspacer\" unselectable=\"on\"> </div>"); 473 return result.toString(); 474 } 475 476 /** 477 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#fillDetails(java.lang.String) 478 */ 479 @Override 480 protected void fillDetails(String detailId) { 481 482 // get content 483 List users = getList().getAllContent(); 484 Iterator itUsers = users.iterator(); 485 while (itUsers.hasNext()) { 486 CmsListItem item = (CmsListItem)itUsers.next(); 487 String userName = item.get(LIST_COLUMN_DISPLAY).toString(); 488 StringBuffer html = new StringBuffer(512); 489 try { 490 if (detailId.equals(LIST_DETAIL_REASON) && (m_reasons != null) && m_reasons.containsKey(userName)) { 491 html.append(m_reasons.get(userName)); 492 } else { 493 html.append(key(Messages.GUI_IMPORTLISTCSV_VALID_USER_0)); 494 } 495 } catch (Exception e) { 496 // noop 497 } 498 item.set(detailId, html.toString()); 499 } 500 } 501 502 /** 503 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#getGroupIcon() 504 */ 505 @Override 506 protected String getGroupIcon() { 507 508 return null; 509 } 510 511 /** 512 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#getListItems() 513 */ 514 @Override 515 protected List getListItems() { 516 517 List ret = new ArrayList(); 518 519 // get content 520 List users = getUsers(); 521 Iterator itUsers = users.iterator(); 522 while (itUsers.hasNext()) { 523 CmsUser user = (CmsUser)itUsers.next(); 524 CmsListItem item = getList().newItem(user.getName()); 525 item.set(LIST_COLUMN_DISPLAY, user.getName()); 526 527 if (isAlreadyAvailable(user.getName())) { 528 if (m_reasons == null) { 529 m_reasons = new HashMap(); 530 } 531 m_reasons.put( 532 user.getName(), 533 Messages.get().container(Messages.GUI_IMPORTLISTCSV_ALREADY_EXISTS_0).key(getLocale())); 534 } 535 if ((m_reasons != null) && m_reasons.containsKey(user.getName())) { 536 item.set(LIST_COLUMN_VALIDATION_HIDDEN, "invalid"); 537 } else { 538 item.set(LIST_COLUMN_VALIDATION_HIDDEN, "valid"); 539 } 540 ret.add(item); 541 } 542 543 return ret; 544 } 545 546 /** 547 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#getUsers() 548 */ 549 @Override 550 protected List getUsers() { 551 552 String separator = null; 553 List values = null; 554 555 m_uploadFile = new File(m_paramImportfile); 556 FileReader fileReader; 557 BufferedReader bufferedReader; 558 List users = null; 559 560 try { 561 fileReader = new FileReader(m_uploadFile); 562 bufferedReader = new BufferedReader(fileReader); 563 String line; 564 boolean headline = true; 565 566 while ((line = bufferedReader.readLine()) != null) { 567 if (users == null) { 568 users = new ArrayList(); 569 } 570 if (separator == null) { 571 separator = CmsXsltUtil.getPreferredDelimiter(line); 572 } 573 List lineValues = CmsStringUtil.splitAsList(line, separator); 574 if (headline) { 575 values = new ArrayList(); 576 Iterator itLineValues = lineValues.iterator(); 577 while (itLineValues.hasNext()) { 578 values.add(itLineValues.next()); 579 } 580 headline = false; 581 } else if (values != null) { 582 CmsUser curUser = new CmsUser(); 583 try { 584 for (int i = 0; i < values.size(); i++) { 585 String curValue = (String)values.get(i); 586 try { 587 Method method = CmsUser.class.getMethod( 588 "set" + curValue.substring(0, 1).toUpperCase() + curValue.substring(1), 589 new Class[] {String.class}); 590 String value = ""; 591 if ((lineValues.size() > i) && (lineValues.get(i) != null)) { 592 value = (String)lineValues.get(i); 593 594 } 595 if (curValue.equals("password")) { 596 if (CmsStringUtil.isEmptyOrWhitespaceOnly(value)) { 597 value = m_paramPassword; 598 } 599 } 600 if (CmsStringUtil.isNotEmptyOrWhitespaceOnly(value) && !value.equals("null")) { 601 method.invoke(curUser, new Object[] {value}); 602 } 603 } catch (NoSuchMethodException ne) { 604 curUser.setAdditionalInfo(curValue, lineValues.get(i)); 605 } catch (IllegalAccessException le) { 606 if (m_reasons == null) { 607 m_reasons = new HashMap(); 608 } 609 m_reasons.put(curUser.getName(), le); 610 } catch (InvocationTargetException te) { 611 if (m_reasons == null) { 612 m_reasons = new HashMap(); 613 } 614 m_reasons.put(curUser.getName(), te); 615 } 616 } 617 } catch (CmsRuntimeException e) { 618 if (m_reasons == null) { 619 m_reasons = new HashMap(); 620 } 621 if (curUser.getName() == null) { 622 m_reasons.put(lineValues.get(0), e); 623 } else { 624 m_reasons.put(curUser.getName(), e); 625 } 626 } 627 users.add(curUser); 628 } 629 } 630 bufferedReader.close(); 631 } catch (IOException e) { 632 //noop 633 } 634 635 // m_reasons 636 637 return users; 638 } 639 640 /** 641 * Initializes the message info object to work with depending on the dialog state and request parameters.<p> 642 */ 643 protected void initExportObject() { 644 645 try { 646 if (CmsStringUtil.isEmpty(getParamAction()) || CmsDialog.DIALOG_INITIAL.equals(getParamAction())) { 647 // create a new list 648 m_reasons = new HashMap(); 649 } else { 650 Map objects = (Map)getSettings().getDialogObject(); 651 if (objects == null) { 652 // using hashtable as most efficient version of a synchronized map 653 objects = new Hashtable(); 654 getSettings().setDialogObject(objects); 655 } 656 m_reasons = (Map)objects.get(getClass().getName()); 657 } 658 } catch (Exception e) { 659 // create a new list 660 m_reasons = new HashMap(); 661 } 662 } 663 664 /** 665 * @see org.opencms.workplace.list.A_CmsListDialog#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest) 666 */ 667 @Override 668 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 669 670 super.initWorkplaceRequestValues(settings, request); 671 if (IMPORT_ACTION.equals(getParamAction())) { 672 setAction(ACTION_IMPORT); 673 } 674 675 // save the current state of the message (may be changed because of the widget values) 676 677 if (m_reasons == null) { 678 // null object: remove the entry from the map 679 680 Map objects = (Map)getSettings().getDialogObject(); 681 if (objects == null) { 682 // using hashtable as most efficient version of a synchronized map 683 objects = new Hashtable(); 684 getSettings().setDialogObject(objects); 685 } 686 objects.remove(getClass().getName()); 687 } else { 688 Map objects = (Map)getSettings().getDialogObject(); 689 if (objects == null) { 690 // using hashtable as most efficient version of a synchronized map 691 objects = new Hashtable(); 692 getSettings().setDialogObject(objects); 693 } 694 objects.put(getClass().getName(), m_reasons); 695 } 696 } 697 698 /** 699 * Checks if the given user name is already available inside the current ou.<p> 700 * 701 * @param userName the user name to check 702 * @return <code>true</code> if the user name is already available, otherwise return <code>false</code> 703 */ 704 protected boolean isAlreadyAvailable(String userName) { 705 706 List availableUsers; 707 try { 708 availableUsers = OpenCms.getOrgUnitManager().getUsers(getCms(), getParamOufqn(), false); 709 } catch (CmsException e) { 710 availableUsers = new ArrayList(); 711 } 712 Iterator itAvailableUsers = availableUsers.iterator(); 713 while (itAvailableUsers.hasNext()) { 714 if (userName.equals(((CmsUser)itAvailableUsers.next()).getSimpleName())) { 715 return true; 716 } 717 } 718 return false; 719 } 720 721 /** 722 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#readUser(java.lang.String) 723 */ 724 @Override 725 protected CmsUser readUser(String name) { 726 727 return null; 728 } 729 730 /** 731 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#setColumns(org.opencms.workplace.list.CmsListMetadata) 732 */ 733 @Override 734 protected void setColumns(CmsListMetadata metadata) { 735 736 initExportObject(); 737 738 super.setColumns(metadata); 739 740 metadata.getColumnDefinition(LIST_COLUMN_GROUPS).setVisible(false); 741 metadata.getColumnDefinition(LIST_COLUMN_ROLE).setVisible(false); 742 metadata.getColumnDefinition(LIST_COLUMN_ACTIVATE).setVisible(false); 743 metadata.getColumnDefinition(LIST_COLUMN_DELETE).setVisible(false); 744 metadata.getColumnDefinition(LIST_COLUMN_NAME).setVisible(false); 745 metadata.getColumnDefinition(LIST_COLUMN_EMAIL).setVisible(false); 746 metadata.getColumnDefinition(LIST_COLUMN_LASTLOGIN).setVisible(false); 747 748 metadata.getColumnDefinition(LIST_COLUMN_DISPLAY).getDefaultAction(LIST_DEFACTION_EDIT).setEnabled(false); 749 metadata.getColumnDefinition(LIST_COLUMN_DISPLAY).setWidth("100%"); 750 751 // create hidden column for state 752 CmsListColumnDefinition hiddenStateCol = new CmsListColumnDefinition(LIST_COLUMN_VALIDATION_HIDDEN); 753 hiddenStateCol.setName(Messages.get().container(Messages.GUI_IMPORTLISTCSV_LIST_COLS_VAIDATION_0)); 754 hiddenStateCol.setVisible(false); 755 hiddenStateCol.setSorteable(true); 756 metadata.addColumn(hiddenStateCol); 757 758 // create column for state 759 CmsListColumnDefinition stateCol = new CmsListColumnDefinition(LIST_COLUMN_VALIDATION); 760 stateCol.setName(Messages.get().container(Messages.GUI_IMPORTLISTCSV_LIST_COLS_VAIDATION_0)); 761 stateCol.setWidth("20"); 762 stateCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 763 stateCol.setSorteable(false); 764 // add action for icon displaying 765 CmsListDirectAction stateAction = new CmsListDirectAction(LIST_ACTION_VALIDATION) { 766 767 /** 768 * @see org.opencms.workplace.tools.A_CmsHtmlIconButton#getIconPath() 769 */ 770 @Override 771 public String getIconPath() { 772 773 String userName = getItem().getId(); 774 775 if (((((CmsUserDataImportList)getWp()).getReasons() != null) 776 && ((CmsUserDataImportList)getWp()).getReasons().containsKey(userName)) 777 || ((CmsUserDataImportList)getWp()).isAlreadyAvailable(userName)) { 778 return ICON_MULTI_DELETE; 779 } 780 return ICON_MULTI_ACTIVATE; 781 } 782 }; 783 stateAction.setName(Messages.get().container(Messages.GUI_IMPORTLISTCSV_LIST_COLS_VAIDATION_0)); 784 stateAction.setIconPath(ICON_MULTI_ACTIVATE); 785 stateAction.setEnabled(false); 786 stateCol.addDirectAction(stateAction); 787 metadata.addColumn(stateCol, 1); 788 } 789 790 /** 791 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#setDeleteAction(org.opencms.workplace.list.CmsListColumnDefinition) 792 */ 793 @Override 794 protected void setDeleteAction(CmsListColumnDefinition deleteCol) { 795 796 // noop 797 } 798 799 /** 800 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#setEditAction(org.opencms.workplace.list.CmsListColumnDefinition) 801 */ 802 @Override 803 protected void setEditAction(CmsListColumnDefinition editCol) { 804 805 CmsListDirectAction editAction = new CmsListDirectAction(LIST_ACTION_EDIT); 806 editAction.setName(Messages.get().container(Messages.GUI_USERS_LIST_ACTION_EDIT_NAME_0)); 807 editAction.setIconPath(PATH_BUTTONS + "user.png"); 808 editAction.setEnabled(false); 809 editCol.addDirectAction(editAction); 810 } 811 812 /** 813 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#setIndependentActions(org.opencms.workplace.list.CmsListMetadata) 814 */ 815 @Override 816 protected void setIndependentActions(CmsListMetadata metadata) { 817 818 // add reason details 819 CmsListItemDetails reasonDetails = new CmsListItemDetails(LIST_DETAIL_REASON); 820 reasonDetails.setAtColumn(LIST_COLUMN_DISPLAY); 821 reasonDetails.setVisible(true); 822 reasonDetails.setShowActionName(Messages.get().container(Messages.GUI_IMPORTLISTCSV_DETAIL_SHOW_REASON_NAME_0)); 823 reasonDetails.setShowActionHelpText( 824 Messages.get().container(Messages.GUI_IMPORTLISTCSV_DETAIL_SHOW_REASON_HELP_0)); 825 reasonDetails.setHideActionName(Messages.get().container(Messages.GUI_IMPORTLISTCSV_DETAIL_HIDE_REASON_NAME_0)); 826 reasonDetails.setHideActionHelpText( 827 Messages.get().container(Messages.GUI_IMPORTLISTCSV_DETAIL_HIDE_REASON_HELP_0)); 828 reasonDetails.setName(Messages.get().container(Messages.GUI_IMPORTLISTCSV_DETAIL_REASON_NAME_0)); 829 reasonDetails.setFormatter(new I_CmsListFormatter() { 830 831 /** 832 * @see org.opencms.workplace.list.I_CmsListFormatter#format(java.lang.Object, java.util.Locale) 833 */ 834 public String format(Object data, Locale locale) { 835 836 StringBuffer html = new StringBuffer(512); 837 html.append("<table border='0' cellspacing='0' cellpadding='0'>\n"); 838 html.append("\t<tr>\n"); 839 html.append("\t\t<td style='white-space:normal;' >\n"); 840 html.append("\t\t\t"); 841 html.append(data == null ? "" : data); 842 html.append("\n"); 843 html.append("\t\t</td>\n"); 844 html.append("\t</tr>\n"); 845 html.append("</table>\n"); 846 return html.toString(); 847 } 848 }); 849 metadata.addItemDetails(reasonDetails); 850 } 851 852 /** 853 * @see org.opencms.workplace.tools.accounts.A_CmsUsersList#setMultiActions(org.opencms.workplace.list.CmsListMetadata) 854 */ 855 @Override 856 protected void setMultiActions(CmsListMetadata metadata) { 857 858 // add the select multi action 859 CmsListMultiAction selectUser = new CmsListMultiAction(LIST_MACTION_SELECT); 860 selectUser.setName(Messages.get().container(Messages.GUI_IMPORTLISTCSV_LIST_MACTION_SELECT_NAME_0)); 861 selectUser.setHelpText(Messages.get().container(Messages.GUI_IMPORTLISTCSV_LIST_MACTION_SELECT_HELP_0)); 862 selectUser.setIconPath(ICON_MULTI_ADD); 863 metadata.addMultiAction(selectUser); 864 } 865}