1 31 32 package org.opencms.workplace.comparison; 33 34 import org.opencms.file.CmsFile; 35 import org.opencms.jsp.CmsJspActionElement; 36 import org.opencms.main.CmsException; 37 import org.opencms.main.CmsLog; 38 import org.opencms.util.CmsDateUtil; 39 import org.opencms.util.CmsStringUtil; 40 import org.opencms.workplace.commons.CmsHistoryList; 41 import org.opencms.workplace.list.A_CmsListDialog; 42 import org.opencms.workplace.list.CmsListColumnAlignEnum; 43 import org.opencms.workplace.list.CmsListColumnDefinition; 44 import org.opencms.workplace.list.CmsListDefaultAction; 45 import org.opencms.workplace.list.CmsListDirectAction; 46 import org.opencms.workplace.list.CmsListIndependentAction; 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 import org.opencms.xml.types.CmsXmlDateTimeValue; 52 53 import java.io.IOException ; 54 import java.text.DateFormat ; 55 import java.util.ArrayList ; 56 import java.util.Date ; 57 import java.util.HashMap ; 58 import java.util.Iterator ; 59 import java.util.List ; 60 import java.util.Map ; 61 62 import javax.servlet.ServletException ; 63 import javax.servlet.http.HttpServletRequest ; 64 import javax.servlet.http.HttpServletResponse ; 65 import javax.servlet.jsp.PageContext ; 66 67 import org.apache.commons.logging.Log; 68 69 79 public class CmsElementComparisonList extends A_CmsListDialog { 80 81 82 public static final String LIST_ACTION_ICON = "ai"; 83 84 85 public static final String LIST_ACTION_STATUS = "at"; 86 87 88 public static final String LIST_COLUMN_ATTRIBUTE = "ca"; 89 90 91 public static final String LIST_COLUMN_ICON = "ci"; 92 93 94 public static final String LIST_COLUMN_LOCALE = "cl"; 95 96 97 public static final String LIST_COLUMN_STATUS = "cs"; 98 99 100 public static final String LIST_COLUMN_TYPE = "cy"; 101 102 103 public static final String LIST_COLUMN_VERSION_1 = "cv"; 104 105 106 public static final String LIST_COLUMN_VERSION_2 = "cw"; 107 108 109 public static final String LIST_DEFACTION_VIEW = "dv"; 110 111 112 public static final String LIST_DETAIL_TYPE = "dt"; 113 114 115 public static final String LIST_IACTION_COMPARE_ALL = "ava"; 116 117 118 public static final String LIST_IACTION_SHOW = "isy"; 119 120 121 public static final String LIST_ID = "hiecl"; 122 123 124 public static final String PARAM_ELEMENT = "element"; 125 126 127 public static final String PARAM_LOCALE = "locale"; 128 129 130 private static final Log LOG = CmsLog.getLog(CmsElementComparisonList.class); 131 132 133 private String m_paramPath1; 134 135 136 private String m_paramPath2; 137 138 139 private String m_paramTagId1; 140 141 142 private String m_paramTagId2; 143 144 145 private String m_paramVersion1; 146 147 148 private String m_paramVersion2; 149 150 151 private boolean m_xmlContentComparisonMode = false; 152 153 158 public CmsElementComparisonList(CmsJspActionElement jsp) { 159 160 this(LIST_ID, jsp); 161 } 162 163 170 public CmsElementComparisonList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 171 172 this(new CmsJspActionElement(context, req, res)); 173 } 174 175 181 protected CmsElementComparisonList(String listId, CmsJspActionElement jsp) { 182 183 super( 184 jsp, 185 listId, 186 Messages.get().container(Messages.GUI_COMPARE_CONTENT_0), 187 LIST_COLUMN_LOCALE, 188 CmsListOrderEnum.ORDER_ASCENDING, 189 null); 190 } 191 192 196 public void executeListIndepActions() { 197 198 if (getParamListAction().equals(LIST_IACTION_COMPARE_ALL)) { 199 Map params = new HashMap (); 201 params.put(CmsHistoryList.PARAM_TAGID_1, getParamTagId1()); 202 params.put(CmsHistoryList.PARAM_TAGID_2, getParamTagId2()); 203 params.put(CmsHistoryList.PARAM_VERSION_1, getParamVersion1()); 204 params.put(CmsHistoryList.PARAM_VERSION_2, getParamVersion2()); 205 params.put(CmsHistoryList.PARAM_PATH_1, getParamPath1()); 206 params.put(CmsHistoryList.PARAM_PATH_2, getParamPath2()); 207 params.put(CmsPropertyComparisonList.PARAM_COMPARE, CmsResourceComparisonDialog.COMPARE_ALL_ELEMENTS); 208 params.put(PARAM_RESOURCE, getParamResource()); 209 try { 211 getToolManager().jspForwardTool(this, "/history/comparison/difference", params); 212 } catch (Exception e) { 213 LOG.debug(e.getMessage(), e); 214 } 215 216 } 217 super.executeListIndepActions(); 218 } 219 220 223 public void executeListMultiActions() { 224 225 throwListUnsupportedActionException(); 226 } 227 228 231 public void executeListSingleActions() throws IOException , ServletException { 232 233 Map params = new HashMap (); 234 params.put(CmsHistoryList.PARAM_TAGID_1, getParamTagId1()); 235 params.put(CmsHistoryList.PARAM_TAGID_2, getParamTagId2()); 236 params.put(CmsHistoryList.PARAM_VERSION_1, getParamVersion1()); 237 params.put(CmsHistoryList.PARAM_VERSION_2, getParamVersion2()); 238 params.put(CmsHistoryList.PARAM_PATH_1, getParamPath1()); 239 params.put(CmsHistoryList.PARAM_PATH_2, getParamPath2()); 240 params.put(PARAM_LOCALE, getSelectedItem().get(LIST_COLUMN_LOCALE).toString()); 241 params.put(PARAM_ELEMENT, getSelectedItem().get(LIST_COLUMN_ATTRIBUTE).toString()); 242 params.put(PARAM_RESOURCE, getParamResource()); 243 getToolManager().jspForwardTool(this, "/history/comparison/difference", params); 245 246 } 247 248 253 public String getParamPath1() { 254 255 return m_paramPath1; 256 } 257 258 263 public String getParamPath2() { 264 265 return m_paramPath2; 266 } 267 268 273 public String getParamTagId1() { 274 275 return m_paramTagId1; 276 } 277 278 283 public String getParamTagId2() { 284 285 return m_paramTagId2; 286 } 287 288 293 public String getParamVersion1() { 294 295 return m_paramVersion1; 296 } 297 298 303 public String getParamVersion2() { 304 305 return m_paramVersion2; 306 } 307 308 313 public void setParamPath1(String paramPath1) { 314 315 m_paramPath1 = paramPath1; 316 } 317 318 323 public void setParamPath2(String paramPath2) { 324 325 m_paramPath2 = paramPath2; 326 } 327 328 333 public void setParamTagId1(String paramTagId1) { 334 335 m_paramTagId1 = paramTagId1; 336 } 337 338 343 public void setParamTagId2(String paramTagId2) { 344 345 m_paramTagId2 = paramTagId2; 346 } 347 348 353 public void setParamVersion1(String paramNewversionid) { 354 355 m_paramVersion1 = paramNewversionid; 356 } 357 358 363 public void setParamVersion2(String paramOldversionid) { 364 365 m_paramVersion2 = paramOldversionid; 366 } 367 368 371 protected void fillDetails(String detailId) { 372 373 } 375 376 379 protected List getListItems() throws CmsException { 380 381 List result = new ArrayList (); 382 CmsFile resource1 = CmsResourceComparisonDialog.readFile( 383 getCms(), 384 getParamPath1(), 385 getParamVersion1(), 386 Integer.parseInt(getParamTagId1())); 387 CmsFile resource2 = CmsResourceComparisonDialog.readFile( 388 getCms(), 389 getParamPath2(), 390 getParamVersion2(), 391 Integer.parseInt(getParamTagId2())); 392 Iterator diffs = new CmsXmlDocumentComparison(getCms(), resource1, resource2).getElements().iterator(); 393 while (diffs.hasNext()) { 394 CmsElementComparison comparison = (CmsElementComparison)diffs.next(); 395 String locale = comparison.getLocale(); 396 String attribute = comparison.getName(); 397 CmsListItem item = getList().newItem(locale + attribute); 398 item.set(LIST_COLUMN_LOCALE, locale); 399 item.set(LIST_COLUMN_ATTRIBUTE, attribute); 400 if (comparison instanceof CmsXmlContentElementComparison) { 401 m_xmlContentComparisonMode = true; 402 item.set(LIST_COLUMN_TYPE, ((CmsXmlContentElementComparison)comparison).getType()); 403 } 404 if (CmsResourceComparison.TYPE_ADDED.equals(comparison.getStatus())) { 405 item.set(LIST_COLUMN_STATUS, key(Messages.GUI_COMPARE_ADDED_0)); 406 } else if (CmsResourceComparison.TYPE_REMOVED.equals(comparison.getStatus())) { 407 item.set(LIST_COLUMN_STATUS, key(Messages.GUI_COMPARE_REMOVED_0)); 408 } else if (CmsResourceComparison.TYPE_CHANGED.equals(comparison.getStatus())) { 409 item.set(LIST_COLUMN_STATUS, 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_STATUS, key(Messages.GUI_COMPARE_UNCHANGED_0)); 416 } 417 } 418 String value1 = CmsStringUtil.escapeHtml(CmsStringUtil.substitute(CmsStringUtil.trimToSize( 419 comparison.getVersion1(), 420 CmsPropertyComparisonList.TRIM_AT_LENGTH), "\n", "")); 421 422 if (comparison instanceof CmsXmlContentElementComparison) { 424 if (((CmsXmlContentElementComparison)comparison).getType().equals(CmsXmlDateTimeValue.TYPE_NAME)) { 425 if (CmsStringUtil.isNotEmpty(value1)) { 426 value1 = CmsDateUtil.getDateTime( 427 new Date (Long.parseLong(value1)), 428 DateFormat.SHORT, 429 getCms().getRequestContext().getLocale()); 430 } 431 } 432 } 433 item.set(LIST_COLUMN_VERSION_1, value1); 434 435 String value2 = CmsStringUtil.escapeHtml(CmsStringUtil.substitute(CmsStringUtil.trimToSize( 436 comparison.getVersion2(), 437 CmsPropertyComparisonList.TRIM_AT_LENGTH), "\n", "")); 438 439 if (comparison instanceof CmsXmlContentElementComparison) { 441 if (((CmsXmlContentElementComparison)comparison).getType().equals(CmsXmlDateTimeValue.TYPE_NAME)) { 442 if (CmsStringUtil.isNotEmpty(value2)) { 443 value2 = CmsDateUtil.getDateTime( 444 new Date (Long.parseLong(value2)), 445 DateFormat.SHORT, 446 getCms().getRequestContext().getLocale()); 447 } 448 } 449 } 450 item.set(LIST_COLUMN_VERSION_2, value2); 451 result.add(item); 452 } 453 getList().getMetadata().getColumnDefinition(LIST_COLUMN_VERSION_1).setName( 454 Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion1())); 455 getList().getMetadata().getColumnDefinition(LIST_COLUMN_VERSION_2).setName( 456 Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion2())); 457 return result; 458 } 459 460 463 protected void setColumns(CmsListMetadata metadata) { 464 465 CmsListColumnDefinition iconCol = new CmsListColumnDefinition(LIST_COLUMN_ICON); 467 iconCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_ICON_0)); 468 iconCol.setWidth("20"); 469 iconCol.setAlign(CmsListColumnAlignEnum.ALIGN_CENTER); 470 iconCol.setSorteable(true); 471 472 CmsListDirectAction addedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_ADDED) { 474 475 public boolean isVisible() { 476 477 String type = getItem().get(LIST_COLUMN_STATUS).toString(); 478 return key(Messages.GUI_COMPARE_ADDED_0).equals(type); 479 } 480 }; 481 addedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_ADDED_0)); 482 addedAction.setIconPath("tools/ex_history/buttons/added.png"); 483 addedAction.setEnabled(true); 484 iconCol.addDirectAction(addedAction); 485 486 CmsListDirectAction removedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_REMOVED) { 488 489 public boolean isVisible() { 490 491 String type = getItem().get(LIST_COLUMN_STATUS).toString(); 492 return key(Messages.GUI_COMPARE_REMOVED_0).equals(type); 493 } 494 }; 495 removedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_REMOVED_0)); 496 removedAction.setIconPath("tools/ex_history/buttons/removed.png"); 497 removedAction.setEnabled(true); 498 iconCol.addDirectAction(removedAction); 499 500 CmsListDirectAction changedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_CHANGED) { 502 503 public boolean isVisible() { 504 505 String type = getItem().get(LIST_COLUMN_STATUS).toString(); 506 return key(Messages.GUI_COMPARE_CHANGED_0).equals(type); 507 } 508 }; 509 changedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_CHANGED_0)); 510 changedAction.setIconPath("tools/ex_history/buttons/changed.png"); 511 changedAction.setEnabled(true); 512 iconCol.addDirectAction(changedAction); 513 514 CmsListDirectAction unchangedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_UNCHANGED) { 516 517 public boolean isVisible() { 518 519 String type = getItem().get(LIST_COLUMN_STATUS).toString(); 520 return key(Messages.GUI_COMPARE_UNCHANGED_0).equals(type); 521 } 522 }; 523 unchangedAction.setName(Messages.get().container(Messages.GUI_COMPARE_ELEM_UNCHANGED_0)); 524 unchangedAction.setIconPath("tools/ex_history/buttons/unchanged.png"); 525 unchangedAction.setEnabled(true); 526 iconCol.addDirectAction(unchangedAction); 527 metadata.addColumn(iconCol); 528 iconCol.setPrintable(false); 529 530 CmsListColumnDefinition statusCol = new CmsListColumnDefinition(LIST_COLUMN_STATUS); 532 statusCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_STATUS_0)); 533 statusCol.setWidth("10%"); 534 metadata.addColumn(statusCol); 535 CmsListDefaultAction statusColAction = new CmsListDefaultAction(LIST_ACTION_STATUS); 536 statusColAction.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_STATUS_0)); 537 statusColAction.setEnabled(true); 538 statusCol.addDefaultAction(statusColAction); 539 metadata.addColumn(statusCol); 540 statusCol.setPrintable(true); 541 542 CmsListColumnDefinition localeCol = new CmsListColumnDefinition(LIST_COLUMN_LOCALE); 544 localeCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_LOCALE_0)); 545 localeCol.setWidth("10%"); 546 metadata.addColumn(localeCol); 547 localeCol.setPrintable(true); 548 549 CmsListColumnDefinition attCol = new CmsListColumnDefinition(LIST_COLUMN_ATTRIBUTE); 551 attCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_NAME_0)); 552 attCol.setWidth("10%"); 553 metadata.addColumn(attCol); 554 attCol.setPrintable(true); 555 556 CmsListColumnDefinition typeCol = new CmsListColumnDefinition(LIST_COLUMN_TYPE); 557 typeCol.setName(Messages.get().container(Messages.GUI_COMPARE_COLS_TYPE_0)); 558 typeCol.setWidth("10%"); 559 typeCol.setVisible(m_xmlContentComparisonMode); 561 metadata.addColumn(typeCol); 562 typeCol.setPrintable(true); 563 564 CmsListColumnDefinition version1Col = new CmsListColumnDefinition(LIST_COLUMN_VERSION_1); 566 version1Col.setName(Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion1())); 567 version1Col.setWidth("35%"); 568 version1Col.setSorteable(false); 569 metadata.addColumn(version1Col); 570 version1Col.setPrintable(true); 571 572 CmsListColumnDefinition version2Col = new CmsListColumnDefinition(LIST_COLUMN_VERSION_2); 574 version2Col.setName(Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion2())); 575 version2Col.setWidth("35%"); 576 version2Col.setSorteable(false); 577 metadata.addColumn(version2Col); 578 version2Col.setPrintable(true); 579 } 580 581 584 protected void setIndependentActions(CmsListMetadata metadata) { 585 586 CmsListIndependentAction compare = new CmsListIndependentAction(LIST_IACTION_COMPARE_ALL); 587 compare.setName(Messages.get().container(Messages.GUI_COMPARE_COMPARE_ALL_0)); 588 compare.setIconPath("tools/ex_history/buttons/compare.png"); 589 compare.setEnabled(true); 590 metadata.addIndependentAction(compare); 591 592 CmsListItemDetails eventDetails = new CmsListItemDetails(LIST_IACTION_SHOW); 594 eventDetails.setVisible(false); 595 eventDetails.setShowActionName(Messages.get().container(Messages.GUI_COMPARE_SHOW_ALL_ELEMENTS_0)); 596 eventDetails.setHideActionName(Messages.get().container(Messages.GUI_COMPARE_HIDE_IDENTICAL_ELEMENTS_0)); 597 metadata.addItemDetails(eventDetails); 598 } 599 600 603 protected void setMultiActions(CmsListMetadata metadata) { 604 605 } 607 } | Popular Tags |