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