001/*
002 * This library is part of OpenCms -
003 * the Open Source Content Management System
004 *
005 * Copyright (c) Alkacon Software GmbH & Co. KG (http://www.alkacon.com)
006 *
007 * This library is free software; you can redistribute it and/or
008 * modify it under the terms of the GNU Lesser General Public
009 * License as published by the Free Software Foundation; either
010 * version 2.1 of the License, or (at your option) any later version.
011 *
012 * This library is distributed in the hope that it will be useful,
013 * but WITHOUT ANY WARRANTY; without even the implied warranty of
014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015 * Lesser General Public License for more details.
016 *
017 * For further information about Alkacon Software GmbH & Co. KG, please see the
018 * company website: http://www.alkacon.com
019 *
020 * For further information about OpenCms, please see the
021 * project website: http://www.opencms.org
022 *
023 * You should have received a copy of the GNU Lesser General Public
024 * License along with this library; if not, write to the Free Software
025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
026 */
027
028package org.opencms.workplace.comparison;
029
030import org.opencms.ade.contenteditor.CmsWidgetUtil;
031import org.opencms.file.CmsFile;
032import org.opencms.file.CmsObject;
033import org.opencms.file.CmsProject;
034import org.opencms.file.CmsResource;
035import org.opencms.file.CmsResourceFilter;
036import org.opencms.file.history.CmsHistoryFile;
037import org.opencms.file.history.CmsHistoryResourceHandler;
038import org.opencms.file.types.CmsResourceTypeImage;
039import org.opencms.file.types.CmsResourceTypeJsp;
040import org.opencms.file.types.CmsResourceTypePlain;
041import org.opencms.file.types.CmsResourceTypePointer;
042import org.opencms.file.types.CmsResourceTypeXmlContent;
043import org.opencms.file.types.CmsResourceTypeXmlPage;
044import org.opencms.file.types.I_CmsResourceType;
045import org.opencms.i18n.CmsLocaleManager;
046import org.opencms.jsp.CmsJspActionElement;
047import org.opencms.main.CmsException;
048import org.opencms.main.CmsLog;
049import org.opencms.main.OpenCms;
050import org.opencms.search.extractors.CmsExtractorMsOfficeOLE2;
051import org.opencms.search.extractors.CmsExtractorPdf;
052import org.opencms.search.extractors.CmsExtractorRtf;
053import org.opencms.search.extractors.I_CmsTextExtractor;
054import org.opencms.util.CmsStringUtil;
055import org.opencms.util.CmsUUID;
056import org.opencms.widgets.I_CmsWidget;
057import org.opencms.widgets.I_CmsWidgetParameter;
058import org.opencms.workplace.CmsDialog;
059import org.opencms.workplace.CmsWorkplaceSettings;
060import org.opencms.workplace.commons.CmsResourceInfoDialog;
061import org.opencms.workplace.list.A_CmsListDialog;
062import org.opencms.workplace.list.CmsMultiListDialog;
063import org.opencms.xml.I_CmsXmlDocument;
064import org.opencms.xml.content.CmsXmlContent;
065import org.opencms.xml.content.CmsXmlContentFactory;
066import org.opencms.xml.content.I_CmsXmlContentValueVisitor;
067import org.opencms.xml.page.CmsXmlPage;
068import org.opencms.xml.page.CmsXmlPageFactory;
069import org.opencms.xml.types.I_CmsXmlContentValue;
070
071import java.io.UnsupportedEncodingException;
072import java.util.ArrayList;
073import java.util.Iterator;
074import java.util.List;
075import java.util.Locale;
076
077import javax.servlet.http.HttpServletRequest;
078import javax.servlet.http.HttpServletResponse;
079import javax.servlet.jsp.PageContext;
080
081import org.apache.commons.logging.Log;
082
083/**
084 * Helper class for managing three lists on the same dialog.<p>
085 *
086 * @since 6.0.0
087 */
088public class CmsResourceComparisonDialog extends CmsDialog {
089
090    /**
091     * Visitor that collects the xpath expressions of xml contents.<p>
092     */
093    class CmsXmlContentTextExtractor implements I_CmsXmlContentValueVisitor {
094
095        /** The StringBuffer to write the extracted text to. */
096        private StringBuffer m_buffer;
097
098        /** The locales of the xml content. */
099        private List<String> m_locales;
100
101        /**
102         * Creates a new CmsXmlContentTextExtractor.<p>
103         *
104         * @param stringBuffer the StringBuffer to append the element text to
105         */
106        CmsXmlContentTextExtractor(StringBuffer stringBuffer) {
107
108            m_buffer = stringBuffer;
109            m_locales = new ArrayList<String>();
110        }
111
112        /**
113         *
114         * @see org.opencms.xml.content.I_CmsXmlContentValueVisitor#visit(org.opencms.xml.types.I_CmsXmlContentValue)
115         */
116        public void visit(I_CmsXmlContentValue value) {
117
118            // only add simple types
119            if (value.isSimpleType()) {
120                String locale = value.getLocale().toString();
121                if (!m_locales.contains(locale)) {
122                    m_buffer.append("\n\n[").append(locale).append(']');
123                    m_locales.add(locale);
124                }
125                m_buffer.append("\n\n[").append(value.getPath()).append("]\n\n");
126
127                I_CmsWidget widget = CmsWidgetUtil.collectWidgetInfo(null, value).getWidget();
128                m_buffer.append(
129                    widget.getWidgetStringValue(
130                        getCms(),
131                        new CmsResourceInfoDialog(getJsp()),
132                        (I_CmsWidgetParameter)value));
133
134            }
135        }
136    }
137
138    /** Constant indicating that all elements are compared.<p> */
139    public static final String COMPARE_ALL_ELEMENTS = "allelements";
140
141    /** Constant indicating that the attributes are compared.<p> */
142    public static final String COMPARE_ATTRIBUTES = "attributes";
143
144    /** Constant indicating that the properties are compared.<p> */
145    public static final String COMPARE_PROPERTIES = "properties";
146
147    /** The log object for this class. */
148    static final Log LOG = CmsLog.getLog(CmsResourceComparisonDialog.class);
149
150    /** The difference dialog. */
151    private CmsDifferenceDialog m_differenceDialog;
152
153    /** Parameter value indicating whether to compare properties, attributes or elements. */
154    private String m_paramCompare;
155
156    /** Parameter value for the element name. */
157    private String m_paramElement;
158
159    /** Parameter value for the structure id of the first file. */
160    private String m_paramId1;
161
162    /** Parameter value for the structure id of the second file. */
163    private String m_paramId2;
164
165    /** Parameter value for the locale. */
166    private String m_paramLocale;
167
168    /** Parameter value for the text mode. */
169    private String m_paramTextmode;
170
171    /** Parameter value for the version of the first file. */
172    private String m_paramVersion1;
173
174    /** Parameter value for the version of the second file. */
175    private String m_paramVersion2;
176
177    /**
178     * Public constructor with JSP action element.<p>
179     *
180     * @param jsp an initialized JSP action element
181     */
182    public CmsResourceComparisonDialog(CmsJspActionElement jsp) {
183
184        super(jsp);
185    }
186
187    /**
188     * Public constructor with JSP variables.<p>
189     *
190     * @param context the JSP page context
191     * @param req the JSP request
192     * @param res the JSP response
193     */
194    public CmsResourceComparisonDialog(PageContext context, HttpServletRequest req, HttpServletResponse res) {
195
196        this(new CmsJspActionElement(context, req, res));
197    }
198
199    /**
200     * Returns either the historical file or the offline file, depending on the version number.<p>
201     *
202     * @param cms the CmsObject to use
203     * @param structureId the structure id of the file
204     * @param version the historical version number
205     *
206     * @return either the historical file or the offline file, depending on the version number
207     *
208     * @throws CmsException if something goes wrong
209     */
210    public static CmsFile readFile(CmsObject cms, CmsUUID structureId, String version) throws CmsException {
211
212        if (Integer.parseInt(version) == CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION) {
213            // offline
214            CmsResource resource = cms.readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION);
215            return cms.readFile(resource);
216        } else {
217            int ver = Integer.parseInt(version);
218            if (ver < 0) {
219                // online
220                CmsProject project = cms.getRequestContext().getCurrentProject();
221                try {
222                    cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
223                    CmsResource resource = cms.readResource(structureId, CmsResourceFilter.IGNORE_EXPIRATION);
224                    return cms.readFile(resource);
225                } finally {
226                    cms.getRequestContext().setCurrentProject(project);
227                }
228            }
229            // backup
230            return cms.readFile((CmsHistoryFile)cms.readResource(structureId, ver));
231        }
232    }
233
234    /**
235     * Returns either the historical resource or the offline resource, depending on the version number.<p>
236     *
237     * @param cms the CmsObject to use
238     * @param id the structure id of the resource
239     * @param version the historical version number
240     *
241     * @return either the historical resource or the offline resource, depending on the version number
242     *
243     * @throws CmsException if something goes wrong
244     */
245    protected static CmsResource readResource(CmsObject cms, CmsUUID id, String version) throws CmsException {
246
247        if (Integer.parseInt(version) == CmsHistoryResourceHandler.PROJECT_OFFLINE_VERSION) {
248            return cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION);
249        } else {
250            int ver = Integer.parseInt(version);
251            if (ver < 0) {
252                CmsProject project = cms.getRequestContext().getCurrentProject();
253                try {
254                    cms.getRequestContext().setCurrentProject(cms.readProject(CmsProject.ONLINE_PROJECT_ID));
255                    return cms.readResource(id, CmsResourceFilter.IGNORE_EXPIRATION);
256                } finally {
257                    cms.getRequestContext().setCurrentProject(project);
258                }
259            }
260            return (CmsResource)cms.readResource(id, ver);
261        }
262    }
263
264    /**
265     * Display method for two list dialogs.<p>
266     *
267     * @throws Exception if something goes wrong
268     */
269    public void displayDialog() throws Exception {
270
271        CmsResourceInfoDialog fileInfo = new CmsResourceInfoDialog(getJsp()) {
272
273            @Override
274            protected String defaultActionHtmlEnd() {
275
276                return "";
277            }
278        };
279        fileInfo.displayDialog(true);
280        if (fileInfo.isForwarded()) {
281            return;
282        }
283
284        CmsPropertyComparisonList propertyDiff = new CmsPropertyComparisonList(getJsp());
285        CmsAttributeComparisonList attributeDiff = new CmsAttributeComparisonList(getJsp());
286        List<A_CmsListDialog> lists = new ArrayList<A_CmsListDialog>();
287        lists.add(attributeDiff);
288        I_CmsResourceType resourceType = OpenCms.getResourceManager().getResourceType(propertyDiff.getResourceType());
289
290        if ((resourceType instanceof CmsResourceTypeXmlContent) || (resourceType instanceof CmsResourceTypeXmlPage)) {
291
292            // display attributes, properties and compared elements
293            CmsElementComparisonList contentDiff = new CmsElementComparisonList(getJsp());
294
295            // get the content of the resource1 and resource2
296            byte[] content1 = readFile(
297                getCms(),
298                propertyDiff.getResource1().getStructureId(),
299                getParamVersion1()).getContents();
300            byte[] content2 = readFile(
301                getCms(),
302                propertyDiff.getResource2().getStructureId(),
303                getParamVersion2()).getContents();
304
305            // display the content comparison only if both files has contents
306            if ((content1.length > 0) && (content2.length > 0)) {
307                lists.add(contentDiff);
308            }
309            lists.add(propertyDiff);
310            CmsMultiListDialog threeLists = new CmsMultiListDialog(lists);
311            // perform the active list actions
312            threeLists.displayDialog(true);
313            // write the dialog just if no list has been forwarded
314            if (threeLists.isForwarded()) {
315                return;
316            }
317            fileInfo.writeDialog();
318            threeLists.writeDialog();
319        } else if (resourceType instanceof CmsResourceTypeImage) {
320
321            // display attributes, properties and images
322            lists.add(propertyDiff);
323            CmsMultiListDialog twoLists = new CmsMultiListDialog(lists) {
324
325                /**
326                 * @see org.opencms.workplace.list.CmsMultiListDialog#defaultActionHtmlEnd()
327                 */
328                @Override
329                public String defaultActionHtmlEnd() {
330
331                    return "";
332                }
333            };
334            twoLists.displayDialog(true);
335            if (twoLists.isForwarded()) {
336                return;
337            }
338            CmsImageComparisonDialog images = new CmsImageComparisonDialog(getJsp());
339            fileInfo.writeDialog();
340            twoLists.writeDialog();
341            // this is very dangerous
342            // it is possible that here a forward is tried, what should not be sence we already wrote to the output stream.
343            // CmsImageComparisonDialog should implement isForwarded, writeDialog and displayDialog(boolean) methods
344            images.displayDialog();
345        } else if (resourceType instanceof CmsResourceTypePointer) {
346
347            lists.add(propertyDiff);
348            CmsMultiListDialog twoLists = new CmsMultiListDialog(lists) {
349
350                /**
351                 * @see org.opencms.workplace.list.CmsMultiListDialog#defaultActionHtmlEnd()
352                 */
353                @Override
354                public String defaultActionHtmlEnd() {
355
356                    return "";
357                }
358            };
359            twoLists.displayDialog(true);
360            if (twoLists.isForwarded()) {
361                return;
362            }
363            CmsPointerComparisonDialog pointers = new CmsPointerComparisonDialog(getJsp());
364            fileInfo.writeDialog();
365            twoLists.writeDialog();
366            // same as for CmsImageComparisonDialog
367            pointers.displayDialog();
368        } else if (propertyDiff.getResource1().isFile()) {
369
370            // display attributes and properties
371            lists.add(propertyDiff);
372            CmsMultiListDialog twoLists = new CmsMultiListDialog(lists);
373            twoLists.displayDialog(true);
374            if (twoLists.isForwarded()) {
375                return;
376            }
377
378            CmsResource resource1 = propertyDiff.getResource1();
379            CmsResource resource2 = propertyDiff.getResource2();
380            String path1 = resource1.getRootPath();
381            String path2 = resource2.getRootPath();
382
383            byte[] content1 = readFile(getCms(), resource1.getStructureId(), getParamVersion1()).getContents();
384            byte[] content2 = readFile(getCms(), resource2.getStructureId(), getParamVersion2()).getContents();
385
386            String originalSource = null;
387            String copySource = null;
388
389            I_CmsTextExtractor textExtractor = null;
390            // only if both files have contents
391            if ((content1.length > 0) && (content2.length > 0)) {
392                if (path1.endsWith(".pdf") && path2.endsWith(".pdf")) {
393                    textExtractor = CmsExtractorPdf.getExtractor();
394                } else if (path1.endsWith(".doc") && path2.endsWith(".doc")) {
395                    textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
396                } else if (path1.endsWith(".xls") && path2.endsWith(".xls")) {
397                    textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
398                } else if (path1.endsWith(".rtf") && path2.endsWith(".rtf")) {
399                    textExtractor = CmsExtractorRtf.getExtractor();
400                } else if (path1.endsWith(".ppt") && path2.endsWith(".ppt")) {
401                    textExtractor = CmsExtractorMsOfficeOLE2.getExtractor();
402                }
403            }
404            if (textExtractor != null) {
405                try {
406                    // extract the content
407                    originalSource = textExtractor.extractText(content1).getContent();
408                    copySource = textExtractor.extractText(content2).getContent();
409                } catch (Exception e) {
410                    // something goes wrong on extracting content
411                    // set the content to null, so the content dialog will not be shown
412                    originalSource = null;
413                    copySource = null;
414                    LOG.error(e.getMessage(), e);
415                }
416            } else if ((resourceType instanceof CmsResourceTypePlain) || (resourceType instanceof CmsResourceTypeJsp)) {
417                originalSource = new String(content1);
418                copySource = new String(content2);
419            }
420            fileInfo.writeDialog();
421            twoLists.writeDialog();
422            if (CmsStringUtil.isNotEmpty(originalSource) && CmsStringUtil.isNotEmpty(copySource)) {
423                m_differenceDialog.setCopySource(copySource);
424                m_differenceDialog.setOriginalSource(originalSource);
425                // same as for CmsImageComparisonDialog
426                m_differenceDialog.displayDialog();
427            }
428        } else {
429            // display attributes and properties
430            lists.add(propertyDiff);
431            CmsMultiListDialog twoLists = new CmsMultiListDialog(lists);
432            twoLists.displayDialog(true);
433            if (twoLists.isForwarded()) {
434                return;
435            }
436
437            fileInfo.writeDialog();
438            twoLists.writeDialog();
439        }
440    }
441
442    /**
443     * Displays the difference dialog.<p>
444     * @throws Exception if something goes wrong
445     */
446    public void displayDifferenceDialog() throws Exception {
447
448        m_differenceDialog.displayDialog();
449    }
450
451    /**
452     * Converts an attribute list to a string.<p>
453     *
454     * @param attributes a list of compared attributes to be converted to a string
455     * @return a string respresentation of the attribute list
456     */
457    public String[] getAttributesAsString(List<?> attributes) {
458
459        Iterator<?> i = attributes.iterator();
460        StringBuffer res1 = new StringBuffer(512);
461        StringBuffer res2 = new StringBuffer(512);
462        while (i.hasNext()) {
463            CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
464            res1.append(key(compare.getName())).append(": ").append(compare.getVersion1()).append("\n");
465            res2.append(key(compare.getName())).append(": ").append(compare.getVersion2()).append("\n");
466        }
467        return new String[] {res1.toString(), res2.toString()};
468    }
469
470    /**
471     * Returns the paramCompare.<p>
472     *
473     * @return the paramCompare
474     */
475    public String getParamCompare() {
476
477        return m_paramCompare;
478    }
479
480    /**
481     * Returns the paramElement.<p>
482     *
483     * @return the paramElement
484     */
485    public String getParamElement() {
486
487        return m_paramElement;
488    }
489
490    /**
491     * Returns the paramId1.<p>
492     *
493     * @return the paramId1
494     */
495    public String getParamId1() {
496
497        return m_paramId1;
498    }
499
500    /**
501     * Returns the paramId2.<p>
502     *
503     * @return the paramId2
504     */
505    public String getParamId2() {
506
507        return m_paramId2;
508    }
509
510    /**
511     * Returns the paramLocale.<p>
512     *
513     * @return the paramLocale
514     */
515    public String getParamLocale() {
516
517        return m_paramLocale;
518    }
519
520    /**
521     * Returns the paramTextmode.<p>
522     *
523     * @return the paramTextmode
524     */
525    public String getParamTextmode() {
526
527        return m_paramTextmode;
528    }
529
530    /**
531     * Returns the paramVersion1.<p>
532     *
533     * @return the paramVersion1
534     */
535    public String getParamVersion1() {
536
537        return m_paramVersion1;
538    }
539
540    /**
541     * Returns the paramVersion2.<p>
542     *
543     * @return the paramVersion2
544     */
545    public String getParamVersion2() {
546
547        return m_paramVersion2;
548    }
549
550    /**
551     * Converts an attribute list to a string.<p>
552     *
553     * @param properties a list of compared properties to be converted to a string
554     * @return a string respresentation of the attribute list
555     */
556    public String[] getPropertiesAsString(List<?> properties) {
557
558        Iterator<?> i = properties.iterator();
559        StringBuffer res1 = new StringBuffer(512);
560        StringBuffer res2 = new StringBuffer(512);
561        while (i.hasNext()) {
562            CmsAttributeComparison compare = (CmsAttributeComparison)i.next();
563            res1.append(compare.getName()).append(": ").append(compare.getVersion1()).append("\n");
564            res2.append(compare.getName()).append(": ").append(compare.getVersion2()).append("\n");
565        }
566        return new String[] {res1.toString(), res2.toString()};
567    }
568
569    /**
570     * Sets the paramCompare.<p>
571     *
572     * @param paramCompare the paramCompare to set
573     */
574    public void setParamCompare(String paramCompare) {
575
576        m_paramCompare = paramCompare;
577    }
578
579    /**
580     * Sets the paramElement.<p>
581     *
582     * @param paramElement the paramElement to set
583     */
584    public void setParamElement(String paramElement) {
585
586        m_paramElement = paramElement;
587    }
588
589    /**
590     * Sets the paramId1.<p>
591     *
592     * @param paramId1 the paramId1 to set
593     */
594    public void setParamId1(String paramId1) {
595
596        m_paramId1 = paramId1;
597    }
598
599    /**
600     * Sets the paramId2.<p>
601     *
602     * @param paramId2 the paramId2 to set
603     */
604    public void setParamId2(String paramId2) {
605
606        m_paramId2 = paramId2;
607    }
608
609    /**
610     * Sets the paramLocale.<p>
611     *
612     * @param paramLocale the paramLocale to set
613     */
614    public void setParamLocale(String paramLocale) {
615
616        m_paramLocale = paramLocale;
617    }
618
619    /**
620     * Sets the paramTextmode.<p>
621     *
622     * @param paramTextmode the paramTextmode to set
623     */
624    public void setParamTextmode(String paramTextmode) {
625
626        m_paramTextmode = paramTextmode;
627    }
628
629    /**
630     * Sets the paramVersion1.<p>
631     *
632     * @param paramVersion1 the paramVersion1 to set
633     */
634    public void setParamVersion1(String paramVersion1) {
635
636        m_paramVersion1 = paramVersion1;
637    }
638
639    /**
640     * Sets the paramVersion2.<p>
641     *
642     * @param paramVersion2 the paramVersion2 to set
643     */
644    public void setParamVersion2(String paramVersion2) {
645
646        m_paramVersion2 = paramVersion2;
647    }
648
649    /**
650     * @see org.opencms.workplace.CmsWorkplace#initWorkplaceRequestValues(org.opencms.workplace.CmsWorkplaceSettings, javax.servlet.http.HttpServletRequest)
651     */
652    @Override
653    protected void initWorkplaceRequestValues(CmsWorkplaceSettings settings, HttpServletRequest request) {
654
655        super.initWorkplaceRequestValues(settings, request);
656        try {
657            CmsResource resource1 = CmsResourceComparisonDialog.readResource(
658                getCms(),
659                new CmsUUID(getParamId1()),
660                getParamVersion1());
661            CmsResource resource2 = CmsResourceComparisonDialog.readResource(
662                getCms(),
663                new CmsUUID(getParamId2()),
664                getParamVersion2());
665            // if certain element is compared, use html difference dialog
666            if (CmsStringUtil.isNotEmpty(getParamElement())) {
667                m_differenceDialog = new CmsHtmlDifferenceDialog(getJsp());
668            } else {
669                m_differenceDialog = new CmsDifferenceDialog(getJsp());
670            }
671            if (CmsResourceComparisonDialog.COMPARE_ATTRIBUTES.equals(getParamCompare())) {
672                List<?> comparedAttributes = CmsResourceComparison.compareAttributes(getCms(), resource1, resource2);
673                String[] attributeStrings = getAttributesAsString(comparedAttributes);
674                m_differenceDialog.setOriginalSource(attributeStrings[0]);
675                m_differenceDialog.setCopySource(attributeStrings[1]);
676            } else if (CmsResourceComparisonDialog.COMPARE_PROPERTIES.equals(getParamCompare())) {
677                List<?> comparedProperties = CmsResourceComparison.compareProperties(
678                    getCms(),
679                    resource1,
680                    getParamVersion1(),
681                    resource2,
682                    getParamVersion2());
683                String[] propertyStrings = getPropertiesAsString(comparedProperties);
684                m_differenceDialog.setOriginalSource(propertyStrings[0]);
685                m_differenceDialog.setCopySource(propertyStrings[1]);
686            } else if (resource1.isFile()) {
687                CmsFile file1 = readFile(getCms(), new CmsUUID(getParamId1()), getParamVersion1());
688                CmsFile file2 = readFile(getCms(), new CmsUUID(getParamId2()), getParamVersion2());
689                setContentAsSource(file1, file2);
690            }
691        } catch (CmsException e) {
692            LOG.error(e.getMessage(), e);
693        } catch (UnsupportedEncodingException e) {
694            LOG.error(e.getMessage(), e);
695        }
696    }
697
698    /**
699     * Returns the content of all elements of an xml document appended.<p>
700     *
701     * @param xmlDoc the xml document to extract the elements from
702     * @return the content of all elements of an xml document appended
703     */
704    @Deprecated
705    private String extractElements(I_CmsXmlDocument xmlDoc) {
706
707        StringBuffer result = new StringBuffer();
708        if (xmlDoc instanceof CmsXmlPage) {
709            List<?> locales = xmlDoc.getLocales();
710            Iterator<?> i = locales.iterator();
711            boolean firstIter = true;
712            while (i.hasNext()) {
713                if (!firstIter) {
714                    result.append("\n\n-----");
715                }
716                Locale locale = (Locale)i.next();
717                result.append("\n\n[").append(locale.toString()).append(']');
718                List<?> elements = xmlDoc.getValues(locale);
719                Iterator<?> j = elements.iterator();
720                while (j.hasNext()) {
721                    I_CmsXmlContentValue value = (I_CmsXmlContentValue)j.next();
722                    result.append("\n\n[");
723                    // output value of name attribute
724                    result.append(value.getElement().attribute(0).getValue());
725                    result.append("]\n\n");
726
727                    I_CmsWidget widget = CmsWidgetUtil.collectWidgetInfo(null, value).getWidget();
728                    result.append(
729                        widget.getWidgetStringValue(
730                            getCms(),
731                            new CmsResourceInfoDialog(getJsp()),
732                            (I_CmsWidgetParameter)value));
733
734                }
735                firstIter = false;
736            }
737        } else if (xmlDoc instanceof CmsXmlContent) {
738            CmsXmlContentTextExtractor visitor = new CmsXmlContentTextExtractor(result);
739            ((CmsXmlContent)xmlDoc).visitAllValuesWith(visitor);
740
741        }
742        return result.toString();
743    }
744
745    /**
746     * Extracts the content from the files according to the file type.<p>
747     *
748     * @param file1 the first file to compare
749     * @param file2 the second file to compare
750     *
751     * @throws CmsException if something goes wrong
752     * @throws UnsupportedEncodingException if the encoding of one file is not supported
753     */
754    private void setContentAsSource(CmsFile file1, CmsFile file2) throws CmsException, UnsupportedEncodingException {
755
756        CmsObject cms = getCms();
757        if (CmsStringUtil.isNotEmpty(getParamElement())) {
758            I_CmsXmlDocument resource1;
759            I_CmsXmlDocument resource2;
760            if (CmsResourceTypeXmlPage.isXmlPage(file1)) {
761                resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
762            } else {
763                resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
764            }
765            if (CmsResourceTypeXmlPage.isXmlPage(file2)) {
766                resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
767            } else {
768                resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
769            }
770            I_CmsXmlContentValue value1 = resource1.getValue(
771                getParamElement(),
772                CmsLocaleManager.getLocale(getParamLocale()));
773            I_CmsXmlContentValue value2 = resource2.getValue(
774                getParamElement(),
775                CmsLocaleManager.getLocale(getParamLocale()));
776            if (value1 == null) {
777                m_differenceDialog.setOriginalSource("");
778            } else {
779                m_differenceDialog.setOriginalSource(value1.getStringValue(cms));
780            }
781            if (value2 == null) {
782                m_differenceDialog.setCopySource("");
783            } else {
784                m_differenceDialog.setCopySource(value2.getStringValue(cms));
785            }
786        } else if (CmsResourceComparisonDialog.COMPARE_ALL_ELEMENTS.equals(getParamCompare())) {
787            I_CmsXmlDocument resource1;
788            I_CmsXmlDocument resource2;
789            if (CmsResourceTypeXmlPage.isXmlPage(file1)) {
790                resource1 = CmsXmlPageFactory.unmarshal(cms, file1);
791            } else {
792                resource1 = CmsXmlContentFactory.unmarshal(cms, file1);
793            }
794            if (CmsResourceTypeXmlPage.isXmlPage(file2)) {
795                resource2 = CmsXmlPageFactory.unmarshal(cms, file2);
796            } else {
797                resource2 = CmsXmlContentFactory.unmarshal(cms, file2);
798            }
799            m_differenceDialog.setOriginalSource(extractElements(resource1));
800            m_differenceDialog.setCopySource(extractElements(resource2));
801
802        } else {
803            // compare whole plain text file
804            m_differenceDialog.setOriginalSource(
805                new String(file1.getContents(), cms.getRequestContext().getEncoding()));
806            m_differenceDialog.setCopySource(new String(file2.getContents(), cms.getRequestContext().getEncoding()));
807        }
808    }
809}