KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * File : $Source: /usr/local/cvs/opencms/src/org/opencms/workplace/comparison/CmsResourceComparisonDialog.java,v $
3  * Date : $Date: 2006/03/30 09:30:30 $
4  * Version: $Revision: 1.4 $
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.file.CmsObject;
36 import org.opencms.file.CmsResourceFilter;
37 import org.opencms.file.types.CmsResourceTypeImage;
38 import org.opencms.file.types.CmsResourceTypeJsp;
39 import org.opencms.file.types.CmsResourceTypePlain;
40 import org.opencms.file.types.CmsResourceTypePointer;
41 import org.opencms.file.types.CmsResourceTypeXmlContent;
42 import org.opencms.file.types.CmsResourceTypeXmlPage;
43 import org.opencms.file.types.I_CmsResourceType;
44 import org.opencms.jsp.CmsJspActionElement;
45 import org.opencms.main.CmsException;
46 import org.opencms.main.CmsLog;
47 import org.opencms.main.OpenCms;
48 import org.opencms.search.extractors.CmsExtractorMsExcel;
49 import org.opencms.search.extractors.CmsExtractorMsPowerPoint;
50 import org.opencms.search.extractors.CmsExtractorMsWord;
51 import org.opencms.search.extractors.CmsExtractorPdf;
52 import org.opencms.search.extractors.CmsExtractorRtf;
53 import org.opencms.search.extractors.I_CmsTextExtractor;
54 import org.opencms.util.CmsStringUtil;
55 import org.opencms.widgets.I_CmsWidget;
56 import org.opencms.widgets.I_CmsWidgetParameter;
57 import org.opencms.workplace.CmsDialog;
58 import org.opencms.workplace.CmsWorkplaceSettings;
59 import org.opencms.workplace.commons.CmsHistoryList;
60 import org.opencms.workplace.list.CmsMultiListDialog;
61 import org.opencms.xml.CmsXmlException;
62 import org.opencms.xml.I_CmsXmlDocument;
63 import org.opencms.xml.content.CmsXmlContent;
64 import org.opencms.xml.content.CmsXmlContentFactory;
65 import org.opencms.xml.content.I_CmsXmlContentValueVisitor;
66 import org.opencms.xml.page.CmsXmlPage;
67 import org.opencms.xml.page.CmsXmlPageFactory;
68 import org.opencms.xml.types.I_CmsXmlContentValue;
69
70 import java.io.UnsupportedEncodingException JavaDoc;
71 import java.util.ArrayList JavaDoc;
72 import java.util.Iterator JavaDoc;
73 import java.util.List JavaDoc;
74 import java.util.Locale JavaDoc;
75
76 import javax.servlet.http.HttpServletRequest JavaDoc;
77 import javax.servlet.http.HttpServletResponse JavaDoc;
78 import javax.servlet.jsp.PageContext JavaDoc;
79
80 import org.apache.commons.logging.Log;
81
82 /**
83  * Helper class for managing three lists on the same dialog.<p>
84  *
85  * @author Jan Baudisch
86  *
87  * @version $Revision: 1.4 $
88  *
89  * @since 6.0.0
90  */

