Source Code Cross Referenced for CmsResourceComparisonDialog.java in  » Content-Management-System » opencms » org » opencms » workplace » comparison » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Content Management System » opencms » org.opencms.workplace.comparison 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


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