1 31 32 package org.opencms.workplace.comparison; 33 34 import org.opencms.file.CmsBackupResourceHandler; 35 import org.opencms.file.types.CmsResourceTypePlain; 36 import org.opencms.jsp.CmsJspActionElement; 37 import org.opencms.main.CmsException; 38 import org.opencms.main.OpenCms; 39 import org.opencms.util.CmsStringUtil; 40 import org.opencms.workplace.CmsWorkplace; 41 import org.opencms.workplace.commons.CmsHistoryList; 42 import org.opencms.workplace.list.CmsListIndependentAction; 43 import org.opencms.workplace.list.CmsListItem; 44 import org.opencms.workplace.list.CmsListItemDetails; 45 import org.opencms.workplace.list.CmsListMetadata; 46 import org.opencms.workplace.list.CmsListOrderEnum; 47 48 import java.io.IOException ; 49 import java.util.ArrayList ; 50 import java.util.HashMap ; 51 import java.util.Iterator ; 52 import java.util.List ; 53 import java.util.Map ; 54 55 import javax.servlet.ServletException ; 56 import javax.servlet.http.HttpServletRequest ; 57 import javax.servlet.http.HttpServletResponse ; 58 import javax.servlet.jsp.PageContext ; 59 60 69 public class CmsAttributeComparisonList extends CmsPropertyComparisonList { 70 71 72 public static final String AC_LIST_ID = "hiacl"; 73 74 79 public CmsAttributeComparisonList(CmsJspActionElement jsp) { 80 81 this(AC_LIST_ID, jsp); 82 } 83 84 91 public CmsAttributeComparisonList(PageContext context, HttpServletRequest req, HttpServletResponse res) { 92 93 this(new CmsJspActionElement(context, req, res)); 94 } 95 96 102 protected CmsAttributeComparisonList(String listId, CmsJspActionElement jsp) { 103 104 super( 105 jsp, 106 listId, 107 Messages.get().container(Messages.GUI_COMPARE_ATTRIBUTES_0), 108 LIST_COLUMN_PROPERTY_NAME, 109 CmsListOrderEnum.ORDER_ASCENDING, 110 null); 111 } 112 113 116 public void executeListSingleActions() throws IOException , ServletException { 117 118 Map params = new HashMap (); 120 params.put(CmsHistoryList.PARAM_TAGID_1, getParamTagId1()); 121 params.put(CmsHistoryList.PARAM_TAGID_2, getParamTagId2()); 122 params.put(CmsHistoryList.PARAM_VERSION_1, getParamVersion1()); 123 params.put(CmsHistoryList.PARAM_VERSION_2, getParamVersion2()); 124 params.put(CmsHistoryList.PARAM_PATH_1, getParamPath1()); 125 params.put(CmsHistoryList.PARAM_PATH_2, getParamPath2()); 126 params.put(PARAM_COMPARE, CmsResourceComparisonDialog.COMPARE_ATTRIBUTES); 127 params.put(PARAM_RESOURCE, getParamResource()); 128 getToolManager().jspForwardTool(this, "/history/comparison/difference", params); 130 } 131 132 135 protected List getListItems() { 136 137 List ret = new ArrayList (); 138 Iterator diffs = CmsResourceComparison.compareAttributes(getCms(), getFile1(), getFile2()).iterator(); 139 while (diffs.hasNext()) { 140 CmsAttributeComparison comparison = (CmsAttributeComparison)diffs.next(); 141 CmsListItem item = getList().newItem(comparison.getName()); 142 item.set(LIST_COLUMN_PROPERTY_NAME, key(comparison.getName())); 143 item.set(LIST_COLUMN_VERSION_1, CmsStringUtil.trimToSize(comparison.getVersion1(), TRIM_AT_LENGTH)); 144 item.set(LIST_COLUMN_VERSION_2, CmsStringUtil.trimToSize(comparison.getVersion2(), TRIM_AT_LENGTH)); 145 if (CmsResourceComparison.TYPE_ADDED.equals(comparison.getStatus())) { 146 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_ADDED_0)); 147 } else if (CmsResourceComparison.TYPE_REMOVED.equals(comparison.getStatus())) { 148 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_REMOVED_0)); 149 } else if (CmsResourceComparison.TYPE_CHANGED.equals(comparison.getStatus())) { 150 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_CHANGED_0)); 151 } else { 152 if (!getList().getMetadata().getItemDetailDefinition(LIST_IACTION_SHOW).isVisible()) { 153 continue; 155 } else { 156 item.set(LIST_COLUMN_TYPE, key(Messages.GUI_COMPARE_UNCHANGED_0)); 157 } 158 } 159 ret.add(item); 160 } 161 getList().getMetadata().getColumnDefinition(LIST_COLUMN_VERSION_1).setName( 162 Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion1())); 163 getList().getMetadata().getColumnDefinition(LIST_COLUMN_VERSION_2).setName( 164 Messages.get().container(Messages.GUI_COMPARE_VERSION_1, getParamVersion2())); 165 return ret; 166 } 167 168 176 protected String getViewVersionButtonHtml(String path, String tagId, String version) { 177 178 String label = Messages.get().container(Messages.GUI_COMPARE_VIEW_VERSION_1, version).key(getLocale()); 179 String iconPath = null; 180 try { 181 String typeName = OpenCms.getResourceManager().getResourceType(getFile1().getTypeId()).getTypeName(); 182 iconPath = "filetypes/" + OpenCms.getWorkplaceManager().getExplorerTypeSetting(typeName).getIcon(); 183 } catch (CmsException e) { 184 iconPath = "filetypes/" 185 + OpenCms.getWorkplaceManager().getExplorerTypeSetting(CmsResourceTypePlain.getStaticTypeName()).getIcon(); 186 } 187 StringBuffer result = new StringBuffer (1024); 188 result.append("<span class='link' onClick=\""); 189 result.append("window.open('"); 190 StringBuffer link = new StringBuffer (1024); 191 if ("-1".equals(tagId)) { 192 link.append(getParamResource()); 194 } else { 195 link.append(CmsBackupResourceHandler.BACKUP_HANDLER); 197 link.append(path); 198 link.append('?'); 199 link.append(CmsBackupResourceHandler.PARAM_VERSIONID); 200 link.append('='); 201 link.append(tagId); 202 } 203 result.append(getJsp().link(link.toString())); 204 result.append("','version','scrollbars=yes', 'resizable=yes', 'width=800', 'height=600')\">"); 205 result.append("<img style='width: 16px; height: 16px;' SRC='"); 206 result.append(CmsWorkplace.getSkinUri()); 207 result.append(iconPath); 208 result.append("' alt='"); 209 result.append(label); 210 result.append("' title='"); 211 result.append(label); 212 result.append("'> <a HREF='#'>"); 213 result.append(label); 214 result.append("</a></span>"); 215 216 return result.toString(); 217 } 218 219 222 protected void setIndependentActions(CmsListMetadata metadata) { 223 224 CmsListIndependentAction viewVersion1 = new CmsListIndependentAction(LIST_ACTION_VIEW1) { 226 227 230 public String buttonHtml(CmsWorkplace wp) { 231 232 return getViewVersionButtonHtml(getParamPath1(), getParamTagId1(), getParamVersion1()); 233 } 234 }; 235 metadata.addIndependentAction(viewVersion1); 236 CmsListIndependentAction viewVersion2 = new CmsListIndependentAction(LIST_ACTION_VIEW2) { 238 239 242 public String buttonHtml(CmsWorkplace wp) { 243 244 return getViewVersionButtonHtml(getParamPath2(), getParamTagId2(), getParamVersion2()); 245 } 246 }; 247 metadata.addIndependentAction(viewVersion2); 248 249 CmsListItemDetails eventDetails = new CmsListItemDetails(LIST_IACTION_SHOW); 251 eventDetails.setVisible(false); 252 eventDetails.setShowActionName(Messages.get().container(Messages.GUI_COMPARE_SHOW_ALL_ATTRIBUTES_0)); 253 eventDetails.setHideActionName(Messages.get().container(Messages.GUI_COMPARE_HIDE_IDENTICAL_ATTRIBUTES_0)); 254 metadata.addItemDetails(eventDetails); 255 } 256 } 257 | Popular Tags |