91 public class CmsResourceComparisonDialog extends CmsDialog {
92
93     /**
94      * Visitor that collects the xpath expressions of xml contents.<p>
95      */

96     class CmsXmlContentTextExtractor implements I_CmsXmlContentValueVisitor {
97
98         /** The StringBuffer to write the extracted text to. */
99         private StringBuffer JavaDoc m_buffer;
100
101         /** The locales of the xml content. */
102         private List m_locales;
103         
104         /**
105          * Creates a new CmsXmlContentTextExtractor.<p>
106          *
107          * @param stringBuffer the StringBuffer to append the element text to
108          */

109         CmsXmlContentTextExtractor(StringBuffer JavaDoc stringBuffer) {
110
111             m_buffer = stringBuffer;
112             m_locales = new ArrayList JavaDoc();
113         }
114
115         /**
116          *
117          * @see org.opencms.xml.content.I_CmsXmlContentValueVisitor#visit(org.opencms.xml.types.I_CmsXmlContentValue)
118          */

119         public void visit(I_CmsXmlContentValue value) {
120
121             // only add simple types
122
if (value.isSimpleType()) {
123                 String JavaDoc locale = value.getLocale().toString();
124                 if (!m_locales.contains(locale)) {
125                     m_buffer.append("\n\n[").append(locale).append(']');
126                     m_locales.add(locale);
127                 }
128                 m_buffer.append("\n\n[").append(value.getPath()).append("]\n\n");
129                 try {
130                     I_CmsWidget widget = value.getDocument().getContentDefinition().getContentHandler().getWidget(value);
131                     m_buffer.append(widget.getWidgetStringValue(
132                         getCms(),
133                         new CmsFileInfoDialog(getJsp()),
134                         (I_CmsWidgetParameter)value));
135                 } catch (CmsXmlException e) {
136                     LOG.error(e.getMessage(), e);
137                 }
138             }
139         }
140     }
141     
142     /** Constant indicating that all elements are compared.<p> */
143     public static final String JavaDoc COMPARE_ALL_ELEMENTS = "allelements";
144     
145     /** Constant indicating that the attributes are compared.<p> */
146     public static final String JavaDoc COMPARE_ATTRIBUTES = "attributes";
147     
148     /** Constant indicating that the properties are compared.<p> */
149     public static final String JavaDoc COMPARE_PROPERTIES = "properties";
150
151     /** The log object for this class. */
152     static final Log LOG = CmsLog.getLog(CmsResourceComparisonDialog.class);
153
154     /** The difference dialog. */
155     private CmsDifferenceDialog m_differenceDialog;
156
157     /** Parameter value indicating wether to compare properties, attributes or elements. */
158     private String JavaDoc m_paramCompare;
159
160     /** Parameter value for the element name. */
161     private String JavaDoc m_paramElement;
162
163     /** Parameter value for the locale. */
164     private String JavaDoc m_paramLocale;
165
166     /** Parameter value for the path of the first file. */
167     private String JavaDoc m_paramPath1;
168
169     /** Parameter value for the path of the second file. */
170     private String JavaDoc m_paramPath2;
171
172     /** Parameter value for the tag id of the first file. */
173     private String JavaDoc m_paramTagId1;
174
175     /** Parameter value for the tag id of the second file. */
176     private String JavaDoc m_paramTagId2;
177
178     /** Parameter value for the text mode. */
179     private String JavaDoc m_paramTextmode;
180
181     /** Parameter value for the version of the first file. */
182     private String JavaDoc m_paramVersion1;
183
184     /** Parameter value for the version of the second file. */
185     private String JavaDoc m_paramVersion2;
186     
187     /**
188      * Public constructor with JSP action element.<p>
189      *
190      * @param jsp an initialized JSP action element
191      */

192     public CmsResourceComparisonDialog(CmsJspActionElement jsp) {
193
194         super(jsp);
195     }
196
197     /**
198      * Public constructor with JSP variables.<p>
199      *
200      * @param context the JSP page context
201      * @param req the JSP request
202      * @param res the JSP response
203      */

204     public CmsResourceComparisonDialog(PageContext JavaDoc context, HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc res) {
205
206         this(new CmsJspActionElement(context, req, res));
207     }
208
209     /**
210      * Returns either the backup file or the offline file, depending on the version number.<p>
211      *
212      * @param cms the CmsObject to use
213      * @param path the path of the file
214      * @param version the backup version
215      * @param tagId the tag id of the file
216      *
217      * @return either the backup file or the offline file, depending on the version number
218      *
219      * @throws CmsException if something goes wrong
220      */

221     protected static CmsFile readFile(CmsObject cms, String JavaDoc path, String JavaDoc version, int tagId) throws CmsException {
222
223         try {
224             cms.getRequestContext().saveSiteRoot();
225             cms.getRequestContext().setSiteRoot("/");
226             if (CmsHistoryList.OFFLINE_PROJECT.equals(version)) {
227                 return cms.readFile(cms.getRequestContext().removeSiteRoot(path), CmsResourceFilter.ALL);
228             } else {
229                 return cms.readBackupFile(cms.getRequestContext().removeSiteRoot(path), tagId);
230             }
231         } finally {
232             cms.getRequestContext().restoreSiteRoot();
233         }
234     }
235
236     /**
237      * Display method for two list dialogs.<p>
238      *
239      * @throws Exception if something goes wrong
240      */

241     public void displayDialog() throws Exception JavaDoc {
242
243         CmsFileInfoDialog fileInfo = new CmsFileInfoDialog(getJsp()) {
244
245             protected String JavaDoc defaultActionHtmlEnd() {
246
247                 return "";
248             }
249         };
250         fileInfo.displayDialog(true);
251         if (fileInfo.isForwarded()) {
252             return;
253         }
254
255         CmsPropertyComparisonList propertyDiff = new CmsPropertyComparisonList(getJsp());
256         CmsAttributeComparisonList attributeDiff = new CmsAttributeComparisonList(getJsp());
257         List lists = new ArrayList JavaDoc();
258         lists.add(attributeDiff);
259         I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(propertyDiff.getResourceType());
260
261         if (resourceType instanceof CmsResourceTypeXmlContent || resourceType instanceof CmsResourceTypeXmlPage) {
262
263             // display attributes, properties and compared elements
264
CmsElementComparisonList contentDiff = new CmsElementComparisonList(getJsp());
265             lists.add(contentDiff);
266             lists.add(propertyDiff);
267             CmsMultiListDialog threeLists = new CmsMultiListDialog(lists);
268             // perform the active list actions
269
threeLists.displayDialog(true);
270             // write the dialog just if no list has been forwarded
271
if (threeLists.isForwarded()) {
272                 return;
273             }
274             fileInfo.writeDialog();
275             threeLists.writeDialog();
276         } else if (resourceType instanceof CmsResourceTypeImage) {
277
278             // display attributes, properties and images
279
lists.add(propertyDiff);
280             CmsMultiListDialog twoLists = new CmsMultiListDialog(lists) {
281
282                 public String JavaDoc defaultActionHtmlEnd() {
283
284                     return "";
285                 }
286             };
287             twoLists.displayDialog(true);
288             if (twoLists.isForwarded()) {
289                 return;
290             }
291             CmsImageComparisonDialog images = new CmsImageComparisonDialog(getJsp());
292             fileInfo.writeDialog();
293             twoLists.writeDialog();
294             // this is very dangerous
295
// it is possible that here a forward is tried, what should not be sence we already wrote to the output stream.
296
// CmsImageComparisonDialog should implement isForwarded, writeDialog and displayDialog(boolean) methods
297
images.displayDialog();
298         } else if (resourceType instanceof CmsResourceTypePointer) {
299
300             lists.add(propertyDiff);
301             CmsMultiListDialog twoLists = new CmsMultiListDialog(lists) {
302
303                 public String JavaDoc defaultActionHtmlEnd() {
304
305                     return "";
306                 }
307             };
308             twoLists.displayDialog(true);
309             if (twoLists.isForwarded()) {
310                 return;
311             }
312             CmsPointerComparisonDialog pointers = new CmsPointerComparisonDialog(getJsp());
313             fileInfo.writeDialog();
314             twoLists.writeDialog();
315             // same as for CmsImageComparisonDialog
316
pointers.displayDialog();
317         } else {
318
319             // display attributes and properties
320
lists.add(propertyDiff);
321             CmsMultiListDialog twoLists = new CmsMultiListDialog(lists);
322             twoLists.displayDialog(true);
323             if (twoLists.isForwarded()) {
324                 return;
325             }
326
327             String JavaDoc path1 = propertyDiff.getParamPath1();
328             String JavaDoc path2 = propertyDiff.getParamPath2();
329
330             byte[] content1 = propertyDiff.getFile1().getContents();
331             byte[] content2 = propertyDiff.getFile2().getContents();
332
333             String JavaDoc originalSource = null;
334             String JavaDoc copySource = null;
335
336             I_CmsTextExtractor textExtractor = null;
337             if (path1.endsWith(".pdf") && path2.endsWith(".pdf")) {
338                 textExtractor = CmsExtractorPdf.getExtractor();
339             } else if (path1.endsWith(".doc") && path2.endsWith(".doc")) {
340                 textExtractor = CmsExtractorMsWord.getExtractor();
341             } else if (path1.endsWith(".xls") && path2.endsWith(".xls")) {
342                 textExtractor = CmsExtractorMsExcel.getExtractor();
343             } else if (path1.endsWith(".rtf") && path2.endsWith(".rtf")) {
344                 textExtractor = CmsExtractorRtf.getExtractor();
345             } else if (path1.endsWith(".ppt") && path2.endsWith(".ppt")) {
346                 textExtractor = CmsExtractorMsPowerPoint.getExtractor();
347             }
348             if (textExtractor != null) {
349                 // extract the content
350
originalSource = textExtractor.extractText(content1).getContent();
351                 copySource = textExtractor.extractText(content2).getContent();
352             } else if (resourceType instanceof CmsResourceTypePlain || resourceType instanceof CmsResourceTypeJsp) {
353                 originalSource = new String JavaDoc(content1);
354                 copySource = new String JavaDoc(content2);
355             }
356             fileInfo.writeDialog();
357             twoLists.writeDialog();
358             if (CmsStringUtil.isNotEmpty(originalSource) && CmsStringUtil.isNotEmpty(copySource)) {
359                 m_differenceDialog.setCopySource(copySource);
360                 m_differenceDialog.setOriginalSource(originalSource);
361                 // same as for CmsImageComparisonDialog
362
m_differenceDialog.displayDialog();
363             }
364         }
365     }
366
367     /**
368      * Displays the difference dialog.<p>
369      * @throws Exception if something goes wrong
370      */

371     public void displayDifferenceDialog() throws Exception JavaDoc {
372
373         m_differenceDialog.displayDialog();
374     }
375
376     /**
377      * Converts an attribute list to a string.<p>
378      *
379      * @param attributes a list of compared attributes to be converted to a string
380      * @return a string respresentation of the attribute list
381      */

382     public String JavaDoc[] getAttributesAsString(List attributes) {
383
384         Iterator JavaDoc i = attributes.iterator();
385         StringBuffer JavaDoc res1 = new StringBuffer JavaDoc(512);
386         StringBuffer JavaDoc res2 = new StringBuffer JavaDoc(512);
387         while (i.hasNext()) {
388             CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
389             res1.append(key(compare.getName())).append(": ").append(compare.getVersion1()).append("\n");
390             res2.append(key(compare.getName())).append(": ").append(compare.getVersion2()).append("\n");
391         }
392         return new String JavaDoc[] {res1.toString(), res2.toString()};
393     }
394
395     /**
396      * Returns the paramCompare.<p>
397      *
398      * @return the paramCompare
399      */

400     public String JavaDoc getParamCompare() {
401
402         return m_paramCompare;
403     }
404
405     /**
406      * Returns the paramElement.<p>
407      *
408      * @return the paramElement
409      */

410     public String JavaDoc getParamElement() {
411
412         return m_paramElement;
413     }
414
415     /**
416      * Returns the paramLocale.<p>
417      *
418      * @return the paramLocale
419      */

420     public String JavaDoc getParamLocale() {
421
422         return m_paramLocale;
423     }
424
425     /**
426      * Returns the paramPath1.<p>
427      *
428      * @return the paramPath1
429      */

430     public String JavaDoc getParamPath1() {
431
432         return m_paramPath1;
433     }
434
435     /**
436      * Returns the paramPath2.<p>
437      *
438      * @return the paramPath2
439      */

440     public String JavaDoc getParamPath2() {
441
442         return m_paramPath2;
443     }
444
445     /**
446      * Returns the paramTagId1.<p>
447      *
448      * @return the paramTagId1
449      */

450     public String JavaDoc getParamTagId1() {
451
452         return m_paramTagId1;
453     }
454
455     /**
456      * Returns the paramTagId2.<p>
457      *
458      * @return the paramTagId2
459      */

460     public String JavaDoc getParamTagId2() {
461
462         return m_paramTagId2;
463     }
464
465     /**
466      * Returns the paramTextmode.<p>
467      *
468      * @return the paramTextmode
469      */

470     public String JavaDoc getParamTextmode() {
471
472         return m_paramTextmode;
473     }
474
475     /**
476      * Returns the paramVersion1.<p>
477      *
478      * @return the paramVersion1
479      */

480     public String JavaDoc getParamVersion1() {
481
482         return m_paramVersion1;
483     }
484
485     /**
486      * Returns the paramVersion2.<p>
487      *
488      * @return the paramVersion2
489      */

490     public String JavaDoc getParamVersion2() {
491
492         return m_paramVersion2;
493     }
494
495     /**
496      * Converts an attribute list to a string.<p>
497      *
498      * @param properties a list of compared properties to be converted to a string
499      * @return a string respresentation of the attribute list
500      */

501     public String JavaDoc[] getPropertiesAsString(List properties) {
502
503         Iterator JavaDoc i = properties.iterator();
504         StringBuffer JavaDoc res1 = new StringBuffer JavaDoc(512);
505         StringBuffer JavaDoc res2 = new StringBuffer JavaDoc(512);
506         while (i.hasNext()) {
507             CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
508             res1.append(compare.getName()).append(": ").append(compare.getVersion1()).append("\n");
509             res2.append(compare.getName()).append(": ").append(compare.getVersion2()).append("\n");
510         }
511         return new String JavaDoc[] {res1.toString(), res2.toString()};
512     }
513
514     /**
515      * Sets the paramCompare.<p>
516      *
517      * @param paramCompare the paramCompare to set
518      */

519     public void setParamCompare(String JavaDoc paramCompare) {
520
521         m_paramCompare = paramCompare;
522     }
523
524     /**
525      * Sets the paramElement.<p>
526      *
527      * @param paramElement the paramElement to set
528      */

529     public void setParamElement(String JavaDoc paramElement) {
530
531         m_paramElement = paramElement;
532     }
533
534     /**
535      * Sets the paramLocale.<p>
536      *
537      * @param paramLocale the paramLocale to set
538      */

539     public void setParamLocale(String JavaDoc paramLocale) {
540
541         m_paramLocale = paramLocale;
542     }
543
544     /**
545      * Sets the paramPath1.<p>
546      *
547      * @param paramPath1 the paramPath1 to set
548      */

549     public void setParamPath1(String JavaDoc paramPath1) {
550
551         m_paramPath1 = paramPath1;
552     }
553
554     /**
555      * Sets the paramPath2.<p>
556      *
557      * @param paramPath2 the paramPath2 to set
558      */

559     public void setParamPath2(String JavaDoc paramPath2) {
560
561         m_paramPath2 = paramPath2;
562     }
563
564     /**
565      * Sets the paramTagId1.<p>
566      *
567      * @param paramTagId1 the paramTagId1 to set
568      */

569     public void setParamTagId1(String JavaDoc paramTagId1) {
570
571         m_paramTagId1 = paramTagId1;
572     }
573
574     /**
575      * Sets the paramTagId2.<p>
576      *
577      * @param paramTagId2 the paramTagId2 to set
578      */

579     public void setParamTagId2(String JavaDoc paramTagId2) {
580
581         m_paramTagId2 = paramTagId2;
582     }
583
584     /**
585      * Sets the paramTextmode.<p>
586      *
587      * @param paramTextmode the paramTextmode to set
588      */

589     public void setParamTextmode(String JavaDoc paramTextmode) {
590
591         m_paramTextmode = paramTextmode;
592     }
593
594     /**
595      * Sets the paramVersion1.<p>
596      *
597      * @param paramVersion1 the paramVersion1 to set
598      */

599     public void setParamVersion1(String JavaDoc paramVersion1) {
600
601         m_paramVersion1 = paramVersion1;
602     }
603
604     /**
605      * Sets the paramVersion2.<p>
606      *
607      * @param paramVersion2 the paramVersion2 to set
608      */

609     public void setParamVersion2(String JavaDoc paramVersion2) {
610
611         m_paramVersion2 = paramVersion2;
612     }
613
614     /**
615      * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
616      */

617     protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest JavaDoc request) {
618
619         super.initWorkplaceRequestValues(settings, request);
620         try {
621             CmsFile file1 = CmsResourceComparisonDialog.readFile(
622                 getCms(),
623                 getParamPath1(),
624                 getParamVersion1(),
625                 Integer.parseInt(getParamTagId1()));
626             CmsFile file2 = CmsResourceComparisonDialog.readFile(
627                 getCms(),
628                 getParamPath2(),
629                 getParamVersion2(),
630                 Integer.parseInt(getParamTagId2()));
631             // if certain element is compared, use html difference dialog
632
if (CmsStringUtil.isNotEmpty(getParamElement())) {
633                 m_differenceDialog = new CmsHtmlDifferenceDialog(getJsp());
634             } else {
635                 m_differenceDialog = new CmsDifferenceDialog(getJsp());
636             }
637             if (CmsResourceComparisonDialog.COMPARE_ATTRIBUTES.equals(getParamCompare())) {
638                 List comparedAttributes = CmsResourceComparison.compareAttributes(getCms(), file1, file2);
639                 String JavaDoc[] attributeStrings = getAttributesAsString(comparedAttributes);
640                 m_differenceDialog.setOriginalSource(attributeStrings[0]);
641                 m_differenceDialog.setCopySource(attributeStrings[1]);
642             } else if (CmsResourceComparisonDialog.COMPARE_PROPERTIES.equals(getParamCompare())) {
643                 List comparedProperties = CmsResourceComparison.compareProperties(getCms(), file1, file2);
644                 String JavaDoc[] propertyStrings = getPropertiesAsString(comparedProperties);
645                 m_differenceDialog.setOriginalSource(propertyStrings[0]);
646                 m_differenceDialog.setCopySource(propertyStrings[1]);
647             } else {
648
649                 setContentAsSource(file1, file2);
650             }
651
652         } catch (CmsException e) {
653
654             LOG.error(e.getMessage(), e);
655         } catch (UnsupportedEncodingException JavaDoc e) {
656
657             LOG.error(e.getMessage(), e);
658         }
659     }
660
661     /**
662      * Returns the content of all elements of an xml document appended.<p>
663      *
664      * @param xmlDoc the xml document to extract the elements from
665      * @return the content of all elements of an xml document appended
666      */

