KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > opencms > workplace > comparison > CmsAttributeComparisonList


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/comparison/CmsAttributeComparisonList.java,v $
3  * Date : $Date: 2006/03/28 07:53:22 $
4  * Version: $Revision: 1.3 $
5  *
6  * This library is part of OpenCms -
7  * the Open Source Content Mananagement System
8  *
9  * Copyright (c) 2005 Alkacon Software GmbH (http://www.alkacon.com)
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * For further information about Alkacon Software GmbH, please see the
22  * company website: http://www.alkacon.com
23  *
24  * For further information about OpenCms, please see the
25  * project website: http://www.opencms.org
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the Free Software
29  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30  */

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 JavaDoc;
49 import java.util.ArrayList JavaDoc;
50 import java.util.HashMap JavaDoc;
51 import java.util.Iterator JavaDoc;
52 import java.util.List JavaDoc;
53 import java.util.Map JavaDoc;
54
55 import javax.servlet.ServletException JavaDoc;
56 import javax.servlet.http.HttpServletRequest JavaDoc;
57 import javax.servlet.http.HttpServletResponse JavaDoc;
58 import javax.servlet.jsp.PageContext JavaDoc;
59
60 /**
61  * List for property comparison including columns for property name and the values. <p>
62  *
63  * @author Jan Baudisch
64  *
65  * @version $Revision: 1.3 $
66  *
67  * @since 6.0.0
68  */

69 public class CmsAttributeComparisonList extends CmsPropertyComparisonList {
70
71     /** List id constant. */
72     public static final String JavaDoc AC_LIST_ID = "hiacl";
73
74     /**
75      * Public constructor.<p>
76      *
77      * @param jsp an initialized JSP action element
78      */

79     public CmsAttributeComparisonList(CmsJspActionElement jsp) {
80
81         this(AC_LIST_ID, jsp);
82     }
83
84     /**
85      * Public constructor with JSP variables.<p>
86      *
87      * @param context the JSP page context
88      * @param req the JSP request
89      * @param res the JSP response
90      */

91     public CmsAttributeComparisonList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
92
93         this(new CmsJspActionElement(context, req, res));
94     }
95
96     /**
97      * Protected constructor.<p>
98      *
99      * @param listId the id of the specialized list
100      * @param jsp an initialized JSP action element
101      */

102     protected CmsAttributeComparisonList(String JavaDoc 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     /**
114      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
115      */

116     public void executeListSingleActions() throws IOException JavaDoc, ServletException JavaDoc {
117
118         // forward to the edit module screen
119
Map JavaDoc params = new HashMap JavaDoc();
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         // forward to the difference screen
129
getToolManager().jspForwardTool(this, "/history/comparison/difference", params);
130     }
131
132     /**
133      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
134      */

135     protected List getListItems() {
136
137         List ret = new ArrayList JavaDoc();
138         Iterator JavaDoc 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                     // do not display entry
154
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     /**
169      * Returns the html code to display a file version.<p>
170      *
171      * @param path the path of the file to be displayed
172      * @param tagId the tag id of the file to be displayed
173      * @param version the version of the file to be displayed
174      * @return the html code to display a file version
175      */

176     protected String JavaDoc getViewVersionButtonHtml(String JavaDoc path, String JavaDoc tagId, String JavaDoc version) {
177
178         String JavaDoc label = Messages.get().container(Messages.GUI_COMPARE_VIEW_VERSION_1, version).key(getLocale());
179         String JavaDoc iconPath = null;
180         try {
181             String JavaDoc 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 JavaDoc result = new StringBuffer JavaDoc(1024);
188         result.append("<span class='link' onClick=\"");
189         result.append("window.open('");
190         StringBuffer JavaDoc link = new StringBuffer JavaDoc(1024);
191         if ("-1".equals(tagId)) {
192             // offline version
193
link.append(getParamResource());
194         } else {
195             // backup version
196
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("'>&nbsp;<a HREF='#'>");
213         result.append(label);
214         result.append("</a></span>");
215
216         return result.toString();
217     }
218     
219     /**
220      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
221      */

222     protected void setIndependentActions(CmsListMetadata metadata) {
223
224         // add the view version action
225
CmsListIndependentAction viewVersion1 = new CmsListIndependentAction(LIST_ACTION_VIEW1) {
226
227             /**
228              * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(org.opencms.workplace.CmsWorkplace)
229              */

230             public String JavaDoc buttonHtml(CmsWorkplace wp) {
231
232                 return getViewVersionButtonHtml(getParamPath1(), getParamTagId1(), getParamVersion1());
233             }
234         };
235         metadata.addIndependentAction(viewVersion1);
236         // add the view version action
237
CmsListIndependentAction viewVersion2 = new CmsListIndependentAction(LIST_ACTION_VIEW2) {
238
239             /**
240              * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#buttonHtml(org.opencms.workplace.CmsWorkplace)
241              */

242             public String JavaDoc buttonHtml(CmsWorkplace wp) {
243
244                 return getViewVersionButtonHtml(getParamPath2(), getParamTagId2(), getParamVersion2());
245             }
246         };
247         metadata.addIndependentAction(viewVersion2);
248
249         // add event details
250
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