1 31 32 package org.opencms.workplace.comparison; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.i18n.CmsMessageContainer; 36 import org.opencms.jsp.CmsJspActionElement; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.CmsLog; 39 import org.opencms.util.CmsStringUtil; 40 import org.opencms.workplace.CmsWorkplaceSettings; 41 import org.opencms.workplace.commons.CmsHistoryList; 42 import org.opencms.workplace.list.A_CmsListDialog; 43 import org.opencms.workplace.list.CmsListColumnAlignEnum; 44 import org.opencms.workplace.list.CmsListColumnDefinition; 45 import org.opencms.workplace.list.CmsListDefaultAction; 46 import org.opencms.workplace.list.CmsListDirectAction; 47 import org.opencms.workplace.list.CmsListItem; 48 import org.opencms.workplace.list.CmsListItemDetails; 49 import org.opencms.workplace.list.CmsListMetadata; 50 import org.opencms.workplace.list.CmsListOrderEnum; 51 52 import java.io.IOException ; 53 import java.util.ArrayList ; 54 import java.util.HashMap ; 55 import java.util.Iterator ; 56 import java.util.List ; 57 import java.util.Map ; 58 59 import javax.servlet.ServletException ; 60 import javax.servlet.http.HttpServletRequest ; 61 import javax.servlet.http.HttpServletResponse ; 62 import javax.servlet.jsp.PageContext ; 63 64 import org.apache.commons.logging.Log; 65 66 75 public class CmsPropertyComparisonList extends A_CmsListDialog { 76 77 78 public static final String LIST_ACTION_VIEW1 = "v1"; 79 80 81 public static final String LIST_ACTION_VIEW2 = "v2"; 82 83 84 public static final String LIST_COLUMN_ICON = "ci"; 85 86 87 public static final String LIST_COLUMN_PROPERTY_NAME = "cp"; 88 89 90 public static final String LIST_COLUMN_TYPE = "cz"; 91 92 93 public static final String LIST_COLUMN_VERSION_1 = "cv"; 94 95 96 public static final String LIST_COLUMN_VERSION_2 = "cw"; 97 98 99 public static final String LIST_DEFACTION_VIEW = "dv"; 100 101 102 public static final String LIST_DETAIL_TYPE = "dt"; 103 104 105 public static final String LIST_IACTION_SHOW = "is"; 106 107 108 public static final String LIST_ID = "hipcl"; 109 110 111 public static final String PARAM_COMPARE = "compare"; 112 113 114 protected static final int TRIM_AT_LENGTH = 60; 115 116 117 private static final Log LOG = CmsLog.getLog(CmsPropertyComparisonList.class); 118 119 120 private CmsFile m_file1; 121 122 123 private CmsFile m_file2; 124 125 126 private String m_paramPath1; 127 128 129 private String m_paramPath2; 130 131 132 private String m_paramTagId1; 133 134 135 private String m_paramTagId2; 136 137 138 private String m_paramVersion1; 139 140 141 private String m_paramVersion2; 142 143 144 private int m_resourceType; 145 146 151 public CmsPropertyComparisonList(CmsJspActionElement jsp) { 152 153 this(LIST_ID, jsp); 154 } 155 156 163 public CmsPropertyComparisonList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 164 165 this(new CmsJspActionElement(context, req, res)); 166 } 167 168 177 protected CmsPropertyComparisonList( 178 CmsJspActionElement jsp, 179 String listId, 180 CmsMessageContainer listName, 181 String sortedColId, 182 CmsListOrderEnum sortOrder, 183 String searchableColId) { 184 185 super(jsp, listId, listName, sortedColId, sortOrder, searchableColId); 186 187 } 188 189 195 protected CmsPropertyComparisonList(String listId, CmsJspActionElement jsp) { 196 197 super( 198 jsp, 199 listId, 200 Messages.get().container(Messages.GUI_COMPARE_PROPERTIES_0), 201 LIST_COLUMN_PROPERTY_NAME, 202 CmsListOrderEnum.ORDER_ASCENDING, 203 null); 204 } 205 206 209 public void executeListMultiActions() { 210 211 throwListUnsupportedActionException(); 212 } 213 214 217 public void executeListSingleActions() throws IOException , ServletException { 218 219 Map params = new HashMap (); 221 params.put(CmsHistoryList.PARAM_TAGID_1, getParamTagId1()); 222 params.put(CmsHistoryList.PARAM_TAGID_2, getParamTagId2()); 223 params.put(CmsHistoryList.PARAM_VERSION_1, getParamVersion1()); 224 params.put(CmsHistoryList.PARAM_VERSION_2, getParamVersion2()); 225 params.put(CmsHistoryList.PARAM_PATH_1, getParamPath1()); 226 params.put(CmsHistoryList.PARAM_PATH_2, getParamPath2()); 227 params.put(PARAM_COMPARE, "properties"); 228 params.put(PARAM_RESOURCE, getParamResource()); 229 getToolManager().jspForwardTool(this, "/history/comparison/difference", params); 231 } 232 233 238 public CmsFile getFile1() { 239 240 return m_file1; 241 } 242 243 248 public CmsFile getFile2() { 249 250 return m_file2; 251 } 252 253 258 public String getParamPath1() { 259 260 return m_paramPath1; 261 } 262 263 268 public String getParamPath2() { 269 270 return m_paramPath2; 271 } 272 273 278 public String getParamTagId1() { 279 280 return m_paramTagId1; 281 } 282 283 288 public String getParamTagId2() { 289 290 return m_paramTagId2; 291 } 292 293 298 public String getParamVersion1() { 299 300 return m_paramVersion1; 301 } 302 303 308 public String getParamVersion2() { 309 310 return m_paramVersion2; 311 } 312 313 318 public int getResourceType() { 319 320 return m_resourceType; 321 } 322 323 328 public void setParamPath1(String paramPath1) { 329 330 m_paramPath1 = paramPath1; 331 } 332 333 338 public void setParamPath2(String paramPath2) { 339 340 m_paramPath2 = paramPath2; 341 } 342 343 348 public void setParamTagId1(String paramTagId1) { 349 350 m_paramTagId1 = paramTagId1; 351 } 352 353 358 public void setParamTagId2(String paramTagId2) { 359 360 m_paramTagId2 = paramTagId2; 361 } 362 363 368 public void setParamVersion1(String paramNewversionid) { 369 370 m_paramVersion1 = paramNewversionid; 371 } 372 373 378 public void setParamVersion2(String paramOldversionid) { 379 380 m_paramVersion2 = paramOldversionid; 381 } 382 383 386 protected void fillDetails(String detailId) { 387 388 } 390 391 394 protected List getListItems() throws CmsException { 395 396 List ret = new ArrayList (); 397 Iterator diffs = CmsResourceComparison.compareProperties(getCms(), getFile1(), getFile2()).iterator(); 398 while (diffs.hasNext()) { 399 CmsAttributeComparison comparison = (CmsAttributeComparison)diffs.next(); 400 CmsListItem item = getList().newItem(comparison.getName()); 401 item.set(LIST_COLUMN_PROPERTY_NAME, comparison.getName()); 402 item.set(LIST_COLUMN_VERSION_1, CmsStringUtil.trimToSize(comparison.getVersion1(), TRIM_AT_LENGTH)); 403 item.set(LIST_COLUMN_VERSION_2, CmsStringUtil.trimToSize(comparison.getVersion2(), TRIM_AT_LENGTH)); 404 if (CmsResourceComparison.TYPE_ADDED.equals(comparison.getStatus())) { 405 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_ADDED_0)); 406 } else if (CmsResourceComparison.TYPE_REMOVED.equals(comparison.getStatus())) { 407 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_REMOVED_0)); 408 } else if (CmsResourceComparison.TYPE_CHANGED.equals(comparison.getStatus())) { 409 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_CHANGED_0)); 410 } else { 411 if (!getList().getMetadata().getItemDetailDefinition(LIST_IACTION_SHOW).isVisible()) { 412 continue; 414 } else { 415 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_UNCHANGED_0)); 416 } 417 } 418 ret.add(item); 419 } 420 getList().getMetadata().getColumnDefinition(LIST_COLUMN_VERSION_1).setName( 421 Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion1())); 422 getList().getMetadata().getColumnDefinition(LIST_COLUMN_VERSION_2).setName( 423 Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion2())); 424 return ret; 425 } 426 427 431 protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) { 432 433 super.initWorkplaceRequestValues(settings, request); 434 try { 435 m_file1 = CmsResourceComparisonDialog.readFile(getCms(), getParamPath1(), 436 getParamVersion1(), Integer.parseInt(getParamTagId1())); 437 m_file2 = CmsResourceComparisonDialog.readFile(getCms(), getParamPath2(), 438 getParamVersion2(), Integer.parseInt(getParamTagId2())); 439 } catch (CmsException e) { 440 441 LOG.error(e.getStackTrace(), e); 442 } 443 m_resourceType = m_file1.getTypeId(); 444 } 445 446 449 protected void setColumns(CmsListMetadata metadata) { 450 451 CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON); 453 iconCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_ICON_0)); 454 iconCol.setWidth("20"); 455 iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 456 iconCol.setSorteable(true); 457 458 CmsListDirectAction addedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_ADDED) { 460 461 464 public boolean isVisible() { 465 466 String type = getItem().get(LIST_COLUMN_TYPE).toString(); 467 return key(Messages.GUI_COMPARE_ADDED_0).equals(type); 468 } 469 }; 470 addedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_ADDED_0)); 471 addedAction.setIconPath("tools/ex_history/buttons/added.png"); 472 addedAction.setEnabled(true); 473 iconCol.addDirectAction(addedAction); 474 475 CmsListDirectAction removedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_REMOVED) { 477 478 481 public boolean isVisible() { 482 483 String type = getItem().get(LIST_COLUMN_TYPE).toString(); 484 return key(Messages.GUI_COMPARE_REMOVED_0).equals(type); 485 } 486 }; 487 removedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_REMOVED_0)); 488 removedAction.setIconPath("tools/ex_history/buttons/removed.png"); 489 removedAction.setEnabled(true); 490 iconCol.addDirectAction(removedAction); 491 492 CmsListDirectAction changedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_CHANGED) { 494 495 498 public boolean isVisible() { 499 500 String type = getItem().get(LIST_COLUMN_TYPE).toString(); 501 return key(Messages.GUI_COMPARE_CHANGED_0).equals(type); 502 } 503 }; 504 changedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_CHANGED_0)); 505 changedAction.setIconPath("tools/ex_history/buttons/changed.png"); 506 changedAction.setEnabled(true); 507 iconCol.addDirectAction(changedAction); 508 509 CmsListDirectAction unchangedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_UNCHANGED) { 511 512 515 public boolean isVisible() { 516 517 String type = getItem().get(LIST_COLUMN_TYPE).toString(); 518 return key(Messages.GUI_COMPARE_UNCHANGED_0).equals(type); 519 } 520 }; 521 unchangedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_UNCHANGED_0)); 522 unchangedAction.setIconPath("tools/ex_history/buttons/unchanged.png"); 523 unchangedAction.setEnabled(true); 524 iconCol.addDirectAction(unchangedAction); 525 metadata.addColumn(iconCol); 526 iconCol.setPrintable(false); 527 528 CmsListColumnDefinition typeCol = new CmsListColumnDefinition(LIST_COLUMN_TYPE); 530 typeCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_STATUS_0)); 531 typeCol.setWidth("10%"); 532 CmsListDefaultAction typeColAction = new CmsListDefaultAction(CmsElementComparisonList.LIST_ACTION_STATUS); 533 typeColAction.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_STATUS_0)); 534 typeColAction.setEnabled(true); 535 typeCol.addDefaultAction(typeColAction); 537 metadata.addColumn(typeCol); 538 typeCol.setPrintable(true); 539 540 CmsListColumnDefinition nameCol = new CmsListColumnDefinition(LIST_COLUMN_PROPERTY_NAME); 542 nameCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_PROPERTY_NAME_0)); 543 nameCol.setWidth("20%"); 544 metadata.addColumn(nameCol); 545 nameCol.setPrintable(true); 546 547 CmsListColumnDefinition version1Col = new CmsListColumnDefinition(LIST_COLUMN_VERSION_1); 549 version1Col.setName(Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion1())); 550 version1Col.setWidth("35%"); 551 version1Col.setSorteable(false); 552 metadata.addColumn(version1Col); 553 version1Col.setPrintable(true); 554 555 CmsListColumnDefinition version2Col = new CmsListColumnDefinition(LIST_COLUMN_VERSION_2); 557 version2Col.setName(Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion2())); 558 version2Col.setWidth("35%"); 559 version2Col.setSorteable(false); 560 metadata.addColumn(version2Col); 561 version2Col.setPrintable(true); 562 } 563 564 568 protected void setIndependentActions(CmsListMetadata metadata) { 569 570 CmsListItemDetails eventDetails = new CmsListItemDetails(LIST_IACTION_SHOW); 572 eventDetails.setVisible(false); 573 eventDetails.setShowActionName(Messages.get().container(Messages.GUI_COMPARE_SHOW_ALL_PROPERTIES_0)); 574 eventDetails.setHideActionName(Messages.get().container(Messages.GUI_COMPARE_HIDE_IDENTICAL_PROPERTIES_0)); 575 metadata.addItemDetails(eventDetails); 576 } 577 578 581 protected void setMultiActions(CmsListMetadata metadata) { 582 583 } 585 } | Popular Tags |