667     private String JavaDoc extractElements(I_CmsXmlDocument xmlDoc) {
668
669         StringBuffer JavaDoc result = new StringBuffer JavaDoc();
670         if (xmlDoc instanceof CmsXmlPage) {
671         List locales = xmlDoc.getLocales();
672         Iterator JavaDoc i = locales.iterator();
673         boolean firstIter = true;
674         while (i.hasNext()) {
675             if (!firstIter) {
676                 result.append("\n\n-----");
677             }
678             Locale JavaDoc locale = (Locale JavaDoc)i.next();
679             result.append("\n\n[").append(locale.toString()).append(']');
680             List elements = xmlDoc.getValues(locale);
681             Iterator JavaDoc j = elements.iterator();
682             while (j.hasNext()) {
683                     I_CmsXmlContentValue value = (I_CmsXmlContentValue)j.next();
684                     result.append("\n\n[");
685                     // output value of name attribute
686
result.append(value.getElement().attribute(0).getValue());
687                     result.append("]\n\n");
688                     try {
689                         I_CmsWidget widget = value.getDocument().getContentDefinition().getContentHandler().getWidget(
690                             value);
691                         result.append(widget.getWidgetStringValue(
692                             getCms(),
693                             new CmsFileInfoDialog(getJsp()),
694                             (I_CmsWidgetParameter)value));
695                     } catch (CmsXmlException e) {
696                         LOG.error(e.getMessage(), e);
697                     }
698                 }
699             firstIter = false;
700         }
701         } else if (xmlDoc instanceof CmsXmlContent) {
702             CmsXmlContentTextExtractor visitor = new CmsXmlContentTextExtractor(result);
703             ((CmsXmlContent)xmlDoc).visitAllValuesWith(visitor);
704             
705         }
706         return result.toString();
707     }
708
709     /**
710      * Extracts the content from the files according to the file type.<p>
711      *
712      * @param file1 the first file to compare
713      * @param file2 the second file to compare
714      *
715      * @throws CmsException if something goes wrong
716      * @throws UnsupportedEncodingException if the encoding of one file is not supported
717      */

