1 31 32 package org.opencms.workplace.commons; 33 34 import org.opencms.file.CmsBackupProject; 35 import org.opencms.file.CmsBackupResource; 36 import org.opencms.file.CmsBackupResourceHandler; 37 import org.opencms.file.CmsFile; 38 import org.opencms.file.CmsObject; 39 import org.opencms.file.CmsResource; 40 import org.opencms.file.CmsResourceFilter; 41 import org.opencms.jsp.CmsJspActionElement; 42 import org.opencms.main.CmsException; 43 import org.opencms.main.CmsLog; 44 import org.opencms.main.CmsRuntimeException; 45 import org.opencms.workplace.list.A_CmsListDialog; 46 import org.opencms.workplace.list.CmsListColumnAlignEnum; 47 import org.opencms.workplace.list.CmsListColumnDefinition; 48 import org.opencms.workplace.list.CmsListDirectAction; 49 import org.opencms.workplace.list.CmsListItem; 50 import org.opencms.workplace.list.CmsListItemActionIconComparator; 51 import org.opencms.workplace.list.CmsListItemDetails; 52 import org.opencms.workplace.list.CmsListItemDetailsFormatter; 53 import org.opencms.workplace.list.CmsListItemSelectionAction; 54 import org.opencms.workplace.list.CmsListMetadata; 55 import org.opencms.workplace.list.CmsListOrderEnum; 56 import org.opencms.workplace.list.CmsListRadioMultiAction; 57 import org.opencms.workplace.list.CmsListResourceIconAction; 58 import org.opencms.workplace.tools.CmsToolDialog; 59 60 import java.io.IOException ; 61 import java.util.ArrayList ; 62 import java.util.Arrays ; 63 import java.util.HashMap ; 64 import java.util.Iterator ; 65 import java.util.List ; 66 import java.util.Map ; 67 68 import javax.servlet.ServletException ; 69 import javax.servlet.http.HttpServletRequest ; 70 import javax.servlet.http.HttpServletResponse ; 71 import javax.servlet.jsp.PageContext ; 72 73 import org.apache.commons.logging.Log; 74 75 85 public class CmsHistoryList extends A_CmsListDialog { 86 87 90 public static class CmsVersionWrapper implements Comparable { 91 92 private Object m_version; 93 94 98 public CmsVersionWrapper(Object version) { 99 100 m_version = version; 101 } 102 103 107 public int compareTo(Object o) { 108 109 CmsVersionWrapper version = (CmsVersionWrapper)o; 110 if (String .class.equals(version.getVersion().getClass()) && Integer .class.equals(getVersion().getClass())) { 111 return -1; 112 } else if (Integer .class.equals(version.getVersion().getClass()) && String .class.equals(getVersion().getClass())) { 113 return 1; 114 } else { 115 return ((Comparable )m_version).compareTo(version.getVersion()); 116 } 117 } 118 119 123 public Object getVersion() { 124 125 return m_version; 126 } 127 128 132 public String toString() { 133 134 return m_version.toString(); 135 } 136 137 } 138 139 140 public static final String GUI_LIST_HISTORY_DETAIL_PROJECT_0 = "lhdp"; 141 142 public static final String LIST_ACTION_RESTORE = "ar"; 143 144 public static final String LIST_ACTION_VIEW = "av"; 145 146 147 public static final String LIST_COLUMN_BACKUP_TAG = "cbt"; 148 149 150 public static final String LIST_COLUMN_DATE_LAST_MODIFIED = "cm"; 151 152 153 public static final String LIST_COLUMN_DATE_PUBLISHED = "cdp"; 154 155 156 public static final String LIST_COLUMN_FILE_TYPE = "ct"; 157 158 159 public static final String LIST_COLUMN_ICON = "ci"; 160 161 162 public static final String LIST_COLUMN_RESOURCE_PATH = "crp"; 163 164 165 public static final String LIST_COLUMN_RESTORE = "cr"; 166 167 168 public static final String LIST_COLUMN_SEL1 = "cs1"; 169 170 171 public static final String LIST_COLUMN_SEL2 = "cs2"; 172 173 174 public static final String LIST_COLUMN_SIZE = "cs"; 175 176 177 public static final String LIST_COLUMN_USER = "cu"; 178 179 180 public static final String LIST_COLUMN_VERSION = "cv"; 181 182 183 public static final String LIST_COLUMN_VIEW = "cp"; 184 185 186 public static final String LIST_ID = "him"; 187 188 189 private static final String LIST_MACTION_COMPARE = "mc"; 190 191 192 public static final String LIST_RACTION_SEL1 = "rs1"; 193 194 195 public static final String LIST_RACTION_SEL2 = "rs2"; 196 197 198 private static final Log LOG = CmsLog.getLog(CmsHistoryList.class); 199 200 201 public static final String OFFLINE_PROJECT = "offline"; 202 203 204 public static final String PARAM_PATH_1 = "path1"; 205 206 207 public static final String PARAM_PATH_2 = "path2"; 208 209 210 public static final String PARAM_TAGID_1 = "tagid1"; 211 212 213 public static final String PARAM_TAGID_2 = "tagid2"; 214 215 216 public static final String PARAM_VERSION_1 = "version1"; 217 218 219 public static final String PARAM_VERSION_2 = "version2"; 220 221 222 public static final String PATH_BUTTONS = "buttons/"; 223 224 229 public CmsHistoryList(CmsJspActionElement jsp) { 230 231 super(jsp, LIST_ID, Messages.get().container(Messages.GUI_HISTORY_0), 232 LIST_COLUMN_VERSION, CmsListOrderEnum.ORDER_DESCENDING, null); 233 } 234 235 242 public CmsHistoryList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 243 244 this(new CmsJspActionElement(context, req, res)); 245 } 246 247 254 public static String getBackupLink(String resourcePath, String versionId) { 255 StringBuffer link = new StringBuffer (); 256 link.append(CmsBackupResourceHandler.BACKUP_HANDLER); 257 link.append(resourcePath); 258 link.append('?'); 259 link.append(CmsBackupResourceHandler.PARAM_VERSIONID); 260 link.append('='); 261 link.append(versionId); 262 return link.toString(); 263 } 264 265 273 public static String readUserNameOfBackupFile(CmsObject cms, CmsFile file) throws CmsException { 274 String userName; 275 try { 276 userName = cms.readUser(file.getUserLastModified()).getName(); 277 } catch (CmsException e) { 278 if (file instanceof CmsBackupResource) { 279 userName = ((CmsBackupResource)file).getLastModifiedByName(); 280 } else { 281 throw e; 282 } 283 } 284 return userName; 285 } 286 287 290 protected String defaultActionHtmlStart() { 291 292 return getList().listJs(getLocale()) + dialogContentStart(getParamTitle()); 293 } 294 295 298 public void executeListMultiActions() throws IOException , ServletException { 299 300 if (getParamListAction().equals(LIST_MACTION_COMPARE)) { 301 CmsListItem item1 = (CmsListItem)getSelectedItems().get(0); 302 CmsListItem item2 = (CmsListItem)getSelectedItems().get(1); 303 Map params = new HashMap (); 304 if (((Comparable )item2.get(LIST_COLUMN_VERSION)).compareTo(item1.get(LIST_COLUMN_VERSION)) > 0) { 305 params.put(PARAM_TAGID_1, item1.getId()); 306 params.put(PARAM_TAGID_2, item2.getId()); 307 params.put(PARAM_VERSION_1, item1.get(LIST_COLUMN_VERSION)); 308 params.put(PARAM_VERSION_2, item2.get(LIST_COLUMN_VERSION)); 309 params.put(PARAM_PATH_1, item1.get(LIST_COLUMN_RESOURCE_PATH)); 310 params.put(PARAM_PATH_2, item2.get(LIST_COLUMN_RESOURCE_PATH)); 311 } else { 312 params.put(PARAM_TAGID_1, item2.getId()); 313 params.put(PARAM_TAGID_2, item1.getId()); 314 params.put(PARAM_VERSION_1, item2.get(LIST_COLUMN_VERSION)); 315 params.put(PARAM_VERSION_2, item1.get(LIST_COLUMN_VERSION)); 316 params.put(PARAM_PATH_1, item2.get(LIST_COLUMN_RESOURCE_PATH)); 317 params.put(PARAM_PATH_2, item1.get(LIST_COLUMN_RESOURCE_PATH)); 318 } 319 params.put(PARAM_ACTION, DIALOG_INITIAL); 320 params.put(PARAM_STYLE, CmsToolDialog.STYLE_NEW); 321 params.put(PARAM_RESOURCE, getParamResource()); 322 getToolManager().jspForwardTool(this, "/history/comparison", params); 323 } 324 refreshList(); 325 } 326 327 330 public void executeListSingleActions() throws IOException , ServletException { 331 332 if (getParamListAction().equals(LIST_ACTION_RESTORE)) { 333 try { 334 performRestoreOperation(); 335 Map params = new HashMap (); 336 params.put(PARAM_ACTION, DIALOG_INITIAL); 337 getToolManager().jspForwardPage(this, "/system/workplace/views/explorer/explorer_files.jsp", params); 338 } catch (CmsException e) { 339 LOG.error(e.getMessage(), e); 340 throw new CmsRuntimeException(e.getMessageContainer()); 341 } 342 } 343 refreshList(); 344 } 345 346 354 private void fillDetailProject(CmsListItem item, String detailId) { 355 356 StringBuffer html = new StringBuffer (); 357 358 Object tagIdObj = item.get(LIST_COLUMN_BACKUP_TAG); 361 if (tagIdObj != null) { 362 364 int tagId = ((Integer )tagIdObj).intValue(); 365 try { 366 CmsBackupProject project = getCms().readBackupProject(tagId); 367 html.append(project.getName()).append("<br/>").append(project.getDescription()); 369 } catch (CmsException cmse) { 370 html.append(cmse.getMessageContainer().key(this.getLocale())); 371 } 372 } 373 item.set(detailId, html.toString()); 374 } 375 376 379 protected void fillDetails(String detailId) { 380 381 List items = getList().getAllContent(); 383 Iterator itItems = items.iterator(); 384 CmsListItem item; 385 while (itItems.hasNext()) { 386 item = (CmsListItem)itItems.next(); 387 if (detailId.equals(GUI_LIST_HISTORY_DETAIL_PROJECT_0)) { 388 fillDetailProject(item, detailId); 389 } 390 } 391 } 392 393 396 protected List getListItems() throws CmsException { 397 398 List result = new ArrayList (); 399 List backupFileHeaders = getCms().readAllBackupFileHeaders(getParamResource()); 400 Iterator i = backupFileHeaders.iterator(); 401 while (i.hasNext()) { 402 CmsBackupResource file = (CmsBackupResource)i.next(); 403 int tagId = file.getTagId(); 405 CmsBackupProject project = getCms().readBackupProject(tagId); 407 String versionId = new Integer (project.getVersionId()).toString(); 408 String filetype = String.valueOf(file.getTypeId()); 409 String dateLastModified = getMessages().getDateTime(file.getDateLastModified()); 410 String datePublished = getMessages().getDateTime(project.getPublishingDate()); 411 CmsListItem item = getList().newItem(versionId); 412 item.set(LIST_COLUMN_VERSION, new CmsVersionWrapper(new Integer (file.getVersionId()))); 414 item.set(LIST_COLUMN_DATE_PUBLISHED, datePublished); 416 item.set(LIST_COLUMN_DATE_LAST_MODIFIED, dateLastModified); 418 item.set(LIST_COLUMN_FILE_TYPE, filetype); 420 item.set(LIST_COLUMN_USER, readUserNameOfBackupFile(getCms(), file)); 422 item.set(LIST_COLUMN_RESOURCE_PATH, file.getRootPath()); 424 item.set(LIST_COLUMN_SIZE, new Integer (file.getLength()).toString()); 426 result.add(item); 427 item.set(LIST_COLUMN_BACKUP_TAG, new Integer (tagId)); 429 } 430 CmsFile offlineFile = getCms().readFile(getParamResource(), CmsResourceFilter.IGNORE_EXPIRATION); 431 432 if (offlineFile.getState() != CmsResource.STATE_UNCHANGED) { 434 CmsListItem item = getList().newItem("-1"); 435 item.set(LIST_COLUMN_VERSION, new CmsVersionWrapper(OFFLINE_PROJECT)); 437 item.set(LIST_COLUMN_DATE_PUBLISHED, "-"); 439 item.set(LIST_COLUMN_DATE_LAST_MODIFIED, getMessages().getDateTime(offlineFile.getDateLastModified())); 441 item.set(LIST_COLUMN_FILE_TYPE, String.valueOf(offlineFile.getTypeId())); 443 item.set(LIST_COLUMN_USER, getCms().readUser(offlineFile.getUserLastModified()).getName()); 445 item.set(LIST_COLUMN_SIZE, new Integer (offlineFile.getLength()).toString()); 447 item.set(LIST_COLUMN_RESOURCE_PATH, offlineFile.getRootPath()); 449 result.add(item); 450 } 451 getList().getMetadata().getColumnDefinition(LIST_COLUMN_SEL1).setVisible(result.size() > 1); 452 getList().getMetadata().getColumnDefinition(LIST_COLUMN_SEL2).setVisible(result.size() > 1); 453 return result; 454 } 455 456 461 protected void performRestoreOperation() throws CmsException { 462 463 int tagId = Integer.parseInt(((CmsListItem)getSelectedItems().get(0)).getId()); 464 String resourcename = getCms().getSitePath(getCms().readResource(getParamResource())); 465 checkLock(getParamResource()); 466 getCms().restoreResourceBackup(resourcename, tagId); 467 } 468 469 472 protected void setColumns(CmsListMetadata metadata) { 473 474 CmsListColumnDefinition previewCol = new CmsListColumnDefinition(LIST_COLUMN_VIEW); 475 previewCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_VIEW_0)); 476 previewCol.setWidth("20"); 477 previewCol.setVisible(false); 478 previewCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 479 previewCol.setSorteable(false); 480 481 CmsListColumnDefinition restoreCol = new CmsListColumnDefinition(LIST_COLUMN_RESTORE); 483 restoreCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_RESTORE_0)); 484 restoreCol.setWidth("20"); 485 restoreCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 486 restoreCol.setListItemComparator(new CmsListItemActionIconComparator()); 487 restoreCol.setSorteable(false); 488 489 CmsListDirectAction restoreAction = new CmsListDirectAction(LIST_ACTION_RESTORE) { 491 public boolean isVisible() { 493 return !"-1".equals(getItem().getId().toString()); 494 } 495 }; 496 restoreAction.setName(Messages.get().container(Messages.GUI_HISTORY_RESTORE_VERSION_0)); 497 restoreAction.setIconPath("tools/ex_history/buttons/restore.png"); 498 restoreAction.setConfirmationMessage(Messages.get().container(Messages.GUI_HISTORY_CONFIRMATION_0)); 499 restoreAction.setEnabled(true); 500 501 restoreCol.addDirectAction(restoreAction); 502 metadata.addColumn(restoreCol); 504 505 CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON); 507 iconCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_VIEW_0)); 508 iconCol.setWidth("20"); 509 iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 510 iconCol.setListItemComparator(new CmsListItemActionIconComparator()); 511 512 CmsListDirectAction fileAction = new CmsListResourceIconAction(LIST_ACTION_VIEW, LIST_COLUMN_FILE_TYPE, getCms()) { 514 public String defButtonHtml(CmsJspActionElement jsp, String id, String helpId, String name, String helpText, 515 boolean enabled, String iconPath, String confirmationMessage, String onClick, boolean singleHelp) { 516 StringBuffer jsCode = new StringBuffer (512); 517 jsCode.append("window.open('"); 518 String versionId = getItem().getId().toString(); 519 if ("-1".equals(versionId)) { 520 jsCode.append(jsp.link(jsp.getRequestContext().removeSiteRoot(getItem().get(LIST_COLUMN_RESOURCE_PATH).toString()))); 522 } else { 523 jsCode.append(jsp.link(getBackupLink(getItem().get(LIST_COLUMN_RESOURCE_PATH).toString(), 524 versionId))); 525 } 526 jsCode.append("','version','scrollbars=yes, resizable=yes, width=800, height=600')"); 527 return super.defButtonHtml(jsp, id, helpId, name, helpText, enabled, 528 iconPath, confirmationMessage, jsCode.toString(), singleHelp); 529 } 530 }; 531 fileAction.setName(Messages.get().container(Messages.GUI_HISTORY_PREVIEW_0)); 532 fileAction.setEnabled(true); 533 iconCol.addDirectAction(fileAction); 534 metadata.addColumn(iconCol); 536 iconCol.setPrintable(false); 537 538 CmsListColumnDefinition versionCol = new CmsListColumnDefinition(LIST_COLUMN_VERSION); 540 versionCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_VERSION_0)); 541 versionCol.setWidth("5%"); 542 versionCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 543 metadata.addColumn(versionCol); 544 545 CmsListColumnDefinition groupCol = new CmsListColumnDefinition(LIST_COLUMN_FILE_TYPE); 547 groupCol.setVisible(false); 548 metadata.addColumn(groupCol); 549 550 CmsListColumnDefinition pathCol = new CmsListColumnDefinition(LIST_COLUMN_RESOURCE_PATH); 552 pathCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_RESOURCE_PATH_0)); 553 pathCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 554 pathCol.setWidth("20%"); 555 metadata.addColumn(pathCol); 556 557 CmsListColumnDefinition datePublishedCol = new CmsListColumnDefinition(LIST_COLUMN_DATE_PUBLISHED); 559 datePublishedCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_DATE_PUBLISHED_0)); 560 datePublishedCol.setWidth("20%"); 561 datePublishedCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 562 metadata.addColumn(datePublishedCol); 563 564 CmsListColumnDefinition nicenameCol = new CmsListColumnDefinition(LIST_COLUMN_DATE_LAST_MODIFIED); 566 nicenameCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_DATE_LAST_MODIFIED_0)); 567 nicenameCol.setWidth("20%"); 568 nicenameCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 569 metadata.addColumn(nicenameCol); 570 571 CmsListColumnDefinition userCol = new CmsListColumnDefinition(LIST_COLUMN_USER); 573 userCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_USER_0)); 574 userCol.setWidth("12%"); 575 userCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 576 metadata.addColumn(userCol); 577 578 CmsListColumnDefinition sizeCol = new CmsListColumnDefinition(LIST_COLUMN_SIZE); 580 sizeCol.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_SIZE_0)); 581 sizeCol.setWidth("13%"); 582 sizeCol.setAlign(CmsListColumnAlignEnum.ALIGN_LEFT); 583 metadata.addColumn(sizeCol); 584 585 CmsListColumnDefinition radioSel1Col = new CmsListColumnDefinition(LIST_COLUMN_SEL1); 587 radioSel1Col.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_VERSION1_0)); 588 radioSel1Col.setWidth("20"); 589 radioSel1Col.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 590 radioSel1Col.setSorteable(false); 591 CmsListItemSelectionAction sel1Action = new CmsListItemSelectionAction(LIST_RACTION_SEL1, LIST_MACTION_COMPARE); 593 sel1Action.setName(Messages.get().container(Messages.GUI_HISTORY_FIRST_VERSION_0)); 594 sel1Action.setEnabled(true); 595 radioSel1Col.addDirectAction(sel1Action); 596 metadata.addColumn(radioSel1Col); 597 598 CmsListColumnDefinition radioSel2Col = new CmsListColumnDefinition(LIST_COLUMN_SEL2); 600 radioSel2Col.setName(Messages.get().container(Messages.GUI_HISTORY_COLS_VERSION2_0)); 601 radioSel2Col.setWidth("20"); 602 radioSel2Col.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 603 radioSel2Col.setSorteable(false); 604 605 CmsListItemSelectionAction sel2Action = new CmsListItemSelectionAction(LIST_RACTION_SEL2, LIST_MACTION_COMPARE); 607 sel2Action.setName(Messages.get().container(Messages.GUI_HISTORY_SECOND_VERSION_0)); 608 sel2Action.setEnabled(true); 609 radioSel2Col.addDirectAction(sel2Action); 610 metadata.addColumn(radioSel2Col); 611 612 CmsListColumnDefinition backupTagCol = new CmsListColumnDefinition(LIST_COLUMN_BACKUP_TAG); 615 backupTagCol.setSorteable(false); 619 backupTagCol.setVisible(false); 620 metadata.addColumn(backupTagCol); 621 } 622 623 626 protected void setIndependentActions(CmsListMetadata metadata) { 627 CmsListItemDetails indexDetails = new CmsListItemDetails(GUI_LIST_HISTORY_DETAIL_PROJECT_0); 629 indexDetails.setAtColumn(LIST_COLUMN_VERSION); 630 indexDetails.setVisible(false); 631 indexDetails.setShowActionName(Messages.get().container(Messages.GUI_LIST_HISTORY_DETAIL_PROJECT_NAME_SHOW_0)); 632 indexDetails.setShowActionHelpText(Messages.get().container( 633 Messages.GUI_LIST_HISTORY_DETAIL_PROJECT_SHOW_HELP_0)); 634 indexDetails.setHideActionName(Messages.get().container(Messages.GUI_LIST_HISTORY_DETAIL_PROJECT_NAME_HIDE_0)); 635 indexDetails.setHideActionHelpText(Messages.get().container( 636 Messages.GUI_LIST_HISTORY_DETAIL_PROJECT_HIDE_HELP_0)); 637 indexDetails.setName(Messages.get().container(Messages.GUI_LIST_HISTORY_DETAIL_PROJECT_INFO_0)); 638 indexDetails.setFormatter(new CmsListItemDetailsFormatter(Messages.get().container( 639 Messages.GUI_LIST_HISTORY_DETAIL_PROJECT_INFO_0))); 640 metadata.addItemDetails(indexDetails); 641 } 642 643 646 protected void setMultiActions(CmsListMetadata metadata) { 647 648 CmsListRadioMultiAction compareAction = new CmsListRadioMultiAction( 650 LIST_MACTION_COMPARE, 651 Arrays.asList(new String [] {LIST_RACTION_SEL1, LIST_RACTION_SEL2})); 652 compareAction.setName(Messages.get().container(Messages.GUI_HISTORY_COMPARE_0)); 653 compareAction.setIconPath("tools/ex_history/buttons/compare.png"); 654 metadata.addMultiAction(compareAction); 655 } 656 } | Popular Tags |