1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 import java.io.IOException;
29 import java.io.File;
30 import java.util.zip.*;
31 
32 public class XmlWrapper
33 {
34     public static void main(String args[]) throws IOException
35     {
36         System.out.println("args.length is " + args.length);
37         if (args.length < 2) {
38             System.out.println("Usage: java XmlWrapper [<zipfile1> <zipfile2>].");
39             //return;
40 		 	System.exit(-1);
41 
42         }
43 
44         XmlWrapper w = new XmlWrapper();
45         File currdirfp = null;
46         try {
47          currdirfp = new File(".");
48         } catch (Exception fx) {
49          System.out.println("Could not get File instance for current directory \n");
50          //return;
51 		 System.exit(-1);
52         }
53 
54         File f1 = null;
55         File f2 = null;
56         String fname1,fname2;
57         try {
58          f1 = File.createTempFile("xmlcomp", ".tmp", currdirfp);
59          f2 = File.createTempFile("xmlcomp", ".tmp", currdirfp);
60         } catch (Exception tx) {
61          System.out.println("Could not create TempFile ");
62          System.out.println("Exception: " + tx.toString());
63          //return;
64 		 System.exit(-1);
65         }
66 
67         fname1 = f1.getAbsolutePath();
68         fname2 = f2.getAbsolutePath();
69 
70         // get content.xml file from zip file and copy it to temporary
71         // filename
72         XmlZipExtract xw1 = new XmlZipExtract(args[0]);
73         try {
74           xw1.getContentXml(fname1);
75         } catch (ZipException e) {
76          System.out.println("Exception: file is not a ZIP file: " + args[0]);
77          f1.delete();
78          f2.delete();
79          //return;
80 		 System.exit(-1);
81         } catch (Exception e) {
82          System.out.println("Exception: Could not extract XML from " + args[0]);
83          System.out.println("Exception: " + e.toString());
84          f1.delete();
85          f2.delete();
86          //return;
87 		 System.exit(-1);
88         }
89 
90         // get content.xml file from zip file and copy it to temporary
91         // filename
92         XmlZipExtract xw2 = new XmlZipExtract(args[1]);
93         try {
94          xw2.getContentXml(fname2);
95         } catch (ZipException e) {
96          System.out.println("Exception: file is not a ZIP file: " + args[0]);
97          f1.delete();
98          f2.delete();
99          //return;
100 		 System.exit(-1);
101         } catch (Exception ex) {
102          System.out.println(ex.getMessage());
103          System.out.println("Exception: Could not extract XML from " + args[1]);
104          System.out.println("Exception: " + ex.toString());
105          f1.delete();
106          f2.delete();
107          //return;
108 		 System.exit(-1);
109         }
110 
111         boolean same = false;
112 
113         try
114         {
115            XmlDiff xmldiff = new XmlDiff();
116 
117            if (args.length == 2) {
118                same = xmldiff.diff(fname1, fname2);
119            } else {
120                same = xmldiff.diff();
121            }
122         }
123         catch (Exception ex)
124         {
125          System.out.println("XmlDiff failed");
126          System.out.println("Exception: " + ex.toString());
127          f1.delete();
128          f2.delete();
129          //return;
130 		 System.exit(-1);
131         }
132 
133         System.out.println("Diff result: " + same);
134         if (same)
135         {
136           System.out.println("XMLDIFFRESULT:PASSED");
137         } else {
138           System.out.println("XMLDIFFRESULT:FAILED");
139         }
140 
141         f1.delete();
142         f2.delete();
143 
144 		if (same)
145 		{
146 			System.exit(2);
147 		}
148 		else
149 		{
150 			System.exit(3);
151 		}
152     }
153 }
154