1 31 32 package org.opencms.workplace.list; 33 34 import org.opencms.db.CmsUserSettings; 35 import org.opencms.file.CmsProject; 36 import org.opencms.file.CmsResource; 37 import org.opencms.file.CmsResourceFilter; 38 import org.opencms.i18n.CmsMessageContainer; 39 import org.opencms.jsp.CmsJspActionElement; 40 import org.opencms.main.CmsException; 41 import org.opencms.main.CmsLog; 42 import org.opencms.util.CmsResourceUtil; 43 import org.opencms.workplace.CmsDialog; 44 import org.opencms.workplace.CmsWorkplace; 45 import org.opencms.workplace.explorer.CmsExplorer; 46 47 import java.util.ArrayList ; 48 import java.util.Date ; 49 import java.util.HashMap ; 50 import java.util.Iterator ; 51 import java.util.List ; 52 import java.util.Map ; 53 54 import org.apache.commons.logging.Log; 55 56 65 public abstract class A_CmsListExplorerDialog extends A_CmsListDialog { 66 67 68 public static final String LIST_ACTION_LOCKICON = "eal"; 69 70 71 public static final String LIST_ACTION_PROJSTATEICON = "eaps"; 72 73 74 public static final String LIST_ACTION_TYPEICON = "eai"; 75 76 77 public static final String LIST_COLUMN_DATECREATE = "ecdc"; 78 79 80 public static final String LIST_COLUMN_DATEEXP = "ecde"; 81 82 83 public static final String LIST_COLUMN_DATELASTMOD = "ecdl"; 84 85 86 public static final String LIST_COLUMN_DATEREL = "ecdr"; 87 88 89 public static final String LIST_COLUMN_LOCKEDBY = "eclb"; 90 91 92 public static final String LIST_COLUMN_LOCKICON = "ecli"; 93 94 95 public static final String LIST_COLUMN_NAME = "ecn"; 96 97 98 public static final String LIST_COLUMN_PERMISSIONS = "ecp"; 99 100 101 public static final String LIST_COLUMN_PROJSTATEICON = "ecpi"; 102 103 104 public static final String LIST_COLUMN_SIZE = "ecz"; 105 106 107 public static final String LIST_COLUMN_STATE = "ecs"; 108 109 110 public static final String LIST_COLUMN_TITLE = "ect"; 111 112 113 public static final String LIST_COLUMN_TYPE = "ecy"; 114 115 116 public static final String LIST_COLUMN_TYPEICON = "ecti"; 117 118 119 public static final String LIST_COLUMN_USERCREATE = "ecuc"; 120 121 122 public static final String LIST_COLUMN_USERLASTMOD = "ecul"; 123 124 125 public static final String LIST_DEFACTION_OPEN = "edo"; 126 127 128 public static final String PATH_EXPLORER_LIST = PATH_DIALOGS + "list-explorer.jsp"; 129 130 131 private static final Log LOG = CmsLog.getLog(A_CmsListExplorerDialog.class); 132 133 134 private Map m_colVisibilities; 135 136 137 private CmsResourceUtil m_resourceUtil; 138 139 146 protected A_CmsListExplorerDialog(CmsJspActionElement jsp, String listId, CmsMessageContainer listName) { 147 148 this(jsp, listId, listName, LIST_COLUMN_NAME, CmsListOrderEnum.ORDER_ASCENDING, LIST_COLUMN_NAME); 149 } 150 151 161 protected A_CmsListExplorerDialog( 162 CmsJspActionElement jsp, 163 String listId, 164 CmsMessageContainer listName, 165 String sortedColId, 166 CmsListOrderEnum sortOrder, 167 String searchableColId) { 168 169 super(jsp, listId, listName, sortedColId, sortOrder, searchableColId); 170 } 171 172 175 public void executeListIndepActions() { 176 177 if (getParamListAction().equals(CmsListIndependentAction.ACTION_EXPLORER_SWITCH_ID)) { 178 Map params = new HashMap (); 179 params.put(CmsDialog.PARAM_ACTION, CmsDialog.DIALOG_INITIAL); 181 params.putAll(getToolManager().getCurrentTool(this).getHandler().getParameters(this)); 182 183 getSettings().setCollector(new CmsListResourcesCollector(getResources())); 184 getSettings().setExplorerMode(CmsExplorer.VIEW_LIST); 185 getSettings().setExplorerProjectId(getProject().getId()); 186 try { 187 getToolManager().jspForwardPage(this, PATH_EXPLORER_LIST, params); 188 } catch (Exception e) { 189 throw new RuntimeException (e); 190 } 191 } 192 super.executeListIndepActions(); 193 } 194 195 198 public CmsHtmlList getList() { 199 200 CmsHtmlList list = super.getList(); 202 if (list != null) { 203 CmsListColumnDefinition colName = list.getMetadata().getColumnDefinition(LIST_COLUMN_NAME); 204 if (colName != null) { 205 ((CmsListOpenResourceAction)colName.getDefaultAction(LIST_DEFACTION_OPEN)).setCms(getCms()); 206 } 207 Iterator it = list.getMetadata().getColumnDefinitions().iterator(); 208 while (it.hasNext()) { 209 CmsListColumnDefinition col = (CmsListColumnDefinition)it.next(); 210 Iterator itActs = col.getDirectActions().iterator(); 211 while (itActs.hasNext()) { 212 I_CmsListDirectAction action = (I_CmsListDirectAction)itActs.next(); 213 if (action instanceof CmsListExplorerDirectAction) { 214 ((CmsListExplorerDirectAction)action).setWp(this); 215 } 216 } 217 } 218 } 219 return list; 220 } 221 222 229 public CmsResource getResource(CmsListItem item) { 230 231 try { 232 return getCms().readResource((String )item.get(LIST_COLUMN_NAME), CmsResourceFilter.ALL); 233 } catch (CmsException e) { 234 return null; 235 } 236 } 237 238 243 public CmsResourceUtil getResourceUtil() { 244 245 if (m_resourceUtil == null) { 246 m_resourceUtil = new CmsResourceUtil(getCms()); 247 m_resourceUtil.setReferenceProject(getProject()); 248 } 249 return m_resourceUtil; 250 } 251 252 259 public CmsResourceUtil getResourceUtil(CmsListItem item) { 260 261 CmsResourceUtil resUtil = getResourceUtil(); 262 resUtil.setResource(getResource(item)); 263 return resUtil; 264 } 265 266 269 public synchronized void refreshList() { 270 271 if (getList() == null) { 272 return; 273 } 274 CmsListState ls = getList().getState(); 275 getList().clear(getLocale()); 276 fillList(); 277 getList().setState(ls, getLocale()); 278 try { 279 getList().setCurrentPage(getSettings().getExplorerPage()); 280 } catch (Throwable e) { 281 } 283 listSave(); 284 } 285 286 289 protected void applyColumnVisibilities() { 290 291 setColumnVisibilities(); 292 CmsListMetadata metadata = getList().getMetadata(); 293 metadata.getColumnDefinition(LIST_COLUMN_TYPEICON).setVisible(isColumnVisible(LIST_COLUMN_TYPEICON.hashCode())); 294 metadata.getColumnDefinition(LIST_COLUMN_LOCKICON).setVisible(isColumnVisible(LIST_COLUMN_LOCKICON.hashCode())); 295 metadata.getColumnDefinition(LIST_COLUMN_PROJSTATEICON).setVisible( 296 isColumnVisible(LIST_COLUMN_PROJSTATEICON.hashCode())); 297 metadata.getColumnDefinition(LIST_COLUMN_NAME).setVisible(isColumnVisible(LIST_COLUMN_NAME.hashCode())); 298 metadata.getColumnDefinition(LIST_COLUMN_TITLE).setVisible(isColumnVisible(CmsUserSettings.FILELIST_TITLE)); 299 metadata.getColumnDefinition(LIST_COLUMN_TYPE).setVisible(isColumnVisible(CmsUserSettings.FILELIST_TYPE)); 300 metadata.getColumnDefinition(LIST_COLUMN_SIZE).setVisible(isColumnVisible(CmsUserSettings.FILELIST_SIZE)); 301 metadata.getColumnDefinition(LIST_COLUMN_PERMISSIONS).setVisible( 302 isColumnVisible(CmsUserSettings.FILELIST_PERMISSIONS)); 303 metadata.getColumnDefinition(LIST_COLUMN_DATELASTMOD).setVisible( 304 isColumnVisible(CmsUserSettings.FILELIST_DATE_LASTMODIFIED)); 305 metadata.getColumnDefinition(LIST_COLUMN_USERLASTMOD).setVisible( 306 isColumnVisible(CmsUserSettings.FILELIST_USER_LASTMODIFIED)); 307 metadata.getColumnDefinition(LIST_COLUMN_DATECREATE).setVisible( 308 isColumnVisible(CmsUserSettings.FILELIST_DATE_CREATED)); 309 metadata.getColumnDefinition(LIST_COLUMN_USERCREATE).setVisible( 310 isColumnVisible(CmsUserSettings.FILELIST_USER_CREATED)); 311 metadata.getColumnDefinition(LIST_COLUMN_DATEREL).setVisible( 312 isColumnVisible(CmsUserSettings.FILELIST_DATE_RELEASED)); 313 metadata.getColumnDefinition(LIST_COLUMN_DATEEXP).setVisible( 314 isColumnVisible(CmsUserSettings.FILELIST_DATE_EXPIRED)); 315 metadata.getColumnDefinition(LIST_COLUMN_STATE).setVisible(isColumnVisible(CmsUserSettings.FILELIST_STATE)); 316 metadata.getColumnDefinition(LIST_COLUMN_LOCKEDBY).setVisible( 317 isColumnVisible(CmsUserSettings.FILELIST_LOCKEDBY)); 318 } 319 320 323 protected String defaultActionHtmlStart() { 324 325 StringBuffer result = new StringBuffer (2048); 326 result.append(htmlStart(null)); 327 result.append(getList().listJs(getLocale())); 328 result.append(CmsListExplorerColumn.getExplorerStyleDef()); 329 result.append(bodyStart("dialog", null)); 330 result.append(dialogStart()); 331 result.append(dialogContentStart(getParamTitle())); 332 return result.toString(); 333 } 334 335 338 protected void executeSelectPage() { 339 340 super.executeSelectPage(); 341 getSettings().setExplorerPage(getList().getCurrentPage()); 342 } 343 344 351 protected List getListItemsFromResources(List resources) { 352 353 List ret = new ArrayList (); 354 if (LOG.isDebugEnabled()) { 355 LOG.debug(Messages.get().getBundle().key(Messages.LOG_PROCESS_PROJECT_VIEW_START_1, new Integer (resources.size()))); 356 } 357 CmsResourceUtil resUtil = getResourceUtil(); 358 applyColumnVisibilities(); 359 Iterator itRes = resources.iterator(); 361 while (itRes.hasNext()) { 362 CmsResource resource = (CmsResource)itRes.next(); 363 if (!resource.getRootPath().startsWith(getJsp().getRequestContext().getSiteRoot()) 364 && !resource.getRootPath().startsWith(CmsWorkplace.VFS_PATH_SYSTEM)) { 365 continue; 366 } 367 resUtil.setResource(resource); 368 CmsListItem item = getList().newItem(resource.getResourceId().toString()); 369 item.set(LIST_COLUMN_NAME, getCms().getSitePath(resource)); 370 item.set(LIST_COLUMN_TITLE, resUtil.getTitle()); 371 item.set(LIST_COLUMN_TYPE, resUtil.getResourceTypeName()); 372 item.set(LIST_COLUMN_SIZE, resUtil.getSizeString()); 373 item.set(LIST_COLUMN_PERMISSIONS, resUtil.getPermissions()); 374 item.set(LIST_COLUMN_DATELASTMOD, new Date (resource.getDateLastModified())); 375 item.set(LIST_COLUMN_USERLASTMOD, resUtil.getUserLastModified()); 376 item.set(LIST_COLUMN_DATECREATE, new Date (resource.getDateCreated())); 377 item.set(LIST_COLUMN_USERCREATE, resUtil.getUserCreated()); 378 item.set(LIST_COLUMN_DATEREL, new Date (resource.getDateReleased())); 379 item.set(LIST_COLUMN_DATEEXP, new Date (resource.getDateExpired())); 380 item.set(LIST_COLUMN_STATE, resUtil.getStateName()); 381 item.set(LIST_COLUMN_LOCKEDBY, resUtil.getLockedByName()); 382 ret.add(item); 383 } 384 if (LOG.isDebugEnabled()) { 385 LOG.debug(Messages.get().getBundle().key(Messages.LOG_PROCESS_PROJECT_VIEW_END_1, new Integer (ret.size()))); 386 } 387 return ret; 388 } 389 390 395 protected CmsProject getProject() { 396 397 return getCms().getRequestContext().currentProject(); 398 } 399 400 405 protected List getResources() { 406 407 List ret = new ArrayList (getList().getContent().size()); 408 Iterator it = getList().getContent().iterator(); 409 while (it.hasNext()) { 410 CmsListItem item = (CmsListItem)it.next(); 411 try { 412 ret.add(getCms().readResource((String )item.get(LIST_COLUMN_NAME))); 413 } catch (CmsException e) { 414 } 416 } 417 return ret; 418 } 419 420 431 protected boolean isColumnVisible(int colFlag) { 432 433 if (m_colVisibilities.get(new Integer (colFlag)) instanceof Boolean ) { 434 return ((Boolean )m_colVisibilities.get(new Integer (colFlag))).booleanValue(); 435 } 436 return false; 437 } 438 439 444 protected void setColumns(CmsListMetadata metadata) { 445 446 setColumnVisibilities(); 447 448 CmsListColumnDefinition typeIconCol = new CmsListColumnDefinition(LIST_COLUMN_TYPEICON); 450 typeIconCol.setName(Messages.get().container(Messages.GUI_EXPLORER_LIST_COLS_ICON_0)); 451 typeIconCol.setHelpText(Messages.get().container(Messages.GUI_EXPLORER_LIST_COLS_ICON_HELP_0)); 452 typeIconCol.setWidth("20"); 453 typeIconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 454 typeIconCol.setListItemComparator(new CmsListItemActionIconComparator()); 455 456 CmsListDirectAction resourceTypeIconAction = new CmsListResourceTypeIconAction(LIST_ACTION_TYPEICON, this); 458 resourceTypeIconAction.setEnabled(false); 459 typeIconCol.addDirectAction(resourceTypeIconAction); 460 metadata.addColumn(typeIconCol); 461 462 CmsListColumnDefinition lockIconCol = new CmsListColumnDefinition(LIST_COLUMN_LOCKICON); 464 lockIconCol.setName(Messages.get().container(Messages.GUI_EXPLORER_LIST_COLS_LOCK_0)); 465 lockIconCol.setWidth("20"); 466 lockIconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 467 lockIconCol.setListItemComparator(new CmsListItemActionIconComparator()); 468 469 CmsListDirectAction resourceLockIconAction = new CmsListResourceLockAction(LIST_ACTION_LOCKICON, this); 471 resourceLockIconAction.setEnabled(false); 472 lockIconCol.addDirectAction(resourceLockIconAction); 473 metadata.addColumn(lockIconCol); 474 475 CmsListColumnDefinition projStateIconCol = new CmsListColumnDefinition(LIST_COLUMN_PROJSTATEICON); 477 projStateIconCol.setName(Messages.get().container(Messages.GUI_EXPLORER_LIST_COLS_PROJSTATE_0)); 478 projStateIconCol.setWidth("20"); 479 480 CmsListDirectAction resourceProjStateAction = new CmsListResourceProjStateAction( 482 LIST_ACTION_PROJSTATEICON, 483 this); 484 resourceProjStateAction.setEnabled(false); 485 projStateIconCol.addDirectAction(resourceProjStateAction); 486 metadata.addColumn(projStateIconCol); 487 488 CmsListColumnDefinition nameCol = new CmsListExplorerColumn(LIST_COLUMN_NAME); 490 nameCol.setName(org.opencms.workplace.explorer.Messages.get().container( 491 org.opencms.workplace.explorer.Messages.GUI_INPUT_NAME_0)); 492 493 CmsListDefaultAction resourceOpenDefAction = new CmsListOpenResourceAction( 495 LIST_DEFACTION_OPEN, 496 getCms(), 497 LIST_COLUMN_NAME); 498 resourceOpenDefAction.setEnabled(true); 499 nameCol.addDefaultAction(resourceOpenDefAction); 500 metadata.addColumn(nameCol); 501 502 CmsListColumnDefinition titleCol = new CmsListExplorerColumn(LIST_COLUMN_TITLE); 504 titleCol.setName(org.opencms.workplace.explorer.Messages.get().container( 505 org.opencms.workplace.explorer.Messages.GUI_INPUT_TITLE_0)); 506 metadata.addColumn(titleCol); 507 508 CmsListColumnDefinition typeCol = new CmsListExplorerColumn(LIST_COLUMN_TYPE); 510 typeCol.setName(org.opencms.workplace.explorer.Messages.get().container( 511 org.opencms.workplace.explorer.Messages.GUI_INPUT_TYPE_0)); 512 metadata.addColumn(typeCol); 513 514 CmsListColumnDefinition sizeCol = new CmsListExplorerColumn(LIST_COLUMN_SIZE); 516 sizeCol.setName(org.opencms.workplace.explorer.Messages.get().container( 517 org.opencms.workplace.explorer.Messages.GUI_INPUT_SIZE_0)); 518 metadata.addColumn(sizeCol); 519 520 CmsListColumnDefinition permissionsCol = new CmsListExplorerColumn(LIST_COLUMN_PERMISSIONS); 522 permissionsCol.setName(org.opencms.workplace.explorer.Messages.get().container( 523 org.opencms.workplace.explorer.Messages.GUI_INPUT_PERMISSIONS_0)); 524 metadata.addColumn(permissionsCol); 525 526 CmsListColumnDefinition dateLastModCol = new CmsListExplorerColumn(LIST_COLUMN_DATELASTMOD); 528 dateLastModCol.setName(org.opencms.workplace.explorer.Messages.get().container( 529 org.opencms.workplace.explorer.Messages.GUI_INPUT_DATELASTMODIFIED_0)); 530 dateLastModCol.setFormatter(CmsListDateMacroFormatter.getDefaultDateFormatter()); 531 metadata.addColumn(dateLastModCol); 532 533 CmsListColumnDefinition userLastModCol = new CmsListExplorerColumn(LIST_COLUMN_USERLASTMOD); 535 userLastModCol.setName(org.opencms.workplace.explorer.Messages.get().container( 536 org.opencms.workplace.explorer.Messages.GUI_INPUT_USERLASTMODIFIED_0)); 537 metadata.addColumn(userLastModCol); 538 539 CmsListColumnDefinition dateCreateCol = new CmsListExplorerColumn(LIST_COLUMN_DATECREATE); 541 dateCreateCol.setName(org.opencms.workplace.explorer.Messages.get().container( 542 org.opencms.workplace.explorer.Messages.GUI_INPUT_DATECREATED_0)); 543 dateCreateCol.setFormatter(CmsListDateMacroFormatter.getDefaultDateFormatter()); 544 metadata.addColumn(dateCreateCol); 545 546 CmsListColumnDefinition userCreateCol = new CmsListExplorerColumn(LIST_COLUMN_USERCREATE); 548 userCreateCol.setName(org.opencms.workplace.explorer.Messages.get().container( 549 org.opencms.workplace.explorer.Messages.GUI_INPUT_USERCREATED_0)); 550 metadata.addColumn(userCreateCol); 551 552 CmsListColumnDefinition dateReleaseCol = new CmsListExplorerColumn(LIST_COLUMN_DATEREL); 554 dateReleaseCol.setName(org.opencms.workplace.explorer.Messages.get().container( 555 org.opencms.workplace.explorer.Messages.GUI_INPUT_DATERELEASED_0)); 556 dateReleaseCol.setFormatter(CmsListDateMacroFormatter.getDefaultDateFormatter(CmsResource.DATE_RELEASED_DEFAULT)); 557 metadata.addColumn(dateReleaseCol); 558 559 CmsListColumnDefinition dateExpirationCol = new CmsListExplorerColumn(LIST_COLUMN_DATEEXP); 561 dateExpirationCol.setName(org.opencms.workplace.explorer.Messages.get().container( 562 org.opencms.workplace.explorer.Messages.GUI_INPUT_DATEEXPIRED_0)); 563 dateExpirationCol.setFormatter(CmsListDateMacroFormatter.getDefaultDateFormatter(CmsResource.DATE_EXPIRED_DEFAULT)); 564 metadata.addColumn(dateExpirationCol); 565 566 CmsListColumnDefinition stateCol = new CmsListExplorerColumn(LIST_COLUMN_STATE); 568 stateCol.setName(org.opencms.workplace.explorer.Messages.get().container( 569 org.opencms.workplace.explorer.Messages.GUI_INPUT_STATE_0)); 570 metadata.addColumn(stateCol); 571 572 CmsListColumnDefinition lockedByCol = new CmsListExplorerColumn(LIST_COLUMN_LOCKEDBY); 574 lockedByCol.setName(org.opencms.workplace.explorer.Messages.get().container( 575 org.opencms.workplace.explorer.Messages.GUI_INPUT_LOCKEDBY_0)); 576 metadata.addColumn(lockedByCol); 577 } 578 579 582 protected void setColumnVisibilities() { 583 584 m_colVisibilities = new HashMap (16); 585 int preferences = new CmsUserSettings(getCms()).getExplorerSettings(); 587 setColumnVisibility(CmsUserSettings.FILELIST_TITLE, preferences); 588 setColumnVisibility(CmsUserSettings.FILELIST_TYPE, preferences); 589 setColumnVisibility(CmsUserSettings.FILELIST_SIZE, preferences); 590 setColumnVisibility(CmsUserSettings.FILELIST_PERMISSIONS, preferences); 591 setColumnVisibility(CmsUserSettings.FILELIST_DATE_LASTMODIFIED, preferences); 592 setColumnVisibility(CmsUserSettings.FILELIST_USER_LASTMODIFIED, preferences); 593 setColumnVisibility(CmsUserSettings.FILELIST_DATE_CREATED, preferences); 594 setColumnVisibility(CmsUserSettings.FILELIST_USER_CREATED, preferences); 595 setColumnVisibility(CmsUserSettings.FILELIST_DATE_RELEASED, preferences); 596 setColumnVisibility(CmsUserSettings.FILELIST_DATE_EXPIRED, preferences); 597 setColumnVisibility(CmsUserSettings.FILELIST_STATE, preferences); 598 setColumnVisibility(CmsUserSettings.FILELIST_LOCKEDBY, preferences); 599 m_colVisibilities.put(new Integer (LIST_COLUMN_TYPEICON.hashCode()), Boolean.TRUE); 601 m_colVisibilities.put(new Integer (LIST_COLUMN_LOCKICON.hashCode()), Boolean.TRUE); 602 m_colVisibilities.put(new Integer (LIST_COLUMN_PROJSTATEICON.hashCode()), Boolean.TRUE); 603 m_colVisibilities.put(new Integer (LIST_COLUMN_NAME.hashCode()), Boolean.TRUE); 604 } 605 606 609 protected void setIndependentActions(CmsListMetadata metadata) { 610 611 metadata.addIndependentAction(CmsListIndependentAction.getDefaultExplorerSwitchAction()); 612 } 613 614 620 private void setColumnVisibility(int colFlag, int prefs) { 621 622 Integer key = new Integer (colFlag); 623 Boolean value = new Boolean ((prefs & colFlag) > 0); 624 m_colVisibilities.put(key, value); 625 } 626 } | Popular Tags |