KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/comparison/CmsPropertyComparisonList.java,v $
3  * Date : $Date: 2006/03/30 09:31:45 $
4  * Version: $Revision: 1.5 $
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.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 JavaDoc;
53 import java.util.ArrayList JavaDoc;
54 import java.util.HashMap JavaDoc;
55 import java.util.Iterator JavaDoc;
56 import java.util.List JavaDoc;
57 import java.util.Map JavaDoc;
58
59 import javax.servlet.ServletException JavaDoc;
60 import javax.servlet.http.HttpServletRequest JavaDoc;
61 import javax.servlet.http.HttpServletResponse JavaDoc;
62 import javax.servlet.jsp.PageContext JavaDoc;
63
64 import org.apache.commons.logging.Log;
65
66 /**
67  * List for property comparison including columns for property name and the values. <p>
68  *
69  * @author Jan Baudisch
70  *
71  * @version $Revision: 1.5 $
72  *
73  * @since 6.0.0
74  */

75 public class CmsPropertyComparisonList extends A_CmsListDialog {
76
77     /** view first file action constant. */
78     public static final String JavaDoc LIST_ACTION_VIEW1 = "v1";
79
80     /** view second file action constant. */
81     public static final String JavaDoc LIST_ACTION_VIEW2 = "v2";
82
83     /** list action id constant. */
84     public static final String JavaDoc LIST_COLUMN_ICON = "ci";
85
86     /** list column id constant. */
87     public static final String JavaDoc LIST_COLUMN_PROPERTY_NAME = "cp";
88
89     /** list action id constant. */
90     public static final String JavaDoc LIST_COLUMN_TYPE = "cz";
91
92     /** list column id constant. */
93     public static final String JavaDoc LIST_COLUMN_VERSION_1 = "cv";
94
95     /** list column id constant. */
96     public static final String JavaDoc LIST_COLUMN_VERSION_2 = "cw";
97
98     /** list default action id constant. */
99     public static final String JavaDoc LIST_DEFACTION_VIEW = "dv";
100
101     /** list independent action id constant. */
102     public static final String JavaDoc LIST_DETAIL_TYPE = "dt";
103
104     /** list independent action id constant. */
105     public static final String JavaDoc LIST_IACTION_SHOW = "is";
106
107     /** List id constant. */
108     public static final String JavaDoc LIST_ID = "hipcl";
109
110     /** request parameter indicating whether attributes, elements or properties are compared.<p> */
111     public static final String JavaDoc PARAM_COMPARE = "compare";
112
113     /** The maximum length of properties and attributes to be displayed.<p> */
114     protected static final int TRIM_AT_LENGTH = 60;
115
116     /** The log object for this class. */
117     private static final Log LOG = CmsLog.getLog(CmsPropertyComparisonList.class);
118
119     /** The first file to compare. */
120     private CmsFile m_file1;
121
122     /** The second file to compare. */
123     private CmsFile m_file2;
124
125     /** Parameter value for the path of the first file. */
126     private String JavaDoc m_paramPath1;
127
128     /** Parameter value for the path of the second file. */
129     private String JavaDoc m_paramPath2;
130
131     /** Parameter value for the tag id of the first file. */
132     private String JavaDoc m_paramTagId1;
133
134     /** Parameter value for the tag id of the second file. */
135     private String JavaDoc m_paramTagId2;
136
137     /** Parameter value for the version of the first file. */
138     private String JavaDoc m_paramVersion1;
139
140     /** Parameter value for the version of the second file. */
141     private String JavaDoc m_paramVersion2;
142
143     /** The type of the files. */
144     private int m_resourceType;
145
146     /**
147      * Public constructor.<p>
148      *
149      * @param jsp an initialized JSP action element
150      */

151     public CmsPropertyComparisonList(CmsJspActionElement jsp) {
152
153         this(LIST_ID, jsp);
154     }
155
156     /**
157      * Public constructor with JSP variables.<p>
158      *
159      * @param context the JSP page context
160      * @param req the JSP request
161      * @param res the JSP response
162      */

163     public CmsPropertyComparisonList(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
164
165         this(new CmsJspActionElement(context, req, res));
166     }
167
168     /**
169      * Public constructor.<p>
170      * @param jsp an initialized JSP action element
171      * @param listId the id of the displayed list
172      * @param listName the name of the list
173      * @param sortedColId the a priory sorted column
174      * @param sortOrder the order of the sorted column
175      * @param searchableColId the column to search into
176      */

177     protected CmsPropertyComparisonList(
178         CmsJspActionElement jsp,
179         String JavaDoc listId,
180         CmsMessageContainer listName,
181         String JavaDoc sortedColId,
182         CmsListOrderEnum sortOrder,
183         String JavaDoc searchableColId) {
184
185         super(jsp, listId, listName, sortedColId, sortOrder, searchableColId);
186
187     }
188
189     /**
190      * Protected constructor.<p>
191      *
192      * @param listId the id of the specialized list
193      * @param jsp an initialized JSP action element
194      */

195     protected CmsPropertyComparisonList(String JavaDoc 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     /**
207      * @see org.opencms.workplace.list.A_CmsListDialog#executeListMultiActions()
208      */

209     public void executeListMultiActions() {
210
211         throwListUnsupportedActionException();
212     }
213
214     /**
215      * @see org.opencms.workplace.list.A_CmsListDialog#executeListSingleActions()
216      */

217     public void executeListSingleActions() throws IOException JavaDoc, ServletException JavaDoc {
218
219         // forward to the edit module screen
220
Map JavaDoc params = new HashMap JavaDoc();
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         // forward to the difference screen
230
getToolManager().jspForwardTool(this, "/history/comparison/difference", params);
231     }
232
233     /**
234      * Returns the file1.<p>
235      *
236      * @return the file1
237      */

238     public CmsFile getFile1() {
239
240         return m_file1;
241     }
242
243     /**
244      * Returns the file2.<p>
245      *
246      * @return the file2
247      */

248     public CmsFile getFile2() {
249
250         return m_file2;
251     }
252
253     /**
254      * Returns the paramPath1.<p>
255      *
256      * @return the paramPath1
257      */

258     public String JavaDoc getParamPath1() {
259
260         return m_paramPath1;
261     }
262
263     /**
264      * Returns the paramPath2.<p>
265      *
266      * @return the paramPath2
267      */

268     public String JavaDoc getParamPath2() {
269
270         return m_paramPath2;
271     }
272
273     /**
274      * Returns the paramTagId1.<p>
275      *
276      * @return the paramTagId1
277      */

278     public String JavaDoc getParamTagId1() {
279
280         return m_paramTagId1;
281     }
282
283     /**
284      * Returns the paramTagId2.<p>
285      *
286      * @return the paramTagId2
287      */

288     public String JavaDoc getParamTagId2() {
289
290         return m_paramTagId2;
291     }
292
293     /**
294      * Returns the paramNewversionid.<p>
295      *
296      * @return the paramNewversionid
297      */

298     public String JavaDoc getParamVersion1() {
299
300         return m_paramVersion1;
301     }
302
303     /**
304      * Returns the paramOldversionid.<p>
305      *
306      * @return the paramOldversionid
307      */

308     public String JavaDoc getParamVersion2() {
309
310         return m_paramVersion2;
311     }
312
313     /**
314      * Returns the resourceType.<p>
315      *
316      * @return the resourceType
317      */

318     public int getResourceType() {
319
320         return m_resourceType;
321     }
322
323     /**
324      * Sets the paramPath1.<p>
325      *
326      * @param paramPath1 the paramPath1 to set
327      */

328     public void setParamPath1(String JavaDoc paramPath1) {
329
330         m_paramPath1 = paramPath1;
331     }
332
333     /**
334      * Sets the paramPath2.<p>
335      *
336      * @param paramPath2 the paramPath2 to set
337      */

338     public void setParamPath2(String JavaDoc paramPath2) {
339
340         m_paramPath2 = paramPath2;
341     }
342
343     /**
344      * Sets the paramTagId1.<p>
345      *
346      * @param paramTagId1 the paramTagId1 to set
347      */

348     public void setParamTagId1(String JavaDoc paramTagId1) {
349
350         m_paramTagId1 = paramTagId1;
351     }
352
353     /**
354      * Sets the paramTagId2.<p>
355      *
356      * @param paramTagId2 the paramTagId2 to set
357      */

358     public void setParamTagId2(String JavaDoc paramTagId2) {
359
360         m_paramTagId2 = paramTagId2;
361     }
362
363     /**
364      * Sets the paramNewversionid.<p>
365      *
366      * @param paramNewversionid the paramNewversionid to set
367      */

368     public void setParamVersion1(String JavaDoc paramNewversionid) {
369
370         m_paramVersion1 = paramNewversionid;
371     }
372
373     /**
374      * Sets the paramOldversionid.<p>
375      *
376      * @param paramOldversionid the paramOldversionid to set
377      */

378     public void setParamVersion2(String JavaDoc paramOldversionid) {
379
380         m_paramVersion2 = paramOldversionid;
381     }
382
383     /**
384      * @see org.opencms.workplace.list.A_CmsListDialog#fillDetails(java.lang.String)
385      */

386     protected void fillDetails(String JavaDoc detailId) {
387
388         // no-op
389
}
390
391     /**
392      * @see org.opencms.workplace.list.A_CmsListDialog#getListItems()
393      */

394     protected List getListItems() throws CmsException {
395
396         List ret = new ArrayList JavaDoc();
397         Iterator JavaDoc 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                     // do not display entry
413
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     /**
428      *
429      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
430      */

431     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc 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     /**
447      * @see org.opencms.workplace.list.A_CmsListDialog#setColumns(org.opencms.workplace.list.CmsListMetadata)
448      */

449     protected void setColumns(CmsListMetadata metadata) {
450
451         // create column for icon
452
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         // add state error action
459
CmsListDirectAction addedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_ADDED) {
460
461             /**
462              * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#isVisible()
463              */

464             public boolean isVisible() {
465
466                 String JavaDoc 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         // add state error action
476
CmsListDirectAction removedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_REMOVED) {
477
478             /**
479              * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#isVisible()
480              */

481             public boolean isVisible() {
482
483                 String JavaDoc 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         // add state error action
493
CmsListDirectAction changedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_CHANGED) {
494
495             /**
496              * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#isVisible()
497              */

498             public boolean isVisible() {
499
500                 String JavaDoc 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         // add state error action
510
CmsListDirectAction unchangedAction = new CmsListDirectAction(CmsResourceComparison.TYPE_UNCHANGED) {
511
512             /**
513              * @see org.opencms.workplace.tools.I_CmsHtmlIconButton#isVisible()
514              */

515             public boolean isVisible() {
516
517                 String JavaDoc 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         // add column for type
529
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         // set action for the name column
536
typeCol.addDefaultAction(typeColAction);
537         metadata.addColumn(typeCol);
538         typeCol.setPrintable(true);
539
540         // add column for name
541
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         // add column for first value
548
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         // add column for second value
556
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     /**
565      *
566      * @see org.opencms.workplace.list.A_CmsListDialog#setIndependentActions(org.opencms.workplace.list.CmsListMetadata)
567      */

568     protected void setIndependentActions(CmsListMetadata metadata) {
569
570         // add event details
571
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     /**
579      * @see org.opencms.workplace.list.A_CmsListDialog#setMultiActions(org.opencms.workplace.list.CmsListMetadata)
580      */

581     protected void setMultiActions(CmsListMetadata metadata) {
582
583         // no-op
584
}
585 }
Popular Tags