718     private void setContentAsSource(CmsFile file1, CmsFile file2) throws CmsException, UnsupportedEncodingException JavaDoc {
719
720         CmsObject cms = getCms();
721         if (CmsStringUtil.isNotEmpty(getParamElement())) {
722
723             I_CmsXmlDocument resource1;
724             I_CmsXmlDocument resource2;
725             if (file1.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
726                 resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
727             } else {
728                 resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
729             }
730             if (file2.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
731                 resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
732             } else {
733                 resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
734             }
735             I_CmsXmlContentValue value1 = resource1.getValue(getParamElement(), new Locale JavaDoc(getParamLocale()));
736             I_CmsXmlContentValue value2 = resource2.getValue(getParamElement(), new Locale JavaDoc(getParamLocale()));
737             if (value1 == null) {
738                 m_differenceDialog.setOriginalSource("");
739             } else {
740                 m_differenceDialog.setOriginalSource(value1.getStringValue(cms));
741             }
742             if (value2 == null) {
743                 m_differenceDialog.setCopySource("");
744             } else {
745                 m_differenceDialog.setCopySource(value2.getStringValue(cms));
746             }
747         } else if (CmsResourceComparisonDialog.COMPARE_ALL_ELEMENTS.equals(getParamCompare())) {
748
749             I_CmsXmlDocument resource1;
750             I_CmsXmlDocument resource2;
751             if (file1.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
752                 resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
753             } else {
754                 resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
755             }
756             if (file2.getTypeId() == CmsResourceTypeXmlPage.getStaticTypeId()) {
757                 resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
758             } else {
759                 resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
760             }
761             m_differenceDialog.setOriginalSource(extractElements(resource1));
762             m_differenceDialog.setCopySource(extractElements(resource2));
763
764         } else {
765             // compare whole plain text file
766
m_differenceDialog.setOriginalSource(new String JavaDoc(file1.getContents(), cms.getRequestContext().getEncoding()));
767             m_differenceDialog.setCopySource(new String JavaDoc(file2.getContents(), cms.getRequestContext().getEncoding()));
768         }
769     }
770 }
771
Popular Tags